Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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"
27 :
28 : #include "contexts.hxx"
29 : #include "SchXMLChartContext.hxx"
30 :
31 : using namespace com::sun::star;
32 : using namespace ::xmloff::token;
33 :
34 : // ==================================================
35 :
36 : class SchXMLBodyContext_Impl : public SvXMLImportContext
37 : {
38 : private:
39 : SchXMLImportHelper& mrImportHelper;
40 :
41 : public:
42 :
43 : SchXMLBodyContext_Impl( SchXMLImportHelper& rImpHelper,
44 : SvXMLImport& rImport, sal_uInt16 nPrfx,
45 : const ::rtl::OUString& rLName );
46 : virtual ~SchXMLBodyContext_Impl();
47 :
48 : virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
49 : const ::rtl::OUString& rLocalName,
50 : const uno::Reference< xml::sax::XAttributeList > & xAttrList );
51 : };
52 :
53 0 : SchXMLBodyContext_Impl::SchXMLBodyContext_Impl(
54 : SchXMLImportHelper& rImpHelper, SvXMLImport& rImport,
55 : sal_uInt16 nPrfx, const ::rtl::OUString& rLName ) :
56 : SvXMLImportContext( rImport, nPrfx, rLName ),
57 0 : mrImportHelper( rImpHelper )
58 : {
59 0 : }
60 :
61 0 : SchXMLBodyContext_Impl::~SchXMLBodyContext_Impl()
62 : {
63 0 : }
64 :
65 0 : SvXMLImportContext *SchXMLBodyContext_Impl::CreateChildContext(
66 : sal_uInt16 nPrefix,
67 : const ::rtl::OUString& rLocalName,
68 : const uno::Reference< xml::sax::XAttributeList > & )
69 : {
70 0 : return new SchXMLBodyContext( mrImportHelper, GetImport(), nPrefix,
71 0 : rLocalName );
72 : }
73 :
74 : // ==================================================
75 :
76 0 : SchXMLDocContext::SchXMLDocContext( SchXMLImportHelper& rImpHelper,
77 : SvXMLImport& rImport,
78 : sal_uInt16 nPrefix,
79 : const rtl::OUString& rLName ) :
80 : SvXMLImportContext( rImport, nPrefix, rLName ),
81 0 : mrImportHelper( rImpHelper )
82 : {
83 : DBG_ASSERT( XML_NAMESPACE_OFFICE == nPrefix &&
84 : ( IsXMLToken( rLName, XML_DOCUMENT ) ||
85 : IsXMLToken( rLName, XML_DOCUMENT_META) ||
86 : IsXMLToken( rLName, XML_DOCUMENT_STYLES) ||
87 : IsXMLToken( rLName, XML_DOCUMENT_CONTENT) ),
88 : "SchXMLDocContext instanciated with no <office:document> element" );
89 0 : }
90 :
91 0 : SchXMLDocContext::~SchXMLDocContext()
92 0 : {}
93 :
94 0 : TYPEINIT1( SchXMLDocContext, SvXMLImportContext );
95 :
96 0 : SvXMLImportContext* SchXMLDocContext::CreateChildContext(
97 : sal_uInt16 nPrefix,
98 : const ::rtl::OUString& rLocalName,
99 : const uno::Reference< xml::sax::XAttributeList >& xAttrList )
100 : {
101 0 : SvXMLImportContext* pContext = 0;
102 0 : const SvXMLTokenMap& rTokenMap = mrImportHelper.GetDocElemTokenMap();
103 0 : sal_uInt16 nFlags = GetImport().getImportFlags();
104 :
105 0 : switch( rTokenMap.Get( nPrefix, rLocalName ))
106 : {
107 : case XML_TOK_DOC_AUTOSTYLES:
108 0 : if( nFlags & IMPORT_AUTOSTYLES )
109 : // not nice, but this is safe, as the SchXMLDocContext class can only by
110 : // instantiated by the chart import class SchXMLImport (header is not exported)
111 : pContext =
112 0 : static_cast< SchXMLImport& >( GetImport() ).CreateStylesContext( rLocalName, xAttrList );
113 0 : break;
114 : case XML_TOK_DOC_STYLES:
115 : // for draw styles containing gradients/hatches/markers and dashes
116 0 : if( nFlags & IMPORT_STYLES )
117 0 : pContext = new SvXMLStylesContext( GetImport(), nPrefix, rLocalName, xAttrList );
118 0 : break;
119 : case XML_TOK_DOC_META:
120 : // we come here in the flat ODF file format,
121 : // if XDocumentPropertiesSupplier is not supported at the model
122 : // DBG_WARNING("XML_TOK_DOC_META: should not have come here, maybe document is invalid?");
123 0 : pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
124 0 : break;
125 : case XML_TOK_DOC_BODY:
126 0 : if( nFlags & IMPORT_CONTENT )
127 0 : pContext = new SchXMLBodyContext_Impl( mrImportHelper, GetImport(), nPrefix, rLocalName );
128 0 : break;
129 : }
130 :
131 : // call parent when no own context was created
132 0 : if( ! pContext )
133 0 : pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
134 :
135 0 : return pContext;
136 : }
137 :
138 : // ==================================================
139 :
140 0 : SchXMLFlatDocContext_Impl::SchXMLFlatDocContext_Impl(
141 : SchXMLImportHelper& i_rImpHelper,
142 : SchXMLImport& i_rImport,
143 : sal_uInt16 i_nPrefix, const ::rtl::OUString & i_rLName,
144 : const uno::Reference<document::XDocumentProperties>& i_xDocProps) :
145 : SvXMLImportContext(i_rImport, i_nPrefix, i_rLName),
146 : SchXMLDocContext(i_rImpHelper, i_rImport, i_nPrefix, i_rLName),
147 : SvXMLMetaDocumentContext(i_rImport, i_nPrefix, i_rLName,
148 0 : i_xDocProps)
149 : {
150 0 : }
151 :
152 0 : SchXMLFlatDocContext_Impl::~SchXMLFlatDocContext_Impl() { }
153 :
154 :
155 0 : SvXMLImportContext *SchXMLFlatDocContext_Impl::CreateChildContext(
156 : sal_uInt16 i_nPrefix, const ::rtl::OUString& i_rLocalName,
157 : const uno::Reference<xml::sax::XAttributeList>& i_xAttrList)
158 : {
159 : // behave like meta base class iff we encounter office:meta
160 : const SvXMLTokenMap& rTokenMap =
161 0 : mrImportHelper.GetDocElemTokenMap();
162 0 : if ( XML_TOK_DOC_META == rTokenMap.Get( i_nPrefix, i_rLocalName ) ) {
163 : return SvXMLMetaDocumentContext::CreateChildContext(
164 0 : i_nPrefix, i_rLocalName, i_xAttrList );
165 : } else {
166 : return SchXMLDocContext::CreateChildContext(
167 0 : i_nPrefix, i_rLocalName, i_xAttrList );
168 : }
169 : }
170 :
171 : // ----------------------------------------
172 :
173 0 : SchXMLBodyContext::SchXMLBodyContext( SchXMLImportHelper& rImpHelper,
174 : SvXMLImport& rImport,
175 : sal_uInt16 nPrefix,
176 : const rtl::OUString& rLName ) :
177 : SvXMLImportContext( rImport, nPrefix, rLName ),
178 0 : mrImportHelper( rImpHelper )
179 : {
180 : DBG_ASSERT( XML_NAMESPACE_OFFICE == nPrefix &&
181 : IsXMLToken( rLName, XML_CHART ),
182 : "SchXMLBodyContext instanciated with no <office:chart> element" );
183 0 : }
184 :
185 0 : SchXMLBodyContext::~SchXMLBodyContext()
186 0 : {}
187 :
188 0 : void SchXMLBodyContext::EndElement()
189 : {
190 0 : }
191 :
192 0 : SvXMLImportContext* SchXMLBodyContext::CreateChildContext(
193 : sal_uInt16 nPrefix,
194 : const rtl::OUString& rLocalName,
195 : const uno::Reference< xml::sax::XAttributeList >& xAttrList )
196 : {
197 0 : SvXMLImportContext* pContext = 0;
198 :
199 : // <chart:chart> element
200 0 : if( nPrefix == XML_NAMESPACE_CHART &&
201 0 : IsXMLToken( rLocalName, XML_CHART ) )
202 : {
203 0 : pContext = mrImportHelper.CreateChartContext( GetImport(),
204 : nPrefix, rLocalName,
205 0 : GetImport().GetModel(),
206 0 : xAttrList );
207 : }
208 0 : else if(nPrefix == XML_NAMESPACE_TABLE &&
209 0 : IsXMLToken( rLocalName, XML_CALCULATION_SETTINGS ))
210 : {
211 : // i99104 handle null date correctly
212 0 : pContext = new SchXMLCalculationSettingsContext ( GetImport(), nPrefix, rLocalName, xAttrList);
213 : }
214 : else
215 : {
216 0 : pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
217 : }
218 :
219 0 : return pContext;
220 : }
221 :
222 :
223 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|