Kaydet (Commit) 26941629 authored tarafından Serge Krot's avatar Serge Krot Kaydeden (comit) Thorsten Behrens

tdf#66398 Import/export docx document protection properties

Added:
+ import/export of all doc protection properties
+ unit test

Change-Id: I7b65cf4f5c7add2a96fef407c243081fcc2b6d8d
Reviewed-on: https://gerrit.libreoffice.org/43156Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarThorsten Behrens <Thorsten.Behrens@CIB.de>
üst b567cfb9
......@@ -945,6 +945,22 @@ DECLARE_OOXMLEXPORT_TEST(testSectionProtection, "sectionprot.odt")
}
}
DECLARE_OOXMLEXPORT_TEST(tdf66398_permissions, "tdf66398_permissions.docx")
{
if (xmlDocPtr pXmlSettings = parseExport("word/settings.xml"))
{
assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "edit", "readOnly");
assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "enforcement", "1");
assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "cryptProviderType", "rsaAES");
assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "cryptAlgorithmClass","hash");
assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "cryptAlgorithmType", "typeAny");
assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "cryptAlgorithmSid", "14");
assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "cryptSpinCount", "100000");
assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "hash", "A0/Xy6KcXljJlZjP0TwJMPJuW2rc46UwXqn2ctxckc2nCECE5i89M85z2Noh3ZEA5NBQ9RJ5ycxiUH6nzmJaKw==");
assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "salt", "B8k6wb1pkjUs4Nv/8QBk/w==");
}
}
DECLARE_OOXMLEXPORT_TEST(testSectionHeader, "sectionprot.odt")
{
if (xmlDocPtr pXmlDoc = parseExport("word/document.xml"))
......
......@@ -21,6 +21,7 @@
#include "docxexportfilter.hxx"
#include "docxattributeoutput.hxx"
#include "docxsdrexport.hxx"
#include "docxhelper.hxx"
#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
#include <com/sun/star/document/XDocumentProperties.hpp>
......@@ -935,6 +936,7 @@ void DocxExport::WriteSettings()
{
pFS->singleElementNS( XML_w, XML_documentProtection, FSNS(XML_w, XML_edit), "forms", FSNS(XML_w, XML_enforcement), "1", FSEND );
}
// Do not justify lines with manual break
if( m_pDoc->getIDocumentSettingAccess().get( DocumentSettingId::DO_NOT_JUSTIFY_LINES_WITH_MANUAL_BREAK ))
{
......@@ -942,6 +944,7 @@ void DocxExport::WriteSettings()
pFS->singleElementNS( XML_w, XML_doNotExpandShiftReturn, FSEND );
pFS->endElementNS( XML_w, XML_compat );
}
// Automatic hyphenation: it's a global setting in Word, it's a paragraph setting in Writer.
// Use the setting from the default style.
SwTextFormatColl* pColl = m_pDoc->getIDocumentStylePoolAccess().GetTextCollFromPool(RES_POOLCOLL_STANDARD, /*bRegardLanguage=*/false);
......@@ -969,11 +972,12 @@ void DocxExport::WriteSettings()
uno::Reference< beans::XPropertySet > xPropSet( m_pDoc->GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW );
uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
OUString aGrabBagName = UNO_NAME_MISC_OBJ_INTEROPGRABBAG;
const OUString aGrabBagName = UNO_NAME_MISC_OBJ_INTEROPGRABBAG;
if ( xPropSetInfo->hasPropertyByName( aGrabBagName ) )
{
uno::Sequence< beans::PropertyValue > propList;
xPropSet->getPropertyValue( aGrabBagName ) >>= propList;
for( sal_Int32 i=0; i < propList.getLength(); ++i )
{
if ( propList[i].Name == "ThemeFontLangProps" )
......@@ -1002,6 +1006,7 @@ void DocxExport::WriteSettings()
uno::Sequence< beans::PropertyValue > aCompatSettingsSequence;
propList[i].Value >>= aCompatSettingsSequence;
for(sal_Int32 j=0; j < aCompatSettingsSequence.getLength(); ++j)
{
uno::Sequence< beans::PropertyValue > aCompatSetting;
......@@ -1025,8 +1030,43 @@ void DocxExport::WriteSettings()
FSNS( XML_w, XML_val ), OUStringToOString(aValue, RTL_TEXTENCODING_UTF8).getStr(),
FSEND);
}
pFS->endElementNS( XML_w, XML_compat );
}
else if (propList[i].Name == "DocumentProtection")
{
sax_fastparser::FastAttributeList* pAttributeList = sax_fastparser::FastSerializerHelper::createAttrList();
uno::Sequence< beans::PropertyValue > rAttributeList;
propList[i].Value >>= rAttributeList;
for (sal_Int32 j = 0; j < rAttributeList.getLength(); ++j)
{
static DocxStringTokenMap const aTokens[] =
{
{ "edit", XML_edit },
{ "enforcement", XML_enforcement },
{ "formatting", XML_formatting },
{ "cryptProviderType", XML_cryptProviderType },
{ "cryptAlgorithmClass", XML_cryptAlgorithmClass },
{ "cryptAlgorithmType", XML_cryptAlgorithmType },
{ "cryptAlgorithmSid", XML_cryptAlgorithmSid },
{ "cryptSpinCount", XML_cryptSpinCount },
{ "hash", XML_hash },
{ "salt", XML_salt },
{ nullptr, 0 }
};
if (sal_Int32 nToken = DocxStringGetToken(aTokens, rAttributeList[j].Name))
pAttributeList->add(FSNS(XML_w, nToken), rAttributeList[j].Value.get<OUString>().toUtf8());
}
if (rAttributeList.getLength())
{
sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
pFS->singleElementNS(XML_w, XML_documentProtection, xAttributeList);
}
}
}
}
......
......@@ -206,10 +206,16 @@ DomainMapper::~DomainMapper()
// Grab-bag handling
comphelper::SequenceAsHashMap aProperties;
// Add the saved w:themeFontLang setting
aProperties["ThemeFontLangProps"] <<= m_pImpl->GetSettingsTable()->GetThemeFontLangProperties();
// Add the saved compat settings
aProperties["CompatSettings"] <<= m_pImpl->GetSettingsTable()->GetCompatSettings();
// Add the saved DocumentProtection settings
aProperties["DocumentProtection"] <<= m_pImpl->GetSettingsTable()->GetDocumentProtectionSettings();
uno::Reference<beans::XPropertySet> xDocProps(m_pImpl->GetTextDocument(), uno::UNO_QUERY);
if (xDocProps.is())
{
......@@ -2810,6 +2816,11 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const PropertyMapPtr& rContext )
pProperties->resolve(*this);
}
break;
case NS_ooxml::LN_EG_RunLevelElts_permStart: // 93164
case NS_ooxml::LN_EG_RunLevelElts_permEnd: // 93165
{
break;
}
default:
{
#ifdef DEBUG_WRITERFILTER
......
......@@ -79,6 +79,8 @@ class SettingsTable : public LoggedProperties, public LoggedTable
css::uno::Sequence<css::beans::PropertyValue> GetCompatSettings() const;
css::uno::Sequence<css::beans::PropertyValue> GetDocumentProtectionSettings() const;
void ApplyProperties(css::uno::Reference<css::text::XTextDocument> const& xDoc);
private:
......
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