LibreOffice Module xmloff (master)  1
contexts.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 #include <xmloff/xmltoken.hxx>
21 #include <xmloff/xmlnamespace.hxx>
22 #include <xmloff/xmlmetai.hxx>
23 #include <xmloff/xmlstyle.hxx>
24 #include <SchXMLImport.hxx>
26 
27 #include "contexts.hxx"
28 
29 #include <sal/log.hxx>
30 
31 using namespace com::sun::star;
32 using namespace ::xmloff::token;
33 
34 namespace {
35 
36 class SchXMLBodyContext_Impl : public SvXMLImportContext
37 {
38 private:
39  SchXMLImportHelper& mrImportHelper;
40 
41 public:
42 
43  SchXMLBodyContext_Impl( SchXMLImportHelper& rImpHelper,
44  SvXMLImport& rImport );
45 
46  virtual void SAL_CALL startFastElement( sal_Int32 /*nElement*/,
47  const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) override {}
48 
49  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
50  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
51 };
52 
53 }
54 
55 SchXMLBodyContext_Impl::SchXMLBodyContext_Impl(
56  SchXMLImportHelper& rImpHelper, SvXMLImport& rImport ) :
57  SvXMLImportContext( rImport ),
58  mrImportHelper( rImpHelper )
59 {
60 }
61 
62 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SchXMLBodyContext_Impl::createFastChildContext(
63  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
64 {
65  return new SchXMLBodyContext( mrImportHelper, GetImport(), nElement );
66 }
67 
69  SvXMLImport& rImport,
70  sal_Int32 nElement ) :
71  SvXMLImportContext( rImport ),
72  mrImportHelper( rImpHelper )
73 {
74  SAL_WARN_IF(( nElement != XML_ELEMENT( OFFICE, XML_DOCUMENT ) &&
75  nElement != XML_ELEMENT( OFFICE, XML_DOCUMENT_META ) &&
76  nElement != XML_ELEMENT( OFFICE, XML_DOCUMENT_STYLES ) &&
77  nElement != XML_ELEMENT( OFFICE, XML_DOCUMENT_CONTENT ) ), "xmloff.chart", "SchXMLDocContext instantiated with no <office:document> element" );
78 }
79 
81 {}
82 
83 
85  sal_uInt16 nPrefix,
86  const OUString& rLocalName,
87  const uno::Reference< xml::sax::XAttributeList >& /*xAttrList*/ )
88 {
89  SvXMLImportContextRef xContext;
90  const SvXMLTokenMap& rTokenMap = mrImportHelper.GetDocElemTokenMap();
91 
92  switch( rTokenMap.Get( nPrefix, rLocalName ))
93  {
94  case XML_TOK_DOC_META:
95  // we come here in the flat ODF file format,
96  // if XDocumentPropertiesSupplier is not supported at the model
97  break;
98  }
99 
100  return xContext;
101 }
102 
103 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SchXMLDocContext::createFastChildContext(
104  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
105 {
107  switch (nElement)
108  {
109  case XML_ELEMENT(OFFICE, XML_BODY):
110  if( nFlags & SvXMLImportFlags::CONTENT )
111  return new SchXMLBodyContext_Impl( mrImportHelper, GetImport() );
112  break;
114  // for draw styles containing gradients/hatches/markers and dashes
115  if( nFlags & SvXMLImportFlags::STYLES )
116  return new SvXMLStylesContext( GetImport() );
117  break;
119  if( nFlags & SvXMLImportFlags::AUTOSTYLES )
120  // not nice, but this is safe, as the SchXMLDocContext class can only by
121  // instantiated by the chart import class SchXMLImport (header is not exported)
122  return
123  static_cast< SchXMLImport& >( GetImport() ).CreateStylesContext();
124  break;
125  }
126  return nullptr;
127 }
128 
130  SchXMLImportHelper& i_rImpHelper,
131  SchXMLImport& i_rImport,
132  sal_Int32 i_nElement,
133  const uno::Reference<document::XDocumentProperties>& i_xDocProps) :
134  SvXMLImportContext(i_rImport),
135  SchXMLDocContext(i_rImpHelper, i_rImport, i_nElement),
136  SvXMLMetaDocumentContext(i_rImport, i_xDocProps)
137 {
138 }
139 
140 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SchXMLFlatDocContext_Impl::createFastChildContext(
141  sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
142 {
143  // behave like meta base class iff we encounter office:meta
144  if ( nElement == XML_ELEMENT( OFFICE, XML_META ) ) {
146  nElement, xAttrList );
147  } else {
149  nElement, xAttrList );
150  }
151 }
152 
154  SvXMLImport& rImport,
155  sal_Int32 nElement ) :
156  SvXMLImportContext( rImport ),
157  mrImportHelper( rImpHelper )
158 {
159  SAL_WARN_IF( nElement != XML_ELEMENT(OFFICE, XML_CHART), "xmloff.chart", "SchXMLBodyContext instantiated with no <office:chart> element" );
160 }
161 
163 {}
164 
165 css::uno::Reference< css::xml::sax::XFastContextHandler > SchXMLBodyContext::createFastChildContext(
166  sal_Int32 /*nElement*/, const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ )
167 {
168  return nullptr;
169 }
170 
172  sal_uInt16 nPrefix,
173  const OUString& rLocalName,
174  const uno::Reference< xml::sax::XAttributeList >& xAttrList )
175 {
176  SvXMLImportContextRef xContext;
177 
178  // <chart:chart> element
179  if( nPrefix == XML_NAMESPACE_CHART &&
180  IsXMLToken( rLocalName, XML_CHART ) )
181  {
183  nPrefix, rLocalName,
184  GetImport().GetModel(),
185  xAttrList );
186  }
187  else if(nPrefix == XML_NAMESPACE_TABLE &&
188  IsXMLToken( rLocalName, XML_CALCULATION_SETTINGS ))
189  {
190  // i99104 handle null date correctly
191  xContext = new SchXMLCalculationSettingsContext ( GetImport(), nPrefix, rLocalName, xAttrList);
192  }
193 
194  return xContext;
195 }
196 
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SchXMLFlatDocContext_Impl(SchXMLImportHelper &i_rImpHelper, SchXMLImport &i_rImport, sal_Int32 i_nElement, const css::uno::Reference< css::document::XDocumentProperties > &i_xDocProps)
Definition: contexts.cxx:129
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3434
SchXMLDocContext(SchXMLImportHelper &rImpHelper, SvXMLImport &rImport, sal_Int32 nElement)
Definition: contexts.cxx:68
constexpr sal_uInt16 XML_NAMESPACE_CHART
virtual ~SchXMLDocContext() override
Definition: contexts.cxx:80
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.
Definition: contexts.cxx:171
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
Definition: contexts.cxx:165
virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
Create a children element context.
Definition: contexts.cxx:84
SvXMLImportFlags
Definition: xmlimp.hxx:108
SchXMLImportHelper & mrImportHelper
Definition: contexts.hxx:84
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
Definition: xmlmetai.cxx:231
SchXMLImportHelper & mrImportHelper
Definition: contexts.hxx:40
sal_uInt16 Get(sal_uInt16 nPrefix, const OUString &rLName) const
Definition: xmltkmap.cxx:99
SvXMLImportContext * CreateChartContext(SvXMLImport &rImport, sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::frame::XModel > &rChartModel, const css::uno::Reference< css::xml::sax::XAttributeList > &rAttrList)
get the context for reading the element with subelements.
With this class you can import a element containing its data as element o...
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
constexpr sal_uInt16 XML_NAMESPACE_TABLE
SvXMLImportFlags getImportFlags() const
Definition: xmlimp.hxx:460
#define SAL_WARN_IF(condition, area, stream)
Handling of tokens in XML:
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:94
SchXMLBodyContext(SchXMLImportHelper &rImpHelper, SvXMLImport &rImport, sal_Int32 nElement)
Definition: contexts.cxx:153
const SvXMLTokenMap & GetDocElemTokenMap()
handles the top-level office:document-meta element of meta.xml documents
Definition: xmlmetai.hxx:35
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
Definition: contexts.cxx:140
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
Definition: contexts.cxx:103
virtual ~SchXMLBodyContext() override
Definition: contexts.cxx:162