Kaydet (Commit) 3179055d authored tarafından Ricardo Montania's avatar Ricardo Montania Kaydeden (comit) Markus Mohrhard

String Cleanup and news OUString methods/constructors

Change-Id: Ia6142020330d0e12650fdc519b66f00e607eac42
Reviewed-on: https://gerrit.libreoffice.org/1491Reviewed-by: 's avatarMarkus Mohrhard <markus.mohrhard@googlemail.com>
Tested-by: 's avatarMarkus Mohrhard <markus.mohrhard@googlemail.com>
üst c4f444dc
...@@ -67,8 +67,6 @@ using namespace com::sun::star::system; ...@@ -67,8 +67,6 @@ using namespace com::sun::star::system;
using namespace com::sun::star::xml; using namespace com::sun::star::xml;
using namespace com::sun::star::xml::sax; using namespace com::sun::star::xml::sax;
using ::rtl::OUString;
class GlobalEventListenerImpl : public ::cppu::WeakImplHelper1< com::sun::star::document::XEventListener > class GlobalEventListenerImpl : public ::cppu::WeakImplHelper1< com::sun::star::document::XEventListener >
{ {
public: public:
...@@ -91,8 +89,8 @@ GlobalEventListenerImpl::GlobalEventListenerImpl( XMLFilterTestDialog* pDialog ) ...@@ -91,8 +89,8 @@ GlobalEventListenerImpl::GlobalEventListenerImpl( XMLFilterTestDialog* pDialog )
void SAL_CALL GlobalEventListenerImpl::notifyEvent( const com::sun::star::document::EventObject& Event ) throw (RuntimeException) void SAL_CALL GlobalEventListenerImpl::notifyEvent( const com::sun::star::document::EventObject& Event ) throw (RuntimeException)
{ {
::SolarMutexGuard aGuard; ::SolarMutexGuard aGuard;
if( (Event.EventName.compareToAscii( RTL_CONSTASCII_STRINGPARAM("OnFocus") ) == 0) || if( (Event.EventName.compareToAscii( "OnFocus" ) == 0) ||
(Event.EventName.compareToAscii( RTL_CONSTASCII_STRINGPARAM("OnUnload") ) == 0) ) (Event.EventName.compareToAscii( "OnUnload" ) == 0) )
{ {
Reference< XComponent > xComp( Event.Source, UNO_QUERY ); Reference< XComponent > xComp( Event.Source, UNO_QUERY );
mpDialog->updateCurrentDocumentButtonState( &xComp ); mpDialog->updateCurrentDocumentButtonState( &xComp );
...@@ -117,7 +115,7 @@ static bool checkComponent( Reference< XComponent >& rxComponent, const OUString ...@@ -117,7 +115,7 @@ static bool checkComponent( Reference< XComponent >& rxComponent, const OUString
if ( rServiceName == "com.sun.star.drawing.DrawingDocument" ) if ( rServiceName == "com.sun.star.drawing.DrawingDocument" )
{ {
// so if we want a draw we need to check if its not an impress // so if we want a draw we need to check if its not an impress
if( !xInfo->supportsService( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.PresentationDocument") ) ) ) if( !xInfo->supportsService( "com.sun.star.presentation.PresentationDocument" ) )
return true; return true;
} }
else else
...@@ -275,11 +273,10 @@ void XMLFilterTestDialog::initDialog() ...@@ -275,11 +273,10 @@ void XMLFilterTestDialog::initDialog()
if( NULL == m_pFilterInfo ) if( NULL == m_pFilterInfo )
return; return;
String aTitle( m_sDialogTitle ); OUString aTitle( m_sDialogTitle );
aTitle.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM("%s") ), m_pFilterInfo->maFilterName ); aTitle = aTitle.replaceAll( "%s", m_pFilterInfo->maFilterName );
SetText( aTitle ); SetText( aTitle );
String aEmpty;
bool bImport = (m_pFilterInfo->maFlags & 1) == 1; bool bImport = (m_pFilterInfo->maFlags & 1) == 1;
bool bExport = (m_pFilterInfo->maFlags & 2) == 2; bool bExport = (m_pFilterInfo->maFlags & 2) == 2;
...@@ -310,8 +307,8 @@ void XMLFilterTestDialog::onExportBrowse() ...@@ -310,8 +307,8 @@ void XMLFilterTestDialog::onExportBrowse()
com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
0 ); 0 );
Reference< XNameAccess > xFilterContainer( mxMSF->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.FilterFactory" )) ), UNO_QUERY ); Reference< XNameAccess > xFilterContainer( mxMSF->createInstance( "com.sun.star.document.FilterFactory" ), UNO_QUERY );
Reference< XNameAccess > xTypeDetection( mxMSF->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.TypeDetection" )) ), UNO_QUERY ); Reference< XNameAccess > xTypeDetection( mxMSF->createInstance( "com.sun.star.document.TypeDetection" ), UNO_QUERY );
if( xFilterContainer.is() && xTypeDetection.is() ) if( xFilterContainer.is() && xTypeDetection.is() )
{ {
Sequence< OUString > aFilterNames( xFilterContainer->getElementNames() ); Sequence< OUString > aFilterNames( xFilterContainer->getElementNames() );
...@@ -384,19 +381,16 @@ void XMLFilterTestDialog::onExportBrowse() ...@@ -384,19 +381,16 @@ void XMLFilterTestDialog::onExportBrowse()
for( n = 0; n < nCount; n++ ) for( n = 0; n < nCount; n++ )
{ {
if( n > 0 ) if( n > 0 )
aExtension += OUString( sal_Unicode(';') ); aExtension += ";";
aExtension += OUString( RTL_CONSTASCII_USTRINGPARAM( "*." )); aExtension += "*." + (*pExtensions++);
aExtension += (*pExtensions++);
} }
} }
} }
} }
String aExtensions( aExtension ); OUString aExtensions( aExtension );
String aFilterName( aInterfaceName ); OUString aFilterName( aInterfaceName );
aFilterName += String( RTL_CONSTASCII_USTRINGPARAM(" (") ); aFilterName += " (" + aExtensions + ")";
aFilterName += aExtensions;
aFilterName += sal_Unicode(')');
aDlg.AddFilter( aFilterName, aExtensions ); aDlg.AddFilter( aFilterName, aExtensions );
...@@ -417,9 +411,9 @@ void XMLFilterTestDialog::onExportBrowse() ...@@ -417,9 +411,9 @@ void XMLFilterTestDialog::onExportBrowse()
Reference< XDesktop2 > xLoader = Desktop::create( comphelper::getComponentContext(mxMSF) ); Reference< XDesktop2 > xLoader = Desktop::create( comphelper::getComponentContext(mxMSF) );
Reference< XInteractionHandler2 > xInter( InteractionHandler::createWithParent(comphelper::getComponentContext(mxMSF), 0) ); Reference< XInteractionHandler2 > xInter( InteractionHandler::createWithParent(comphelper::getComponentContext(mxMSF), 0) );
OUString aFrame( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ); OUString aFrame( "_default" );
Sequence< PropertyValue > aArguments(1); Sequence< PropertyValue > aArguments(1);
aArguments[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "InteractionHandler" )); aArguments[0].Name = "InteractionHandler";
aArguments[0].Value <<= xInter; aArguments[0].Value <<= xInter;
Reference< XComponent > xComp( xLoader->loadComponentFromURL( m_sExportRecentFile, aFrame, 0, aArguments ) ); Reference< XComponent > xComp( xLoader->loadComponentFromURL( m_sExportRecentFile, aFrame, 0, aArguments ) );
if( xComp.is() ) if( xComp.is() )
...@@ -448,9 +442,9 @@ void XMLFilterTestDialog::doExport( Reference< XComponent > xComp ) ...@@ -448,9 +442,9 @@ void XMLFilterTestDialog::doExport( Reference< XComponent > xComp )
Reference< XStorable > xStorable( xComp, UNO_QUERY ); Reference< XStorable > xStorable( xComp, UNO_QUERY );
if( xStorable.is() ) if( xStorable.is() )
{ {
String leadingChars; OUString lead;
String ext(RTL_CONSTASCII_USTRINGPARAM(".xml")); OUString ext(".xml");
utl::TempFile aTempFile(leadingChars, &ext); TempFile aTempFile(lead, &ext);
OUString aTempFileURL( aTempFile.GetURL() ); OUString aTempFileURL( aTempFile.GetURL() );
const application_info_impl* pAppInfo = getApplicationInfo( m_pFilterInfo->maExportService ); const application_info_impl* pAppInfo = getApplicationInfo( m_pFilterInfo->maExportService );
...@@ -466,19 +460,19 @@ void XMLFilterTestDialog::doExport( Reference< XComponent > xComp ) ...@@ -466,19 +460,19 @@ void XMLFilterTestDialog::doExport( Reference< XComponent > xComp )
int i = 0; int i = 0;
aSourceData[i ].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "OutputStream" ) ); aSourceData[i ].Name = OUString( "OutputStream" );
aSourceData[i++].Value <<= xIS; aSourceData[i++].Value <<= xIS;
aSourceData[i].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Indent" ) ); aSourceData[i ].Name = OUString( "Indent" );
aSourceData[i++].Value <<= (sal_Bool)sal_True; aSourceData[i++].Value <<= (sal_Bool)sal_True;
if( bUseDocType ) if( bUseDocType )
{ {
aSourceData[i ].Name = OUString(RTL_CONSTASCII_USTRINGPARAM("DocType_Public")); aSourceData[i ].Name = OUString( "DocType_Public" );
aSourceData[i++].Value <<= m_pFilterInfo->maDocType; aSourceData[i++].Value <<= m_pFilterInfo->maDocType;
} }
Reference< XExportFilter > xExporter( mxMSF->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.documentconversion.XSLTFilter" )) ), UNO_QUERY ); Reference< XExportFilter > xExporter( mxMSF->createInstance( "com.sun.star.documentconversion.XSLTFilter" ), UNO_QUERY );
Reference< XDocumentHandler > xHandler( xExporter, UNO_QUERY ); Reference< XDocumentHandler > xHandler( xExporter, UNO_QUERY );
if( xHandler.is() ) if( xHandler.is() )
{ {
...@@ -494,8 +488,8 @@ void XMLFilterTestDialog::doExport( Reference< XComponent > xComp ) ...@@ -494,8 +488,8 @@ void XMLFilterTestDialog::doExport( Reference< XComponent > xComp )
{ {
try try
{ {
xGrfResolver = Reference< XGraphicObjectResolver >::query( xDocFac->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.ExportGraphicObjectResolver" )) ) ); xGrfResolver = Reference< XGraphicObjectResolver >::query( xDocFac->createInstance( "com.sun.star.document.ExportGraphicObjectResolver" ) );
xObjectResolver = Reference< XEmbeddedObjectResolver >::query( xDocFac->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.ExportEmbeddedObjectResolver" )) ) ); xObjectResolver = Reference< XEmbeddedObjectResolver >::query( xDocFac->createInstance( "com.sun.star.document.ExportEmbeddedObjectResolver" ) );
} }
catch( const Exception& ) catch( const Exception& )
{ {
...@@ -519,7 +513,7 @@ void XMLFilterTestDialog::doExport( Reference< XComponent > xComp ) ...@@ -519,7 +513,7 @@ void XMLFilterTestDialog::doExport( Reference< XComponent > xComp )
xExporter2->setSourceDocument( xComp ); xExporter2->setSourceDocument( xComp );
Sequence< PropertyValue > aDescriptor( 1 ); Sequence< PropertyValue > aDescriptor( 1 );
aDescriptor[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "FileName" ) ); aDescriptor[0].Name = OUString( "FileName" );
aDescriptor[0].Value <<= aTempFileURL; aDescriptor[0].Value <<= aTempFileURL;
if( xFilter->filter( aDescriptor ) ) if( xFilter->filter( aDescriptor ) )
...@@ -540,7 +534,7 @@ void XMLFilterTestDialog::displayXMLFile( const OUString& rURL ) ...@@ -540,7 +534,7 @@ void XMLFilterTestDialog::displayXMLFile( const OUString& rURL )
{ {
Reference< XSystemShellExecute > xSystemShellExecute( Reference< XSystemShellExecute > xSystemShellExecute(
SystemShellExecute::create(comphelper::getProcessComponentContext()) ); SystemShellExecute::create(comphelper::getProcessComponentContext()) );
xSystemShellExecute->execute( rURL, rtl::OUString(), SystemShellExecuteFlags::URIS_ONLY ); xSystemShellExecute->execute( rURL, OUString(), SystemShellExecuteFlags::URIS_ONLY );
} }
void XMLFilterTestDialog::onImportBrowse() void XMLFilterTestDialog::onImportBrowse()
...@@ -548,8 +542,8 @@ void XMLFilterTestDialog::onImportBrowse() ...@@ -548,8 +542,8 @@ void XMLFilterTestDialog::onImportBrowse()
// Open Fileopen-Dialog // Open Fileopen-Dialog
::sfx2::FileDialogHelper aDlg( ::sfx2::FileDialogHelper aDlg(
com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 ); com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 );
String aFilterName( m_pFilterInfo->maInterfaceName ); OUString aFilterName( m_pFilterInfo->maInterfaceName );
String aExtensions; OUString aExtensions;
int nLastIndex = 0; int nLastIndex = 0;
int nCurrentIndex = 0; int nCurrentIndex = 0;
...@@ -558,26 +552,24 @@ void XMLFilterTestDialog::onImportBrowse() ...@@ -558,26 +552,24 @@ void XMLFilterTestDialog::onImportBrowse()
nLastIndex = m_pFilterInfo->maExtension.indexOf( sal_Unicode( ';' ), nLastIndex ); nLastIndex = m_pFilterInfo->maExtension.indexOf( sal_Unicode( ';' ), nLastIndex );
if( i > 0 ) if( i > 0 )
aExtensions += ';'; aExtensions += ";";
aExtensions += String( RTL_CONSTASCII_USTRINGPARAM("*.") ); aExtensions += "*.";
if( nLastIndex == -1 ) if( nLastIndex == -1 )
{ {
aExtensions += String( m_pFilterInfo->maExtension.copy( nCurrentIndex ) ); aExtensions += OUString( m_pFilterInfo->maExtension.copy( nCurrentIndex ) );
} }
else else
{ {
aExtensions += String( m_pFilterInfo->maExtension.copy( nCurrentIndex, nLastIndex - nCurrentIndex ) ); aExtensions += OUString( m_pFilterInfo->maExtension.copy( nCurrentIndex, nLastIndex - nCurrentIndex ) );
nCurrentIndex = nLastIndex + 1; nCurrentIndex = nLastIndex + 1;
nLastIndex = nCurrentIndex; nLastIndex = nCurrentIndex;
} }
} }
aFilterName += String( RTL_CONSTASCII_USTRINGPARAM( " (" ) ); aFilterName += " (" + aExtensions + ")";
aFilterName += aExtensions;
aFilterName += sal_Unicode(')');
aDlg.AddFilter( aFilterName, aExtensions ); aDlg.AddFilter( aFilterName, aExtensions );
aDlg.SetDisplayDirectory( m_sImportRecentFile ); aDlg.SetDisplayDirectory( m_sImportRecentFile );
...@@ -603,23 +595,23 @@ void XMLFilterTestDialog::import( const OUString& rURL ) ...@@ -603,23 +595,23 @@ void XMLFilterTestDialog::import( const OUString& rURL )
Reference< XDesktop2 > xLoader = Desktop::create( comphelper::getComponentContext(mxMSF) ); Reference< XDesktop2 > xLoader = Desktop::create( comphelper::getComponentContext(mxMSF) );
Reference< XInteractionHandler2 > xInter( InteractionHandler::createWithParent(comphelper::getComponentContext(mxMSF), 0) ); Reference< XInteractionHandler2 > xInter( InteractionHandler::createWithParent(comphelper::getComponentContext(mxMSF), 0) );
OUString aFrame( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ); OUString aFrame( "_default" );
Sequence< PropertyValue > aArguments(2); Sequence< PropertyValue > aArguments(2);
aArguments[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" )); aArguments[0].Name = OUString( "FilterName" );
aArguments[0].Value <<= m_pFilterInfo->maFilterName; aArguments[0].Value <<= m_pFilterInfo->maFilterName;
aArguments[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "InteractionHandler" )); aArguments[1].Name = OUString( "InteractionHandler" );
aArguments[1].Value <<= xInter; aArguments[1].Value <<= xInter;
xLoader->loadComponentFromURL( rURL, aFrame, 0, aArguments ); xLoader->loadComponentFromURL( rURL, aFrame, 0, aArguments );
if( m_pCBXDisplaySource->IsChecked() ) if( m_pCBXDisplaySource->IsChecked() )
{ {
String lead; OUString lead;
String ext(RTL_CONSTASCII_USTRINGPARAM(".xml")); OUString ext( ".xml" );
TempFile aTempFile(lead, &ext); TempFile aTempFile(lead, &ext);
OUString aTempFileURL( aTempFile.GetURL() ); OUString aTempFileURL( aTempFile.GetURL() );
Reference< XImportFilter > xImporter( mxMSF->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.documentconversion.XSLTFilter" )) ), UNO_QUERY ); Reference< XImportFilter > xImporter( mxMSF->createInstance( "com.sun.star.documentconversion.XSLTFilter" ), UNO_QUERY );
if( xImporter.is() ) if( xImporter.is() )
{ {
osl::File aInputFile( rURL ); osl::File aInputFile( rURL );
...@@ -630,13 +622,13 @@ void XMLFilterTestDialog::import( const OUString& rURL ) ...@@ -630,13 +622,13 @@ void XMLFilterTestDialog::import( const OUString& rURL )
Sequence< PropertyValue > aSourceData( 3 ); Sequence< PropertyValue > aSourceData( 3 );
int i = 0; int i = 0;
aSourceData[i ].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "InputStream" )); aSourceData[i ].Name = OUString( "InputStream" );
aSourceData[i++].Value <<= xIS; aSourceData[i++].Value <<= xIS;
aSourceData[i ].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "FileName" )); aSourceData[i ].Name = OUString( "FileName" );
aSourceData[i++].Value <<= rURL; aSourceData[i++].Value <<= rURL;
aSourceData[i ].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Indent" )); aSourceData[i ].Name = OUString( "Indent" );
aSourceData[i++].Value <<= (sal_Bool)sal_True; aSourceData[i++].Value <<= (sal_Bool)sal_True;
Reference< XWriter > xWriter = Writer::create( comphelper::getComponentContext(mxMSF) ); Reference< XWriter > xWriter = Writer::create( comphelper::getComponentContext(mxMSF) );
......
...@@ -41,7 +41,8 @@ public: ...@@ -41,7 +41,8 @@ public:
The extension string may be f.e. ".txt" or "", if no extension string is The extension string may be f.e. ".txt" or "", if no extension string is
given, ".tmp" is used. given, ".tmp" is used.
*/ */
TempFile( const String& rLeadingChars, const String* pExtension=NULL, const String* pParent=NULL, sal_Bool bDirectory=sal_False ); TempFile( const String& rLeadingChars, const String* pExtension=NULL, const String* pParent=NULL, sal_Bool bDirectory=sal_False );
TempFile( const OUString& rLeadingChars, const OUString* pExtension=NULL, const OUString* pParent=NULL, sal_Bool bDirectory=sal_False );
/** TempFile will be removed from disk in dtor if EnableKillingTempFile was /** TempFile will be removed from disk in dtor if EnableKillingTempFile was
called before. TempDirs will be removed recursively in that case. */ called before. TempDirs will be removed recursively in that case. */
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
using namespace osl; using namespace osl;
namespace { struct TempNameBase_Impl : public rtl::Static< ::rtl::OUString, TempNameBase_Impl > {}; } namespace { struct TempNameBase_Impl : public rtl::Static< OUString, TempNameBase_Impl > {}; }
struct TempFile_Impl struct TempFile_Impl
{ {
...@@ -48,9 +48,9 @@ String GetSystemTempDir_Impl() ...@@ -48,9 +48,9 @@ String GetSystemTempDir_Impl()
char sBuf[_MAX_PATH]; char sBuf[_MAX_PATH];
const char *pDir = TempDirImpl(sBuf); const char *pDir = TempDirImpl(sBuf);
::rtl::OString aTmpA( pDir ); OString aTmpA( pDir );
::rtl::OUString aTmp = ::rtl::OStringToOUString( aTmpA, osl_getThreadTextEncoding() ); OUString aTmp = ::rtl::OStringToOUString( aTmpA, osl_getThreadTextEncoding() );
rtl::OUString aRet; OUString aRet;
FileBase::getFileURLFromSystemPath( aTmp, aRet ); FileBase::getFileURLFromSystemPath( aTmp, aRet );
String aName = aRet; String aName = aRet;
if( aName.GetChar(aName.Len()-1) != '/' ) if( aName.GetChar(aName.Len()-1) != '/' )
...@@ -66,8 +66,8 @@ String ConstructTempDir_Impl( const String* pParent ) ...@@ -66,8 +66,8 @@ String ConstructTempDir_Impl( const String* pParent )
if ( pParent && pParent->Len() ) if ( pParent && pParent->Len() )
{ {
// if parent given try to use it // if parent given try to use it
rtl::OUString aTmp( *pParent ); OUString aTmp( *pParent );
rtl::OUString aRet; OUString aRet;
// test for valid filename // test for valid filename
{ {
...@@ -84,7 +84,7 @@ String ConstructTempDir_Impl( const String* pParent ) ...@@ -84,7 +84,7 @@ String ConstructTempDir_Impl( const String* pParent )
if ( !aName.Len() ) if ( !aName.Len() )
{ {
// if no parent or invalid parent : use system directory // if no parent or invalid parent : use system directory
::rtl::OUString& rTempNameBase_Impl = TempNameBase_Impl::get(); OUString& rTempNameBase_Impl = TempNameBase_Impl::get();
if ( rTempNameBase_Impl.isEmpty() ) if ( rTempNameBase_Impl.isEmpty() )
rTempNameBase_Impl = GetSystemTempDir_Impl(); rTempNameBase_Impl = GetSystemTempDir_Impl();
aName = rTempNameBase_Impl; aName = rTempNameBase_Impl;
...@@ -98,6 +98,45 @@ String ConstructTempDir_Impl( const String* pParent ) ...@@ -98,6 +98,45 @@ String ConstructTempDir_Impl( const String* pParent )
return aName; return aName;
} }
OUString ConstructTempDir_Impl( const OUString* pParent )
{
OUString aName;
if ( pParent && pParent->getLength() )
{
// if parent given try to use it
OUString aTmp( *pParent );
OUString aRet;
// test for valid filename
{
::osl::DirectoryItem aItem;
sal_Int32 i = aRet.getLength();
if ( aRet[i-1] == '/' )
i--;
if ( DirectoryItem::get( aRet.copy(0, i), aItem ) == FileBase::E_None )
aName = aRet;
}
}
if ( !aName.isEmpty() )
{
// if no parent or invalid parent : use system directory
OUString& rTempNameBase_Impl = TempNameBase_Impl::get();
if ( rTempNameBase_Impl.isEmpty() )
rTempNameBase_Impl = GetSystemTempDir_Impl();
aName = rTempNameBase_Impl;
}
// Make sure that directory ends with a separator
xub_StrLen i = aName.getLength();
if( i>0 && aName[i-1] != '/' )
aName += "/";
return aName;
}
void CreateTempName_Impl( String& rName, sal_Bool bKeep, sal_Bool bDir = sal_True ) void CreateTempName_Impl( String& rName, sal_Bool bKeep, sal_Bool bDir = sal_True )
{ {
// add a suitable tempname // add a suitable tempname
...@@ -105,14 +144,14 @@ void CreateTempName_Impl( String& rName, sal_Bool bKeep, sal_Bool bDir = sal_Tru ...@@ -105,14 +144,14 @@ void CreateTempName_Impl( String& rName, sal_Bool bKeep, sal_Bool bDir = sal_Tru
// ER 13.07.00 why not radix 36 [0-9A-Z] ?!? // ER 13.07.00 why not radix 36 [0-9A-Z] ?!?
const unsigned nRadix = 26; const unsigned nRadix = 26;
String aName( rName ); String aName( rName );
aName += rtl::OUString("sv"); aName += OUString("sv");
rName.Erase(); rName.Erase();
static unsigned long u = Time::GetSystemTicks(); static unsigned long u = Time::GetSystemTicks();
for ( unsigned long nOld = u; ++u != nOld; ) for ( unsigned long nOld = u; ++u != nOld; )
{ {
u %= (nRadix*nRadix*nRadix); u %= (nRadix*nRadix*nRadix);
rtl::OUString aTmp = rtl::OUStringBuffer(aName). OUString aTmp = OUStringBuffer(aName).
append((sal_Int32)(unsigned)u, nRadix). append((sal_Int32)(unsigned)u, nRadix).
append(".tmp"). append(".tmp").
makeStringAndClear(); makeStringAndClear();
...@@ -191,13 +230,64 @@ TempFile::TempFile( const String& rLeadingChars, const String* pExtension, ...@@ -191,13 +230,64 @@ TempFile::TempFile( const String& rLeadingChars, const String* pExtension,
aName += rLeadingChars; aName += rLeadingChars;
for ( sal_Int32 i=0;; i++ ) for ( sal_Int32 i=0;; i++ )
{ {
rtl::OUStringBuffer aTmpBuffer(aName); OUStringBuffer aTmpBuffer(aName);
aTmpBuffer.append(i);
if ( pExtension )
aTmpBuffer.append(*pExtension);
else
aTmpBuffer.append(".tmp");
OUString aTmp = aTmpBuffer.makeStringAndClear();
if ( bDirectory )
{
FileBase::RC err = Directory::create( aTmp );
if ( err == FileBase::E_None )
{
pImp->aName = aTmp;
break;
}
else if ( err != FileBase::E_EXIST )
// if f.e. name contains invalid chars stop trying to create dirs
break;
}
else
{
File aFile( aTmp );
FileBase::RC err = aFile.open(osl_File_OpenFlag_Create);
if ( err == FileBase::E_None )
{
pImp->aName = aTmp;
aFile.close();
break;
}
else if ( err != FileBase::E_EXIST )
// if f.e. name contains invalid chars stop trying to create dirs
break;
}
}
}
TempFile::TempFile( const OUString& rLeadingChars, const OUString* pExtension,
const OUString* pParent, sal_Bool bDirectory )
: pImp( new TempFile_Impl )
, bKillingFileEnabled( sal_False )
{
pImp-> bIsDirectory = bDirectory;
// get correct directory
OUString aName = ConstructTempDir_Impl( pParent );
// now use special naming scheme (name takes leading chars and an index couting up from zero
aName += rLeadingChars;
for ( sal_Int32 i=0;; i++ )
{
OUStringBuffer aTmpBuffer(aName);
aTmpBuffer.append(i); aTmpBuffer.append(i);
if ( pExtension ) if ( pExtension )
aTmpBuffer.append(*pExtension); aTmpBuffer.append(*pExtension);
else else
aTmpBuffer.append(".tmp"); aTmpBuffer.append(".tmp");
rtl::OUString aTmp = aTmpBuffer.makeStringAndClear(); OUString aTmp = aTmpBuffer.makeStringAndClear();
if ( bDirectory ) if ( bDirectory )
{ {
...@@ -248,7 +338,7 @@ TempFile::~TempFile() ...@@ -248,7 +338,7 @@ TempFile::~TempFile()
String TempFile::GetName() const String TempFile::GetName() const
{ {
rtl::OUString aTmp; OUString aTmp;
aTmp = pImp->aName; aTmp = pImp->aName;
return aTmp; return aTmp;
} }
......
...@@ -69,6 +69,9 @@ public: ...@@ -69,6 +69,9 @@ public:
TempFile( const String& rLeadingChars, const String* pExtension=NULL, const String* pParent=NULL, TempFile( const String& rLeadingChars, const String* pExtension=NULL, const String* pParent=NULL,
sal_Bool bDirectory=sal_False); sal_Bool bDirectory=sal_False);
TempFile( const OUString& rLeadingChars, const OUString* pExtension=NULL, const OUString* pParent=NULL,
sal_Bool bDirectory=sal_False);
/** /**
Same as above; additionally the name starts with some given characters followed by a counter ( example: Same as above; additionally the name starts with some given characters followed by a counter ( example:
rLeadingChars="abc" means "abc0","abc1" and so on, depending on existing files in the folder ). rLeadingChars="abc" means "abc0","abc1" and so on, depending on existing files in the folder ).
......
...@@ -42,7 +42,7 @@ using namespace osl; ...@@ -42,7 +42,7 @@ using namespace osl;
namespace namespace
{ {
struct TempNameBase_Impl struct TempNameBase_Impl
: public rtl::Static< ::rtl::OUString, TempNameBase_Impl > {}; : public rtl::Static< OUString, TempNameBase_Impl > {};
} }
namespace utl namespace utl
...@@ -60,23 +60,23 @@ struct TempFile_Impl ...@@ -60,23 +60,23 @@ struct TempFile_Impl
{} {}
}; };
rtl::OUString getParentName( const rtl::OUString& aFileName ) OUString getParentName( const OUString& aFileName )
{ {
sal_Int32 lastIndex = aFileName.lastIndexOf( sal_Unicode('/') ); sal_Int32 lastIndex = aFileName.lastIndexOf( sal_Unicode('/') );
rtl::OUString aParent = aFileName.copy( 0,lastIndex ); OUString aParent = aFileName.copy( 0,lastIndex );
if( aParent[ aParent.getLength()-1] == sal_Unicode(':') && aParent.getLength() == 6 ) if( aParent[ aParent.getLength()-1] == sal_Unicode(':') && aParent.getLength() == 6 )
aParent += rtl::OUString("/"); aParent += "/";
if( 0 == aParent.compareToAscii( "file://" ) ) if( aParent == "file://" )
aParent = rtl::OUString("file:///"); aParent = "file:///";
return aParent; return aParent;
} }
sal_Bool ensuredir( const rtl::OUString& rUnqPath ) sal_Bool ensuredir( const OUString& rUnqPath )
{ {
rtl::OUString aPath; OUString aPath;
if ( rUnqPath.isEmpty() ) if ( rUnqPath.isEmpty() )
return sal_False; return sal_False;
...@@ -107,7 +107,7 @@ umask(old_mode); ...@@ -107,7 +107,7 @@ umask(old_mode);
if( !bSuccess ) if( !bSuccess )
{ {
// perhaps parent(s) don't exist // perhaps parent(s) don't exist
rtl::OUString aParentDir = getParentName( aPath ); OUString aParentDir = getParentName( aPath );
if ( aParentDir != aPath ) if ( aParentDir != aPath )
{ {
bSuccess = ensuredir( getParentName( aPath ) ); bSuccess = ensuredir( getParentName( aPath ) );
...@@ -136,10 +136,10 @@ String ConstructTempDir_Impl( const String* pParent ) ...@@ -136,10 +136,10 @@ String ConstructTempDir_Impl( const String* pParent )
comphelper::getProcessComponentContext() ) ); comphelper::getProcessComponentContext() ) );
// if parent given try to use it // if parent given try to use it
rtl::OUString aTmp( *pParent ); OUString aTmp( *pParent );
// test for valid filename // test for valid filename
rtl::OUString aRet; OUString aRet;
::osl::FileBase::getFileURLFromSystemPath( ::osl::FileBase::getFileURLFromSystemPath(
::ucbhelper::getSystemPathFromFileURL( pBroker, aTmp ), ::ucbhelper::getSystemPathFromFileURL( pBroker, aTmp ),
aRet ); aRet );
...@@ -157,10 +157,10 @@ String ConstructTempDir_Impl( const String* pParent ) ...@@ -157,10 +157,10 @@ String ConstructTempDir_Impl( const String* pParent )
if ( !aName.Len() ) if ( !aName.Len() )
{ {
::rtl::OUString &rTempNameBase_Impl = TempNameBase_Impl::get(); OUString &rTempNameBase_Impl = TempNameBase_Impl::get();
if (rTempNameBase_Impl.isEmpty()) if (rTempNameBase_Impl.isEmpty())
{ {
::rtl::OUString ustrTempDirURL; OUString ustrTempDirURL;
::osl::FileBase::RC rc = ::osl::File::getTempDirURL( ::osl::FileBase::RC rc = ::osl::File::getTempDirURL(
ustrTempDirURL ); ustrTempDirURL );
if (rc == ::osl::FileBase::E_None) if (rc == ::osl::FileBase::E_None)
...@@ -180,6 +180,62 @@ String ConstructTempDir_Impl( const String* pParent ) ...@@ -180,6 +180,62 @@ String ConstructTempDir_Impl( const String* pParent )
return aName; return aName;
} }
OUString ConstructTempDir_Impl( const OUString* pParent )
{
OUString aName;
if ( pParent && pParent->getLength() )
{
com::sun::star::uno::Reference<
com::sun::star::ucb::XUniversalContentBroker > pBroker(
com::sun::star::ucb::UniversalContentBroker::create(
comphelper::getProcessComponentContext() ) );
// if parent given try to use it
OUString aTmp( *pParent );
// test for valid filename
OUString aRet;
::osl::FileBase::getFileURLFromSystemPath(
::ucbhelper::getSystemPathFromFileURL( pBroker, aTmp ),
aRet );
if ( !aRet.isEmpty() )
{
::osl::DirectoryItem aItem;
sal_Int32 i = aRet.getLength();
if ( aRet[i-1] == '/' )
i--;
if ( DirectoryItem::get( aRet.copy(0, i), aItem ) == FileBase::E_None )
aName = aRet;
}
}
if ( !aName.isEmpty() )
{
OUString &rTempNameBase_Impl = TempNameBase_Impl::get();
if (rTempNameBase_Impl.isEmpty())
{
OUString ustrTempDirURL;
::osl::FileBase::RC rc = ::osl::File::getTempDirURL(
ustrTempDirURL );
if (rc == ::osl::FileBase::E_None)
rTempNameBase_Impl = ustrTempDirURL;
}
// if no parent or invalid parent : use default directory
DBG_ASSERT( !rTempNameBase_Impl.isEmpty(), "No TempDir!" );
aName = rTempNameBase_Impl;
ensuredir( aName );
}
// Make sure that directory ends with a separator
sal_Int32 i = aName.getLength();
if( i>0 && aName[i-1] != '/' )
aName += "/";
return aName;
}
void CreateTempName_Impl( String& rName, sal_Bool bKeep, sal_Bool bDir = sal_True ) void CreateTempName_Impl( String& rName, sal_Bool bKeep, sal_Bool bDir = sal_True )
{ {
// add a suitable tempname // add a suitable tempname
...@@ -187,7 +243,7 @@ void CreateTempName_Impl( String& rName, sal_Bool bKeep, sal_Bool bDir = sal_Tru ...@@ -187,7 +243,7 @@ void CreateTempName_Impl( String& rName, sal_Bool bKeep, sal_Bool bDir = sal_Tru
unsigned const nRadix = 36; unsigned const nRadix = 36;
unsigned long const nMax = (nRadix*nRadix*nRadix*nRadix*nRadix*nRadix); unsigned long const nMax = (nRadix*nRadix*nRadix*nRadix*nRadix*nRadix);
String aName( rName ); String aName( rName );
aName += rtl::OUString( "lu" ); aName += OUString( "lu" );
rName.Erase(); rName.Erase();
static unsigned long u = Time::GetSystemTicks() % nMax; static unsigned long u = Time::GetSystemTicks() % nMax;
...@@ -195,8 +251,8 @@ void CreateTempName_Impl( String& rName, sal_Bool bKeep, sal_Bool bDir = sal_Tru ...@@ -195,8 +251,8 @@ void CreateTempName_Impl( String& rName, sal_Bool bKeep, sal_Bool bDir = sal_Tru
{ {
u %= nMax; u %= nMax;
String aTmp( aName ); String aTmp( aName );
aTmp += rtl::OUString::valueOf(static_cast<sal_Int64>(u), nRadix); aTmp += OUString::valueOf(static_cast<sal_Int64>(u), nRadix);
aTmp += rtl::OUString( ".tmp" ); aTmp += OUString( ".tmp" );
if ( bDir ) if ( bDir )
{ {
...@@ -272,7 +328,7 @@ void lcl_createName(TempFile_Impl& _rImpl,const String& rLeadingChars,sal_Bool _ ...@@ -272,7 +328,7 @@ void lcl_createName(TempFile_Impl& _rImpl,const String& rLeadingChars,sal_Bool _
if ( pExtension ) if ( pExtension )
aTmp += *pExtension; aTmp += *pExtension;
else else
aTmp += rtl::OUString( ".tmp" ); aTmp += OUString( ".tmp" );
if ( bDirectory ) if ( bDirectory )
{ {
FileBase::RC err = Directory::create( aTmp ); FileBase::RC err = Directory::create( aTmp );
...@@ -321,6 +377,74 @@ umask(old_mode); ...@@ -321,6 +377,74 @@ umask(old_mode);
} }
void lcl_createName(TempFile_Impl& _rImpl,const OUString& rLeadingChars,sal_Bool _bStartWithZero, const OUString* pExtension, const OUString* pParent, sal_Bool bDirectory)
{
_rImpl.bIsDirectory = bDirectory;
// get correct directory
OUString aName = ConstructTempDir_Impl( pParent );
sal_Bool bUseNumber = _bStartWithZero;
// now use special naming scheme ( name takes leading chars and an index counting up from zero
aName += rLeadingChars;
for ( sal_Int32 i=0;; i++ )
{
OUString aTmp( aName );
if ( bUseNumber )
aTmp += OUString::valueOf( static_cast< sal_Int32>(i) );
bUseNumber = sal_True;
if ( pExtension )
aTmp += *pExtension;
else
aTmp += ".tmp";
if ( bDirectory )
{
FileBase::RC err = Directory::create( aTmp );
if ( err == FileBase::E_None )
{
_rImpl.aName = aTmp;
break;
}
else if ( err != FileBase::E_EXIST )
// if f.e. name contains invalid chars stop trying to create dirs
break;
}
else
{
File aFile( aTmp );
#ifdef UNX
/* RW permission for the user only! */
mode_t old_mode = umask(077);
#endif
FileBase::RC err = aFile.open(osl_File_OpenFlag_Create);
#ifdef UNX
umask(old_mode);
#endif
if ( err == FileBase::E_None || err == FileBase::E_NOLCK )
{
_rImpl.aName = aTmp;
aFile.close();
break;
}
else if ( err != FileBase::E_EXIST )
{
// if f.e. name contains invalid chars stop trying to create dirs
// but if there is a folder with such name proceed further
DirectoryItem aTmpItem;
FileStatus aTmpStatus( osl_FileStatus_Mask_Type );
if ( DirectoryItem::get( aTmp, aTmpItem ) != FileBase::E_None
|| aTmpItem.getFileStatus( aTmpStatus ) != FileBase::E_None
|| aTmpStatus.getFileType() != FileStatus::Directory )
break;
}
}
if ( !_bStartWithZero )
aTmp += OUString::valueOf( static_cast<sal_Int32>(i) );
}
}
String TempFile::CreateTempName( const String* pParent ) String TempFile::CreateTempName( const String* pParent )
{ {
// get correct directory // get correct directory
...@@ -330,7 +454,7 @@ String TempFile::CreateTempName( const String* pParent ) ...@@ -330,7 +454,7 @@ String TempFile::CreateTempName( const String* pParent )
CreateTempName_Impl( aName, sal_False ); CreateTempName_Impl( aName, sal_False );
// convert to file URL // convert to file URL
rtl::OUString aTmp; OUString aTmp;
if ( aName.Len() ) if ( aName.Len() )
FileBase::getSystemPathFromFileURL( aName, aTmp ); FileBase::getSystemPathFromFileURL( aName, aTmp );
return aTmp; return aTmp;
...@@ -355,6 +479,14 @@ TempFile::TempFile( const String& rLeadingChars, const String* pExtension, const ...@@ -355,6 +479,14 @@ TempFile::TempFile( const String& rLeadingChars, const String* pExtension, const
{ {
lcl_createName(*pImp,rLeadingChars,sal_True, pExtension, pParent, bDirectory); lcl_createName(*pImp,rLeadingChars,sal_True, pExtension, pParent, bDirectory);
} }
TempFile::TempFile( const OUString& rLeadingChars, const OUString* pExtension, const OUString* pParent, sal_Bool bDirectory)
: pImp( new TempFile_Impl )
, bKillingFileEnabled( sal_False )
{
lcl_createName(*pImp,rLeadingChars,sal_True, pExtension, pParent, bDirectory);
}
TempFile::TempFile( const String& rLeadingChars,sal_Bool _bStartWithZero, const String* pExtension, const String* pParent, sal_Bool bDirectory) TempFile::TempFile( const String& rLeadingChars,sal_Bool _bStartWithZero, const String* pExtension, const String* pParent, sal_Bool bDirectory)
: pImp( new TempFile_Impl ) : pImp( new TempFile_Impl )
, bKillingFileEnabled( sal_False ) , bKillingFileEnabled( sal_False )
...@@ -388,7 +520,7 @@ sal_Bool TempFile::IsValid() const ...@@ -388,7 +520,7 @@ sal_Bool TempFile::IsValid() const
String TempFile::GetFileName() const String TempFile::GetFileName() const
{ {
rtl::OUString aTmp; OUString aTmp;
FileBase::getSystemPathFromFileURL( pImp->aName, aTmp ); FileBase::getSystemPathFromFileURL( pImp->aName, aTmp );
return aTmp; return aTmp;
} }
...@@ -397,7 +529,7 @@ String TempFile::GetURL() const ...@@ -397,7 +529,7 @@ String TempFile::GetURL() const
{ {
if ( !pImp->aURL.Len() ) if ( !pImp->aURL.Len() )
{ {
rtl::OUString aTmp; OUString aTmp;
LocalFileHelper::ConvertPhysicalNameToURL( GetFileName(), aTmp ); LocalFileHelper::ConvertPhysicalNameToURL( GetFileName(), aTmp );
pImp->aURL = aTmp; pImp->aURL = aTmp;
} }
...@@ -432,7 +564,7 @@ String TempFile::SetTempNameBaseDirectory( const String &rBaseName ) ...@@ -432,7 +564,7 @@ String TempFile::SetTempNameBaseDirectory( const String &rBaseName )
if( !rBaseName.Len() ) if( !rBaseName.Len() )
return String(); return String();
rtl::OUString aUnqPath( rBaseName ); OUString aUnqPath( rBaseName );
// remove trailing slash // remove trailing slash
if ( rBaseName.GetChar( rBaseName.Len() - 1 ) == sal_Unicode( '/' ) ) if ( rBaseName.GetChar( rBaseName.Len() - 1 ) == sal_Unicode( '/' ) )
...@@ -448,14 +580,14 @@ String TempFile::SetTempNameBaseDirectory( const String &rBaseName ) ...@@ -448,14 +580,14 @@ String TempFile::SetTempNameBaseDirectory( const String &rBaseName )
bRet = sal_True; bRet = sal_True;
// failure to create base directory means returning an empty string // failure to create base directory means returning an empty string
rtl::OUString aTmp; OUString aTmp;
if ( bRet ) if ( bRet )
{ {
// append own internal directory // append own internal directory
bRet = sal_True; bRet = sal_True;
::rtl::OUString &rTempNameBase_Impl = TempNameBase_Impl::get(); OUString &rTempNameBase_Impl = TempNameBase_Impl::get();
rTempNameBase_Impl = rBaseName; rTempNameBase_Impl = rBaseName;
rTempNameBase_Impl += rtl::OUString('/'); rTempNameBase_Impl += "/";
TempFile aBase( NULL, sal_True ); TempFile aBase( NULL, sal_True );
if ( aBase.IsValid() ) if ( aBase.IsValid() )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment