Kaydet (Commit) 49696cc7 authored tarafından Mike Kaganski's avatar Mike Kaganski

Some refactor of lockfile classes to minimize interface

Change-Id: Icc67c31d6a2351b6504429e25067c25353233f5f
Reviewed-on: https://gerrit.libreoffice.org/69947
Tested-by: Jenkins
Reviewed-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
üst 107fd827
...@@ -33,10 +33,7 @@ namespace svt { ...@@ -33,10 +33,7 @@ namespace svt {
class SVL_DLLPUBLIC GenDocumentLockFile : public LockFileCommon class SVL_DLLPUBLIC GenDocumentLockFile : public LockFileCommon
{ {
public: public:
/// Specify the lockfile URL directly GenDocumentLockFile(const OUString& aLockFileURL);
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 );
virtual ~GenDocumentLockFile() override; virtual ~GenDocumentLockFile() override;
bool CreateOwnLockFile(); bool CreateOwnLockFile();
......
...@@ -47,19 +47,16 @@ private: ...@@ -47,19 +47,16 @@ private:
protected: protected:
::osl::Mutex m_aMutex; ::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: public:
/// Specify the lockfile URL directly LockFileCommon(const OUString& aLockFileURL);
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 );
virtual ~LockFileCommon(); virtual ~LockFileCommon();
const OUString& GetURL() const; const OUString& GetURL() const;
void SetURL(const OUString& aURL); 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 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 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 ); static OUString ParseName( const css::uno::Sequence< sal_Int8 >& aBuffer, sal_Int32& o_nCurPos );
......
...@@ -11,38 +11,10 @@ ...@@ -11,38 +11,10 @@
#define INCLUDED_SVL_MSODOCUMENTLOCKFILE_HXX #define INCLUDED_SVL_MSODOCUMENTLOCKFILE_HXX
#include <svl/svldllapi.h> #include <svl/svldllapi.h>
#include <svl/lockfilecommon.hxx>
#include <svl/documentlockfile.hxx> #include <svl/documentlockfile.hxx>
#include <com/sun/star/lang/XComponent.hpp> #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_WORD_LOCKFILE_SIZE 162
#define MSO_EXCEL_AND_POWERPOINT_LOCKFILE_SIZE 165 #define MSO_EXCEL_AND_POWERPOINT_LOCKFILE_SIZE 165
#define MSO_USERNAME_MAX_LENGTH 52 #define MSO_USERNAME_MAX_LENGTH 52
...@@ -53,11 +25,14 @@ namespace svt ...@@ -53,11 +25,14 @@ namespace svt
class SVL_DLLPUBLIC MSODocumentLockFile : public GenDocumentLockFile class SVL_DLLPUBLIC MSODocumentLockFile : public GenDocumentLockFile
{ {
private: private:
OUString m_sOrigURL; enum class AppType
{
static bool isWordFormat(const OUString& aOrigURL); Word,
static bool isExcelFormat(const OUString& aOrigURL); Excel,
static bool isPowerPointFormat(const OUString& aOrigURL); PowerPoint
};
static AppType getAppType(const OUString& sOrigURL);
AppType m_eAppType;
protected: protected:
virtual void virtual void
...@@ -70,9 +45,6 @@ public: ...@@ -70,9 +45,6 @@ public:
MSODocumentLockFile(const OUString& aOrigURL); MSODocumentLockFile(const OUString& aOrigURL);
virtual ~MSODocumentLockFile() override; 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 LockFileEntry GetLockData() override;
virtual void RemoveFile() override; virtual void RemoveFile() override;
......
...@@ -54,14 +54,8 @@ using namespace ::com::sun::star; ...@@ -54,14 +54,8 @@ using namespace ::com::sun::star;
namespace svt { namespace svt {
GenDocumentLockFile::GenDocumentLockFile( const OUString& aURL ) GenDocumentLockFile::GenDocumentLockFile(const OUString& aLockFileURL)
: LockFileCommon( aURL ) : LockFileCommon(aLockFileURL)
{
}
GenDocumentLockFile::GenDocumentLockFile( const OUString& aOrigURL, const OUString& aPrefix )
: LockFileCommon( aOrigURL, aPrefix )
{ {
} }
...@@ -179,7 +173,7 @@ void GenDocumentLockFile::RemoveFileDirectly() ...@@ -179,7 +173,7 @@ void GenDocumentLockFile::RemoveFileDirectly()
DocumentLockFile::DocumentLockFile( const OUString& aOrigURL ) DocumentLockFile::DocumentLockFile( const OUString& aOrigURL )
: GenDocumentLockFile( aOrigURL, ".~lock." ) : GenDocumentLockFile(GenerateOwnLockFileURL(aOrigURL, ".~lock."))
{ {
} }
......
...@@ -54,17 +54,11 @@ using namespace ::com::sun::star; ...@@ -54,17 +54,11 @@ using namespace ::com::sun::star;
namespace svt { 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() LockFileCommon::~LockFileCommon()
{ {
} }
...@@ -82,15 +76,11 @@ void LockFileCommon::SetURL(const OUString& aURL) ...@@ -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 ) ); INetURLObject aURL = ResolveLinks(INetURLObject(aOrigURL));
aURL.SetName(aPrefix + aURL.GetName() + "%23" /*'#'*/);
OUString aShareURLString = aDocURL.GetPartBeforeLastName(); return aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE);
aShareURLString += aPrefix;
aShareURLString += aDocURL.GetName();
aShareURLString += "%23"; // '#'
return INetURLObject( aShareURLString ).GetMainURL( INetURLObject::DecodeMechanism::NONE );
} }
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
*/ */
#include <svl/msodocumentlockfile.hxx> #include <svl/msodocumentlockfile.hxx>
#include <rtl/ustring.hxx>
#include <sal/log.hxx> #include <sal/log.hxx>
#include <algorithm> #include <algorithm>
#include <ucbhelper/content.hxx> #include <ucbhelper/content.hxx>
...@@ -21,60 +20,69 @@ ...@@ -21,60 +20,69 @@
namespace svt namespace svt
{ {
bool MSODocumentLockFile::isWordFormat(const OUString& aOrigURL) namespace
{ {
INetURLObject aDocURL = LockFileCommon::ResolveLinks(INetURLObject(aOrigURL)); bool isWordFormat(const OUString& sExt)
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)
{ {
INetURLObject aDocURL = LockFileCommon::ResolveLinks(INetURLObject(aOrigURL)); return sExt.equalsIgnoreAsciiCase("DOC") || sExt.equalsIgnoreAsciiCase("DOCX")
|| sExt.equalsIgnoreAsciiCase("RTF") || sExt.equalsIgnoreAsciiCase("ODT");
return //aDocURL.GetFileExtension().compareToIgnoreAsciiCase("XLS") || // MSO does not create lockfile for XLS
aDocURL.GetFileExtension().compareToIgnoreAsciiCase("XLSX") == 0
|| aDocURL.GetFileExtension().compareToIgnoreAsciiCase("ODS") == 0;
} }
bool MSODocumentLockFile::isPowerPointFormat(const OUString& aOrigURL) bool isExcelFormat(const OUString& sExt)
{ {
INetURLObject aDocURL = LockFileCommon::ResolveLinks(INetURLObject(aOrigURL)); return //sExt.equalsIgnoreAsciiCase("XLS") || // MSO does not create lockfile for XLS
sExt.equalsIgnoreAsciiCase("XLSX") || sExt.equalsIgnoreAsciiCase("ODS");
return aDocURL.GetFileExtension().compareToIgnoreAsciiCase("PPTX") == 0
|| aDocURL.GetFileExtension().compareToIgnoreAsciiCase("PPT") == 0
|| aDocURL.GetFileExtension().compareToIgnoreAsciiCase("ODP") == 0;
} }
MSODocumentLockFile::MSODocumentLockFile(const OUString& aOrigURL) bool isPowerPointFormat(const OUString& sExt)
: GenDocumentLockFile(GenerateURL(aOrigURL, "~$"))
, m_sOrigURL(aOrigURL)
{ {
return sExt.equalsIgnoreAsciiCase("PPTX") || sExt.equalsIgnoreAsciiCase("PPT")
|| sExt.equalsIgnoreAsciiCase("ODP");
} }
MSODocumentLockFile::~MSODocumentLockFile() {} // Need to generate different lock file name for MSO.
OUString GenerateMSOLockFileURL(const OUString& aOrigURL)
OUString MSODocumentLockFile::GenerateURL(const OUString& aOrigURL, const OUString& aPrefix)
{ {
INetURLObject aURL = LockFileCommon::ResolveLinks(INetURLObject(aOrigURL)); INetURLObject aURL = LockFileCommon::ResolveLinks(INetURLObject(aOrigURL));
// For text documents MSO Word cuts some of the first characters of the file name // For text documents MSO Word cuts some of the first characters of the file name
OUString sFileName = aURL.GetName(); OUString sFileName = aURL.GetName();
if (isWordFormat(aOrigURL)) const OUString sExt = aURL.GetFileExtension();
if (isWordFormat(sExt))
{ {
const sal_Int32 nFileNameLength const sal_Int32 nFileNameLength = sFileName.getLength() - sExt.getLength() - 1;
= sFileName.getLength() - aURL.GetFileExtension().getLength() - 1;
if (nFileNameLength >= 8) if (nFileNameLength >= 8)
sFileName = sFileName.copy(2); sFileName = sFileName.copy(2);
else if (nFileNameLength == 7) else if (nFileNameLength == 7)
sFileName = sFileName.copy(1); sFileName = sFileName.copy(1);
} }
aURL.SetName(aPrefix + sFileName); aURL.SetName("~$" + sFileName);
return aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE); 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( void MSODocumentLockFile::WriteEntryToStream(
const LockFileEntry& aEntry, const css::uno::Reference<css::io::XOutputStream>& xOutput) const LockFileEntry& aEntry, const css::uno::Reference<css::io::XOutputStream>& xOutput)
...@@ -82,8 +90,8 @@ void MSODocumentLockFile::WriteEntryToStream( ...@@ -82,8 +90,8 @@ void MSODocumentLockFile::WriteEntryToStream(
::osl::MutexGuard aGuard(m_aMutex); ::osl::MutexGuard aGuard(m_aMutex);
// Reallocate the date with the right size, different lock file size for different components // Reallocate the date with the right size, different lock file size for different components
int nLockFileSize = isWordFormat(m_sOrigURL) ? MSO_WORD_LOCKFILE_SIZE int nLockFileSize = m_eAppType == AppType::Word ? MSO_WORD_LOCKFILE_SIZE
: MSO_EXCEL_AND_POWERPOINT_LOCKFILE_SIZE; : MSO_EXCEL_AND_POWERPOINT_LOCKFILE_SIZE;
css::uno::Sequence<sal_Int8> aData(nLockFileSize); css::uno::Sequence<sal_Int8> aData(nLockFileSize);
// Write out the user name's length as a single byte integer // Write out the user name's length as a single byte integer
...@@ -105,32 +113,26 @@ void MSODocumentLockFile::WriteEntryToStream( ...@@ -105,32 +113,26 @@ void MSODocumentLockFile::WriteEntryToStream(
} }
// Fill up the remaining bytes with dummy data // 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); aData[nIndex] = static_cast<sal_Int8>(0);
++nIndex; ++nIndex;
} [[fallthrough]];
} case AppType::Excel:
else if (isExcelFormat(m_sOrigURL)) while (nIndex < MSO_USERNAME_MAX_LENGTH + 3)
{ {
while (nIndex < MSO_USERNAME_MAX_LENGTH + 3) aData[nIndex] = static_cast<sal_Int8>(0x20);
{ ++nIndex;
aData[nIndex] = static_cast<sal_Int8>(0x20); }
++nIndex; break;
}
}
else
{
aData[nIndex] = static_cast<sal_Int8>(0);
++nIndex;
while (nIndex < MSO_USERNAME_MAX_LENGTH + 3)
{
aData[nIndex] = static_cast<sal_Int8>(0x20);
++nIndex;
}
} }
// At the next position we have the user name's length again, but now as a 2 byte integer // 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( ...@@ -150,26 +152,28 @@ void MSODocumentLockFile::WriteEntryToStream(
} }
// Fill the remaining part with dummy bits // Fill the remaining part with dummy bits
if (isWordFormat(m_sOrigURL)) switch (m_eAppType)
{ {
while (nIndex < nLockFileSize) case AppType::Word:
{ 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)
{ {
aData[nIndex] = static_cast<sal_Int8>(0); aData[nIndex] = static_cast<sal_Int8>(0);
++nIndex; ++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); xOutput->writeBytes(aData);
...@@ -248,7 +252,10 @@ void MSODocumentLockFile::RemoveFile() ...@@ -248,7 +252,10 @@ void MSODocumentLockFile::RemoveFile()
bool MSODocumentLockFile::IsMSOSupportedFileFormat(const OUString& aURL) 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 } // namespace svt
......
...@@ -53,7 +53,7 @@ namespace svt { ...@@ -53,7 +53,7 @@ namespace svt {
ShareControlFile::ShareControlFile( const OUString& aOrigURL ) ShareControlFile::ShareControlFile( const OUString& aOrigURL )
: LockFileCommon( aOrigURL, ".~sharing." ) : LockFileCommon(GenerateOwnLockFileURL(aOrigURL, ".~sharing."))
{ {
if ( !m_xStream.is() && !GetURL().isEmpty() ) if ( !m_xStream.is() && !GetURL().isEmpty() )
{ {
......
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