1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include <tools/debug.hxx>
27 #include <xmloff/xmltoken.hxx>
28 #include "xmloff/xmlnmspe.hxx"
29 #include <xmloff/xmlmetai.hxx>
30 #include <xmloff/xmlstyle.hxx>
31 #include "SchXMLImport.hxx"
32 #include "SchXMLCalculationSettingsContext.hxx"
33
34 #include "contexts.hxx"
35 #include "SchXMLChartContext.hxx"
36
37 using namespace com::sun::star;
38 using namespace ::xmloff::token;
39
40 // ==================================================
41
42 class SchXMLBodyContext_Impl : public SvXMLImportContext
43 {
44 private:
45 SchXMLImportHelper& mrImportHelper;
46
47 public:
48
49 SchXMLBodyContext_Impl( SchXMLImportHelper& rImpHelper,
50 SvXMLImport& rImport, sal_uInt16 nPrfx,
51 const ::rtl::OUString& rLName );
52 virtual ~SchXMLBodyContext_Impl();
53
54 virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
55 const ::rtl::OUString& rLocalName,
56 const uno::Reference< xml::sax::XAttributeList > & xAttrList );
57 };
58
SchXMLBodyContext_Impl(SchXMLImportHelper & rImpHelper,SvXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName)59 SchXMLBodyContext_Impl::SchXMLBodyContext_Impl(
60 SchXMLImportHelper& rImpHelper, SvXMLImport& rImport,
61 sal_uInt16 nPrfx, const ::rtl::OUString& rLName ) :
62 SvXMLImportContext( rImport, nPrfx, rLName ),
63 mrImportHelper( rImpHelper )
64 {
65 }
66
~SchXMLBodyContext_Impl()67 SchXMLBodyContext_Impl::~SchXMLBodyContext_Impl()
68 {
69 }
70
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> &)71 SvXMLImportContext *SchXMLBodyContext_Impl::CreateChildContext(
72 sal_uInt16 nPrefix,
73 const ::rtl::OUString& rLocalName,
74 const uno::Reference< xml::sax::XAttributeList > & )
75 {
76 return new SchXMLBodyContext( mrImportHelper, GetImport(), nPrefix,
77 rLocalName );
78 }
79
80 // ==================================================
81
SchXMLDocContext(SchXMLImportHelper & rImpHelper,SvXMLImport & rImport,sal_uInt16 nPrefix,const rtl::OUString & rLName)82 SchXMLDocContext::SchXMLDocContext( SchXMLImportHelper& rImpHelper,
83 SvXMLImport& rImport,
84 sal_uInt16 nPrefix,
85 const rtl::OUString& rLName ) :
86 SvXMLImportContext( rImport, nPrefix, rLName ),
87 mrImportHelper( rImpHelper )
88 {
89 DBG_ASSERT( XML_NAMESPACE_OFFICE == nPrefix &&
90 ( IsXMLToken( rLName, XML_DOCUMENT ) ||
91 IsXMLToken( rLName, XML_DOCUMENT_META) ||
92 IsXMLToken( rLName, XML_DOCUMENT_STYLES) ||
93 IsXMLToken( rLName, XML_DOCUMENT_CONTENT) ),
94 "SchXMLDocContext instanciated with no <office:document> element" );
95 }
96
~SchXMLDocContext()97 SchXMLDocContext::~SchXMLDocContext()
98 {}
99
100 TYPEINIT1( SchXMLDocContext, SvXMLImportContext );
101
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)102 SvXMLImportContext* SchXMLDocContext::CreateChildContext(
103 sal_uInt16 nPrefix,
104 const ::rtl::OUString& rLocalName,
105 const uno::Reference< xml::sax::XAttributeList >& xAttrList )
106 {
107 SvXMLImportContext* pContext = 0;
108 const SvXMLTokenMap& rTokenMap = mrImportHelper.GetDocElemTokenMap();
109 sal_uInt16 nFlags = GetImport().getImportFlags();
110
111 switch( rTokenMap.Get( nPrefix, rLocalName ))
112 {
113 case XML_TOK_DOC_AUTOSTYLES:
114 if( nFlags & IMPORT_AUTOSTYLES )
115 // not nice, but this is safe, as the SchXMLDocContext class can only by
116 // instantiated by the chart import class SchXMLImport (header is not exported)
117 pContext =
118 static_cast< SchXMLImport& >( GetImport() ).CreateStylesContext( rLocalName, xAttrList );
119 break;
120 case XML_TOK_DOC_STYLES:
121 // for draw styles containing gradients/hatches/markers and dashes
122 if( nFlags & IMPORT_STYLES )
123 pContext = new SvXMLStylesContext( GetImport(), nPrefix, rLocalName, xAttrList );
124 break;
125 case XML_TOK_DOC_META:
126 // we come here in the flat ODF file format,
127 // if XDocumentPropertiesSupplier is not supported at the model
128 // DBG_WARNING("XML_TOK_DOC_META: should not have come here, maybe document is invalid?");
129 pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
130 break;
131 case XML_TOK_DOC_BODY:
132 if( nFlags & IMPORT_CONTENT )
133 pContext = new SchXMLBodyContext_Impl( mrImportHelper, GetImport(), nPrefix, rLocalName );
134 break;
135 }
136
137 // call parent when no own context was created
138 if( ! pContext )
139 pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
140
141 return pContext;
142 }
143
144 // ==================================================
145
SchXMLFlatDocContext_Impl(SchXMLImportHelper & i_rImpHelper,SchXMLImport & i_rImport,sal_uInt16 i_nPrefix,const::rtl::OUString & i_rLName,const uno::Reference<document::XDocumentProperties> & i_xDocProps,const uno::Reference<xml::sax::XDocumentHandler> & i_xDocBuilder)146 SchXMLFlatDocContext_Impl::SchXMLFlatDocContext_Impl(
147 SchXMLImportHelper& i_rImpHelper,
148 SchXMLImport& i_rImport,
149 sal_uInt16 i_nPrefix, const ::rtl::OUString & i_rLName,
150 const uno::Reference<document::XDocumentProperties>& i_xDocProps,
151 const uno::Reference<xml::sax::XDocumentHandler>& i_xDocBuilder) :
152 SvXMLImportContext(i_rImport, i_nPrefix, i_rLName),
153 SchXMLDocContext(i_rImpHelper, i_rImport, i_nPrefix, i_rLName),
154 SvXMLMetaDocumentContext(i_rImport, i_nPrefix, i_rLName,
155 i_xDocProps, i_xDocBuilder)
156 {
157 }
158
~SchXMLFlatDocContext_Impl()159 SchXMLFlatDocContext_Impl::~SchXMLFlatDocContext_Impl() { }
160
161
CreateChildContext(sal_uInt16 i_nPrefix,const::rtl::OUString & i_rLocalName,const uno::Reference<xml::sax::XAttributeList> & i_xAttrList)162 SvXMLImportContext *SchXMLFlatDocContext_Impl::CreateChildContext(
163 sal_uInt16 i_nPrefix, const ::rtl::OUString& i_rLocalName,
164 const uno::Reference<xml::sax::XAttributeList>& i_xAttrList)
165 {
166 // behave like meta base class iff we encounter office:meta
167 const SvXMLTokenMap& rTokenMap =
168 mrImportHelper.GetDocElemTokenMap();
169 if ( XML_TOK_DOC_META == rTokenMap.Get( i_nPrefix, i_rLocalName ) ) {
170 return SvXMLMetaDocumentContext::CreateChildContext(
171 i_nPrefix, i_rLocalName, i_xAttrList );
172 } else {
173 return SchXMLDocContext::CreateChildContext(
174 i_nPrefix, i_rLocalName, i_xAttrList );
175 }
176 }
177
178 // ----------------------------------------
179
SchXMLBodyContext(SchXMLImportHelper & rImpHelper,SvXMLImport & rImport,sal_uInt16 nPrefix,const rtl::OUString & rLName)180 SchXMLBodyContext::SchXMLBodyContext( SchXMLImportHelper& rImpHelper,
181 SvXMLImport& rImport,
182 sal_uInt16 nPrefix,
183 const rtl::OUString& rLName ) :
184 SvXMLImportContext( rImport, nPrefix, rLName ),
185 mrImportHelper( rImpHelper )
186 {
187 DBG_ASSERT( XML_NAMESPACE_OFFICE == nPrefix &&
188 IsXMLToken( rLName, XML_CHART ),
189 "SchXMLBodyContext instanciated with no <office:chart> element" );
190 }
191
~SchXMLBodyContext()192 SchXMLBodyContext::~SchXMLBodyContext()
193 {}
194
EndElement()195 void SchXMLBodyContext::EndElement()
196 {
197 }
198
CreateChildContext(sal_uInt16 nPrefix,const rtl::OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)199 SvXMLImportContext* SchXMLBodyContext::CreateChildContext(
200 sal_uInt16 nPrefix,
201 const rtl::OUString& rLocalName,
202 const uno::Reference< xml::sax::XAttributeList >& xAttrList )
203 {
204 SvXMLImportContext* pContext = 0;
205
206 // <chart:chart> element
207 if( nPrefix == XML_NAMESPACE_CHART &&
208 IsXMLToken( rLocalName, XML_CHART ) )
209 {
210 pContext = mrImportHelper.CreateChartContext( GetImport(),
211 nPrefix, rLocalName,
212 GetImport().GetModel(),
213 xAttrList );
214 }
215 else if(nPrefix == XML_NAMESPACE_TABLE &&
216 IsXMLToken( rLocalName, XML_CALCULATION_SETTINGS ))
217 {
218 // i99104 handle null date correctly
219 pContext = new SchXMLCalculationSettingsContext ( GetImport(), nPrefix, rLocalName, xAttrList);
220 }
221 else
222 {
223 pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
224 }
225
226 return pContext;
227 }
228
229
230