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 class SchXMLBodyContext_Impl
: public SvXMLImportContext
37 SchXMLImportHelper
& mrImportHelper
;
41 SchXMLBodyContext_Impl( SchXMLImportHelper
& rImpHelper
,
42 SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
43 const OUString
& rLName
);
44 virtual ~SchXMLBodyContext_Impl();
46 virtual SvXMLImportContext
*CreateChildContext( sal_uInt16 nPrefix
,
47 const OUString
& rLocalName
,
48 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
) override
;
51 SchXMLBodyContext_Impl::SchXMLBodyContext_Impl(
52 SchXMLImportHelper
& rImpHelper
, SvXMLImport
& rImport
,
53 sal_uInt16 nPrfx
, const OUString
& rLName
) :
54 SvXMLImportContext( rImport
, nPrfx
, rLName
),
55 mrImportHelper( rImpHelper
)
59 SchXMLBodyContext_Impl::~SchXMLBodyContext_Impl()
63 SvXMLImportContext
*SchXMLBodyContext_Impl::CreateChildContext(
65 const OUString
& rLocalName
,
66 const uno::Reference
< xml::sax::XAttributeList
> & )
68 return new SchXMLBodyContext( mrImportHelper
, GetImport(), nPrefix
,
72 SchXMLDocContext::SchXMLDocContext( SchXMLImportHelper
& rImpHelper
,
75 const OUString
& rLName
) :
76 SvXMLImportContext( rImport
, nPrefix
, rLName
),
77 mrImportHelper( rImpHelper
)
79 SAL_WARN_IF( (XML_NAMESPACE_OFFICE
!= nPrefix
) ||
80 ( !IsXMLToken( rLName
, XML_DOCUMENT
) &&
81 !IsXMLToken( rLName
, XML_DOCUMENT_META
) &&
82 !IsXMLToken( rLName
, XML_DOCUMENT_STYLES
) &&
83 !IsXMLToken( rLName
, XML_DOCUMENT_CONTENT
) ), "xmloff.chart", "SchXMLDocContext instantiated with no <office:document> element" );
86 SchXMLDocContext::~SchXMLDocContext()
90 SvXMLImportContext
* SchXMLDocContext::CreateChildContext(
92 const OUString
& rLocalName
,
93 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
95 SvXMLImportContext
* pContext
= nullptr;
96 const SvXMLTokenMap
& rTokenMap
= mrImportHelper
.GetDocElemTokenMap();
97 SvXMLImportFlags nFlags
= GetImport().getImportFlags();
99 switch( rTokenMap
.Get( nPrefix
, rLocalName
))
101 case XML_TOK_DOC_AUTOSTYLES
:
102 if( nFlags
& SvXMLImportFlags::AUTOSTYLES
)
103 // not nice, but this is safe, as the SchXMLDocContext class can only by
104 // instantiated by the chart import class SchXMLImport (header is not exported)
106 static_cast< SchXMLImport
& >( GetImport() ).CreateStylesContext( rLocalName
, xAttrList
);
108 case XML_TOK_DOC_STYLES
:
109 // for draw styles containing gradients/hatches/markers and dashes
110 if( nFlags
& SvXMLImportFlags::STYLES
)
111 pContext
= new SvXMLStylesContext( GetImport(), nPrefix
, rLocalName
, xAttrList
);
113 case XML_TOK_DOC_META
:
114 // we come here in the flat ODF file format,
115 // if XDocumentPropertiesSupplier is not supported at the model
116 pContext
= SvXMLImportContext::CreateChildContext( nPrefix
, rLocalName
, xAttrList
);
118 case XML_TOK_DOC_BODY
:
119 if( nFlags
& SvXMLImportFlags::CONTENT
)
120 pContext
= new SchXMLBodyContext_Impl( mrImportHelper
, GetImport(), nPrefix
, rLocalName
);
124 // call parent when no own context was created
126 pContext
= SvXMLImportContext::CreateChildContext( nPrefix
, rLocalName
, xAttrList
);
131 SchXMLFlatDocContext_Impl::SchXMLFlatDocContext_Impl(
132 SchXMLImportHelper
& i_rImpHelper
,
133 SchXMLImport
& i_rImport
,
134 sal_uInt16 i_nPrefix
, const OUString
& i_rLName
,
135 const uno::Reference
<document::XDocumentProperties
>& i_xDocProps
) :
136 SvXMLImportContext(i_rImport
, i_nPrefix
, i_rLName
),
137 SchXMLDocContext(i_rImpHelper
, i_rImport
, i_nPrefix
, i_rLName
),
138 SvXMLMetaDocumentContext(i_rImport
, i_nPrefix
, i_rLName
,
143 SchXMLFlatDocContext_Impl::~SchXMLFlatDocContext_Impl() { }
145 SvXMLImportContext
*SchXMLFlatDocContext_Impl::CreateChildContext(
146 sal_uInt16 i_nPrefix
, const OUString
& i_rLocalName
,
147 const uno::Reference
<xml::sax::XAttributeList
>& i_xAttrList
)
149 // behave like meta base class iff we encounter office:meta
150 const SvXMLTokenMap
& rTokenMap
=
151 mrImportHelper
.GetDocElemTokenMap();
152 if ( XML_TOK_DOC_META
== rTokenMap
.Get( i_nPrefix
, i_rLocalName
) ) {
153 return SvXMLMetaDocumentContext::CreateChildContext(
154 i_nPrefix
, i_rLocalName
, i_xAttrList
);
156 return SchXMLDocContext::CreateChildContext(
157 i_nPrefix
, i_rLocalName
, i_xAttrList
);
161 SchXMLBodyContext::SchXMLBodyContext( SchXMLImportHelper
& rImpHelper
,
162 SvXMLImport
& rImport
,
164 const OUString
& rLName
) :
165 SvXMLImportContext( rImport
, nPrefix
, rLName
),
166 mrImportHelper( rImpHelper
)
168 SAL_WARN_IF( (XML_NAMESPACE_OFFICE
!= nPrefix
) ||
169 !IsXMLToken( rLName
, XML_CHART
), "xmloff.chart", "SchXMLBodyContext instantiated with no <office:chart> element" );
172 SchXMLBodyContext::~SchXMLBodyContext()
175 void SchXMLBodyContext::EndElement()
179 SvXMLImportContext
* SchXMLBodyContext::CreateChildContext(
181 const OUString
& rLocalName
,
182 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
184 SvXMLImportContext
* pContext
= nullptr;
186 // <chart:chart> element
187 if( nPrefix
== XML_NAMESPACE_CHART
&&
188 IsXMLToken( rLocalName
, XML_CHART
) )
190 pContext
= mrImportHelper
.CreateChartContext( GetImport(),
192 GetImport().GetModel(),
195 else if(nPrefix
== XML_NAMESPACE_TABLE
&&
196 IsXMLToken( rLocalName
, XML_CALCULATION_SETTINGS
))
198 // i99104 handle null date correctly
199 pContext
= new SchXMLCalculationSettingsContext ( GetImport(), nPrefix
, rLocalName
, xAttrList
);
203 pContext
= SvXMLImportContext::CreateChildContext( nPrefix
, rLocalName
, xAttrList
);
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */