LibreOffice Module writerfilter (master) 1
DocumentProtection.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21#include "TagLogger.hxx"
22#include <vector>
24
25using namespace com::sun::star;
26
28{
30 : LoggedProperties("DocumentProtection")
31 , m_nEdit(
32 NS_ooxml::
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)
36 , m_bReadOnly(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")
42 , m_CryptSpinCount(0)
43{
44}
45
47
49{
50 int nIntValue = val.getInt();
51 OUString sStringValue = val.getString();
52
53 switch (nName)
54 {
55 case NS_ooxml::LN_CT_DocProtect_edit: // 92037
56 m_nEdit = nIntValue;
57 // multiple DocProtect_edits should not exist. If they do, last one wins
59 m_bProtectForm = false;
60 m_bReadOnly = false;
61 switch (nIntValue)
62 {
63 case NS_ooxml::LN_Value_doc_ST_DocProtect_trackedChanges:
64 {
67 break;
68 }
69 case NS_ooxml::LN_Value_doc_ST_DocProtect_forms:
70 m_bProtectForm = true;
71 break;
72 case NS_ooxml::LN_Value_doc_ST_DocProtect_readOnly:
73 m_bReadOnly = true;
74 break;
75 }
76 break;
77 case NS_ooxml::LN_CT_DocProtect_enforcement: // 92039
78 m_bEnforcement = (nIntValue != 0);
79 break;
80 case NS_ooxml::LN_CT_DocProtect_formatting: // 92038
81 m_bFormatting = (nIntValue != 0);
82 break;
83 case NS_ooxml::LN_AG_Password_cryptProviderType: // 92025
84 m_nCryptProviderType = nIntValue;
85 break;
86 case NS_ooxml::LN_AG_Password_cryptAlgorithmClass: // 92026
87 if (nIntValue == NS_ooxml::LN_Value_doc_ST_AlgClass_hash) // 92023
89 break;
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";
93 break;
94 case NS_ooxml::LN_AG_Password_cryptAlgorithmSid: // 92028
95 m_sCryptAlgorithmSid = sStringValue;
96 break;
97 case NS_ooxml::LN_AG_Password_cryptSpinCount: // 92029
98 m_CryptSpinCount = nIntValue;
99 break;
100 case NS_ooxml::LN_AG_Password_hash: // 92035
101 m_sHash = sStringValue;
102 break;
103 case NS_ooxml::LN_AG_Password_salt: // 92036
104 m_sSalt = sStringValue;
105 break;
106 default:
107 {
108#ifdef DBG_UTIL
109 TagLogger::getInstance().element("unhandled");
110#endif
111 }
112 }
113}
114
116
118{
119 std::vector<beans::PropertyValue> documentProtection;
120
121 if (enabled())
122 {
123 // w:edit
124 {
125 beans::PropertyValue aValue;
126 aValue.Name = "edit";
127
128 switch (m_nEdit)
129 {
130 case NS_ooxml::LN_Value_doc_ST_DocProtect_none:
131 aValue.Value <<= OUString("none");
132 break;
133 case NS_ooxml::LN_Value_doc_ST_DocProtect_readOnly:
134 aValue.Value <<= OUString("readOnly");
135 break;
136 case NS_ooxml::LN_Value_doc_ST_DocProtect_comments:
137 aValue.Value <<= OUString("comments");
138 break;
139 case NS_ooxml::LN_Value_doc_ST_DocProtect_trackedChanges:
140 aValue.Value <<= OUString("trackedChanges");
141 break;
142 case NS_ooxml::LN_Value_doc_ST_DocProtect_forms:
143 aValue.Value <<= OUString("forms");
144 break;
145 default:
146 {
147#ifdef DBG_UTIL
148 TagLogger::getInstance().element("unhandled");
149#endif
150 }
151 }
152
153 documentProtection.push_back(aValue);
154 }
155
156 // w:enforcement
157 if (m_bEnforcement)
158 {
159 beans::PropertyValue aValue;
160 aValue.Name = "enforcement";
161 aValue.Value <<= OUString("1");
162 documentProtection.push_back(aValue);
163 }
164
165 // w:formatting
166 if (m_bFormatting)
167 {
168 beans::PropertyValue aValue;
169 aValue.Name = "formatting";
170 aValue.Value <<= OUString("1");
171 documentProtection.push_back(aValue);
172 }
173
174 // w:cryptProviderType
175 {
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);
183 }
184
185 // w:cryptAlgorithmClass
186 {
187 beans::PropertyValue aValue;
188 aValue.Name = "cryptAlgorithmClass";
189 aValue.Value <<= m_sCryptAlgorithmClass;
190 documentProtection.push_back(aValue);
191 }
192
193 // w:cryptAlgorithmType
194 {
195 beans::PropertyValue aValue;
196 aValue.Name = "cryptAlgorithmType";
197 aValue.Value <<= m_sCryptAlgorithmType;
198 documentProtection.push_back(aValue);
199 }
200
201 // w:cryptAlgorithmSid
202 {
203 beans::PropertyValue aValue;
204 aValue.Name = "cryptAlgorithmSid";
205 aValue.Value <<= m_sCryptAlgorithmSid;
206 documentProtection.push_back(aValue);
207 }
208
209 // w:cryptSpinCount
210 {
211 beans::PropertyValue aValue;
212 aValue.Name = "cryptSpinCount";
213 aValue.Value <<= OUString::number(m_CryptSpinCount);
214 documentProtection.push_back(aValue);
215 }
216
217 // w:hash
218 {
219 beans::PropertyValue aValue;
220 aValue.Name = "hash";
221 aValue.Value <<= m_sHash;
222 documentProtection.push_back(aValue);
223 }
224
225 // w:salt
226 {
227 beans::PropertyValue aValue;
228 aValue.Name = "salt";
229 aValue.Value <<= m_sSalt;
230 documentProtection.push_back(aValue);
231 }
232 }
233
234 return comphelper::containerToSequence(documentProtection);
235}
236
237} //namespace writerfilter::dmapper
238
239/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
An SPRM: Section, Paragraph and Run Modifier.
static TagLogger & getInstance()
Definition: TagLogger.cxx:95
void element(const std::string &name)
Definition: TagLogger.cxx:102
virtual int getInt() const =0
Returns integer representation of the value.
virtual OUString getString() const =0
Returns string representation of the value.
sal_Int32 m_nEdit
Document Editing Restrictions.
virtual void lcl_sprm(Sprm &sprm) override
css::uno::Sequence< css::beans::PropertyValue > toSequence() const
virtual void lcl_attribute(Id Name, Value &val) override
bool m_bReadOnly
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
sal_uInt32 Id