Kaydet (Commit) 5db1e20b authored tarafından Tamás Zolnai's avatar Tamás Zolnai

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: 's avatarTamás Zolnai <tamas.zolnai@collabora.com>
üst 0ed7e590
...@@ -29,23 +29,41 @@ namespace com { namespace sun { namespace star { namespace io { class XOutputStr ...@@ -29,23 +29,41 @@ namespace com { namespace sun { namespace star { namespace io { class XOutputStr
namespace svt { 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: public:
DocumentLockFile( const OUString& aOrigURL ); /// Specify the lockfile URL directly
~DocumentLockFile(); 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(); bool CreateOwnLockFile();
LockFileEntry GetLockData();
bool OverwriteOwnLockFile(); bool OverwriteOwnLockFile();
/// Delete the Lockfile, if current user is the owner /// Delete the Lockfile, if current user is the owner
void RemoveFile(); virtual void RemoveFile();
/// Only delete lockfile, disregarding ownership /// Only delete lockfile, disregarding ownership
void RemoveFileDirectly(); 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;
}; };
} }
......
...@@ -38,18 +38,27 @@ typedef o3tl::enumarray<LockFileComponent,OUString> LockFileEntry; ...@@ -38,18 +38,27 @@ typedef o3tl::enumarray<LockFileComponent,OUString> LockFileEntry;
namespace svt { 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 class SVL_DLLPUBLIC LockFileCommon
{ {
protected: private:
::osl::Mutex m_aMutex;
OUString m_aURL; OUString m_aURL;
INetURLObject ResolveLinks( const INetURLObject& aDocURL ) const; protected:
::osl::Mutex m_aMutex;
public: 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& 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 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 );
...@@ -58,6 +67,8 @@ public: ...@@ -58,6 +67,8 @@ public:
static OUString GetOOOUserName(); static OUString GetOOOUserName();
static OUString GetCurrentLocalTime(); static OUString GetCurrentLocalTime();
static LockFileEntry GenerateOwnEntry(); static LockFileEntry GenerateOwnEntry();
INetURLObject ResolveLinks( const INetURLObject& aDocURL ) const;
}; };
} }
......
/* -*- 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: */
...@@ -53,7 +53,7 @@ public: ...@@ -53,7 +53,7 @@ public:
// The constructor will throw exception in case the stream can not be opened // The constructor will throw exception in case the stream can not be opened
ShareControlFile( const OUString& aOrigURL ); ShareControlFile( const OUString& aOrigURL );
~ShareControlFile(); virtual ~ShareControlFile() override;
std::vector< LockFileEntry > GetUsersData(); std::vector< LockFileEntry > GetUsersData();
void SetUsersDataAndStore( const std::vector< LockFileEntry >& aUserNames ); void SetUsersDataAndStore( const std::vector< LockFileEntry >& aUserNames );
......
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t; 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/.
#
$(eval $(call gb_CppunitTest_CppunitTest,svl_lockfiles))
$(eval $(call gb_CppunitTest_use_sdk_api,svl_lockfiles))
$(eval $(call gb_CppunitTest_use_api,svl_lockfiles,\
udkapi \
offapi \
oovbaapi \
))
$(eval $(call gb_CppunitTest_use_ure,svl_lockfiles))
$(eval $(call gb_CppunitTest_use_vcl,svl_lockfiles))
$(eval $(call gb_CppunitTest_add_exception_objects,svl_lockfiles, \
svl/qa/unit/lockfiles/test_lockfiles \
))
$(eval $(call gb_CppunitTest_use_libraries,svl_lockfiles, \
comphelper \
cppu \
cppuhelper \
tl \
sal \
svl \
svt \
sw \
test \
unotest \
utl \
vcl \
))
$(eval $(call gb_CppunitTest_use_rdb,svl_lockfiles,services))
$(eval $(call gb_CppunitTest_use_custom_headers,svl_lockfiles,\
officecfg/registry \
))
$(eval $(call gb_CppunitTest_use_configuration,svl_lockfiles))
# vim: set noet sw=4 ts=4:
...@@ -158,7 +158,8 @@ $(eval $(call gb_Library_add_exception_objects,svl,\ ...@@ -158,7 +158,8 @@ $(eval $(call gb_Library_add_exception_objects,svl,\
svl/source/misc/PasswordHelper \ svl/source/misc/PasswordHelper \
svl/source/misc/adrparse \ svl/source/misc/adrparse \
$(if $(filter DESKTOP,$(BUILD_TYPE)),\ $(if $(filter DESKTOP,$(BUILD_TYPE)),\
svl/source/misc/documentlockfile) \ svl/source/misc/documentlockfile \
svl/source/misc/msodocumentlockfile) \
svl/source/misc/filenotation \ svl/source/misc/filenotation \
svl/source/misc/fstathelper \ svl/source/misc/fstathelper \
svl/source/misc/getstringresource \ svl/source/misc/getstringresource \
......
...@@ -34,6 +34,7 @@ $(eval $(call gb_Module_add_check_targets,svl,\ ...@@ -34,6 +34,7 @@ $(eval $(call gb_Module_add_check_targets,svl,\
CppunitTest_svl_itempool \ CppunitTest_svl_itempool \
CppunitTest_svl_items \ CppunitTest_svl_items \
CppunitTest_svl_lngmisc \ CppunitTest_svl_lngmisc \
CppunitTest_svl_lockfiles \
CppunitTest_svl_notify \ CppunitTest_svl_notify \
CppunitTest_svl_qa_cppunit \ CppunitTest_svl_qa_cppunit \
CppunitTest_svl_urihelper \ CppunitTest_svl_urihelper \
......
This diff is collapsed.
...@@ -54,39 +54,34 @@ using namespace ::com::sun::star; ...@@ -54,39 +54,34 @@ using namespace ::com::sun::star;
namespace svt { namespace svt {
DocumentLockFile::DocumentLockFile( const OUString& aOrigURL ) GenDocumentLockFile::GenDocumentLockFile( const OUString& aURL )
: LockFileCommon( aOrigURL, ".~lock." ) : LockFileCommon( aURL )
{ {
} }
DocumentLockFile::~DocumentLockFile() GenDocumentLockFile::GenDocumentLockFile( const OUString& aOrigURL, const OUString& aPrefix )
: LockFileCommon( aOrigURL, aPrefix )
{ {
} }
void DocumentLockFile::WriteEntryToStream( const LockFileEntry& aEntry, const uno::Reference< io::XOutputStream >& xOutput ) GenDocumentLockFile::~GenDocumentLockFile()
{ {
::osl::MutexGuard aGuard( m_aMutex ); }
OUStringBuffer aBuffer; uno::Reference< io::XInputStream > GenDocumentLockFile::OpenStream()
{
::osl::MutexGuard aGuard( m_aMutex );
for ( LockFileComponent lft : o3tl::enumrange<LockFileComponent>() ) uno::Reference < css::ucb::XCommandEnvironment > xEnv;
{ ::ucbhelper::Content aSourceContent( GetURL(), xEnv, comphelper::getProcessComponentContext() );
aBuffer.append( EscapeCharacters( aEntry[lft] ) );
if ( lft < LockFileComponent::LAST )
aBuffer.append( ',' );
else
aBuffer.append( ';' );
}
OString aStringData( OUStringToOString( aBuffer.makeStringAndClear(), RTL_TEXTENCODING_UTF8 ) ); // the file can be opened readonly, no locking will be done
uno::Sequence< sal_Int8 > aData( reinterpret_cast<sal_Int8 const *>(aStringData.getStr()), aStringData.getLength() ); return aSourceContent.openStream();
xOutput->writeBytes( aData );
} }
bool GenDocumentLockFile::CreateOwnLockFile()
bool DocumentLockFile::CreateOwnLockFile()
{ {
::osl::MutexGuard aGuard( m_aMutex ); ::osl::MutexGuard aGuard( m_aMutex );
...@@ -110,7 +105,7 @@ bool DocumentLockFile::CreateOwnLockFile() ...@@ -110,7 +105,7 @@ bool DocumentLockFile::CreateOwnLockFile()
xSeekable->seek( 0 ); xSeekable->seek( 0 );
uno::Reference < css::ucb::XCommandEnvironment > xEnv; uno::Reference < css::ucb::XCommandEnvironment > xEnv;
::ucbhelper::Content aTargetContent( m_aURL, xEnv, comphelper::getProcessComponentContext() ); ::ucbhelper::Content aTargetContent( GetURL(), xEnv, comphelper::getProcessComponentContext() );
ucb::InsertCommandArgument aInsertArg; ucb::InsertCommandArgument aInsertArg;
aInsertArg.Data = xInput; aInsertArg.Data = xInput;
...@@ -132,50 +127,13 @@ bool DocumentLockFile::CreateOwnLockFile() ...@@ -132,50 +127,13 @@ bool DocumentLockFile::CreateOwnLockFile()
return true; return true;
} }
bool GenDocumentLockFile::OverwriteOwnLockFile()
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()
{ {
// allows to overwrite the lock file with the current data // allows to overwrite the lock file with the current data
try try
{ {
uno::Reference < css::ucb::XCommandEnvironment > xEnv; uno::Reference < css::ucb::XCommandEnvironment > xEnv;
::ucbhelper::Content aTargetContent( m_aURL, xEnv, comphelper::getProcessComponentContext() ); ::ucbhelper::Content aTargetContent( GetURL(), xEnv, comphelper::getProcessComponentContext() );
LockFileEntry aNewEntry = GenerateOwnEntry(); LockFileEntry aNewEntry = GenerateOwnEntry();
...@@ -195,8 +153,7 @@ bool DocumentLockFile::OverwriteOwnLockFile() ...@@ -195,8 +153,7 @@ bool DocumentLockFile::OverwriteOwnLockFile()
return true; return true;
} }
void GenDocumentLockFile::RemoveFile()
void DocumentLockFile::RemoveFile()
{ {
::osl::MutexGuard aGuard( m_aMutex ); ::osl::MutexGuard aGuard( m_aMutex );
...@@ -212,15 +169,71 @@ void DocumentLockFile::RemoveFile() ...@@ -212,15 +169,71 @@ void DocumentLockFile::RemoveFile()
RemoveFileDirectly(); RemoveFileDirectly();
} }
void DocumentLockFile::RemoveFileDirectly() void GenDocumentLockFile::RemoveFileDirectly()
{ {
uno::Reference < css::ucb::XCommandEnvironment > xEnv; uno::Reference < css::ucb::XCommandEnvironment > xEnv;
::ucbhelper::Content aCnt(m_aURL, xEnv, comphelper::getProcessComponentContext()); ::ucbhelper::Content aCnt(GetURL(), xEnv, comphelper::getProcessComponentContext());
aCnt.executeCommand("delete", aCnt.executeCommand("delete",
uno::makeAny(true)); 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 } // namespace svt
......
...@@ -54,7 +54,35 @@ using namespace ::com::sun::star; ...@@ -54,7 +54,35 @@ using namespace ::com::sun::star;
namespace svt { namespace svt {
LockFileCommon::LockFileCommon( const OUString& aURL )
{
m_aURL = aURL;
}
LockFileCommon::LockFileCommon( const OUString& aOrigURL, const OUString& aPrefix ) LockFileCommon::LockFileCommon( const OUString& aOrigURL, const OUString& aPrefix )
{
m_aURL = GenerateURL(aOrigURL, aPrefix);
}
LockFileCommon::~LockFileCommon()
{
}
const OUString& LockFileCommon::GetURL() const
{
return m_aURL;
}
void LockFileCommon::SetURL(const OUString& aURL)
{
m_aURL = aURL;
}
OUString LockFileCommon::GenerateURL( const OUString& aOrigURL, const OUString& aPrefix )
{ {
INetURLObject aDocURL = ResolveLinks( INetURLObject( aOrigURL ) ); INetURLObject aDocURL = ResolveLinks( INetURLObject( aOrigURL ) );
...@@ -62,12 +90,7 @@ LockFileCommon::LockFileCommon( const OUString& aOrigURL, const OUString& aPrefi ...@@ -62,12 +90,7 @@ LockFileCommon::LockFileCommon( const OUString& aOrigURL, const OUString& aPrefi
aShareURLString += aPrefix; aShareURLString += aPrefix;
aShareURLString += aDocURL.GetName(); aShareURLString += aDocURL.GetName();
aShareURLString += "%23"; // '#' aShareURLString += "%23"; // '#'
m_aURL = INetURLObject( aShareURLString ).GetMainURL( INetURLObject::DecodeMechanism::NONE ); return INetURLObject( aShareURLString ).GetMainURL( INetURLObject::DecodeMechanism::NONE );
}
LockFileCommon::~LockFileCommon()
{
} }
......
/* -*- 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/.
*/
#include <svl/msodocumentlockfile.hxx>
#include <rtl/ustring.hxx>
#include <sal/log.hxx>
#include <algorithm>
#include <com/sun/star/io/IOException.hpp>
#include <com/sun/star/io/XOutputStream.hpp>
#include <com/sun/star/io/XInputStream.hpp>
namespace svt
{
bool MSODocumentLockFile::isWordFormat(const OUString& aOrigURL) const
{
INetURLObject aDocURL = 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) const
{
INetURLObject aDocURL = 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;
}
bool MSODocumentLockFile::isPowerPointFormat(const OUString& aOrigURL) const
{
INetURLObject aDocURL = ResolveLinks(INetURLObject(aOrigURL));
return aDocURL.GetFileExtension().compareToIgnoreAsciiCase("PPTX") == 0
|| aDocURL.GetFileExtension().compareToIgnoreAsciiCase("PPT") == 0
|| aDocURL.GetFileExtension().compareToIgnoreAsciiCase("ODP") == 0;
}
MSODocumentLockFile::MSODocumentLockFile(const OUString& aOrigURL)
: GenDocumentLockFile(GenerateURL(aOrigURL, "~$"))
, m_sOrigURL(aOrigURL)
{
}
MSODocumentLockFile::~MSODocumentLockFile() {}
OUString MSODocumentLockFile::GenerateURL(const OUString& aOrigURL, const OUString& aPrefix)
{
INetURLObject aDocURL = ResolveLinks(INetURLObject(aOrigURL));
OUString aURL = aDocURL.GetPartBeforeLastName();
aURL += aPrefix;
// For text documents MSO Word cuts some of the first characters of the file name
OUString sFileName = aDocURL.GetName();
if (isWordFormat(aOrigURL))
{
sal_Int32 nFileNameLength
= aDocURL.GetName().getLength() - aDocURL.GetFileExtension().getLength() - 1;
if (nFileNameLength >= 8)
aURL += sFileName.copy(2);
else if (nFileNameLength == 7)
aURL += sFileName.copy(1);
else
aURL += sFileName;
}
else
{
aURL += sFileName;
}
return INetURLObject(aURL).GetMainURL(INetURLObject::DecodeMechanism::NONE);
}
void MSODocumentLockFile::WriteEntryToStream(
const LockFileEntry& aEntry, const css::uno::Reference<css::io::XOutputStream>& xOutput)
{
::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;
css::uno::Sequence<sal_Int8> aData(nLockFileSize);
// Write out the user name's length as a single byte integer
// The maximum length is 52 in MSO, so we'll need to truncate the user name if it's longer
OUString aUserName = aEntry[LockFileComponent::OOOUSERNAME];
int nIndex = 0;
aData[nIndex] = static_cast<sal_Int8>(
std::min(aUserName.getLength(), sal_Int32(MSO_USERNAME_MAX_LENGTH)));
if (aUserName.getLength() > MSO_USERNAME_MAX_LENGTH)
aUserName = aUserName.copy(0, MSO_USERNAME_MAX_LENGTH);
// From the second position write out the user name using one byte characters.
nIndex = 1;
for (int nChar = 0; nChar < aUserName.getLength(); ++nChar)
{
aData[nIndex] = static_cast<sal_Int8>(aUserName[nChar]);
++nIndex;
}
// Fill up the remaining bytes with dummy data
if (isWordFormat(m_sOrigURL))
{
while (nIndex < MSO_USERNAME_MAX_LENGTH + 2)
{
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;