merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / chart / contexts.cxx
blob48cdf9a68343d5f1e74425a2baabfe9dd43ec93c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: contexts.cxx,v $
10 * $Revision: 1.14 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include <tools/debug.hxx>
34 #include <xmloff/xmltoken.hxx>
35 #include "xmlnmspe.hxx"
36 #include <xmloff/xmlmetai.hxx>
37 #include <xmloff/xmlstyle.hxx>
38 #include "SchXMLImport.hxx"
39 #include "SchXMLCalculationSettingsContext.hxx"
41 // #ifndef _XMLOFF_XMLCHARTSTYLECONTEXT_HXX_
42 // #include "XMLChartStyleContext.hxx"
43 // #endif
44 #include <com/sun/star/chart/XChartDocument.hpp>
45 #include <com/sun/star/chart/XChartDataArray.hpp>
46 #include <com/sun/star/chart/ChartDataRowSource.hpp>
48 #include "contexts.hxx"
49 #include "SchXMLChartContext.hxx"
51 using namespace com::sun::star;
52 using namespace ::xmloff::token;
54 // ==================================================
56 class SchXMLBodyContext_Impl : public SvXMLImportContext
58 private:
59 SchXMLImportHelper& mrImportHelper;
61 public:
63 SchXMLBodyContext_Impl( SchXMLImportHelper& rImpHelper,
64 SvXMLImport& rImport, sal_uInt16 nPrfx,
65 const ::rtl::OUString& rLName );
66 virtual ~SchXMLBodyContext_Impl();
68 virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
69 const ::rtl::OUString& rLocalName,
70 const uno::Reference< xml::sax::XAttributeList > & xAttrList );
73 SchXMLBodyContext_Impl::SchXMLBodyContext_Impl(
74 SchXMLImportHelper& rImpHelper, SvXMLImport& rImport,
75 sal_uInt16 nPrfx, const ::rtl::OUString& rLName ) :
76 SvXMLImportContext( rImport, nPrfx, rLName ),
77 mrImportHelper( rImpHelper )
81 SchXMLBodyContext_Impl::~SchXMLBodyContext_Impl()
85 SvXMLImportContext *SchXMLBodyContext_Impl::CreateChildContext(
86 sal_uInt16 nPrefix,
87 const ::rtl::OUString& rLocalName,
88 const uno::Reference< xml::sax::XAttributeList > & )
90 return new SchXMLBodyContext( mrImportHelper, GetImport(), nPrefix,
91 rLocalName );
94 // ==================================================
96 SchXMLDocContext::SchXMLDocContext( SchXMLImportHelper& rImpHelper,
97 SvXMLImport& rImport,
98 USHORT nPrefix,
99 const rtl::OUString& rLName ) :
100 SvXMLImportContext( rImport, nPrefix, rLName ),
101 mrImportHelper( rImpHelper )
103 DBG_ASSERT( XML_NAMESPACE_OFFICE == nPrefix &&
104 ( IsXMLToken( rLName, XML_DOCUMENT ) ||
105 IsXMLToken( rLName, XML_DOCUMENT_META) ||
106 IsXMLToken( rLName, XML_DOCUMENT_STYLES) ||
107 IsXMLToken( rLName, XML_DOCUMENT_CONTENT) ),
108 "SchXMLDocContext instanciated with no <office:document> element" );
111 SchXMLDocContext::~SchXMLDocContext()
114 TYPEINIT1( SchXMLDocContext, SvXMLImportContext );
116 SvXMLImportContext* SchXMLDocContext::CreateChildContext(
117 sal_uInt16 nPrefix,
118 const ::rtl::OUString& rLocalName,
119 const uno::Reference< xml::sax::XAttributeList >& xAttrList )
121 SvXMLImportContext* pContext = 0;
122 const SvXMLTokenMap& rTokenMap = mrImportHelper.GetDocElemTokenMap();
123 sal_uInt16 nFlags = GetImport().getImportFlags();
125 switch( rTokenMap.Get( nPrefix, rLocalName ))
127 case XML_TOK_DOC_AUTOSTYLES:
128 if( nFlags & IMPORT_AUTOSTYLES )
129 // not nice, but this is safe, as the SchXMLDocContext class can only by
130 // instantiated by the chart import class SchXMLImport (header is not exported)
131 pContext =
132 static_cast< SchXMLImport& >( GetImport() ).CreateStylesContext( rLocalName, xAttrList );
133 break;
134 case XML_TOK_DOC_STYLES:
135 // for draw styles containing gradients/hatches/markers and dashes
136 if( nFlags & IMPORT_STYLES )
137 pContext = new SvXMLStylesContext( GetImport(), nPrefix, rLocalName, xAttrList );
138 break;
139 case XML_TOK_DOC_META:
140 // we come here in the flat ODF file format,
141 // if XDocumentPropertiesSupplier is not supported at the model
142 // DBG_WARNING("XML_TOK_DOC_META: should not have come here, maybe document is invalid?");
143 pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
144 break;
145 case XML_TOK_DOC_BODY:
146 if( nFlags & IMPORT_CONTENT )
147 pContext = new SchXMLBodyContext_Impl( mrImportHelper, GetImport(), nPrefix, rLocalName );
148 break;
151 // call parent when no own context was created
152 if( ! pContext )
153 pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
155 return pContext;
158 // ==================================================
160 SchXMLFlatDocContext_Impl::SchXMLFlatDocContext_Impl(
161 SchXMLImportHelper& i_rImpHelper,
162 SchXMLImport& i_rImport,
163 USHORT i_nPrefix, const ::rtl::OUString & i_rLName,
164 const uno::Reference<document::XDocumentProperties>& i_xDocProps,
165 const uno::Reference<xml::sax::XDocumentHandler>& i_xDocBuilder) :
166 SvXMLImportContext(i_rImport, i_nPrefix, i_rLName),
167 SchXMLDocContext(i_rImpHelper, i_rImport, i_nPrefix, i_rLName),
168 SvXMLMetaDocumentContext(i_rImport, i_nPrefix, i_rLName,
169 i_xDocProps, i_xDocBuilder)
173 SchXMLFlatDocContext_Impl::~SchXMLFlatDocContext_Impl() { }
176 SvXMLImportContext *SchXMLFlatDocContext_Impl::CreateChildContext(
177 USHORT i_nPrefix, const ::rtl::OUString& i_rLocalName,
178 const uno::Reference<xml::sax::XAttributeList>& i_xAttrList)
180 // behave like meta base class iff we encounter office:meta
181 const SvXMLTokenMap& rTokenMap =
182 mrImportHelper.GetDocElemTokenMap();
183 if ( XML_TOK_DOC_META == rTokenMap.Get( i_nPrefix, i_rLocalName ) ) {
184 return SvXMLMetaDocumentContext::CreateChildContext(
185 i_nPrefix, i_rLocalName, i_xAttrList );
186 } else {
187 return SchXMLDocContext::CreateChildContext(
188 i_nPrefix, i_rLocalName, i_xAttrList );
192 // ----------------------------------------
194 SchXMLBodyContext::SchXMLBodyContext( SchXMLImportHelper& rImpHelper,
195 SvXMLImport& rImport,
196 USHORT nPrefix,
197 const rtl::OUString& rLName ) :
198 SvXMLImportContext( rImport, nPrefix, rLName ),
199 mrImportHelper( rImpHelper )
201 DBG_ASSERT( XML_NAMESPACE_OFFICE == nPrefix &&
202 IsXMLToken( rLName, XML_CHART ),
203 "SchXMLBodyContext instanciated with no <office:chart> element" );
206 SchXMLBodyContext::~SchXMLBodyContext()
209 void SchXMLBodyContext::EndElement()
213 SvXMLImportContext* SchXMLBodyContext::CreateChildContext(
214 sal_uInt16 nPrefix,
215 const rtl::OUString& rLocalName,
216 const uno::Reference< xml::sax::XAttributeList >& xAttrList )
218 SvXMLImportContext* pContext = 0;
220 // <chart:chart> element
221 if( nPrefix == XML_NAMESPACE_CHART &&
222 IsXMLToken( rLocalName, XML_CHART ) )
224 pContext = mrImportHelper.CreateChartContext( GetImport(),
225 nPrefix, rLocalName,
226 GetImport().GetModel(),
227 xAttrList );
229 else if(nPrefix == XML_NAMESPACE_TABLE &&
230 IsXMLToken( rLocalName, XML_CALCULATION_SETTINGS ))
232 // i99104 handle null date correctly
233 pContext = new SchXMLCalculationSettingsContext ( GetImport(), nPrefix, rLocalName, xAttrList);
235 else
237 pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
240 return pContext;