LibreOffice Module xmloff (master)  1
SchXMLTextListContext.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 
22 
23 #include <xmloff/xmlnmspe.hxx>
24 #include <xmloff/xmltoken.hxx>
25 
26 using ::com::sun::star::uno::Sequence;
27 using ::com::sun::star::uno::Reference;
28 using namespace com::sun::star;
29 using namespace ::xmloff::token;
30 
31 namespace {
32 
33 class SchXMLListItemContext : public SvXMLImportContext
34 {
35 public:
36  SchXMLListItemContext( SvXMLImport& rImport, const OUString& rLocalName, OUString& rText );
37 
38  virtual void StartElement( const Reference< xml::sax::XAttributeList >& xAttrList ) override;
39  virtual void EndElement() override;
40 
41  virtual SvXMLImportContextRef CreateChildContext(
42  sal_uInt16 nPrefix,
43  const OUString& rLocalName,
44  const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList ) override;
45 
46 private:
47  OUString& m_rText;
48 };
49 
50 }
51 
52 SchXMLListItemContext::SchXMLListItemContext(
53  SvXMLImport& rImport
54  , const OUString& rLocalName
55  , OUString& rText )
56  : SvXMLImportContext( rImport, XML_NAMESPACE_TEXT, rLocalName )
57  , m_rText( rText )
58 {
59 }
60 
61 void SchXMLListItemContext::StartElement( const Reference< xml::sax::XAttributeList >& /*xAttrList*/ )
62 {
63 }
64 
65 void SchXMLListItemContext::EndElement()
66 {
67 }
68 
69 SvXMLImportContextRef SchXMLListItemContext::CreateChildContext(
70  sal_uInt16 nPrefix, const OUString& rLocalName,
71  const uno::Reference< xml::sax::XAttributeList >& )
72 {
73  SvXMLImportContext* pContext = nullptr;
74  if( (nPrefix == XML_NAMESPACE_TEXT ||
75  nPrefix == XML_NAMESPACE_LO_EXT) && IsXMLToken( rLocalName, XML_P ) )
76  pContext = new SchXMLParagraphContext( GetImport(), rLocalName, m_rText );
77  return pContext;
78 }
79 
81  SvXMLImport& rImport
82  , const OUString& rLocalName
83  , Sequence< OUString>& rTextList )
84  : SvXMLImportContext( rImport, XML_NAMESPACE_TEXT, rLocalName )
85  , m_rTextList( rTextList )
86  , m_aTextVector()
87 {
88 }
89 
91 {
92 }
93 
94 void SchXMLTextListContext::StartElement( const Reference< xml::sax::XAttributeList >& /*xAttrList*/ )
95 {
96 }
97 
99 {
100  sal_Int32 nCount = m_aTextVector.size();
101  m_rTextList.realloc(nCount);
102  for( sal_Int32 nN=0; nN<nCount; nN++ )
103  m_rTextList[nN]=m_aTextVector[nN];
104 }
105 
107  sal_uInt16 nPrefix, const OUString& rLocalName,
108  const uno::Reference< xml::sax::XAttributeList >& )
109 {
110  SvXMLImportContext* pContext = nullptr;
111  if( nPrefix == XML_NAMESPACE_TEXT && IsXMLToken( rLocalName, XML_LIST_ITEM ) )
112  {
113  m_aTextVector.emplace_back( );
114  pContext = new SchXMLListItemContext( GetImport(), rLocalName, m_aTextVector.back() );
115  }
116  return pContext;
117 }
118 
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr sal_uInt16 XML_NAMESPACE_LO_EXT
Definition: xmlnmspe.hxx:80
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3422
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
Create a children element context.
constexpr sal_uInt16 XML_NAMESPACE_TEXT
Definition: xmlnmspe.hxx:31
int nCount
virtual void EndElement() override
EndElement is called before a context will be destructed, but after an elements context has been pars...
css::uno::Sequence< OUString > & m_rTextList
SchXMLTextListContext(SvXMLImport &rImport, const OUString &rLocalName, css::uno::Sequence< OUString > &rTextList)
virtual ~SchXMLTextListContext() override
std::vector< OUString > m_aTextVector
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
Handling of tokens in XML:
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...