1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLLineNumberingImportContext.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "XMLLineNumberingImportContext.hxx"
34 #include "XMLLineNumberingSeparatorImportContext.hxx"
35 #include "com/sun/star/beans/XPropertySet.hpp"
36 #include "com/sun/star/text/XLineNumberingProperties.hpp"
37 #include <com/sun/star/style/LineNumberPosition.hpp>
38 #include <com/sun/star/style/NumberingType.hpp>
39 #include <xmloff/xmlimp.hxx>
40 #include <xmloff/xmluconv.hxx>
41 #include "xmlnmspe.hxx"
42 #include <xmloff/nmspmap.hxx>
43 #include <xmloff/xmltoken.hxx>
44 #include <xmloff/xmlnumi.hxx>
47 using namespace ::com::sun::star
;
48 using namespace ::com::sun::star::uno
;
49 using namespace ::com::sun::star::style
;
50 using namespace ::xmloff::token
;
52 using ::com::sun::star::beans::XPropertySet
;
53 using ::com::sun::star::xml::sax::XAttributeList
;
54 using ::com::sun::star::text::XLineNumberingProperties
;
55 using ::rtl::OUString
;
57 TYPEINIT1( XMLLineNumberingImportContext
, SvXMLStyleContext
);
60 XMLLineNumberingImportContext::XMLLineNumberingImportContext(
63 const OUString
& rLocalName
,
64 const Reference
<XAttributeList
> & xAttrList
)
65 : SvXMLStyleContext(rImport
, nPrfx
, rLocalName
, xAttrList
, XML_STYLE_FAMILY_TEXT_LINENUMBERINGCONFIG
)
66 , sCharStyleName(RTL_CONSTASCII_USTRINGPARAM("CharStyleName"))
67 , sCountEmptyLines(RTL_CONSTASCII_USTRINGPARAM("CountEmptyLines"))
68 , sCountLinesInFrames(RTL_CONSTASCII_USTRINGPARAM("CountLinesInFrames"))
69 , sDistance(RTL_CONSTASCII_USTRINGPARAM("Distance"))
70 , sInterval(RTL_CONSTASCII_USTRINGPARAM("Interval"))
71 , sSeparatorText(RTL_CONSTASCII_USTRINGPARAM("SeparatorText"))
72 , sNumberPosition(RTL_CONSTASCII_USTRINGPARAM("NumberPosition"))
73 , sNumberingType(RTL_CONSTASCII_USTRINGPARAM("NumberingType"))
74 , sIsOn(RTL_CONSTASCII_USTRINGPARAM("IsOn"))
75 , sRestartAtEachPage(RTL_CONSTASCII_USTRINGPARAM("RestartAtEachPage"))
76 , sSeparatorInterval(RTL_CONSTASCII_USTRINGPARAM("SeparatorInterval"))
77 , sNumFormat(GetXMLToken(XML_1
))
78 , sNumLetterSync(GetXMLToken(XML_FALSE
))
80 , nNumberPosition(style::LineNumberPosition::LEFT
)
82 , nSeparatorIncrement(-1)
83 , bNumberLines(sal_True
)
84 , bCountEmptyLines(sal_True
)
85 , bCountInFloatingFrames(sal_False
)
86 , bRestartNumbering(sal_False
)
90 XMLLineNumberingImportContext::~XMLLineNumberingImportContext()
94 void XMLLineNumberingImportContext::StartElement(
95 const Reference
<XAttributeList
> & xAttrList
)
97 static SvXMLTokenMapEntry aLineNumberingTokenMap
[] =
99 { XML_NAMESPACE_TEXT
, XML_STYLE_NAME
, XML_TOK_LINENUMBERING_STYLE_NAME
},
100 { XML_NAMESPACE_TEXT
, XML_NUMBER_LINES
,
101 XML_TOK_LINENUMBERING_NUMBER_LINES
},
102 { XML_NAMESPACE_TEXT
, XML_COUNT_EMPTY_LINES
,
103 XML_TOK_LINENUMBERING_COUNT_EMPTY_LINES
},
104 { XML_NAMESPACE_TEXT
, XML_COUNT_IN_TEXT_BOXES
,
105 XML_TOK_LINENUMBERING_COUNT_IN_TEXT_BOXES
},
106 { XML_NAMESPACE_TEXT
, XML_RESTART_ON_PAGE
,
107 XML_TOK_LINENUMBERING_RESTART_NUMBERING
},
108 { XML_NAMESPACE_TEXT
, XML_OFFSET
, XML_TOK_LINENUMBERING_OFFSET
},
109 { XML_NAMESPACE_STYLE
, XML_NUM_FORMAT
, XML_TOK_LINENUMBERING_NUM_FORMAT
},
110 { XML_NAMESPACE_STYLE
, XML_NUM_LETTER_SYNC
,
111 XML_TOK_LINENUMBERING_NUM_LETTER_SYNC
},
112 { XML_NAMESPACE_TEXT
, XML_NUMBER_POSITION
,
113 XML_TOK_LINENUMBERING_NUMBER_POSITION
},
114 { XML_NAMESPACE_TEXT
, XML_INCREMENT
, XML_TOK_LINENUMBERING_INCREMENT
},
115 // { XML_NAMESPACE_TEXT, XML_LINENUMBERING_CONFIGURATION,
116 // XML_TOK_LINENUMBERING_LINENUMBERING_CONFIGURATION },
117 // { XML_NAMESPACE_TEXT, XML_INCREMENT, XML_TOK_LINENUMBERING_INCREMENT },
118 // { XML_NAMESPACE_TEXT, XML_LINENUMBERING_SEPARATOR,
119 // XML_TOK_LINENUMBERING_LINENUMBERING_SEPARATOR },
124 SvXMLTokenMap
aTokenMap(aLineNumberingTokenMap
);
126 // process attributes
127 sal_Int16 nLength
= xAttrList
->getLength();
128 for(sal_Int16 i
=0; i
<nLength
; i
++)
131 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
132 GetKeyByAttrName( xAttrList
->getNameByIndex(i
), &sLocalName
);
135 (enum LineNumberingToken
)aTokenMap
.Get(nPrefix
, sLocalName
),
136 xAttrList
->getValueByIndex(i
));
140 void XMLLineNumberingImportContext::ProcessAttribute(
141 enum LineNumberingToken eToken
,
149 case XML_TOK_LINENUMBERING_STYLE_NAME
:
153 case XML_TOK_LINENUMBERING_NUMBER_LINES
:
154 if (SvXMLUnitConverter::convertBool(bTmp
, sValue
))
160 case XML_TOK_LINENUMBERING_COUNT_EMPTY_LINES
:
161 if (SvXMLUnitConverter::convertBool(bTmp
, sValue
))
163 bCountEmptyLines
= bTmp
;
167 case XML_TOK_LINENUMBERING_COUNT_IN_TEXT_BOXES
:
168 if (SvXMLUnitConverter::convertBool(bTmp
, sValue
))
170 bCountInFloatingFrames
= bTmp
;
174 case XML_TOK_LINENUMBERING_RESTART_NUMBERING
:
175 if (SvXMLUnitConverter::convertBool(bTmp
, sValue
))
177 bRestartNumbering
= bTmp
;
181 case XML_TOK_LINENUMBERING_OFFSET
:
182 if (GetImport().GetMM100UnitConverter().
183 convertMeasure(nTmp
, sValue
))
189 case XML_TOK_LINENUMBERING_NUM_FORMAT
:
193 case XML_TOK_LINENUMBERING_NUM_LETTER_SYNC
:
194 sNumLetterSync
= sValue
;
197 case XML_TOK_LINENUMBERING_NUMBER_POSITION
:
199 static const SvXMLEnumMapEntry aLineNumberPositionMap
[] =
201 { XML_LEFT
, style::LineNumberPosition::LEFT
},
202 { XML_RIGHT
, style::LineNumberPosition::RIGHT
},
203 { XML_INSIDE
, style::LineNumberPosition::INSIDE
},
204 { XML_OUTSIDE
, style::LineNumberPosition::OUTSIDE
},
205 { XML_TOKEN_INVALID
, 0 }
209 if (SvXMLUnitConverter::convertEnum(nTmp16
, sValue
,
210 aLineNumberPositionMap
))
212 nNumberPosition
= nTmp16
;
217 case XML_TOK_LINENUMBERING_INCREMENT
:
218 if (SvXMLUnitConverter::convertNumber(nTmp
, sValue
, 0))
220 nIncrement
= (sal_Int16
)nTmp
;
226 void XMLLineNumberingImportContext::CreateAndInsert(sal_Bool
)
228 // insert and block mode is handled in insertStyleFamily
230 // we'll try to get the LineNumberingProperties
231 Reference
<XLineNumberingProperties
> xSupplier(GetImport().GetModel(),
235 Reference
<XPropertySet
> xLineNumbering
=
236 xSupplier
->getLineNumberingProperties();
238 if (xLineNumbering
.is())
242 // set style name (if it exists)
243 if ( GetImport().GetStyles()->FindStyleChildContext(
244 XML_STYLE_FAMILY_TEXT_TEXT
, sStyleName
) != NULL
)
246 aAny
<<= GetImport().GetStyleDisplayName(
247 XML_STYLE_FAMILY_TEXT_TEXT
, sStyleName
);
248 xLineNumbering
->setPropertyValue(sCharStyleName
, aAny
);
252 xLineNumbering
->setPropertyValue(sSeparatorText
, aAny
);
255 xLineNumbering
->setPropertyValue(sDistance
, aAny
);
257 aAny
<<= nNumberPosition
;
258 xLineNumbering
->setPropertyValue(sNumberPosition
, aAny
);
263 xLineNumbering
->setPropertyValue(sInterval
, aAny
);
266 if (nSeparatorIncrement
>= 0)
268 aAny
<<= nSeparatorIncrement
;
269 xLineNumbering
->setPropertyValue(sSeparatorInterval
, aAny
);
272 aAny
.setValue(&bNumberLines
, ::getBooleanCppuType());
273 xLineNumbering
->setPropertyValue(sIsOn
, aAny
);
275 aAny
.setValue(&bCountEmptyLines
, ::getBooleanCppuType());
276 xLineNumbering
->setPropertyValue(sCountEmptyLines
, aAny
);
278 aAny
.setValue(&bCountInFloatingFrames
, ::getBooleanCppuType());
279 xLineNumbering
->setPropertyValue(sCountLinesInFrames
, aAny
);
281 aAny
.setValue(&bRestartNumbering
, ::getBooleanCppuType());
282 xLineNumbering
->setPropertyValue(sRestartAtEachPage
, aAny
);
284 sal_Int16 nNumType
= NumberingType::ARABIC
;
285 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType
,
289 xLineNumbering
->setPropertyValue(sNumberingType
, aAny
);
294 SvXMLImportContext
* XMLLineNumberingImportContext::CreateChildContext(
296 const OUString
& rLocalName
,
297 const Reference
<XAttributeList
> & xAttrList
)
299 if ( (nPrefix
== XML_NAMESPACE_TEXT
) &&
300 IsXMLToken(rLocalName
, XML_LINENUMBERING_SEPARATOR
) )
302 return new XMLLineNumberingSeparatorImportContext(GetImport(),
308 // unknown element: default context
309 return SvXMLImportContext::CreateChildContext(nPrefix
, rLocalName
,
314 void XMLLineNumberingImportContext::SetSeparatorText(
315 const OUString
& sText
)
320 void XMLLineNumberingImportContext::SetSeparatorIncrement(
323 nSeparatorIncrement
= nIncr
;