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