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 <sal/log.hxx>
24 #include <xmloff/xmlimp.hxx>
25 #include <xmloff/xmlnamespace.hxx>
26 #include <xmloff/xmltoken.hxx>
27 #include <xmloff/namespacemap.hxx>
28 
29 #include <com/sun/star/xml/sax/XAttributeList.hpp>
30 
31 using namespace com::sun::star;
32 using namespace ::xmloff::token;
33 
35  OUString& rText,
36  OUString * pOutId /* = 0 */ ) :
37  SvXMLImportContext( rImport ),
38  mrText( rText ),
39  mpId( pOutId )
40 {
41 }
42 
44 {}
45 
47  sal_Int32 /*nElement*/,
48  const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
49 {
50  // remember the id. It is used for storing the original cell range string in
51  // a local table (cached data)
52  if( !mpId )
53  return;
54 
55  bool bHaveXmlId( false );
56 
57  for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
58  {
59  switch(aIter.getToken())
60  {
61  case XML_ELEMENT(XML, XML_ID):
62  (*mpId) = aIter.toString();
63  bHaveXmlId = true;
64  break;
65  case XML_ELEMENT(TEXT, XML_ID):
66  { // text:id shall be ignored if xml:id exists
67  if (!bHaveXmlId)
68  {
69  (*mpId) = aIter.toString();
70  }
71  break;
72  }
73  default:
74  XMLOFF_WARN_UNKNOWN("xmloff", aIter);
75  }
76  }
77 }
78 
80 {
81  mrText = maBuffer.makeStringAndClear();
82 }
83 
84 css::uno::Reference< css::xml::sax::XFastContextHandler > SchXMLParagraphContext::createFastChildContext(
85  sal_Int32 nElement,
86  const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
87 {
88  if( nElement == XML_ELEMENT(TEXT, XML_TAB_STOP) )
89  {
90  maBuffer.append( u'\x0009'); // tabulator
91  }
92  else if( nElement == XML_ELEMENT(TEXT, XML_LINE_BREAK) )
93  {
94  maBuffer.append( u'\x000A'); // linefeed
95  }
96  else
97  XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
98 
99  return nullptr;
100 }
101 
102 void SchXMLParagraphContext::characters( const OUString& rChars )
103 {
104  maBuffer.append( rChars );
105 }
106 
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SchXMLParagraphContext(SvXMLImport &rImport, OUString &rText, OUString *pOutId=nullptr)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
#define XMLOFF_WARN_UNKNOWN(area, rIter)
Definition: xmlictxt.hxx:113
float u
virtual ~SchXMLParagraphContext() override
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
Handling of tokens in XML:
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
endFastElement is called before a context will be destructed, but after an elements context has been ...
#define XMLOFF_WARN_UNKNOWN_ELEMENT(area, token)
Definition: xmlictxt.hxx:119
virtual void SAL_CALL characters(const OUString &rChars) override
This method is called for all characters that are contained in the current element.
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
TEXT