summaryrefslogtreecommitdiff
path: root/svl
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2019-03-30 15:33:41 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2019-03-30 17:16:42 +0100
commit49696cc78fefa6d7f1c27a722b576c8d749c20d6 (patch)
tree540858c41c9d6c02fdd9f2fbaa30c3257099e232 /svl
parent107fd82751c35818152eabd45bdf882972d3c100 (diff)
Some refactor of lockfile classes to minimize interface
Change-Id: Icc67c31d6a2351b6504429e25067c25353233f5f Reviewed-on: https://gerrit.libreoffice.org/69947 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'svl')
-rw-r--r--svl/source/misc/documentlockfile.cxx12
-rw-r--r--svl/source/misc/lockfilecommon.cxx22
-rw-r--r--svl/source/misc/msodocumentlockfile.cxx153
-rw-r--r--svl/source/misc/sharecontrolfile.cxx2
4 files changed, 90 insertions, 99 deletions
diff --git a/svl/source/misc/documentlockfile.cxx b/svl/source/misc/documentlockfile.cxx
index 1bdf7ce5f386..3233852e6355 100644
--- a/svl/source/misc/documentlockfile.cxx
+++ b/svl/source/misc/documentlockfile.cxx
@@ -54,14 +54,8 @@ using namespace ::com::sun::star;
namespace svt {
-GenDocumentLockFile::GenDocumentLockFile( const OUString& aURL )
-: LockFileCommon( aURL )
-{
-}
-
-
-GenDocumentLockFile::GenDocumentLockFile( const OUString& aOrigURL, const OUString& aPrefix )
-: LockFileCommon( aOrigURL, aPrefix )
+GenDocumentLockFile::GenDocumentLockFile(const OUString& aLockFileURL)
+ : LockFileCommon(aLockFileURL)
{
}
@@ -179,7 +173,7 @@ void GenDocumentLockFile::RemoveFileDirectly()
DocumentLockFile::DocumentLockFile( const OUString& aOrigURL )
-: GenDocumentLockFile( aOrigURL, ".~lock." )
+ : GenDocumentLockFile(GenerateOwnLockFileURL(aOrigURL, ".~lock."))
{
}
diff --git a/svl/source/misc/lockfilecommon.cxx b/svl/source/misc/lockfilecommon.cxx
index 175220a532eb..ce0bdd662290 100644
--- a/svl/source/misc/lockfilecommon.cxx
+++ b/svl/source/misc/lockfilecommon.cxx
@@ -54,17 +54,11 @@ using namespace ::com::sun::star;
namespace svt {
-LockFileCommon::LockFileCommon( const OUString& aURL )
+LockFileCommon::LockFileCommon(const OUString& aLockFileURL)
+ : m_aURL(aLockFileURL)
{
- m_aURL = aURL;
-}
-
-LockFileCommon::LockFileCommon( const OUString& aOrigURL, const OUString& aPrefix )
-{
- m_aURL = GenerateURL(aOrigURL, aPrefix);
}
-
LockFileCommon::~LockFileCommon()
{
}
@@ -82,15 +76,11 @@ void LockFileCommon::SetURL(const OUString& aURL)
}
-OUString LockFileCommon::GenerateURL( const OUString& aOrigURL, const OUString& aPrefix )
+OUString LockFileCommon::GenerateOwnLockFileURL(const OUString& aOrigURL, const OUString& aPrefix)
{
- INetURLObject aDocURL = ResolveLinks( INetURLObject( aOrigURL ) );
-
- OUString aShareURLString = aDocURL.GetPartBeforeLastName();
- aShareURLString += aPrefix;
- aShareURLString += aDocURL.GetName();
- aShareURLString += "%23"; // '#'
- return INetURLObject( aShareURLString ).GetMainURL( INetURLObject::DecodeMechanism::NONE );
+ INetURLObject aURL = ResolveLinks(INetURLObject(aOrigURL));
+ aURL.SetName(aPrefix + aURL.GetName() + "%23" /*'#'*/);
+ return aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE);
}
diff --git a/svl/source/misc/msodocumentlockfile.cxx b/svl/source/misc/msodocumentlockfile.cxx
index aa9f651fae16..e0fc562e7a27 100644
--- a/svl/source/misc/msodocumentlockfile.cxx
+++ b/svl/source/misc/msodocumentlockfile.cxx
@@ -8,7 +8,6 @@
*/
#include <svl/msodocumentlockfile.hxx>
-#include <rtl/ustring.hxx>
#include <sal/log.hxx>
#include <algorithm>
#include <ucbhelper/content.hxx>
@@ -21,60 +20,69 @@
namespace svt
{
-bool MSODocumentLockFile::isWordFormat(const OUString& aOrigURL)
+namespace
{
- INetURLObject aDocURL = LockFileCommon::ResolveLinks(INetURLObject(aOrigURL));
-
- return aDocURL.GetFileExtension().compareToIgnoreAsciiCase("DOC") == 0
- || aDocURL.GetFileExtension().compareToIgnoreAsciiCase("DOCX") == 0
- || aDocURL.GetFileExtension().compareToIgnoreAsciiCase("RTF") == 0
- || aDocURL.GetFileExtension().compareToIgnoreAsciiCase("ODT") == 0;
-}
-
-bool MSODocumentLockFile::isExcelFormat(const OUString& aOrigURL)
+bool isWordFormat(const OUString& sExt)
{
- INetURLObject aDocURL = LockFileCommon::ResolveLinks(INetURLObject(aOrigURL));
-
- return //aDocURL.GetFileExtension().compareToIgnoreAsciiCase("XLS") || // MSO does not create lockfile for XLS
- aDocURL.GetFileExtension().compareToIgnoreAsciiCase("XLSX") == 0
- || aDocURL.GetFileExtension().compareToIgnoreAsciiCase("ODS") == 0;
+ return sExt.equalsIgnoreAsciiCase("DOC") || sExt.equalsIgnoreAsciiCase("DOCX")
+ || sExt.equalsIgnoreAsciiCase("RTF") || sExt.equalsIgnoreAsciiCase("ODT");
}
-bool MSODocumentLockFile::isPowerPointFormat(const OUString& aOrigURL)
+bool isExcelFormat(const OUString& sExt)
{
- INetURLObject aDocURL = LockFileCommon::ResolveLinks(INetURLObject(aOrigURL));
-
- return aDocURL.GetFileExtension().compareToIgnoreAsciiCase("PPTX") == 0
- || aDocURL.GetFileExtension().compareToIgnoreAsciiCase("PPT") == 0
- || aDocURL.GetFileExtension().compareToIgnoreAsciiCase("ODP") == 0;
+ return //sExt.equalsIgnoreAsciiCase("XLS") || // MSO does not create lockfile for XLS
+ sExt.equalsIgnoreAsciiCase("XLSX") || sExt.equalsIgnoreAsciiCase("ODS");
}
-MSODocumentLockFile::MSODocumentLockFile(const OUString& aOrigURL)
- : GenDocumentLockFile(GenerateURL(aOrigURL, "~$"))
- , m_sOrigURL(aOrigURL)
+bool isPowerPointFormat(const OUString& sExt)
{
+ return sExt.equalsIgnoreAsciiCase("PPTX") || sExt.equalsIgnoreAsciiCase("PPT")
+ || sExt.equalsIgnoreAsciiCase("ODP");
}
-MSODocumentLockFile::~MSODocumentLockFile() {}
-
-OUString MSODocumentLockFile::GenerateURL(const OUString& aOrigURL, const OUString& aPrefix)
+// Need to generate different lock file name for MSO.
+OUString GenerateMSOLockFileURL(const OUString& aOrigURL)
{
INetURLObject aURL = LockFileCommon::ResolveLinks(INetURLObject(aOrigURL));
// For text documents MSO Word cuts some of the first characters of the file name
OUString sFileName = aURL.GetName();
- if (isWordFormat(aOrigURL))
+ const OUString sExt = aURL.GetFileExtension();
+
+ if (isWordFormat(sExt))
{
- const sal_Int32 nFileNameLength
- = sFileName.getLength() - aURL.GetFileExtension().getLength() - 1;
+ const sal_Int32 nFileNameLength = sFileName.getLength() - sExt.getLength() - 1;
if (nFileNameLength >= 8)
sFileName = sFileName.copy(2);
else if (nFileNameLength == 7)
sFileName = sFileName.copy(1);
}
- aURL.SetName(aPrefix + sFileName);
+ aURL.SetName("~$" + sFileName);
return aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE);
}
+}
+
+// static
+MSODocumentLockFile::AppType MSODocumentLockFile::getAppType(const OUString& sOrigURL)
+{
+ AppType eResult = AppType::PowerPoint;
+ INetURLObject aDocURL = LockFileCommon::ResolveLinks(INetURLObject(sOrigURL));
+ const OUString sExt = aDocURL.GetFileExtension();
+ if (isWordFormat(sExt))
+ eResult = AppType::Word;
+ else if (isExcelFormat(sExt))
+ eResult = AppType::Excel;
+
+ return eResult;
+}
+
+MSODocumentLockFile::MSODocumentLockFile(const OUString& aOrigURL)
+ : GenDocumentLockFile(GenerateMSOLockFileURL(aOrigURL))
+ , m_eAppType(getAppType(aOrigURL))
+{
+}
+
+MSODocumentLockFile::~MSODocumentLockFile() {}
void MSODocumentLockFile::WriteEntryToStream(
const LockFileEntry& aEntry, const css::uno::Reference<css::io::XOutputStream>& xOutput)
@@ -82,8 +90,8 @@ void MSODocumentLockFile::WriteEntryToStream(
::osl::MutexGuard aGuard(m_aMutex);
// Reallocate the date with the right size, different lock file size for different components
- int nLockFileSize = isWordFormat(m_sOrigURL) ? MSO_WORD_LOCKFILE_SIZE
- : MSO_EXCEL_AND_POWERPOINT_LOCKFILE_SIZE;
+ int nLockFileSize = m_eAppType == AppType::Word ? MSO_WORD_LOCKFILE_SIZE
+ : MSO_EXCEL_AND_POWERPOINT_LOCKFILE_SIZE;
css::uno::Sequence<sal_Int8> aData(nLockFileSize);
// Write out the user name's length as a single byte integer
@@ -105,32 +113,26 @@ void MSODocumentLockFile::WriteEntryToStream(
}
// Fill up the remaining bytes with dummy data
- if (isWordFormat(m_sOrigURL))
+ switch (m_eAppType)
{
- while (nIndex < MSO_USERNAME_MAX_LENGTH + 2)
- {
+ case AppType::Word:
+ while (nIndex < MSO_USERNAME_MAX_LENGTH + 2)
+ {
+ aData[nIndex] = static_cast<sal_Int8>(0);
+ ++nIndex;
+ }
+ break;
+ case AppType::PowerPoint:
aData[nIndex] = static_cast<sal_Int8>(0);
++nIndex;
- }
- }
- else if (isExcelFormat(m_sOrigURL))
- {
- while (nIndex < MSO_USERNAME_MAX_LENGTH + 3)
- {
- aData[nIndex] = static_cast<sal_Int8>(0x20);
- ++nIndex;
- }
- }
- else
- {
- aData[nIndex] = static_cast<sal_Int8>(0);
- ++nIndex;
-
- while (nIndex < MSO_USERNAME_MAX_LENGTH + 3)
- {
- aData[nIndex] = static_cast<sal_Int8>(0x20);
- ++nIndex;
- }
+ [[fallthrough]];
+ case AppType::Excel:
+ while (nIndex < MSO_USERNAME_MAX_LENGTH + 3)
+ {
+ aData[nIndex] = static_cast<sal_Int8>(0x20);
+ ++nIndex;
+ }
+ break;
}
// At the next position we have the user name's length again, but now as a 2 byte integer
@@ -150,26 +152,28 @@ void MSODocumentLockFile::WriteEntryToStream(
}
// Fill the remaining part with dummy bits
- if (isWordFormat(m_sOrigURL))
+ switch (m_eAppType)
{
- while (nIndex < nLockFileSize)
- {
- aData[nIndex] = static_cast<sal_Int8>(0);
- ++nIndex;
- }
- }
- else
- {
- while (nIndex < nLockFileSize)
- {
- aData[nIndex] = static_cast<sal_Int8>(0x20);
- ++nIndex;
- if (nIndex < nLockFileSize)
+ case AppType::Word:
+ while (nIndex < nLockFileSize)
{
aData[nIndex] = static_cast<sal_Int8>(0);
++nIndex;
}
- }
+ break;
+ case AppType::Excel:
+ case AppType::PowerPoint:
+ while (nIndex < nLockFileSize)
+ {
+ aData[nIndex] = static_cast<sal_Int8>(0x20);
+ ++nIndex;
+ if (nIndex < nLockFileSize)
+ {
+ aData[nIndex] = static_cast<sal_Int8>(0);
+ ++nIndex;
+ }
+ }
+ break;
}
xOutput->writeBytes(aData);
@@ -248,7 +252,10 @@ void MSODocumentLockFile::RemoveFile()
bool MSODocumentLockFile::IsMSOSupportedFileFormat(const OUString& aURL)
{
- return isWordFormat(aURL) || isExcelFormat(aURL) || isPowerPointFormat(aURL);
+ INetURLObject aDocURL = LockFileCommon::ResolveLinks(INetURLObject(aURL));
+ const OUString sExt = aDocURL.GetFileExtension();
+
+ return isWordFormat(sExt) || isExcelFormat(sExt) || isPowerPointFormat(sExt);
}
} // namespace svt
diff --git a/svl/source/misc/sharecontrolfile.cxx b/svl/source/misc/sharecontrolfile.cxx
index 26e8015b6d06..d4c8ef794687 100644
--- a/svl/source/misc/sharecontrolfile.cxx
+++ b/svl/source/misc/sharecontrolfile.cxx
@@ -53,7 +53,7 @@ namespace svt {
ShareControlFile::ShareControlFile( const OUString& aOrigURL )
-: LockFileCommon( aOrigURL, ".~sharing." )
+ : LockFileCommon(GenerateOwnLockFileURL(aOrigURL, ".~sharing."))
{
if ( !m_xStream.is() && !GetURL().isEmpty() )
{