xref: /trunk/main/xmloff/source/chart/contexts.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
30*cdf0e10cSrcweir #include <tools/debug.hxx>
31*cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
32*cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
33*cdf0e10cSrcweir #include <xmloff/xmlmetai.hxx>
34*cdf0e10cSrcweir #include <xmloff/xmlstyle.hxx>
35*cdf0e10cSrcweir #include "SchXMLImport.hxx"
36*cdf0e10cSrcweir #include "SchXMLCalculationSettingsContext.hxx"
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir #include "contexts.hxx"
39*cdf0e10cSrcweir #include "SchXMLChartContext.hxx"
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir using namespace com::sun::star;
42*cdf0e10cSrcweir using namespace ::xmloff::token;
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir // ==================================================
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir class SchXMLBodyContext_Impl : public SvXMLImportContext
47*cdf0e10cSrcweir {
48*cdf0e10cSrcweir private:
49*cdf0e10cSrcweir     SchXMLImportHelper& mrImportHelper;
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir public:
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir     SchXMLBodyContext_Impl( SchXMLImportHelper& rImpHelper,
54*cdf0e10cSrcweir                 SvXMLImport& rImport, sal_uInt16 nPrfx,
55*cdf0e10cSrcweir                 const ::rtl::OUString& rLName );
56*cdf0e10cSrcweir     virtual ~SchXMLBodyContext_Impl();
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir     virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
59*cdf0e10cSrcweir             const ::rtl::OUString& rLocalName,
60*cdf0e10cSrcweir                 const uno::Reference< xml::sax::XAttributeList > & xAttrList );
61*cdf0e10cSrcweir };
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir SchXMLBodyContext_Impl::SchXMLBodyContext_Impl(
64*cdf0e10cSrcweir         SchXMLImportHelper& rImpHelper, SvXMLImport& rImport,
65*cdf0e10cSrcweir         sal_uInt16 nPrfx, const ::rtl::OUString& rLName ) :
66*cdf0e10cSrcweir     SvXMLImportContext( rImport, nPrfx, rLName ),
67*cdf0e10cSrcweir     mrImportHelper( rImpHelper )
68*cdf0e10cSrcweir {
69*cdf0e10cSrcweir }
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir SchXMLBodyContext_Impl::~SchXMLBodyContext_Impl()
72*cdf0e10cSrcweir {
73*cdf0e10cSrcweir }
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir SvXMLImportContext *SchXMLBodyContext_Impl::CreateChildContext(
76*cdf0e10cSrcweir         sal_uInt16 nPrefix,
77*cdf0e10cSrcweir         const ::rtl::OUString& rLocalName,
78*cdf0e10cSrcweir         const uno::Reference< xml::sax::XAttributeList > & )
79*cdf0e10cSrcweir {
80*cdf0e10cSrcweir     return new SchXMLBodyContext( mrImportHelper, GetImport(), nPrefix,
81*cdf0e10cSrcweir                                   rLocalName );
82*cdf0e10cSrcweir }
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir // ==================================================
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir SchXMLDocContext::SchXMLDocContext( SchXMLImportHelper& rImpHelper,
87*cdf0e10cSrcweir                                     SvXMLImport& rImport,
88*cdf0e10cSrcweir                                     sal_uInt16 nPrefix,
89*cdf0e10cSrcweir                                     const rtl::OUString& rLName ) :
90*cdf0e10cSrcweir         SvXMLImportContext( rImport, nPrefix, rLName ),
91*cdf0e10cSrcweir         mrImportHelper( rImpHelper )
92*cdf0e10cSrcweir {
93*cdf0e10cSrcweir     DBG_ASSERT( XML_NAMESPACE_OFFICE == nPrefix &&
94*cdf0e10cSrcweir         ( IsXMLToken( rLName, XML_DOCUMENT ) ||
95*cdf0e10cSrcweir           IsXMLToken( rLName, XML_DOCUMENT_META) ||
96*cdf0e10cSrcweir           IsXMLToken( rLName, XML_DOCUMENT_STYLES) ||
97*cdf0e10cSrcweir           IsXMLToken( rLName, XML_DOCUMENT_CONTENT) ),
98*cdf0e10cSrcweir                 "SchXMLDocContext instanciated with no <office:document> element" );
99*cdf0e10cSrcweir }
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir SchXMLDocContext::~SchXMLDocContext()
102*cdf0e10cSrcweir {}
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir TYPEINIT1( SchXMLDocContext, SvXMLImportContext );
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir SvXMLImportContext* SchXMLDocContext::CreateChildContext(
107*cdf0e10cSrcweir     sal_uInt16 nPrefix,
108*cdf0e10cSrcweir     const ::rtl::OUString& rLocalName,
109*cdf0e10cSrcweir     const uno::Reference< xml::sax::XAttributeList >& xAttrList )
110*cdf0e10cSrcweir {
111*cdf0e10cSrcweir     SvXMLImportContext* pContext = 0;
112*cdf0e10cSrcweir     const SvXMLTokenMap& rTokenMap = mrImportHelper.GetDocElemTokenMap();
113*cdf0e10cSrcweir     sal_uInt16 nFlags = GetImport().getImportFlags();
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir     switch( rTokenMap.Get( nPrefix, rLocalName ))
116*cdf0e10cSrcweir     {
117*cdf0e10cSrcweir         case XML_TOK_DOC_AUTOSTYLES:
118*cdf0e10cSrcweir             if( nFlags & IMPORT_AUTOSTYLES )
119*cdf0e10cSrcweir                 // not nice, but this is safe, as the SchXMLDocContext class can only by
120*cdf0e10cSrcweir                 // instantiated by the chart import class SchXMLImport (header is not exported)
121*cdf0e10cSrcweir                 pContext =
122*cdf0e10cSrcweir                     static_cast< SchXMLImport& >( GetImport() ).CreateStylesContext( rLocalName, xAttrList );
123*cdf0e10cSrcweir             break;
124*cdf0e10cSrcweir         case XML_TOK_DOC_STYLES:
125*cdf0e10cSrcweir             // for draw styles containing gradients/hatches/markers and dashes
126*cdf0e10cSrcweir             if( nFlags & IMPORT_STYLES )
127*cdf0e10cSrcweir                 pContext = new SvXMLStylesContext( GetImport(), nPrefix, rLocalName, xAttrList );
128*cdf0e10cSrcweir             break;
129*cdf0e10cSrcweir         case XML_TOK_DOC_META:
130*cdf0e10cSrcweir           // we come here in the flat ODF file format,
131*cdf0e10cSrcweir           // if XDocumentPropertiesSupplier is not supported at the model
132*cdf0e10cSrcweir //        DBG_WARNING("XML_TOK_DOC_META: should not have come here, maybe document is invalid?");
133*cdf0e10cSrcweir             pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
134*cdf0e10cSrcweir             break;
135*cdf0e10cSrcweir         case XML_TOK_DOC_BODY:
136*cdf0e10cSrcweir             if( nFlags & IMPORT_CONTENT )
137*cdf0e10cSrcweir                 pContext = new SchXMLBodyContext_Impl( mrImportHelper, GetImport(), nPrefix, rLocalName );
138*cdf0e10cSrcweir             break;
139*cdf0e10cSrcweir     }
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir     // call parent when no own context was created
142*cdf0e10cSrcweir     if( ! pContext )
143*cdf0e10cSrcweir         pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir     return pContext;
146*cdf0e10cSrcweir }
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir // ==================================================
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir SchXMLFlatDocContext_Impl::SchXMLFlatDocContext_Impl(
151*cdf0e10cSrcweir         SchXMLImportHelper& i_rImpHelper,
152*cdf0e10cSrcweir         SchXMLImport& i_rImport,
153*cdf0e10cSrcweir         sal_uInt16 i_nPrefix, const ::rtl::OUString & i_rLName,
154*cdf0e10cSrcweir         const uno::Reference<document::XDocumentProperties>& i_xDocProps,
155*cdf0e10cSrcweir         const uno::Reference<xml::sax::XDocumentHandler>& i_xDocBuilder) :
156*cdf0e10cSrcweir     SvXMLImportContext(i_rImport, i_nPrefix, i_rLName),
157*cdf0e10cSrcweir     SchXMLDocContext(i_rImpHelper, i_rImport, i_nPrefix, i_rLName),
158*cdf0e10cSrcweir     SvXMLMetaDocumentContext(i_rImport, i_nPrefix, i_rLName,
159*cdf0e10cSrcweir         i_xDocProps, i_xDocBuilder)
160*cdf0e10cSrcweir {
161*cdf0e10cSrcweir }
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir SchXMLFlatDocContext_Impl::~SchXMLFlatDocContext_Impl() { }
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir SvXMLImportContext *SchXMLFlatDocContext_Impl::CreateChildContext(
167*cdf0e10cSrcweir     sal_uInt16 i_nPrefix, const ::rtl::OUString& i_rLocalName,
168*cdf0e10cSrcweir     const uno::Reference<xml::sax::XAttributeList>& i_xAttrList)
169*cdf0e10cSrcweir {
170*cdf0e10cSrcweir     // behave like meta base class iff we encounter office:meta
171*cdf0e10cSrcweir     const SvXMLTokenMap& rTokenMap =
172*cdf0e10cSrcweir         mrImportHelper.GetDocElemTokenMap();
173*cdf0e10cSrcweir     if ( XML_TOK_DOC_META == rTokenMap.Get( i_nPrefix, i_rLocalName ) ) {
174*cdf0e10cSrcweir         return SvXMLMetaDocumentContext::CreateChildContext(
175*cdf0e10cSrcweir                     i_nPrefix, i_rLocalName, i_xAttrList );
176*cdf0e10cSrcweir     } else {
177*cdf0e10cSrcweir         return SchXMLDocContext::CreateChildContext(
178*cdf0e10cSrcweir                     i_nPrefix, i_rLocalName, i_xAttrList );
179*cdf0e10cSrcweir     }
180*cdf0e10cSrcweir }
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir // ----------------------------------------
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir SchXMLBodyContext::SchXMLBodyContext( SchXMLImportHelper& rImpHelper,
185*cdf0e10cSrcweir                                       SvXMLImport& rImport,
186*cdf0e10cSrcweir                                       sal_uInt16 nPrefix,
187*cdf0e10cSrcweir                                       const rtl::OUString& rLName ) :
188*cdf0e10cSrcweir         SvXMLImportContext( rImport, nPrefix, rLName ),
189*cdf0e10cSrcweir         mrImportHelper( rImpHelper )
190*cdf0e10cSrcweir {
191*cdf0e10cSrcweir     DBG_ASSERT( XML_NAMESPACE_OFFICE == nPrefix &&
192*cdf0e10cSrcweir                 IsXMLToken( rLName, XML_CHART ),
193*cdf0e10cSrcweir                 "SchXMLBodyContext instanciated with no <office:chart> element" );
194*cdf0e10cSrcweir }
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir SchXMLBodyContext::~SchXMLBodyContext()
197*cdf0e10cSrcweir {}
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir void SchXMLBodyContext::EndElement()
200*cdf0e10cSrcweir {
201*cdf0e10cSrcweir }
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir SvXMLImportContext* SchXMLBodyContext::CreateChildContext(
204*cdf0e10cSrcweir     sal_uInt16 nPrefix,
205*cdf0e10cSrcweir     const rtl::OUString& rLocalName,
206*cdf0e10cSrcweir     const uno::Reference< xml::sax::XAttributeList >& xAttrList )
207*cdf0e10cSrcweir {
208*cdf0e10cSrcweir     SvXMLImportContext* pContext = 0;
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir     // <chart:chart> element
211*cdf0e10cSrcweir     if( nPrefix == XML_NAMESPACE_CHART &&
212*cdf0e10cSrcweir         IsXMLToken( rLocalName, XML_CHART ) )
213*cdf0e10cSrcweir     {
214*cdf0e10cSrcweir         pContext = mrImportHelper.CreateChartContext( GetImport(),
215*cdf0e10cSrcweir                                                       nPrefix, rLocalName,
216*cdf0e10cSrcweir                                                       GetImport().GetModel(),
217*cdf0e10cSrcweir                                                       xAttrList );
218*cdf0e10cSrcweir     }
219*cdf0e10cSrcweir     else if(nPrefix == XML_NAMESPACE_TABLE &&
220*cdf0e10cSrcweir             IsXMLToken( rLocalName, XML_CALCULATION_SETTINGS ))
221*cdf0e10cSrcweir     {
222*cdf0e10cSrcweir         // i99104 handle null date correctly
223*cdf0e10cSrcweir         pContext = new SchXMLCalculationSettingsContext ( GetImport(), nPrefix, rLocalName, xAttrList);
224*cdf0e10cSrcweir     }
225*cdf0e10cSrcweir     else
226*cdf0e10cSrcweir     {
227*cdf0e10cSrcweir         pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
228*cdf0e10cSrcweir     }
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir     return pContext;
231*cdf0e10cSrcweir }
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir 
234