Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / xmloff / source / chart / contexts.cxx
blobfe73372b4fa3bfccc6975cb2074a3d7839cf8184
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <tools/debug.hxx>
21 #include <xmloff/xmltoken.hxx>
22 #include <xmloff/xmlnmspe.hxx>
23 #include <xmloff/xmlmetai.hxx>
24 #include <xmloff/xmlstyle.hxx>
25 #include "SchXMLImport.hxx"
26 #include "SchXMLCalculationSettingsContext.hxx"
28 #include "contexts.hxx"
29 #include "SchXMLChartContext.hxx"
31 using namespace com::sun::star;
32 using namespace ::xmloff::token;
34 class SchXMLBodyContext_Impl : public SvXMLImportContext
36 private:
37 SchXMLImportHelper& mrImportHelper;
39 public:
41 SchXMLBodyContext_Impl( SchXMLImportHelper& rImpHelper,
42 SvXMLImport& rImport, sal_uInt16 nPrfx,
43 const OUString& rLName );
44 virtual ~SchXMLBodyContext_Impl();
46 virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
47 const OUString& rLocalName,
48 const uno::Reference< xml::sax::XAttributeList > & xAttrList ) override;
51 SchXMLBodyContext_Impl::SchXMLBodyContext_Impl(
52 SchXMLImportHelper& rImpHelper, SvXMLImport& rImport,
53 sal_uInt16 nPrfx, const OUString& rLName ) :
54 SvXMLImportContext( rImport, nPrfx, rLName ),
55 mrImportHelper( rImpHelper )
59 SchXMLBodyContext_Impl::~SchXMLBodyContext_Impl()
63 SvXMLImportContext *SchXMLBodyContext_Impl::CreateChildContext(
64 sal_uInt16 nPrefix,
65 const OUString& rLocalName,
66 const uno::Reference< xml::sax::XAttributeList > & )
68 return new SchXMLBodyContext( mrImportHelper, GetImport(), nPrefix,
69 rLocalName );
72 SchXMLDocContext::SchXMLDocContext( SchXMLImportHelper& rImpHelper,
73 SvXMLImport& rImport,
74 sal_uInt16 nPrefix,
75 const OUString& rLName ) :
76 SvXMLImportContext( rImport, nPrefix, rLName ),
77 mrImportHelper( rImpHelper )
79 SAL_WARN_IF( (XML_NAMESPACE_OFFICE != nPrefix) ||
80 ( !IsXMLToken( rLName, XML_DOCUMENT ) &&
81 !IsXMLToken( rLName, XML_DOCUMENT_META) &&
82 !IsXMLToken( rLName, XML_DOCUMENT_STYLES) &&
83 !IsXMLToken( rLName, XML_DOCUMENT_CONTENT) ), "xmloff.chart", "SchXMLDocContext instantiated with no <office:document> element" );
86 SchXMLDocContext::~SchXMLDocContext()
90 SvXMLImportContext* SchXMLDocContext::CreateChildContext(
91 sal_uInt16 nPrefix,
92 const OUString& rLocalName,
93 const uno::Reference< xml::sax::XAttributeList >& xAttrList )
95 SvXMLImportContext* pContext = nullptr;
96 const SvXMLTokenMap& rTokenMap = mrImportHelper.GetDocElemTokenMap();
97 SvXMLImportFlags nFlags = GetImport().getImportFlags();
99 switch( rTokenMap.Get( nPrefix, rLocalName ))
101 case XML_TOK_DOC_AUTOSTYLES:
102 if( nFlags & SvXMLImportFlags::AUTOSTYLES )
103 // not nice, but this is safe, as the SchXMLDocContext class can only by
104 // instantiated by the chart import class SchXMLImport (header is not exported)
105 pContext =
106 static_cast< SchXMLImport& >( GetImport() ).CreateStylesContext( rLocalName, xAttrList );
107 break;
108 case XML_TOK_DOC_STYLES:
109 // for draw styles containing gradients/hatches/markers and dashes
110 if( nFlags & SvXMLImportFlags::STYLES )
111 pContext = new SvXMLStylesContext( GetImport(), nPrefix, rLocalName, xAttrList );
112 break;
113 case XML_TOK_DOC_META:
114 // we come here in the flat ODF file format,
115 // if XDocumentPropertiesSupplier is not supported at the model
116 pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
117 break;
118 case XML_TOK_DOC_BODY:
119 if( nFlags & SvXMLImportFlags::CONTENT )
120 pContext = new SchXMLBodyContext_Impl( mrImportHelper, GetImport(), nPrefix, rLocalName );
121 break;
124 // call parent when no own context was created
125 if( ! pContext )
126 pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
128 return pContext;
131 SchXMLFlatDocContext_Impl::SchXMLFlatDocContext_Impl(
132 SchXMLImportHelper& i_rImpHelper,
133 SchXMLImport& i_rImport,
134 sal_uInt16 i_nPrefix, const OUString & i_rLName,
135 const uno::Reference<document::XDocumentProperties>& i_xDocProps) :
136 SvXMLImportContext(i_rImport, i_nPrefix, i_rLName),
137 SchXMLDocContext(i_rImpHelper, i_rImport, i_nPrefix, i_rLName),
138 SvXMLMetaDocumentContext(i_rImport, i_nPrefix, i_rLName,
139 i_xDocProps)
143 SchXMLFlatDocContext_Impl::~SchXMLFlatDocContext_Impl() { }
145 SvXMLImportContext *SchXMLFlatDocContext_Impl::CreateChildContext(
146 sal_uInt16 i_nPrefix, const OUString& i_rLocalName,
147 const uno::Reference<xml::sax::XAttributeList>& i_xAttrList)
149 // behave like meta base class iff we encounter office:meta
150 const SvXMLTokenMap& rTokenMap =
151 mrImportHelper.GetDocElemTokenMap();
152 if ( XML_TOK_DOC_META == rTokenMap.Get( i_nPrefix, i_rLocalName ) ) {
153 return SvXMLMetaDocumentContext::CreateChildContext(
154 i_nPrefix, i_rLocalName, i_xAttrList );
155 } else {
156 return SchXMLDocContext::CreateChildContext(
157 i_nPrefix, i_rLocalName, i_xAttrList );
161 SchXMLBodyContext::SchXMLBodyContext( SchXMLImportHelper& rImpHelper,
162 SvXMLImport& rImport,
163 sal_uInt16 nPrefix,
164 const OUString& rLName ) :
165 SvXMLImportContext( rImport, nPrefix, rLName ),
166 mrImportHelper( rImpHelper )
168 SAL_WARN_IF( (XML_NAMESPACE_OFFICE != nPrefix) ||
169 !IsXMLToken( rLName, XML_CHART ), "xmloff.chart", "SchXMLBodyContext instantiated with no <office:chart> element" );
172 SchXMLBodyContext::~SchXMLBodyContext()
175 void SchXMLBodyContext::EndElement()
179 SvXMLImportContext* SchXMLBodyContext::CreateChildContext(
180 sal_uInt16 nPrefix,
181 const OUString& rLocalName,
182 const uno::Reference< xml::sax::XAttributeList >& xAttrList )
184 SvXMLImportContext* pContext = nullptr;
186 // <chart:chart> element
187 if( nPrefix == XML_NAMESPACE_CHART &&
188 IsXMLToken( rLocalName, XML_CHART ) )
190 pContext = mrImportHelper.CreateChartContext( GetImport(),
191 nPrefix, rLocalName,
192 GetImport().GetModel(),
193 xAttrList );
195 else if(nPrefix == XML_NAMESPACE_TABLE &&
196 IsXMLToken( rLocalName, XML_CALCULATION_SETTINGS ))
198 // i99104 handle null date correctly
199 pContext = new SchXMLCalculationSettingsContext ( GetImport(), nPrefix, rLocalName, xAttrList);
201 else
203 pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
206 return pContext;
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */