summaryrefslogtreecommitdiff
path: root/svl/source/misc/documentlockfile.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'svl/source/misc/documentlockfile.cxx')
-rw-r--r--svl/source/misc/documentlockfile.cxx140
1 files changed, 75 insertions, 65 deletions
diff --git a/svl/source/misc/documentlockfile.cxx b/svl/source/misc/documentlockfile.cxx
index 837005bd6f85..1bdf7ce5f386 100644
--- a/svl/source/misc/documentlockfile.cxx
+++ b/svl/source/misc/documentlockfile.cxx
@@ -54,42 +54,34 @@ using namespace ::com::sun::star;
namespace svt {
-bool DocumentLockFile::m_bAllowInteraction = true;
+GenDocumentLockFile::GenDocumentLockFile( const OUString& aURL )
+: LockFileCommon( aURL )
+{
+}
-DocumentLockFile::DocumentLockFile( const OUString& aOrigURL )
-: LockFileCommon( aOrigURL, ".~lock." )
+GenDocumentLockFile::GenDocumentLockFile( const OUString& aOrigURL, const OUString& aPrefix )
+: LockFileCommon( aOrigURL, aPrefix )
{
}
-DocumentLockFile::~DocumentLockFile()
+GenDocumentLockFile::~GenDocumentLockFile()
{
}
-
-void DocumentLockFile::WriteEntryToStream( const LockFileEntry& aEntry, const uno::Reference< io::XOutputStream >& xOutput )
+uno::Reference< io::XInputStream > GenDocumentLockFile::OpenStream()
{
::osl::MutexGuard aGuard( m_aMutex );
- OUStringBuffer aBuffer;
-
- for ( LockFileComponent lft : o3tl::enumrange<LockFileComponent>() )
- {
- aBuffer.append( EscapeCharacters( aEntry[lft] ) );
- if ( lft < LockFileComponent::LAST )
- aBuffer.append( ',' );
- else
- aBuffer.append( ';' );
- }
+ uno::Reference < css::ucb::XCommandEnvironment > xEnv;
+ ::ucbhelper::Content aSourceContent( GetURL(), xEnv, comphelper::getProcessComponentContext() );
- OString aStringData( OUStringToOString( aBuffer.makeStringAndClear(), RTL_TEXTENCODING_UTF8 ) );
- uno::Sequence< sal_Int8 > aData( reinterpret_cast<sal_Int8 const *>(aStringData.getStr()), aStringData.getLength() );
- xOutput->writeBytes( aData );
+ // the file can be opened readonly, no locking will be done
+ return aSourceContent.openStream();
}
-
-bool DocumentLockFile::CreateOwnLockFile()
+bool GenDocumentLockFile::CreateOwnLockFile()
{
::osl::MutexGuard aGuard( m_aMutex );
@@ -113,7 +105,7 @@ bool DocumentLockFile::CreateOwnLockFile()
xSeekable->seek( 0 );
uno::Reference < css::ucb::XCommandEnvironment > xEnv;
- ::ucbhelper::Content aTargetContent( m_aURL, xEnv, comphelper::getProcessComponentContext() );
+ ::ucbhelper::Content aTargetContent( GetURL(), xEnv, comphelper::getProcessComponentContext() );
ucb::InsertCommandArgument aInsertArg;
aInsertArg.Data = xInput;
@@ -135,50 +127,13 @@ bool DocumentLockFile::CreateOwnLockFile()
return true;
}
-
-LockFileEntry DocumentLockFile::GetLockData()
-{
- ::osl::MutexGuard aGuard( m_aMutex );
-
- uno::Reference< io::XInputStream > xInput = OpenStream();
- if ( !xInput.is() )
- throw uno::RuntimeException();
-
- const sal_Int32 nBufLen = 32000;
- uno::Sequence< sal_Int8 > aBuffer( nBufLen );
-
- sal_Int32 nRead = 0;
-
- nRead = xInput->readBytes( aBuffer, nBufLen );
- xInput->closeInput();
-
- if ( nRead == nBufLen )
- throw io::WrongFormatException();
-
- sal_Int32 nCurPos = 0;
- return ParseEntry( aBuffer, nCurPos );
-}
-
-
-uno::Reference< io::XInputStream > DocumentLockFile::OpenStream()
-{
- ::osl::MutexGuard aGuard( m_aMutex );
-
- uno::Reference < css::ucb::XCommandEnvironment > xEnv;
- ::ucbhelper::Content aSourceContent( m_aURL, xEnv, comphelper::getProcessComponentContext() );
-
- // the file can be opened readonly, no locking will be done
- return aSourceContent.openStream();
-}
-
-
-bool DocumentLockFile::OverwriteOwnLockFile()
+bool GenDocumentLockFile::OverwriteOwnLockFile()
{
// allows to overwrite the lock file with the current data
try
{
uno::Reference < css::ucb::XCommandEnvironment > xEnv;
- ::ucbhelper::Content aTargetContent( m_aURL, xEnv, comphelper::getProcessComponentContext() );
+ ::ucbhelper::Content aTargetContent( GetURL(), xEnv, comphelper::getProcessComponentContext() );
LockFileEntry aNewEntry = GenerateOwnEntry();
@@ -198,8 +153,7 @@ bool DocumentLockFile::OverwriteOwnLockFile()
return true;
}
-
-void DocumentLockFile::RemoveFile()
+void GenDocumentLockFile::RemoveFile()
{
::osl::MutexGuard aGuard( m_aMutex );
@@ -215,15 +169,71 @@ void DocumentLockFile::RemoveFile()
RemoveFileDirectly();
}
-void DocumentLockFile::RemoveFileDirectly()
+void GenDocumentLockFile::RemoveFileDirectly()
{
uno::Reference < css::ucb::XCommandEnvironment > xEnv;
- ::ucbhelper::Content aCnt(m_aURL, xEnv, comphelper::getProcessComponentContext());
+ ::ucbhelper::Content aCnt(GetURL(), xEnv, comphelper::getProcessComponentContext());
aCnt.executeCommand("delete",
uno::makeAny(true));
}
+DocumentLockFile::DocumentLockFile( const OUString& aOrigURL )
+: GenDocumentLockFile( aOrigURL, ".~lock." )
+{
+}
+
+
+DocumentLockFile::~DocumentLockFile()
+{
+}
+
+
+void DocumentLockFile::WriteEntryToStream( const LockFileEntry& aEntry, const uno::Reference< io::XOutputStream >& xOutput )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
+ OUStringBuffer aBuffer;
+
+ for ( LockFileComponent lft : o3tl::enumrange<LockFileComponent>() )
+ {
+ aBuffer.append( EscapeCharacters( aEntry[lft] ) );
+ if ( lft < LockFileComponent::LAST )
+ aBuffer.append( ',' );
+ else
+ aBuffer.append( ';' );
+ }
+
+ OString aStringData( OUStringToOString( aBuffer.makeStringAndClear(), RTL_TEXTENCODING_UTF8 ) );
+ uno::Sequence< sal_Int8 > aData( reinterpret_cast<sal_Int8 const *>(aStringData.getStr()), aStringData.getLength() );
+ xOutput->writeBytes( aData );
+}
+
+LockFileEntry DocumentLockFile::GetLockData()
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
+ uno::Reference< io::XInputStream > xInput = OpenStream();
+ if ( !xInput.is() )
+ throw uno::RuntimeException();
+
+ const sal_Int32 nBufLen = 32000;
+ uno::Sequence< sal_Int8 > aBuffer( nBufLen );
+
+ sal_Int32 nRead = 0;
+
+ nRead = xInput->readBytes( aBuffer, nBufLen );
+ xInput->closeInput();
+
+ if ( nRead == nBufLen )
+ throw io::WrongFormatException();
+
+ sal_Int32 nCurPos = 0;
+ return ParseEntry( aBuffer, nCurPos );
+}
+
+
+
} // namespace svt