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>
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
31using namespace com::sun::star;
32using namespace ::xmloff::token;
33
34namespace {
35
36class SchXMLBodyContext_Impl : public SvXMLImportContext
37{
38private:
39 SchXMLImportHelper& mrImportHelper;
40
41public:
42
43 SchXMLBodyContext_Impl( SchXMLImportHelper& rImpHelper,
44 SvXMLImport& rImport );
45
46 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
47 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
48};
49
50}
51
52SchXMLBodyContext_Impl::SchXMLBodyContext_Impl(
53 SchXMLImportHelper& rImpHelper, SvXMLImport& rImport ) :
54 SvXMLImportContext( rImport ),
55 mrImportHelper( rImpHelper )
56{
57}
58
59uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SchXMLBodyContext_Impl::createFastChildContext(
60 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
61{
62 return new SchXMLBodyContext( mrImportHelper, GetImport(), nElement );
63}
64
66 SvXMLImport& rImport,
67 sal_Int32 nElement ) :
68 SvXMLImportContext( rImport ),
69 mrImportHelper( rImpHelper )
70{
71 SAL_WARN_IF(( nElement != XML_ELEMENT( OFFICE, XML_DOCUMENT ) &&
72 nElement != XML_ELEMENT( OFFICE, XML_DOCUMENT_META ) &&
73 nElement != XML_ELEMENT( OFFICE, XML_DOCUMENT_STYLES ) &&
74 nElement != XML_ELEMENT( OFFICE, XML_DOCUMENT_CONTENT ) ), "xmloff.chart", "SchXMLDocContext instantiated with no <office:document> element" );
75}
76
78{}
79
80
81uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SchXMLDocContext::createFastChildContext(
82 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
83{
84 SvXMLImportFlags nFlags = GetImport().getImportFlags();
85 switch (nElement)
86 {
88 if( nFlags & SvXMLImportFlags::CONTENT )
89 return new SchXMLBodyContext_Impl( mrImportHelper, GetImport() );
90 break;
92 // for draw styles containing gradients/hatches/markers and dashes
93 if( nFlags & SvXMLImportFlags::STYLES )
94 return new SvXMLStylesContext( GetImport() );
95 break;
97 if( nFlags & SvXMLImportFlags::AUTOSTYLES )
98 // not nice, but this is safe, as the SchXMLDocContext class can only by
99 // instantiated by the chart import class SchXMLImport (header is not exported)
100 return
101 static_cast< SchXMLImport& >( GetImport() ).CreateStylesContext();
102 break;
104 // we come here in the flat ODF file format,
105 // if XDocumentPropertiesSupplier is not supported at the model
106 break;
107 }
108 return nullptr;
109}
110
112 SchXMLImportHelper& i_rImpHelper,
113 SchXMLImport& i_rImport,
114 sal_Int32 i_nElement,
115 const uno::Reference<document::XDocumentProperties>& i_xDocProps) :
116 SvXMLImportContext(i_rImport),
117 SchXMLDocContext(i_rImpHelper, i_rImport, i_nElement),
118 SvXMLMetaDocumentContext(i_rImport, i_xDocProps)
119{
120}
121
122uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SchXMLFlatDocContext_Impl::createFastChildContext(
123 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
124{
125 // behave like meta base class iff we encounter office:meta
126 if ( nElement == XML_ELEMENT( OFFICE, XML_META ) ) {
128 nElement, xAttrList );
129 } else {
131 nElement, xAttrList );
132 }
133}
134
136 SvXMLImport& rImport,
137 sal_Int32 nElement ) :
138 SvXMLImportContext( rImport ),
139 mrImportHelper( rImpHelper )
140{
141 SAL_WARN_IF( nElement != XML_ELEMENT(OFFICE, XML_CHART), "xmloff.chart", "SchXMLBodyContext instantiated with no <office:chart> element" );
142}
143
145{}
146
147css::uno::Reference< css::xml::sax::XFastContextHandler > SchXMLBodyContext::createFastChildContext(
148 sal_Int32 nElement,
149 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
150{
151 css::uno::Reference< css::xml::sax::XFastContextHandler > xContext;
152
153 // <chart:chart> element
154 if( nElement == XML_ELEMENT(CHART, XML_CHART) )
155 {
156 xContext = mrImportHelper.CreateChartContext( GetImport(), GetImport().GetModel() );
157 }
158 else if(nElement == XML_ELEMENT(TABLE, XML_CALCULATION_SETTINGS ))
159 {
160 // i99104 handle null date correctly
161 xContext = new SchXMLCalculationSettingsContext ( GetImport(), xAttrList);
162 }
163 else
164 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
165
166 return xContext;
167}
168
169/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SchXMLBodyContext(SchXMLImportHelper &rImpHelper, SvXMLImport &rImport, sal_Int32 nElement)
Definition: contexts.cxx:135
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
Definition: contexts.cxx:147
virtual ~SchXMLBodyContext() override
Definition: contexts.cxx:144
SchXMLImportHelper & mrImportHelper
Definition: contexts.hxx:70
virtual ~SchXMLDocContext() override
Definition: contexts.cxx:77
SchXMLDocContext(SchXMLImportHelper &rImpHelper, SvXMLImport &rImport, sal_Int32 nElement)
Definition: contexts.cxx:65
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:81
SchXMLImportHelper & mrImportHelper
Definition: contexts.hxx:38
SchXMLFlatDocContext_Impl(SchXMLImportHelper &i_rImpHelper, SchXMLImport &i_rImport, sal_Int32 i_nElement, const css::uno::Reference< css::document::XDocumentProperties > &i_xDocProps)
Definition: contexts.cxx:111
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:122
With this class you can import a <chart:chart> element containing its data as <table:table> element o...
SvXMLImportContext * CreateChartContext(SvXMLImport &rImport, const css::uno::Reference< css::frame::XModel > &rChartModel)
get the context for reading the <chart:chart> element with subelements.
This class deliberately does not support XWeak, to improve performance when loading large documents.
Definition: xmlictxt.hxx:48
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:60
virtual css::uno::Reference< XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
Definition: xmlictxt.cxx:59
handles the top-level office:document-meta element of meta.xml documents
Definition: xmlmetai.hxx:37
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:223
#define SAL_WARN_IF(condition, area, stream)
Handling of tokens in XML:
@ XML_AUTOMATIC_STYLES
Definition: xmltoken.hxx:303
@ XML_DOCUMENT_CONTENT
Definition: xmltoken.hxx:702
@ XML_CALCULATION_SETTINGS
Definition: xmltoken.hxx:390
TABLE
#define XMLOFF_WARN_UNKNOWN_ELEMENT(area, token)
Definition: xmlictxt.hxx:120
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97
SvXMLImportFlags
Definition: xmlimp.hxx:111