Bump for 3.6-28
[LibreOffice.git] / xmloff / source / chart / contexts.cxx
blobb7456d857eecc91f98d6d745f68e27d6c2747cda
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <tools/debug.hxx>
30 #include <xmloff/xmltoken.hxx>
31 #include "xmloff/xmlnmspe.hxx"
32 #include <xmloff/xmlmetai.hxx>
33 #include <xmloff/xmlstyle.hxx>
34 #include "SchXMLImport.hxx"
35 #include "SchXMLCalculationSettingsContext.hxx"
37 #include "contexts.hxx"
38 #include "SchXMLChartContext.hxx"
40 using namespace com::sun::star;
41 using namespace ::xmloff::token;
43 // ==================================================
45 class SchXMLBodyContext_Impl : public SvXMLImportContext
47 private:
48 SchXMLImportHelper& mrImportHelper;
50 public:
52 SchXMLBodyContext_Impl( SchXMLImportHelper& rImpHelper,
53 SvXMLImport& rImport, sal_uInt16 nPrfx,
54 const ::rtl::OUString& rLName );
55 virtual ~SchXMLBodyContext_Impl();
57 virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
58 const ::rtl::OUString& rLocalName,
59 const uno::Reference< xml::sax::XAttributeList > & xAttrList );
62 SchXMLBodyContext_Impl::SchXMLBodyContext_Impl(
63 SchXMLImportHelper& rImpHelper, SvXMLImport& rImport,
64 sal_uInt16 nPrfx, const ::rtl::OUString& rLName ) :
65 SvXMLImportContext( rImport, nPrfx, rLName ),
66 mrImportHelper( rImpHelper )
70 SchXMLBodyContext_Impl::~SchXMLBodyContext_Impl()
74 SvXMLImportContext *SchXMLBodyContext_Impl::CreateChildContext(
75 sal_uInt16 nPrefix,
76 const ::rtl::OUString& rLocalName,
77 const uno::Reference< xml::sax::XAttributeList > & )
79 return new SchXMLBodyContext( mrImportHelper, GetImport(), nPrefix,
80 rLocalName );
83 // ==================================================
85 SchXMLDocContext::SchXMLDocContext( SchXMLImportHelper& rImpHelper,
86 SvXMLImport& rImport,
87 sal_uInt16 nPrefix,
88 const rtl::OUString& rLName ) :
89 SvXMLImportContext( rImport, nPrefix, rLName ),
90 mrImportHelper( rImpHelper )
92 DBG_ASSERT( XML_NAMESPACE_OFFICE == nPrefix &&
93 ( IsXMLToken( rLName, XML_DOCUMENT ) ||
94 IsXMLToken( rLName, XML_DOCUMENT_META) ||
95 IsXMLToken( rLName, XML_DOCUMENT_STYLES) ||
96 IsXMLToken( rLName, XML_DOCUMENT_CONTENT) ),
97 "SchXMLDocContext instanciated with no <office:document> element" );
100 SchXMLDocContext::~SchXMLDocContext()
103 TYPEINIT1( SchXMLDocContext, SvXMLImportContext );
105 SvXMLImportContext* SchXMLDocContext::CreateChildContext(
106 sal_uInt16 nPrefix,
107 const ::rtl::OUString& rLocalName,
108 const uno::Reference< xml::sax::XAttributeList >& xAttrList )
110 SvXMLImportContext* pContext = 0;
111 const SvXMLTokenMap& rTokenMap = mrImportHelper.GetDocElemTokenMap();
112 sal_uInt16 nFlags = GetImport().getImportFlags();
114 switch( rTokenMap.Get( nPrefix, rLocalName ))
116 case XML_TOK_DOC_AUTOSTYLES:
117 if( nFlags & IMPORT_AUTOSTYLES )
118 // not nice, but this is safe, as the SchXMLDocContext class can only by
119 // instantiated by the chart import class SchXMLImport (header is not exported)
120 pContext =
121 static_cast< SchXMLImport& >( GetImport() ).CreateStylesContext( rLocalName, xAttrList );
122 break;
123 case XML_TOK_DOC_STYLES:
124 // for draw styles containing gradients/hatches/markers and dashes
125 if( nFlags & IMPORT_STYLES )
126 pContext = new SvXMLStylesContext( GetImport(), nPrefix, rLocalName, xAttrList );
127 break;
128 case XML_TOK_DOC_META:
129 // we come here in the flat ODF file format,
130 // if XDocumentPropertiesSupplier is not supported at the model
131 // DBG_WARNING("XML_TOK_DOC_META: should not have come here, maybe document is invalid?");
132 pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
133 break;
134 case XML_TOK_DOC_BODY:
135 if( nFlags & IMPORT_CONTENT )
136 pContext = new SchXMLBodyContext_Impl( mrImportHelper, GetImport(), nPrefix, rLocalName );
137 break;
140 // call parent when no own context was created
141 if( ! pContext )
142 pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
144 return pContext;
147 // ==================================================
149 SchXMLFlatDocContext_Impl::SchXMLFlatDocContext_Impl(
150 SchXMLImportHelper& i_rImpHelper,
151 SchXMLImport& i_rImport,
152 sal_uInt16 i_nPrefix, const ::rtl::OUString & i_rLName,
153 const uno::Reference<document::XDocumentProperties>& i_xDocProps,
154 const uno::Reference<xml::sax::XDocumentHandler>& i_xDocBuilder) :
155 SvXMLImportContext(i_rImport, i_nPrefix, i_rLName),
156 SchXMLDocContext(i_rImpHelper, i_rImport, i_nPrefix, i_rLName),
157 SvXMLMetaDocumentContext(i_rImport, i_nPrefix, i_rLName,
158 i_xDocProps, i_xDocBuilder)
162 SchXMLFlatDocContext_Impl::~SchXMLFlatDocContext_Impl() { }
165 SvXMLImportContext *SchXMLFlatDocContext_Impl::CreateChildContext(
166 sal_uInt16 i_nPrefix, const ::rtl::OUString& i_rLocalName,
167 const uno::Reference<xml::sax::XAttributeList>& i_xAttrList)
169 // behave like meta base class iff we encounter office:meta
170 const SvXMLTokenMap& rTokenMap =
171 mrImportHelper.GetDocElemTokenMap();
172 if ( XML_TOK_DOC_META == rTokenMap.Get( i_nPrefix, i_rLocalName ) ) {
173 return SvXMLMetaDocumentContext::CreateChildContext(
174 i_nPrefix, i_rLocalName, i_xAttrList );
175 } else {
176 return SchXMLDocContext::CreateChildContext(
177 i_nPrefix, i_rLocalName, i_xAttrList );
181 // ----------------------------------------
183 SchXMLBodyContext::SchXMLBodyContext( SchXMLImportHelper& rImpHelper,
184 SvXMLImport& rImport,
185 sal_uInt16 nPrefix,
186 const rtl::OUString& rLName ) :
187 SvXMLImportContext( rImport, nPrefix, rLName ),
188 mrImportHelper( rImpHelper )
190 DBG_ASSERT( XML_NAMESPACE_OFFICE == nPrefix &&
191 IsXMLToken( rLName, XML_CHART ),
192 "SchXMLBodyContext instanciated with no <office:chart> element" );
195 SchXMLBodyContext::~SchXMLBodyContext()
198 void SchXMLBodyContext::EndElement()
202 SvXMLImportContext* SchXMLBodyContext::CreateChildContext(
203 sal_uInt16 nPrefix,
204 const rtl::OUString& rLocalName,
205 const uno::Reference< xml::sax::XAttributeList >& xAttrList )
207 SvXMLImportContext* pContext = 0;
209 // <chart:chart> element
210 if( nPrefix == XML_NAMESPACE_CHART &&
211 IsXMLToken( rLocalName, XML_CHART ) )
213 pContext = mrImportHelper.CreateChartContext( GetImport(),
214 nPrefix, rLocalName,
215 GetImport().GetModel(),
216 xAttrList );
218 else if(nPrefix == XML_NAMESPACE_TABLE &&
219 IsXMLToken( rLocalName, XML_CALCULATION_SETTINGS ))
221 // i99104 handle null date correctly
222 pContext = new SchXMLCalculationSettingsContext ( GetImport(), nPrefix, rLocalName, xAttrList);
224 else
226 pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
229 return pContext;
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */