diff options
author | Tamás Zolnai <tamas.zolnai@collabora.com> | 2019-03-23 15:53:27 +0100 |
---|---|---|
committer | Tamás Zolnai <tamas.zolnai@collabora.com> | 2019-03-23 20:11:33 +0100 |
commit | 5db1e20b8b0942dac2d50f3cd34532bb61147020 (patch) | |
tree | f0b4d4de9980308e6ebeebcb33030a6b2ac7352e /include | |
parent | 0ed7e590746db719f15b97a5d9cfca9b1ad3c773 (diff) |
Introduce new lockfile handler for MSO like lockfiles
* Implement writing of MSO lockfiles
* Grab the already implemented parsing code (tryMSOwnerFile method)
and put it together into one class
* Add tests about the generated URL for lockfiles and the lockfile content
* MSO lockfiles are not written yet by LO, next step is to integrate
this code into the locking mechanism.
Change-Id: I3b0ed1975cd57dfd006d4e1890b23c307890de5c
Reviewed-on: https://gerrit.libreoffice.org/69582
Tested-by: Jenkins
Reviewed-by: Tamás Zolnai <tamas.zolnai@collabora.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/svl/documentlockfile.hxx | 36 | ||||
-rw-r--r-- | include/svl/lockfilecommon.hxx | 21 | ||||
-rw-r--r-- | include/svl/msodocumentlockfile.hxx | 82 | ||||
-rw-r--r-- | include/svl/sharecontrolfile.hxx | 2 |
4 files changed, 126 insertions, 15 deletions
diff --git a/include/svl/documentlockfile.hxx b/include/svl/documentlockfile.hxx index f91aa352c56e..87334e4b73e7 100644 --- a/include/svl/documentlockfile.hxx +++ b/include/svl/documentlockfile.hxx @@ -29,23 +29,41 @@ namespace com { namespace sun { namespace star { namespace io { class XOutputStr namespace svt { -class SVL_DLLPUBLIC DocumentLockFile : public LockFileCommon +/// Generalized class for LO and MSO lockfile handling. +class SVL_DLLPUBLIC GenDocumentLockFile : public LockFileCommon { - css::uno::Reference< css::io::XInputStream > OpenStream(); - - void WriteEntryToStream( const LockFileEntry& aEntry, const css::uno::Reference< css::io::XOutputStream >& xStream ); - public: - DocumentLockFile( const OUString& aOrigURL ); - ~DocumentLockFile(); + /// 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 ); + virtual ~GenDocumentLockFile() override; bool CreateOwnLockFile(); - LockFileEntry GetLockData(); bool OverwriteOwnLockFile(); /// Delete the Lockfile, if current user is the owner - void RemoveFile(); + virtual void RemoveFile(); /// Only delete lockfile, disregarding ownership void RemoveFileDirectly(); + + virtual LockFileEntry GetLockData() = 0; + +protected: + virtual void WriteEntryToStream( const LockFileEntry& aEntry, const css::uno::Reference< css::io::XOutputStream >& xStream ) = 0; + css::uno::Reference< css::io::XInputStream > OpenStream(); +}; + +/// Class implementing reading and writing LO lockfiles. +class SVL_DLLPUBLIC DocumentLockFile : public GenDocumentLockFile +{ +protected: + virtual void WriteEntryToStream( const LockFileEntry& aEntry, const css::uno::Reference< css::io::XOutputStream >& xStream ) override; + +public: + DocumentLockFile( const OUString& aOrigURL ); + virtual ~DocumentLockFile() override; + + virtual LockFileEntry GetLockData() override; }; } diff --git a/include/svl/lockfilecommon.hxx b/include/svl/lockfilecommon.hxx index 4c5c6b5fe2e7..e99ed64d7f36 100644 --- a/include/svl/lockfilecommon.hxx +++ b/include/svl/lockfilecommon.hxx @@ -38,18 +38,27 @@ typedef o3tl::enumarray<LockFileComponent,OUString> LockFileEntry; namespace svt { -// This is a general implementation that is used in document lock file implementation and in sharing control file implementation +/// This is a general implementation that is used in document lock file implementation and in sharing control file implementation class SVL_DLLPUBLIC LockFileCommon { -protected: - ::osl::Mutex m_aMutex; +private: OUString m_aURL; - INetURLObject ResolveLinks( const INetURLObject& aDocURL ) const; +protected: + ::osl::Mutex m_aMutex; 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(); + 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 ); @@ -58,6 +67,8 @@ public: static OUString GetOOOUserName(); static OUString GetCurrentLocalTime(); static LockFileEntry GenerateOwnEntry(); + + INetURLObject ResolveLinks( const INetURLObject& aDocURL ) const; }; } diff --git a/include/svl/msodocumentlockfile.hxx b/include/svl/msodocumentlockfile.hxx new file mode 100644 index 000000000000..5a6753389370 --- /dev/null +++ b/include/svl/msodocumentlockfile.hxx @@ -0,0 +1,82 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_SVL_MSODOCUMENTLOCKFILE_HXX +#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 + +namespace svt +{ +/// Class implementing reading and writing MSO lockfiles. +class SVL_DLLPUBLIC MSODocumentLockFile : public GenDocumentLockFile +{ +private: + OUString m_sOrigURL; + + bool isWordFormat(const OUString& aOrigURL) const; + bool isExcelFormat(const OUString& aOrigURL) const; + bool isPowerPointFormat(const OUString& aOrigURL) const; + +protected: + virtual void + WriteEntryToStream(const LockFileEntry& aEntry, + const css::uno::Reference<css::io::XOutputStream>& xStream) override; + +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; +}; +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/include/svl/sharecontrolfile.hxx b/include/svl/sharecontrolfile.hxx index 8dfa91669ddc..dd52d48da8f7 100644 --- a/include/svl/sharecontrolfile.hxx +++ b/include/svl/sharecontrolfile.hxx @@ -53,7 +53,7 @@ public: // The constructor will throw exception in case the stream can not be opened ShareControlFile( const OUString& aOrigURL ); - ~ShareControlFile(); + virtual ~ShareControlFile() override; std::vector< LockFileEntry > GetUsersData(); void SetUsersDataAndStore( const std::vector< LockFileEntry >& aUserNames ); |