LibreOffice Module xmloff (master)  1
SchXMLParagraphContext.cxx
Go to the documentation of this file.
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 
22 
23 #include <xmloff/xmlimp.hxx>
24 #include <xmloff/xmlnmspe.hxx>
25 #include <xmloff/xmltoken.hxx>
26 #include <xmloff/nmspmap.hxx>
27 
28 #include <com/sun/star/xml/sax/XAttributeList.hpp>
29 
30 using namespace com::sun::star;
31 using namespace ::xmloff::token;
32 
34  const OUString& rLocalName,
35  OUString& rText,
36  OUString * pOutId /* = 0 */ ) :
37  SvXMLImportContext( rImport, XML_NAMESPACE_TEXT, rLocalName ),
38  mrText( rText ),
39  mpId( pOutId )
40 {
41 }
42 
44 {}
45 
46 void SchXMLParagraphContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
47 {
48  // remember the id. It is used for storing the original cell range string in
49  // a local table (cached data)
50  if( !mpId )
51  return;
52 
53  sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
54  bool bHaveXmlId( false );
55 
56  for( sal_Int16 i = 0; i < nAttrCount; i++ )
57  {
58  OUString sAttrName = xAttrList->getNameByIndex( i );
59  OUString aLocalName;
60  sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
61 
62  if (IsXMLToken(aLocalName, XML_ID))
63  {
64  if (nPrefix == XML_NAMESPACE_XML)
65  {
66  (*mpId) = xAttrList->getValueByIndex( i );
67  bHaveXmlId = true;
68  }
69  if (nPrefix == XML_NAMESPACE_TEXT)
70  { // text:id shall be ignored if xml:id exists
71  if (!bHaveXmlId)
72  {
73  (*mpId) = xAttrList->getValueByIndex( i );
74  }
75  }
76  }
77  }
78 }
79 
81 {
82  mrText = maBuffer.makeStringAndClear();
83 }
84 
86  sal_uInt16 nPrefix,
87  const OUString& rLocalName,
88  const uno::Reference< xml::sax::XAttributeList >& )
89 {
90  if( nPrefix == XML_NAMESPACE_TEXT )
91  {
93  {
94  maBuffer.append( u'\x0009'); // tabulator
95  }
96  else if( rLocalName == ::xmloff::token::GetXMLToken( ::xmloff::token::XML_LINE_BREAK ))
97  {
98  maBuffer.append( u'\x000A'); // linefeed
99  }
100  }
101 
102  return nullptr;
103 }
104 
105 void SchXMLParagraphContext::Characters( const OUString& rChars )
106 {
107  maBuffer.append( rChars );
108 }
109 
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3428
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
StartElement is called after a context has been constructed and before an elements context is parsed...
SvXMLNamespaceMap & GetNamespaceMap()
Definition: xmlimp.hxx:401
constexpr sal_uInt16 XML_NAMESPACE_TEXT
Definition: xmlnmspe.hxx:31
virtual void EndElement() override
EndElement is called before a context will be destructed, but after an elements context has been pars...
sal_uInt16 GetKeyByAttrName(const OUString &rAttrName, OUString *pPrefix, OUString *pLocalName, OUString *pNamespace) const
Definition: nmspmap.cxx:437
constexpr sal_uInt16 XML_NAMESPACE_XML
Definition: xmlnmspe.hxx:51
SchXMLParagraphContext(SvXMLImport &rImport, const OUString &rLocalName, OUString &rText, OUString *pOutId=nullptr)
int i
float u
virtual ~SchXMLParagraphContext() override
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
virtual void Characters(const OUString &rChars) override
This method is called for all characters that are contained in the current element.
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3372
Handling of tokens in XML:
virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
Create a children element context.