1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "DocumentProtection.hxx"
21 #include "TagLogger.hxx"
23 #include <comphelper/sequence.hxx>
25 using namespace com::sun::star
;
27 namespace writerfilter::dmapper
29 DocumentProtection::DocumentProtection()
30 : LoggedProperties("DocumentProtection")
33 LN_Value_doc_ST_DocProtect_none
) // Specifies that no editing restrictions have been applied to the document
34 , m_bProtectForm(false)
35 , m_bRedlineProtection(false)
37 , m_bEnforcement(false)
38 , m_bFormatting(false)
39 , m_nCryptProviderType(NS_ooxml::LN_Value_doc_ST_CryptProv_rsaAES
)
40 , m_sCryptAlgorithmClass("hash")
41 , m_sCryptAlgorithmType("typeAny")
46 DocumentProtection::~DocumentProtection() {}
48 void DocumentProtection::lcl_attribute(Id nName
, Value
& val
)
50 int nIntValue
= val
.getInt();
51 OUString sStringValue
= val
.getString();
55 case NS_ooxml::LN_CT_DocProtect_edit
: // 92037
57 // multiple DocProtect_edits should not exist. If they do, last one wins
58 m_bRedlineProtection
= false;
59 m_bProtectForm
= false;
63 case NS_ooxml::LN_Value_doc_ST_DocProtect_trackedChanges
:
65 m_bRedlineProtection
= true;
66 m_sRedlineProtectionKey
= m_sHash
;
69 case NS_ooxml::LN_Value_doc_ST_DocProtect_forms
:
70 m_bProtectForm
= true;
72 case NS_ooxml::LN_Value_doc_ST_DocProtect_readOnly
:
77 case NS_ooxml::LN_CT_DocProtect_enforcement
: // 92039
78 m_bEnforcement
= (nIntValue
!= 0);
80 case NS_ooxml::LN_CT_DocProtect_formatting
: // 92038
81 m_bFormatting
= (nIntValue
!= 0);
83 case NS_ooxml::LN_AG_Password_cryptProviderType
: // 92025
84 m_nCryptProviderType
= nIntValue
;
86 case NS_ooxml::LN_AG_Password_cryptAlgorithmClass
: // 92026
87 if (nIntValue
== NS_ooxml::LN_Value_doc_ST_AlgClass_hash
) // 92023
88 m_sCryptAlgorithmClass
= "hash";
90 case NS_ooxml::LN_AG_Password_cryptAlgorithmType
: // 92027
91 if (nIntValue
== NS_ooxml::LN_Value_doc_ST_AlgType_typeAny
) // 92024
92 m_sCryptAlgorithmType
= "typeAny";
94 case NS_ooxml::LN_AG_Password_cryptAlgorithmSid
: // 92028
95 m_sCryptAlgorithmSid
= sStringValue
;
97 case NS_ooxml::LN_AG_Password_cryptSpinCount
: // 92029
98 m_CryptSpinCount
= nIntValue
;
100 case NS_ooxml::LN_AG_Password_hash
: // 92035
101 m_sHash
= sStringValue
;
103 case NS_ooxml::LN_AG_Password_salt
: // 92036
104 m_sSalt
= sStringValue
;
109 TagLogger::getInstance().element("unhandled");
115 void DocumentProtection::lcl_sprm(Sprm
& /*rSprm*/) {}
117 uno::Sequence
<beans::PropertyValue
> DocumentProtection::toSequence() const
119 std::vector
<beans::PropertyValue
> documentProtection
;
125 beans::PropertyValue aValue
;
126 aValue
.Name
= "edit";
130 case NS_ooxml::LN_Value_doc_ST_DocProtect_none
:
131 aValue
.Value
<<= OUString("none");
133 case NS_ooxml::LN_Value_doc_ST_DocProtect_readOnly
:
134 aValue
.Value
<<= OUString("readOnly");
136 case NS_ooxml::LN_Value_doc_ST_DocProtect_comments
:
137 aValue
.Value
<<= OUString("comments");
139 case NS_ooxml::LN_Value_doc_ST_DocProtect_trackedChanges
:
140 aValue
.Value
<<= OUString("trackedChanges");
142 case NS_ooxml::LN_Value_doc_ST_DocProtect_forms
:
143 aValue
.Value
<<= OUString("forms");
148 TagLogger::getInstance().element("unhandled");
153 documentProtection
.push_back(aValue
);
159 beans::PropertyValue aValue
;
160 aValue
.Name
= "enforcement";
161 aValue
.Value
<<= OUString("1");
162 documentProtection
.push_back(aValue
);
168 beans::PropertyValue aValue
;
169 aValue
.Name
= "formatting";
170 aValue
.Value
<<= OUString("1");
171 documentProtection
.push_back(aValue
);
174 // w:cryptProviderType
176 beans::PropertyValue aValue
;
177 aValue
.Name
= "cryptProviderType";
178 if (m_nCryptProviderType
== NS_ooxml::LN_Value_doc_ST_CryptProv_rsaAES
)
179 aValue
.Value
<<= OUString("rsaAES");
180 else if (m_nCryptProviderType
== NS_ooxml::LN_Value_doc_ST_CryptProv_rsaFull
)
181 aValue
.Value
<<= OUString("rsaFull");
182 documentProtection
.push_back(aValue
);
185 // w:cryptAlgorithmClass
187 beans::PropertyValue aValue
;
188 aValue
.Name
= "cryptAlgorithmClass";
189 aValue
.Value
<<= m_sCryptAlgorithmClass
;
190 documentProtection
.push_back(aValue
);
193 // w:cryptAlgorithmType
195 beans::PropertyValue aValue
;
196 aValue
.Name
= "cryptAlgorithmType";
197 aValue
.Value
<<= m_sCryptAlgorithmType
;
198 documentProtection
.push_back(aValue
);
201 // w:cryptAlgorithmSid
203 beans::PropertyValue aValue
;
204 aValue
.Name
= "cryptAlgorithmSid";
205 aValue
.Value
<<= m_sCryptAlgorithmSid
;
206 documentProtection
.push_back(aValue
);
211 beans::PropertyValue aValue
;
212 aValue
.Name
= "cryptSpinCount";
213 aValue
.Value
<<= OUString::number(m_CryptSpinCount
);
214 documentProtection
.push_back(aValue
);
219 beans::PropertyValue aValue
;
220 aValue
.Name
= "hash";
221 aValue
.Value
<<= m_sHash
;
222 documentProtection
.push_back(aValue
);
227 beans::PropertyValue aValue
;
228 aValue
.Name
= "salt";
229 aValue
.Value
<<= m_sSalt
;
230 documentProtection
.push_back(aValue
);
234 return comphelper::containerToSequence(documentProtection
);
237 } //namespace writerfilter::dmapper
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */