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 "XMLSectionFootnoteConfigImport.hxx"
21 :
22 : #include <rtl/ustring.hxx>
23 : #include <com/sun/star/uno/Reference.h>
24 : #include <com/sun/star/xml/sax/XAttributeList.hpp>
25 : #include <com/sun/star/style/NumberingType.hpp>
26 : #include <sax/tools/converter.hxx>
27 : #include <xmloff/xmlimp.hxx>
28 : #include <xmloff/xmltoken.hxx>
29 : #include <xmloff/xmluconv.hxx>
30 : #include <xmloff/xmlprmap.hxx>
31 : #include "xmloff/xmlnmspe.hxx"
32 : #include <xmloff/nmspmap.hxx>
33 : #include <xmloff/maptype.hxx>
34 : #include <xmloff/xmlnumi.hxx>
35 : #include <xmloff/txtprmap.hxx>
36 :
37 : #include <vector>
38 :
39 :
40 : using namespace ::xmloff::token;
41 : using namespace ::com::sun::star::style;
42 :
43 : using ::rtl::OUString;
44 : using ::std::vector;
45 : using ::com::sun::star::uno::Any;
46 : using ::com::sun::star::uno::Reference;
47 : using ::com::sun::star::xml::sax::XAttributeList;
48 :
49 :
50 0 : TYPEINIT1(XMLSectionFootnoteConfigImport, SvXMLImportContext);
51 :
52 :
53 0 : XMLSectionFootnoteConfigImport::XMLSectionFootnoteConfigImport(
54 : SvXMLImport& rImport,
55 : sal_uInt16 nPrefix,
56 : const OUString& rLocalName,
57 : vector<XMLPropertyState> & rProps,
58 : const UniReference<XMLPropertySetMapper> & rMapperRef) :
59 : SvXMLImportContext(rImport, nPrefix, rLocalName),
60 : rProperties(rProps),
61 0 : rMapper(rMapperRef)
62 : {
63 0 : }
64 :
65 0 : XMLSectionFootnoteConfigImport::~XMLSectionFootnoteConfigImport()
66 : {
67 0 : }
68 :
69 0 : void XMLSectionFootnoteConfigImport::StartElement(
70 : const Reference<XAttributeList> & xAttrList)
71 : {
72 0 : sal_Bool bEnd = sal_True; // we're inside the element, so this is true
73 0 : sal_Bool bNumOwn = sal_False;
74 0 : sal_Bool bNumRestart = sal_False;
75 0 : sal_Bool bEndnote = sal_False;
76 0 : sal_Int16 nNumRestartAt = 0;
77 0 : OUString sNumPrefix;
78 0 : OUString sNumSuffix;
79 0 : OUString sNumFormat;
80 0 : OUString sNumLetterSync;
81 :
82 : // iterate over xattribute list and fill values
83 0 : sal_Int16 nLength = xAttrList->getLength();
84 0 : for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
85 : {
86 0 : OUString sLocalName;
87 0 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
88 0 : GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
89 0 : &sLocalName );
90 0 : OUString sAttrValue = xAttrList->getValueByIndex(nAttr);
91 :
92 0 : if (XML_NAMESPACE_TEXT == nPrefix)
93 : {
94 0 : if (IsXMLToken(sLocalName, XML_START_VALUE))
95 : {
96 : sal_Int32 nTmp;
97 0 : if (::sax::Converter::convertNumber(nTmp, sAttrValue))
98 : {
99 0 : nNumRestartAt = static_cast< sal_Int16 >( nTmp ) - 1;
100 0 : bNumRestart = sal_True;
101 : }
102 : }
103 0 : else if( IsXMLToken( sLocalName, XML_NOTE_CLASS ) )
104 : {
105 0 : if( IsXMLToken( sAttrValue, XML_ENDNOTE ) )
106 0 : bEndnote = sal_True;
107 : }
108 : }
109 0 : else if (XML_NAMESPACE_STYLE == nPrefix)
110 : {
111 0 : if (IsXMLToken(sLocalName, XML_NUM_PREFIX))
112 : {
113 0 : sNumPrefix = sAttrValue;
114 0 : bNumOwn = sal_True;
115 : }
116 0 : else if (IsXMLToken(sLocalName, XML_NUM_SUFFIX))
117 : {
118 0 : sNumSuffix = sAttrValue;
119 0 : bNumOwn = sal_True;
120 : }
121 0 : else if (IsXMLToken(sLocalName, XML_NUM_FORMAT))
122 : {
123 0 : sNumFormat = sAttrValue;
124 0 : bNumOwn = sal_True;
125 : }
126 0 : else if (IsXMLToken(sLocalName, XML_NUM_LETTER_SYNC))
127 : {
128 0 : sNumLetterSync = sAttrValue;
129 0 : bNumOwn = sal_True;
130 : }
131 : }
132 0 : }
133 :
134 : // OK, now we have all values and can fill the XMLPropertyState vector
135 0 : Any aAny;
136 :
137 0 : aAny.setValue( &bNumOwn, ::getBooleanCppuType() );
138 : sal_Int32 nIndex = rMapper->FindEntryIndex( bEndnote ?
139 0 : CTF_SECTION_ENDNOTE_NUM_OWN : CTF_SECTION_FOOTNOTE_NUM_OWN );
140 0 : XMLPropertyState aNumOwn( nIndex, aAny );
141 0 : rProperties.push_back( aNumOwn );
142 :
143 0 : aAny.setValue( &bNumRestart, ::getBooleanCppuType() );
144 : nIndex = rMapper->FindEntryIndex( bEndnote ?
145 0 : CTF_SECTION_ENDNOTE_NUM_RESTART : CTF_SECTION_FOOTNOTE_NUM_RESTART );
146 0 : XMLPropertyState aNumRestart( nIndex, aAny );
147 0 : rProperties.push_back( aNumRestart );
148 :
149 0 : aAny <<= nNumRestartAt;
150 : nIndex = rMapper->FindEntryIndex( bEndnote ?
151 : CTF_SECTION_ENDNOTE_NUM_RESTART_AT :
152 0 : CTF_SECTION_FOOTNOTE_NUM_RESTART_AT );
153 0 : XMLPropertyState aNumRestartAtState( nIndex, aAny );
154 0 : rProperties.push_back( aNumRestartAtState );
155 :
156 0 : sal_Int16 nNumType = NumberingType::ARABIC;
157 0 : GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
158 : sNumFormat,
159 0 : sNumLetterSync );
160 0 : aAny <<= nNumType;
161 : nIndex = rMapper->FindEntryIndex( bEndnote ?
162 0 : CTF_SECTION_ENDNOTE_NUM_TYPE : CTF_SECTION_FOOTNOTE_NUM_TYPE );
163 0 : XMLPropertyState aNumFormatState( nIndex, aAny );
164 0 : rProperties.push_back( aNumFormatState );
165 :
166 0 : aAny <<= sNumPrefix;
167 : nIndex = rMapper->FindEntryIndex( bEndnote ?
168 0 : CTF_SECTION_ENDNOTE_NUM_PREFIX : CTF_SECTION_FOOTNOTE_NUM_PREFIX );
169 0 : XMLPropertyState aPrefixState( nIndex, aAny );
170 0 : rProperties.push_back( aPrefixState );
171 :
172 0 : aAny <<= sNumSuffix;
173 : nIndex = rMapper->FindEntryIndex( bEndnote ?
174 0 : CTF_SECTION_ENDNOTE_NUM_SUFFIX : CTF_SECTION_FOOTNOTE_NUM_SUFFIX );
175 0 : XMLPropertyState aSuffixState( nIndex, aAny );
176 0 : rProperties.push_back( aSuffixState );
177 :
178 0 : aAny.setValue( &bEnd, ::getBooleanCppuType() );
179 : nIndex = rMapper->FindEntryIndex( bEndnote ?
180 0 : CTF_SECTION_ENDNOTE_END : CTF_SECTION_FOOTNOTE_END );
181 0 : XMLPropertyState aEndState( nIndex, aAny );
182 0 : rProperties.push_back( aEndState );
183 0 : }
184 :
185 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|