1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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"
28 #include "contexts.hxx"
29 #include "SchXMLChartContext.hxx"
31 using namespace com::sun::star
;
32 using namespace ::xmloff::token
;
34 // ==================================================
36 class SchXMLBodyContext_Impl
: public SvXMLImportContext
39 SchXMLImportHelper
& mrImportHelper
;
43 SchXMLBodyContext_Impl( SchXMLImportHelper
& rImpHelper
,
44 SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
45 const OUString
& rLName
);
46 virtual ~SchXMLBodyContext_Impl();
48 virtual SvXMLImportContext
*CreateChildContext( sal_uInt16 nPrefix
,
49 const OUString
& rLocalName
,
50 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
);
53 SchXMLBodyContext_Impl::SchXMLBodyContext_Impl(
54 SchXMLImportHelper
& rImpHelper
, SvXMLImport
& rImport
,
55 sal_uInt16 nPrfx
, const OUString
& rLName
) :
56 SvXMLImportContext( rImport
, nPrfx
, rLName
),
57 mrImportHelper( rImpHelper
)
61 SchXMLBodyContext_Impl::~SchXMLBodyContext_Impl()
65 SvXMLImportContext
*SchXMLBodyContext_Impl::CreateChildContext(
67 const OUString
& rLocalName
,
68 const uno::Reference
< xml::sax::XAttributeList
> & )
70 return new SchXMLBodyContext( mrImportHelper
, GetImport(), nPrefix
,
74 // ==================================================
76 SchXMLDocContext::SchXMLDocContext( SchXMLImportHelper
& rImpHelper
,
79 const OUString
& rLName
) :
80 SvXMLImportContext( rImport
, nPrefix
, rLName
),
81 mrImportHelper( rImpHelper
)
83 SAL_WARN_IF( (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
) ), "xmloff.chart", "SchXMLDocContext instanciated with no <office:document> element" );
90 SchXMLDocContext::~SchXMLDocContext()
93 TYPEINIT1( SchXMLDocContext
, SvXMLImportContext
);
95 SvXMLImportContext
* SchXMLDocContext::CreateChildContext(
97 const OUString
& rLocalName
,
98 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
100 SvXMLImportContext
* pContext
= 0;
101 const SvXMLTokenMap
& rTokenMap
= mrImportHelper
.GetDocElemTokenMap();
102 sal_uInt16 nFlags
= GetImport().getImportFlags();
104 switch( rTokenMap
.Get( nPrefix
, rLocalName
))
106 case XML_TOK_DOC_AUTOSTYLES
:
107 if( nFlags
& IMPORT_AUTOSTYLES
)
108 // not nice, but this is safe, as the SchXMLDocContext class can only by
109 // instantiated by the chart import class SchXMLImport (header is not exported)
111 static_cast< SchXMLImport
& >( GetImport() ).CreateStylesContext( rLocalName
, xAttrList
);
113 case XML_TOK_DOC_STYLES
:
114 // for draw styles containing gradients/hatches/markers and dashes
115 if( nFlags
& IMPORT_STYLES
)
116 pContext
= new SvXMLStylesContext( GetImport(), nPrefix
, rLocalName
, xAttrList
);
118 case XML_TOK_DOC_META
:
119 // we come here in the flat ODF file format,
120 // if XDocumentPropertiesSupplier is not supported at the model
121 // DBG_WARNING("XML_TOK_DOC_META: should not have come here, maybe document is invalid?");
122 pContext
= SvXMLImportContext::CreateChildContext( nPrefix
, rLocalName
, xAttrList
);
124 case XML_TOK_DOC_BODY
:
125 if( nFlags
& IMPORT_CONTENT
)
126 pContext
= new SchXMLBodyContext_Impl( mrImportHelper
, GetImport(), nPrefix
, rLocalName
);
130 // call parent when no own context was created
132 pContext
= SvXMLImportContext::CreateChildContext( nPrefix
, rLocalName
, xAttrList
);
137 // ==================================================
139 SchXMLFlatDocContext_Impl::SchXMLFlatDocContext_Impl(
140 SchXMLImportHelper
& i_rImpHelper
,
141 SchXMLImport
& i_rImport
,
142 sal_uInt16 i_nPrefix
, const OUString
& i_rLName
,
143 const uno::Reference
<document::XDocumentProperties
>& i_xDocProps
) :
144 SvXMLImportContext(i_rImport
, i_nPrefix
, i_rLName
),
145 SchXMLDocContext(i_rImpHelper
, i_rImport
, i_nPrefix
, i_rLName
),
146 SvXMLMetaDocumentContext(i_rImport
, i_nPrefix
, i_rLName
,
151 SchXMLFlatDocContext_Impl::~SchXMLFlatDocContext_Impl() { }
154 SvXMLImportContext
*SchXMLFlatDocContext_Impl::CreateChildContext(
155 sal_uInt16 i_nPrefix
, const OUString
& i_rLocalName
,
156 const uno::Reference
<xml::sax::XAttributeList
>& i_xAttrList
)
158 // behave like meta base class iff we encounter office:meta
159 const SvXMLTokenMap
& rTokenMap
=
160 mrImportHelper
.GetDocElemTokenMap();
161 if ( XML_TOK_DOC_META
== rTokenMap
.Get( i_nPrefix
, i_rLocalName
) ) {
162 return SvXMLMetaDocumentContext::CreateChildContext(
163 i_nPrefix
, i_rLocalName
, i_xAttrList
);
165 return SchXMLDocContext::CreateChildContext(
166 i_nPrefix
, i_rLocalName
, i_xAttrList
);
170 // ----------------------------------------
172 SchXMLBodyContext::SchXMLBodyContext( SchXMLImportHelper
& rImpHelper
,
173 SvXMLImport
& rImport
,
175 const OUString
& rLName
) :
176 SvXMLImportContext( rImport
, nPrefix
, rLName
),
177 mrImportHelper( rImpHelper
)
179 SAL_WARN_IF( (XML_NAMESPACE_OFFICE
!= nPrefix
) ||
180 !IsXMLToken( rLName
, XML_CHART
), "xmloff.chart", "SchXMLBodyContext instanciated with no <office:chart> element" );
183 SchXMLBodyContext::~SchXMLBodyContext()
186 void SchXMLBodyContext::EndElement()
190 SvXMLImportContext
* SchXMLBodyContext::CreateChildContext(
192 const OUString
& rLocalName
,
193 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
195 SvXMLImportContext
* pContext
= 0;
197 // <chart:chart> element
198 if( nPrefix
== XML_NAMESPACE_CHART
&&
199 IsXMLToken( rLocalName
, XML_CHART
) )
201 pContext
= mrImportHelper
.CreateChartContext( GetImport(),
203 GetImport().GetModel(),
206 else if(nPrefix
== XML_NAMESPACE_TABLE
&&
207 IsXMLToken( rLocalName
, XML_CALCULATION_SETTINGS
))
209 // i99104 handle null date correctly
210 pContext
= new SchXMLCalculationSettingsContext ( GetImport(), nPrefix
, rLocalName
, xAttrList
);
214 pContext
= SvXMLImportContext::CreateChildContext( nPrefix
, rLocalName
, xAttrList
);
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */