Update ooo320-m1
[ooovba.git] / xmloff / source / style / XMLFootnoteSeparatorImport.cxx
blobcd07088eb1804cd4c23447c29f5a657179b7633c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLFootnoteSeparatorImport.cxx,v $
10 * $Revision: 1.10 $
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 "XMLFootnoteSeparatorImport.hxx"
35 #ifndef _RTL_USTRING
36 #include <rtl/ustring.hxx>
37 #endif
38 #include <com/sun/star/uno/Reference.h>
39 #include <com/sun/star/xml/sax/XAttributeList.hpp>
40 #include <com/sun/star/text/HorizontalAdjust.hpp>
41 #include <xmloff/xmlimp.hxx>
42 #include <xmloff/xmltoken.hxx>
43 #include <xmloff/xmluconv.hxx>
44 #include <xmloff/xmlprmap.hxx>
45 #include "xmlnmspe.hxx"
46 #include <xmloff/nmspmap.hxx>
47 #include <xmloff/maptype.hxx>
49 #ifndef _XMLOFF_PAGEMASTERSTYLEMAP_HXX
50 #include <xmloff/PageMasterStyleMap.hxx>
51 #endif
52 #include <tools/debug.hxx>
53 #include <tools/color.hxx>
55 #include <vector>
58 using namespace ::com::sun::star;
59 using namespace ::xmloff::token;
61 using ::rtl::OUString;
62 using ::std::vector;
63 using ::com::sun::star::uno::Any;
64 using ::com::sun::star::uno::Reference;
65 using ::com::sun::star::xml::sax::XAttributeList;
68 TYPEINIT1(XMLFootnoteSeparatorImport, SvXMLImportContext);
71 XMLFootnoteSeparatorImport::XMLFootnoteSeparatorImport(
72 SvXMLImport& rImport,
73 sal_uInt16 nPrefix,
74 const OUString& rLocalName,
75 vector<XMLPropertyState> & rProps,
76 const UniReference<XMLPropertySetMapper> & rMapperRef,
77 sal_Int32 nIndex) :
78 SvXMLImportContext(rImport, nPrefix, rLocalName),
79 rProperties(rProps),
80 rMapper(rMapperRef),
81 nPropIndex(nIndex)
85 XMLFootnoteSeparatorImport::~XMLFootnoteSeparatorImport()
89 void XMLFootnoteSeparatorImport::StartElement(
90 const Reference<XAttributeList> & xAttrList)
92 // get the values from the properties
93 sal_Int16 nLineWeight = 0;
94 sal_Int32 nLineColor = 0;
95 sal_Int8 nLineRelWidth = 0;
96 sal_Int16 eLineAdjust = text::HorizontalAdjust_LEFT; // enum text::HorizontalAdjust
97 sal_Int32 nLineTextDistance = 0;
98 sal_Int32 nLineDistance = 0;
100 // iterate over xattribute list and fill values
101 sal_Int16 nLength = xAttrList->getLength();
102 for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
104 OUString sLocalName;
105 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
106 GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
107 &sLocalName );
109 if (XML_NAMESPACE_STYLE == nPrefix)
111 OUString sAttrValue = xAttrList->getValueByIndex(nAttr);
112 sal_Int32 nTmp;
113 if (IsXMLToken( sLocalName, XML_WIDTH ))
115 if (GetImport().GetMM100UnitConverter().convertMeasure(
116 nTmp, sAttrValue))
118 nLineWeight = (sal_Int16)nTmp;
121 else if (IsXMLToken( sLocalName, XML_DISTANCE_BEFORE_SEP ))
123 if (GetImport().GetMM100UnitConverter().convertMeasure(
124 nTmp, sAttrValue))
125 nLineTextDistance = nTmp;
127 else if (IsXMLToken( sLocalName, XML_DISTANCE_AFTER_SEP ))
129 if (GetImport().GetMM100UnitConverter().convertMeasure(
130 nTmp, sAttrValue))
131 nLineDistance = nTmp;
133 else if (IsXMLToken( sLocalName, XML_ADJUSTMENT ))
135 sal_uInt16 nTmpU;
136 static const SvXMLEnumMapEntry aXML_HorizontalAdjust_Enum[] =
138 { XML_LEFT, text::HorizontalAdjust_LEFT },
139 { XML_CENTER, text::HorizontalAdjust_CENTER },
140 { XML_RIGHT, text::HorizontalAdjust_RIGHT },
141 { XML_TOKEN_INVALID, 0 }
144 if (SvXMLUnitConverter::convertEnum(
145 nTmpU, sAttrValue, aXML_HorizontalAdjust_Enum))
146 eLineAdjust = (sal_Int16)nTmpU;
148 else if (IsXMLToken( sLocalName, XML_REL_WIDTH ))
150 if (SvXMLUnitConverter::convertPercent(nTmp, sAttrValue))
151 nLineRelWidth = (sal_uInt8)nTmp;
153 else if (IsXMLToken( sLocalName, XML_COLOR ))
155 Color aColor;
156 if (SvXMLUnitConverter::convertColor(aColor, sAttrValue))
157 nLineColor = (sal_Int32)aColor.GetColor();
162 // OK, now we have all values and can fill the XMLPropertyState vector
163 Any aAny;
164 sal_Int32 nIndex;
166 aAny <<= eLineAdjust;
167 nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_ADJUST);
168 XMLPropertyState aLineAdjust( nIndex, aAny);
169 rProperties.push_back(aLineAdjust);
171 aAny <<= nLineColor;
172 nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_COLOR);
173 XMLPropertyState aLineColor( nIndex, aAny );
174 rProperties.push_back(aLineColor);
176 aAny <<= nLineDistance;
177 nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_DISTANCE);
178 XMLPropertyState aLineDistance( nIndex, aAny );
179 rProperties.push_back(aLineDistance);
181 aAny <<= nLineRelWidth;
182 nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_WIDTH);
183 XMLPropertyState aLineRelWidth( nIndex, aAny);
184 rProperties.push_back(aLineRelWidth);
186 aAny <<= nLineTextDistance;
187 nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_DISTANCE);
188 XMLPropertyState aLineTextDistance( nIndex, aAny);
189 rProperties.push_back(aLineTextDistance);
191 DBG_ASSERT( rMapper->FindEntryIndex(CTF_PM_FTN_LINE_WEIGTH) == nPropIndex,
192 "Received wrong property map index!" );
193 aAny <<= nLineWeight;
194 XMLPropertyState aLineWeight( nPropIndex, aAny );
195 rProperties.push_back(aLineWeight);