1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include "XMLLineNumberingSeparatorImportContext.hxx"
27 #include "XMLLineNumberingImportContext.hxx"
28 #include <xmloff/xmlimp.hxx>
29 #include <xmloff/nmspmap.hxx>
30 #include "xmloff/xmlnmspe.hxx"
31 #include <xmloff/xmltoken.hxx>
32 #include <xmloff/xmluconv.hxx>
33 
34 
35 using namespace ::com::sun::star::uno;
36 
37 using ::com::sun::star::xml::sax::XAttributeList;
38 using ::rtl::OUString;
39 using ::rtl::OUStringBuffer;
40 using ::xmloff::token::IsXMLToken;
41 using ::xmloff::token::XML_INCREMENT;
42 
43 TYPEINIT1( XMLLineNumberingSeparatorImportContext, SvXMLImportContext );
44 
XMLLineNumberingSeparatorImportContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLocalName,XMLLineNumberingImportContext & rLineNumbering)45 XMLLineNumberingSeparatorImportContext::XMLLineNumberingSeparatorImportContext(
46 	SvXMLImport& rImport,
47 	sal_uInt16 nPrfx,
48 	const OUString& rLocalName,
49 	XMLLineNumberingImportContext& rLineNumbering) :
50 		SvXMLImportContext(rImport, nPrfx, rLocalName),
51 		rLineNumberingContext(rLineNumbering)
52 {
53 }
54 
~XMLLineNumberingSeparatorImportContext()55 XMLLineNumberingSeparatorImportContext::~XMLLineNumberingSeparatorImportContext()
56 {
57 }
58 
StartElement(const Reference<XAttributeList> & xAttrList)59 void XMLLineNumberingSeparatorImportContext::StartElement(
60 	const Reference<XAttributeList> & xAttrList)
61 {
62 	sal_Int16 nLength = xAttrList->getLength();
63 	for(sal_Int16 i=0; i<nLength; i++)
64 	{
65 		OUString sLocalName;
66 		sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
67 			GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
68 
69 		if ( (nPrefix == XML_NAMESPACE_TEXT) &&
70 			 IsXMLToken(sLocalName, XML_INCREMENT) )
71 		{
72 			sal_Int32 nTmp;
73 			if (SvXMLUnitConverter::convertNumber(
74 				nTmp, xAttrList->getValueByIndex(i), 0))
75 			{
76 				rLineNumberingContext.SetSeparatorIncrement((sal_Int16)nTmp);
77 			}
78 			// else: invalid number -> ignore
79 		}
80 		// else: unknown attribute -> ignore
81 	}
82 }
83 
Characters(const OUString & rChars)84 void XMLLineNumberingSeparatorImportContext::Characters(
85 	const OUString& rChars )
86 {
87 	sSeparatorBuf.append(rChars);
88 }
89 
EndElement()90 void XMLLineNumberingSeparatorImportContext::EndElement()
91 {
92 	rLineNumberingContext.SetSeparatorText(sSeparatorBuf.makeStringAndClear());
93 }
94