[Libreoffice-commits] core.git: include/svl svl/source
Mike Kaganski (via logerrit)
logerrit at kemper.freedesktop.org
Sat Mar 30 16:17:03 UTC 2019
include/svl/documentlockfile.hxx | 5 -
include/svl/lockfilecommon.hxx | 11 --
include/svl/msodocumentlockfile.hxx | 44 +--------
svl/source/misc/documentlockfile.cxx | 12 --
svl/source/misc/lockfilecommon.cxx | 22 +---
svl/source/misc/msodocumentlockfile.cxx | 153 ++++++++++++++++----------------
svl/source/misc/sharecontrolfile.cxx | 2
7 files changed, 103 insertions(+), 146 deletions(-)
New commits:
commit 49696cc78fefa6d7f1c27a722b576c8d749c20d6
Author: Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Sat Mar 30 15:33:41 2019 +0300
Commit: Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Sat Mar 30 17:16:42 2019 +0100
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 at collabora.com>
diff --git a/include/svl/documentlockfile.hxx b/include/svl/documentlockfile.hxx
index 79bb087c8362..e38a9af1646a 100644
--- a/include/svl/documentlockfile.hxx
+++ b/include/svl/documentlockfile.hxx
@@ -33,10 +33,7 @@ namespace svt {
class SVL_DLLPUBLIC GenDocumentLockFile : public LockFileCommon
{
public:
- /// Specify the lockfile URL directly
- GenDocumentLockFile( const OUString& aURL );
- /// Let the object generate and own URL based on the original file's URL and a prefix
- GenDocumentLockFile( const OUString& aOrigURL, const OUString& aPrefix );
+ GenDocumentLockFile(const OUString& aLockFileURL);
virtual ~GenDocumentLockFile() override;
bool CreateOwnLockFile();
diff --git a/include/svl/lockfilecommon.hxx b/include/svl/lockfilecommon.hxx
index 97210d010279..77349c48a4a4 100644
--- a/include/svl/lockfilecommon.hxx
+++ b/include/svl/lockfilecommon.hxx
@@ -47,19 +47,16 @@ private:
protected:
::osl::Mutex m_aMutex;
+ /// This method generates the URL of the lock file based on the document URL and the specified prefix.
+ static OUString GenerateOwnLockFileURL(const OUString& aOrigURL, const OUString& aPrefix);
+
public:
- /// Specify the lockfile URL directly
- LockFileCommon( const OUString& aURL );
- /// Let the object generate and own URL based on the original file's URL and a prefix
- LockFileCommon( const OUString& aOrigURL, const OUString& aPrefix );
+ LockFileCommon(const OUString& aLockFileURL);
virtual ~LockFileCommon();
const OUString& GetURL() const;
void SetURL(const OUString& aURL);
- /// This method generates the URL of the lock file based on the document URL and the specified prefix.
- virtual OUString GenerateURL( const OUString& aOrigURL, const OUString& aPrefix );
-
static void ParseList( const css::uno::Sequence< sal_Int8 >& aBuffer, std::vector< LockFileEntry > &rOutput );
static LockFileEntry ParseEntry( const css::uno::Sequence< sal_Int8 >& aBuffer, sal_Int32& o_nCurPos );
static OUString ParseName( const css::uno::Sequence< sal_Int8 >& aBuffer, sal_Int32& o_nCurPos );
diff --git a/include/svl/msodocumentlockfile.hxx b/include/svl/msodocumentlockfile.hxx
index cd0db0ffb6d9..322972fefe25 100644
--- a/include/svl/msodocumentlockfile.hxx
+++ b/include/svl/msodocumentlockfile.hxx
@@ -11,38 +11,10 @@
#define INCLUDED_SVL_MSODOCUMENTLOCKFILE_HXX
#include <svl/svldllapi.h>
-#include <svl/lockfilecommon.hxx>
#include <svl/documentlockfile.hxx>
#include <com/sun/star/lang/XComponent.hpp>
-namespace com
-{
-namespace sun
-{
-namespace star
-{
-namespace io
-{
-class XInputStream;
-}
-}
-}
-}
-namespace com
-{
-namespace sun
-{
-namespace star
-{
-namespace io
-{
-class XOutputStream;
-}
-}
-}
-}
-
#define MSO_WORD_LOCKFILE_SIZE 162
#define MSO_EXCEL_AND_POWERPOINT_LOCKFILE_SIZE 165
#define MSO_USERNAME_MAX_LENGTH 52
@@ -53,11 +25,14 @@ namespace svt
class SVL_DLLPUBLIC MSODocumentLockFile : public GenDocumentLockFile
{
private:
- OUString m_sOrigURL;
-
- static bool isWordFormat(const OUString& aOrigURL);
- static bool isExcelFormat(const OUString& aOrigURL);
- static bool isPowerPointFormat(const OUString& aOrigURL);
+ enum class AppType
+ {
+ Word,
+ Excel,
+ PowerPoint
+ };
+ static AppType getAppType(const OUString& sOrigURL);
+ AppType m_eAppType;
protected:
virtual void
@@ -70,9 +45,6 @@ public:
MSODocumentLockFile(const OUString& aOrigURL);
virtual ~MSODocumentLockFile() override;
- /// Need to generate different lock file name for MSO.
- virtual OUString GenerateURL(const OUString& aOrigURL, const OUString& aPrefix) override;
-
virtual LockFileEntry GetLockData() override;
virtual void RemoveFile() override;
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() )
{
More information about the Libreoffice-commits
mailing list