Line data Source code
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 :
20 : #include "XMLLineNumberingImportContext.hxx"
21 : #include "XMLLineNumberingSeparatorImportContext.hxx"
22 : #include "com/sun/star/beans/XPropertySet.hpp"
23 : #include "com/sun/star/text/XLineNumberingProperties.hpp"
24 : #include <com/sun/star/style/LineNumberPosition.hpp>
25 : #include <com/sun/star/style/NumberingType.hpp>
26 : #include <sax/tools/converter.hxx>
27 : #include <xmloff/xmlimp.hxx>
28 : #include <xmloff/xmluconv.hxx>
29 : #include "xmloff/xmlnmspe.hxx"
30 : #include <xmloff/nmspmap.hxx>
31 : #include <xmloff/xmltoken.hxx>
32 : #include <xmloff/xmlnumi.hxx>
33 :
34 :
35 : using namespace ::com::sun::star;
36 : using namespace ::com::sun::star::uno;
37 : using namespace ::com::sun::star::style;
38 : using namespace ::xmloff::token;
39 :
40 : using ::com::sun::star::beans::XPropertySet;
41 : using ::com::sun::star::xml::sax::XAttributeList;
42 : using ::com::sun::star::text::XLineNumberingProperties;
43 : using ::rtl::OUString;
44 :
45 0 : TYPEINIT1( XMLLineNumberingImportContext, SvXMLStyleContext );
46 :
47 :
48 17 : XMLLineNumberingImportContext::XMLLineNumberingImportContext(
49 : SvXMLImport& rImport,
50 : sal_uInt16 nPrfx,
51 : const OUString& rLocalName,
52 : const Reference<XAttributeList> & xAttrList)
53 : : SvXMLStyleContext(rImport, nPrfx, rLocalName, xAttrList, XML_STYLE_FAMILY_TEXT_LINENUMBERINGCONFIG)
54 : , sCharStyleName("CharStyleName")
55 : , sCountEmptyLines("CountEmptyLines")
56 : , sCountLinesInFrames("CountLinesInFrames")
57 : , sDistance("Distance")
58 : , sInterval("Interval")
59 : , sSeparatorText("SeparatorText")
60 : , sNumberPosition("NumberPosition")
61 : , sNumberingType("NumberingType")
62 : , sIsOn("IsOn")
63 : , sRestartAtEachPage("RestartAtEachPage")
64 : , sSeparatorInterval("SeparatorInterval")
65 17 : , sNumFormat(GetXMLToken(XML_1))
66 17 : , sNumLetterSync(GetXMLToken(XML_FALSE))
67 : , nOffset(-1)
68 : , nNumberPosition(style::LineNumberPosition::LEFT)
69 : , nIncrement(-1)
70 : , nSeparatorIncrement(-1)
71 : , bNumberLines(sal_True)
72 : , bCountEmptyLines(sal_True)
73 : , bCountInFloatingFrames(sal_False)
74 51 : , bRestartNumbering(sal_False)
75 : {
76 17 : }
77 :
78 34 : XMLLineNumberingImportContext::~XMLLineNumberingImportContext()
79 : {
80 34 : }
81 :
82 17 : void XMLLineNumberingImportContext::StartElement(
83 : const Reference<XAttributeList> & xAttrList)
84 : {
85 : static SvXMLTokenMapEntry aLineNumberingTokenMap[] =
86 : {
87 : { XML_NAMESPACE_TEXT, XML_STYLE_NAME, XML_TOK_LINENUMBERING_STYLE_NAME },
88 : { XML_NAMESPACE_TEXT, XML_NUMBER_LINES,
89 : XML_TOK_LINENUMBERING_NUMBER_LINES },
90 : { XML_NAMESPACE_TEXT, XML_COUNT_EMPTY_LINES,
91 : XML_TOK_LINENUMBERING_COUNT_EMPTY_LINES },
92 : { XML_NAMESPACE_TEXT, XML_COUNT_IN_TEXT_BOXES,
93 : XML_TOK_LINENUMBERING_COUNT_IN_TEXT_BOXES },
94 : { XML_NAMESPACE_TEXT, XML_RESTART_ON_PAGE,
95 : XML_TOK_LINENUMBERING_RESTART_NUMBERING },
96 : { XML_NAMESPACE_TEXT, XML_OFFSET, XML_TOK_LINENUMBERING_OFFSET },
97 : { XML_NAMESPACE_STYLE, XML_NUM_FORMAT, XML_TOK_LINENUMBERING_NUM_FORMAT },
98 : { XML_NAMESPACE_STYLE, XML_NUM_LETTER_SYNC,
99 : XML_TOK_LINENUMBERING_NUM_LETTER_SYNC },
100 : { XML_NAMESPACE_TEXT, XML_NUMBER_POSITION,
101 : XML_TOK_LINENUMBERING_NUMBER_POSITION },
102 : { XML_NAMESPACE_TEXT, XML_INCREMENT, XML_TOK_LINENUMBERING_INCREMENT },
103 : // { XML_NAMESPACE_TEXT, XML_LINENUMBERING_CONFIGURATION,
104 : // XML_TOK_LINENUMBERING_LINENUMBERING_CONFIGURATION },
105 : // { XML_NAMESPACE_TEXT, XML_INCREMENT, XML_TOK_LINENUMBERING_INCREMENT },
106 : // { XML_NAMESPACE_TEXT, XML_LINENUMBERING_SEPARATOR,
107 : // XML_TOK_LINENUMBERING_LINENUMBERING_SEPARATOR },
108 :
109 : XML_TOKEN_MAP_END
110 : };
111 :
112 17 : SvXMLTokenMap aTokenMap(aLineNumberingTokenMap);
113 :
114 : // process attributes
115 17 : sal_Int16 nLength = xAttrList->getLength();
116 102 : for(sal_Int16 i=0; i<nLength; i++)
117 : {
118 85 : OUString sLocalName;
119 85 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
120 170 : GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
121 :
122 : ProcessAttribute(
123 85 : (enum LineNumberingToken)aTokenMap.Get(nPrefix, sLocalName),
124 170 : xAttrList->getValueByIndex(i));
125 102 : }
126 17 : }
127 :
128 85 : void XMLLineNumberingImportContext::ProcessAttribute(
129 : enum LineNumberingToken eToken,
130 : OUString sValue)
131 : {
132 85 : bool bTmp(false);
133 : sal_Int32 nTmp;
134 :
135 85 : switch (eToken)
136 : {
137 : case XML_TOK_LINENUMBERING_STYLE_NAME:
138 0 : sStyleName = sValue;
139 0 : break;
140 :
141 : case XML_TOK_LINENUMBERING_NUMBER_LINES:
142 17 : if (::sax::Converter::convertBool(bTmp, sValue))
143 : {
144 17 : bNumberLines = bTmp;
145 : }
146 17 : break;
147 :
148 : case XML_TOK_LINENUMBERING_COUNT_EMPTY_LINES:
149 0 : if (::sax::Converter::convertBool(bTmp, sValue))
150 : {
151 0 : bCountEmptyLines = bTmp;
152 : }
153 0 : break;
154 :
155 : case XML_TOK_LINENUMBERING_COUNT_IN_TEXT_BOXES:
156 0 : if (::sax::Converter::convertBool(bTmp, sValue))
157 : {
158 0 : bCountInFloatingFrames = bTmp;
159 : }
160 0 : break;
161 :
162 : case XML_TOK_LINENUMBERING_RESTART_NUMBERING:
163 0 : if (::sax::Converter::convertBool(bTmp, sValue))
164 : {
165 0 : bRestartNumbering = bTmp;
166 : }
167 0 : break;
168 :
169 : case XML_TOK_LINENUMBERING_OFFSET:
170 17 : if (GetImport().GetMM100UnitConverter().
171 : convertMeasureToCore(nTmp, sValue))
172 : {
173 17 : nOffset = nTmp;
174 : }
175 17 : break;
176 :
177 : case XML_TOK_LINENUMBERING_NUM_FORMAT:
178 17 : sNumFormat = sValue;
179 17 : break;
180 :
181 : case XML_TOK_LINENUMBERING_NUM_LETTER_SYNC:
182 0 : sNumLetterSync = sValue;
183 0 : break;
184 :
185 : case XML_TOK_LINENUMBERING_NUMBER_POSITION:
186 : {
187 : static const SvXMLEnumMapEntry aLineNumberPositionMap[] =
188 : {
189 : { XML_LEFT, style::LineNumberPosition::LEFT },
190 : { XML_RIGHT, style::LineNumberPosition::RIGHT },
191 : { XML_INSIDE, style::LineNumberPosition::INSIDE },
192 : { XML_OUTSIDE, style::LineNumberPosition::OUTSIDE },
193 : { XML_TOKEN_INVALID, 0 }
194 : };
195 :
196 : sal_uInt16 nTmp16;
197 17 : if (SvXMLUnitConverter::convertEnum(nTmp16, sValue,
198 17 : aLineNumberPositionMap))
199 : {
200 17 : nNumberPosition = nTmp16;
201 : }
202 : break;
203 : }
204 :
205 : case XML_TOK_LINENUMBERING_INCREMENT:
206 17 : if (::sax::Converter::convertNumber(nTmp, sValue, 0))
207 : {
208 17 : nIncrement = (sal_Int16)nTmp;
209 : }
210 17 : break;
211 : }
212 85 : }
213 :
214 17 : void XMLLineNumberingImportContext::CreateAndInsert(sal_Bool)
215 : {
216 : // insert and block mode is handled in insertStyleFamily
217 :
218 : // we'll try to get the LineNumberingProperties
219 17 : Reference<XLineNumberingProperties> xSupplier(GetImport().GetModel(),
220 17 : UNO_QUERY);
221 17 : if (xSupplier.is())
222 : {
223 : Reference<XPropertySet> xLineNumbering =
224 17 : xSupplier->getLineNumberingProperties();
225 :
226 17 : if (xLineNumbering.is())
227 : {
228 17 : Any aAny;
229 :
230 : // set style name (if it exists)
231 34 : if ( GetImport().GetStyles()->FindStyleChildContext(
232 34 : XML_STYLE_FAMILY_TEXT_TEXT, sStyleName ) != NULL )
233 : {
234 0 : aAny <<= GetImport().GetStyleDisplayName(
235 0 : XML_STYLE_FAMILY_TEXT_TEXT, sStyleName );
236 0 : xLineNumbering->setPropertyValue(sCharStyleName, aAny);
237 : }
238 :
239 17 : aAny <<= sSeparator;
240 17 : xLineNumbering->setPropertyValue(sSeparatorText, aAny);
241 :
242 17 : aAny <<= nOffset;
243 17 : xLineNumbering->setPropertyValue(sDistance, aAny);
244 :
245 17 : aAny <<= nNumberPosition;
246 17 : xLineNumbering->setPropertyValue(sNumberPosition, aAny);
247 :
248 17 : if (nIncrement >= 0)
249 : {
250 17 : aAny <<= nIncrement;
251 17 : xLineNumbering->setPropertyValue(sInterval, aAny);
252 : }
253 :
254 17 : if (nSeparatorIncrement >= 0)
255 : {
256 0 : aAny <<= nSeparatorIncrement;
257 0 : xLineNumbering->setPropertyValue(sSeparatorInterval, aAny);
258 : }
259 :
260 17 : aAny.setValue(&bNumberLines, ::getBooleanCppuType());
261 17 : xLineNumbering->setPropertyValue(sIsOn, aAny);
262 :
263 17 : aAny.setValue(&bCountEmptyLines, ::getBooleanCppuType());
264 17 : xLineNumbering->setPropertyValue(sCountEmptyLines, aAny);
265 :
266 17 : aAny.setValue(&bCountInFloatingFrames, ::getBooleanCppuType());
267 17 : xLineNumbering->setPropertyValue(sCountLinesInFrames, aAny);
268 :
269 17 : aAny.setValue(&bRestartNumbering, ::getBooleanCppuType());
270 17 : xLineNumbering->setPropertyValue(sRestartAtEachPage, aAny);
271 :
272 17 : sal_Int16 nNumType = NumberingType::ARABIC;
273 17 : GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
274 : sNumFormat,
275 34 : sNumLetterSync );
276 17 : aAny <<= nNumType;
277 17 : xLineNumbering->setPropertyValue(sNumberingType, aAny);
278 17 : }
279 17 : }
280 17 : }
281 :
282 0 : SvXMLImportContext* XMLLineNumberingImportContext::CreateChildContext(
283 : sal_uInt16 nPrefix,
284 : const OUString& rLocalName,
285 : const Reference<XAttributeList> & xAttrList )
286 : {
287 0 : if ( (nPrefix == XML_NAMESPACE_TEXT) &&
288 0 : IsXMLToken(rLocalName, XML_LINENUMBERING_SEPARATOR) )
289 : {
290 0 : return new XMLLineNumberingSeparatorImportContext(GetImport(),
291 : nPrefix, rLocalName,
292 0 : *this);
293 : }
294 : else
295 : {
296 : // unknown element: default context
297 : return SvXMLImportContext::CreateChildContext(nPrefix, rLocalName,
298 0 : xAttrList);
299 : }
300 : }
301 :
302 0 : void XMLLineNumberingImportContext::SetSeparatorText(
303 : const OUString& sText)
304 : {
305 0 : sSeparator = sText;
306 0 : }
307 :
308 0 : void XMLLineNumberingImportContext::SetSeparatorIncrement(
309 : sal_Int16 nIncr)
310 : {
311 0 : nSeparatorIncrement = nIncr;
312 0 : }
313 :
314 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|