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