diff options
author | Serge Krot <Serge.Krot@cib.de> | 2017-09-29 18:01:54 +0200 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2017-10-06 08:06:59 +0200 |
commit | 2694162969cf86ef366d3ce812fccd0630acc800 (patch) | |
tree | d138fe58a69d5c048f31e5a571b52b86a36db558 /writerfilter | |
parent | b567cfb980435df131d776915bce9152135bdf0f (diff) |
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/43156
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Diffstat (limited to 'writerfilter')
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper.cxx | 11 | ||||
-rw-r--r-- | writerfilter/source/dmapper/SettingsTable.cxx | 219 | ||||
-rw-r--r-- | writerfilter/source/dmapper/SettingsTable.hxx | 2 |
3 files changed, 223 insertions, 9 deletions
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx index a158615c583e..f492c2c2d033 100644 --- a/writerfilter/source/dmapper/DomainMapper.cxx +++ b/writerfilter/source/dmapper/DomainMapper.cxx @@ -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 diff --git a/writerfilter/source/dmapper/SettingsTable.cxx b/writerfilter/source/dmapper/SettingsTable.cxx index 9c5fed0ec78a..b747eb37abdb 100644 --- a/writerfilter/source/dmapper/SettingsTable.cxx +++ b/writerfilter/source/dmapper/SettingsTable.cxx @@ -39,6 +39,176 @@ namespace writerfilter { namespace dmapper { + /** Document protection restrictions + * + * This element specifies the set of document protection restrictions which have been applied to the contents of a + * WordprocessingML document.These restrictions should be enforced by applications editing this document + * when the enforcement attribute is turned on, and ignored(but persisted) otherwise.Document protection is a + * set of restrictions used to prevent unintentional changes to all or part of a WordprocessingML document. + */ + struct DocumentProtection_Impl + { + /** Document Editing Restrictions + * + * Possible values: + * - NS_ooxml::LN_Value_doc_ST_DocProtect_none + * - NS_ooxml::LN_Value_doc_ST_DocProtect_readOnly + * - NS_ooxml::LN_Value_doc_ST_DocProtect_comments + * - NS_ooxml::LN_Value_doc_ST_DocProtect_trackedChanges + * - NS_ooxml::LN_Value_doc_ST_DocProtect_forms + */ + sal_Int32 m_nEdit; + bool m_bEnforcement; + bool m_bFormatting; + + /** Provider type + * + * Possible values: + * "rsaAES" - NS_ooxml::LN_Value_doc_ST_CryptProv_rsaAES + * "rsaFull" - NS_ooxml::LN_Value_doc_ST_CryptProv_rsaFull + */ + sal_Int32 m_nCryptProviderType; + OUString m_sCryptAlgorithmClass; + OUString m_sCryptAlgorithmType; + OUString m_sCryptAlgorithmSid; + sal_Int32 m_CryptSpinCount; + OUString m_sHash; + OUString m_sSalt; + + DocumentProtection_Impl() + : m_nEdit(NS_ooxml::LN_Value_doc_ST_DocProtect_none) // Specifies that no editing restrictions have been applied to the document + , m_bEnforcement(false) + , m_bFormatting(false) + , m_nCryptProviderType(NS_ooxml::LN_Value_doc_ST_CryptProv_rsaAES) + , m_sCryptAlgorithmClass("hash") + , m_sCryptAlgorithmType("typeAny") + , m_CryptSpinCount(0) + { + } + + css::uno::Sequence<css::beans::PropertyValue> toSequence() const; + + bool enabled() const + { + return ! isNone(); + } + + bool isNone() const { return m_nEdit == NS_ooxml::LN_Value_doc_ST_DocProtect_none; }; + // bool isReadOnly() const { return m_nEdit == NS_ooxml::LN_Value_doc_ST_DocProtect_readOnly; }; + // bool isComments() const { return m_nEdit == NS_ooxml::LN_Value_doc_ST_DocProtect_comments; }; + // bool isTrackChanges() const { return m_nEdit == NS_ooxml::LN_Value_doc_ST_DocProtect_trackedChanges; }; + bool isForms() const { return m_nEdit == NS_ooxml::LN_Value_doc_ST_DocProtect_forms; }; + }; + + css::uno::Sequence<css::beans::PropertyValue> DocumentProtection_Impl::toSequence() const + { + std::vector<beans::PropertyValue> documentProtection; + + if (enabled()) + { + // w:edit + { + beans::PropertyValue aValue; + aValue.Name = "edit"; + + switch (m_nEdit) + { + case NS_ooxml::LN_Value_doc_ST_DocProtect_none: aValue.Value <<= OUString("none"); break; + case NS_ooxml::LN_Value_doc_ST_DocProtect_readOnly: aValue.Value <<= OUString("readOnly"); break; + case NS_ooxml::LN_Value_doc_ST_DocProtect_comments: aValue.Value <<= OUString("comments"); break; + case NS_ooxml::LN_Value_doc_ST_DocProtect_trackedChanges: aValue.Value <<= OUString("trackedChanges"); break; + case NS_ooxml::LN_Value_doc_ST_DocProtect_forms: aValue.Value <<= OUString("forms"); break; + default: + { +#ifdef DEBUG_WRITERFILTER + TagLogger::getInstance().element("unhandled"); +#endif + } + } + + documentProtection.push_back(aValue); + } + + // w:enforcement + if (m_bEnforcement) + { + beans::PropertyValue aValue; + aValue.Name = "enforcement"; + aValue.Value <<= OUString("1"); + documentProtection.push_back(aValue); + } + + // w:formatting + if (m_bFormatting) + { + beans::PropertyValue aValue; + aValue.Name = "formatting"; + aValue.Value <<= OUString("1"); + documentProtection.push_back(aValue); + } + + // w:cryptProviderType + { + beans::PropertyValue aValue; + aValue.Name = "cryptProviderType"; + if (m_nCryptProviderType == NS_ooxml::LN_Value_doc_ST_CryptProv_rsaAES) + aValue.Value <<= OUString("rsaAES"); + else if (m_nCryptProviderType == NS_ooxml::LN_Value_doc_ST_CryptProv_rsaFull) + aValue.Value <<= OUString("rsaFull"); + documentProtection.push_back(aValue); + } + + // w:cryptAlgorithmClass + { + beans::PropertyValue aValue; + aValue.Name = "cryptAlgorithmClass"; + aValue.Value <<= m_sCryptAlgorithmClass; + documentProtection.push_back(aValue); + } + + // w:cryptAlgorithmType + { + beans::PropertyValue aValue; + aValue.Name = "cryptAlgorithmType"; + aValue.Value <<= m_sCryptAlgorithmType; + documentProtection.push_back(aValue); + } + + // w:cryptAlgorithmSid + { + beans::PropertyValue aValue; + aValue.Name = "cryptAlgorithmSid"; + aValue.Value <<= m_sCryptAlgorithmSid; + documentProtection.push_back(aValue); + } + + // w:cryptSpinCount + { + beans::PropertyValue aValue; + aValue.Name = "cryptSpinCount"; + aValue.Value <<= OUString::number(m_CryptSpinCount); + documentProtection.push_back(aValue); + } + + // w:hash + { + beans::PropertyValue aValue; + aValue.Name = "hash"; + aValue.Value <<= m_sHash; + documentProtection.push_back(aValue); + } + + // w:salt + { + beans::PropertyValue aValue; + aValue.Name = "salt"; + aValue.Value <<= m_sSalt; + documentProtection.push_back(aValue); + } + } + + return comphelper::containerToSequence(documentProtection); + } struct SettingsTable_Impl { @@ -71,6 +241,8 @@ struct SettingsTable_Impl std::vector<beans::PropertyValue> m_aCompatSettings; uno::Sequence<beans::PropertyValue> m_pCurrentCompatSetting; + DocumentProtection_Impl m_DocumentProtection; + SettingsTable_Impl() : m_nDefaultTabStop( 720 ) //default is 1/2 in , m_bRecordChanges(false) @@ -147,12 +319,40 @@ void SettingsTable::lcl_attribute(Id nName, Value & val) m_pImpl->m_pCurrentCompatSetting[2].Name = "val"; m_pImpl->m_pCurrentCompatSetting[2].Value <<= sStringValue; break; - case NS_ooxml::LN_CT_DocProtect_edit: - m_pImpl->m_bProtectForm = (nIntValue == NS_ooxml::LN_Value_doc_ST_DocProtect_forms); + case NS_ooxml::LN_CT_DocProtect_edit: // 92037 + m_pImpl->m_DocumentProtection.m_nEdit = nIntValue; + m_pImpl->m_bProtectForm = m_pImpl->m_DocumentProtection.isForms(); break; - case NS_ooxml::LN_CT_DocProtect_enforcement: + case NS_ooxml::LN_CT_DocProtect_enforcement: // 92039 + m_pImpl->m_DocumentProtection.m_bEnforcement = (nIntValue != 0); m_pImpl->m_bProtectForm &= (bool)nIntValue; break; + case NS_ooxml::LN_CT_DocProtect_formatting: // 92038 + m_pImpl->m_DocumentProtection.m_bFormatting = (nIntValue != 0); + break; + case NS_ooxml::LN_AG_Password_cryptProviderType: // 92025 + m_pImpl->m_DocumentProtection.m_nCryptProviderType = nIntValue; + break; + case NS_ooxml::LN_AG_Password_cryptAlgorithmClass: // 92026 + if (nIntValue == NS_ooxml::LN_Value_doc_ST_AlgClass_hash) // 92023 + m_pImpl->m_DocumentProtection.m_sCryptAlgorithmClass = "hash"; + break; + case NS_ooxml::LN_AG_Password_cryptAlgorithmType: // 92027 + if (nIntValue == NS_ooxml::LN_Value_doc_ST_AlgType_typeAny) // 92024 + m_pImpl->m_DocumentProtection.m_sCryptAlgorithmType = "typeAny"; + break; + case NS_ooxml::LN_AG_Password_cryptAlgorithmSid: // 92028 + m_pImpl->m_DocumentProtection.m_sCryptAlgorithmSid = sStringValue; + break; + case NS_ooxml::LN_AG_Password_cryptSpinCount: // 92029 + m_pImpl->m_DocumentProtection.m_CryptSpinCount = nIntValue; + break; + case NS_ooxml::LN_AG_Password_hash: // 92035 + m_pImpl->m_DocumentProtection.m_sHash = sStringValue; + break; + case NS_ooxml::LN_AG_Password_salt: // 92036 + m_pImpl->m_DocumentProtection.m_sSalt = sStringValue; + break; default: { #ifdef DEBUG_WRITERFILTER @@ -184,9 +384,7 @@ void SettingsTable::lcl_sprm(Sprm& rSprm) case NS_ooxml::LN_CT_Settings_view: //PropertySetValues - need to be resolved { - writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps(); - if( pProperties.get()) - pProperties->resolve(*this); + resolveSprmProps(*this, rSprm); } break; case NS_ooxml::LN_CT_Settings_stylePaneFormatFilter: // 92493; @@ -226,9 +424,7 @@ void SettingsTable::lcl_sprm(Sprm& rSprm) } break; case NS_ooxml::LN_CT_Settings_documentProtection: - { - resolveSprmProps(*this, rSprm); - } + resolveSprmProps(*this, rSprm); break; case NS_ooxml::LN_CT_Compat_usePrinterMetrics: m_pImpl->m_bUsePrinterMetrics = nIntValue; @@ -376,6 +572,11 @@ uno::Sequence<beans::PropertyValue> SettingsTable::GetCompatSettings() const return comphelper::containerToSequence(m_pImpl->m_aCompatSettings); } +css::uno::Sequence<css::beans::PropertyValue> SettingsTable::GetDocumentProtectionSettings() const +{ + return m_pImpl->m_DocumentProtection.toSequence(); +} + static bool lcl_isDefault(const uno::Reference<beans::XPropertyState>& xPropertyState, const OUString& rPropertyName) { return xPropertyState->getPropertyState(rPropertyName) == beans::PropertyState_DEFAULT_VALUE; diff --git a/writerfilter/source/dmapper/SettingsTable.hxx b/writerfilter/source/dmapper/SettingsTable.hxx index 28db5c26fb73..2a80bd186fc1 100644 --- a/writerfilter/source/dmapper/SettingsTable.hxx +++ b/writerfilter/source/dmapper/SettingsTable.hxx @@ -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: |