android: Update app-specific/MIME type icons
[LibreOffice.git] / writerfilter / source / dmapper / DocumentProtection.cxx
blobdddf964c4022a1d8be4d7c58a6546d7500d72771
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
22 #include <vector>
23 #include <comphelper/sequence.hxx>
25 using namespace com::sun::star;
27 namespace writerfilter::dmapper
29 DocumentProtection::DocumentProtection()
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)
46 DocumentProtection::~DocumentProtection() {}
48 void DocumentProtection::lcl_attribute(Id nName, Value& val)
50 int nIntValue = val.getInt();
51 OUString sStringValue = val.getString();
53 switch (nName)
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
58 m_bRedlineProtection = false;
59 m_bProtectForm = false;
60 m_bReadOnly = false;
61 switch (nIntValue)
63 case NS_ooxml::LN_Value_doc_ST_DocProtect_trackedChanges:
65 m_bRedlineProtection = true;
66 m_sRedlineProtectionKey = m_sHash;
67 break;
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;
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
88 m_sCryptAlgorithmClass = "hash";
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:
108 #ifdef DBG_UTIL
109 TagLogger::getInstance().element("unhandled");
110 #endif
115 void DocumentProtection::lcl_sprm(Sprm& /*rSprm*/) {}
117 uno::Sequence<beans::PropertyValue> DocumentProtection::toSequence() const
119 std::vector<beans::PropertyValue> documentProtection;
121 if (enabled())
123 // w:edit
125 beans::PropertyValue aValue;
126 aValue.Name = "edit";
128 switch (m_nEdit)
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:
147 #ifdef DBG_UTIL
148 TagLogger::getInstance().element("unhandled");
149 #endif
153 documentProtection.push_back(aValue);
156 // w:enforcement
157 if (m_bEnforcement)
159 beans::PropertyValue aValue;
160 aValue.Name = "enforcement";
161 aValue.Value <<= OUString("1");
162 documentProtection.push_back(aValue);
165 // w:formatting
166 if (m_bFormatting)
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);
209 // w:cryptSpinCount
211 beans::PropertyValue aValue;
212 aValue.Name = "cryptSpinCount";
213 aValue.Value <<= OUString::number(m_CryptSpinCount);
214 documentProtection.push_back(aValue);
217 // w:hash
219 beans::PropertyValue aValue;
220 aValue.Name = "hash";
221 aValue.Value <<= m_sHash;
222 documentProtection.push_back(aValue);
225 // w:salt
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: */