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 <xmloff/xmltoken.hxx>
21 #include <xmloff/xmlnamespace.hxx>
22 #include <xmloff/xmlmetai.hxx>
23 #include <xmloff/xmlstyle.hxx>
24 #include <SchXMLImport.hxx>
25 #include "SchXMLCalculationSettingsContext.hxx"
27 #include "contexts.hxx"
29 #include <sal/log.hxx>
31 using namespace com::sun::star
;
32 using namespace ::xmloff::token
;
36 class SchXMLBodyContext_Impl
: public SvXMLImportContext
39 SchXMLImportHelper
& mrImportHelper
;
43 SchXMLBodyContext_Impl( SchXMLImportHelper
& rImpHelper
,
44 SvXMLImport
& rImport
);
46 virtual css::uno::Reference
< css::xml::sax::XFastContextHandler
> SAL_CALL
createFastChildContext(
47 sal_Int32 nElement
, const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
) override
;
52 SchXMLBodyContext_Impl::SchXMLBodyContext_Impl(
53 SchXMLImportHelper
& rImpHelper
, SvXMLImport
& rImport
) :
54 SvXMLImportContext( rImport
),
55 mrImportHelper( rImpHelper
)
59 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
SchXMLBodyContext_Impl::createFastChildContext(
60 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& /*xAttrList*/ )
62 return new SchXMLBodyContext( mrImportHelper
, GetImport(), nElement
);
65 SchXMLDocContext::SchXMLDocContext( SchXMLImportHelper
& rImpHelper
,
67 sal_Int32 nElement
) :
68 SvXMLImportContext( rImport
),
69 mrImportHelper( rImpHelper
)
71 SAL_WARN_IF(( nElement
!= XML_ELEMENT( OFFICE
, XML_DOCUMENT
) &&
72 nElement
!= XML_ELEMENT( OFFICE
, XML_DOCUMENT_META
) &&
73 nElement
!= XML_ELEMENT( OFFICE
, XML_DOCUMENT_STYLES
) &&
74 nElement
!= XML_ELEMENT( OFFICE
, XML_DOCUMENT_CONTENT
) ), "xmloff.chart", "SchXMLDocContext instantiated with no <office:document> element" );
77 SchXMLDocContext::~SchXMLDocContext()
81 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
SchXMLDocContext::createFastChildContext(
82 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& /*xAttrList*/ )
84 SvXMLImportFlags nFlags
= GetImport().getImportFlags();
87 case XML_ELEMENT(OFFICE
, XML_BODY
):
88 if( nFlags
& SvXMLImportFlags::CONTENT
)
89 return new SchXMLBodyContext_Impl( mrImportHelper
, GetImport() );
91 case XML_ELEMENT(OFFICE
, XML_STYLES
):
92 // for draw styles containing gradients/hatches/markers and dashes
93 if( nFlags
& SvXMLImportFlags::STYLES
)
94 return new SvXMLStylesContext( GetImport() );
96 case XML_ELEMENT(OFFICE
, XML_AUTOMATIC_STYLES
):
97 if( nFlags
& SvXMLImportFlags::AUTOSTYLES
)
98 // not nice, but this is safe, as the SchXMLDocContext class can only by
99 // instantiated by the chart import class SchXMLImport (header is not exported)
101 static_cast< SchXMLImport
& >( GetImport() ).CreateStylesContext();
103 case XML_ELEMENT(OFFICE
, XML_META
):
104 // we come here in the flat ODF file format,
105 // if XDocumentPropertiesSupplier is not supported at the model
111 SchXMLFlatDocContext_Impl::SchXMLFlatDocContext_Impl(
112 SchXMLImportHelper
& i_rImpHelper
,
113 SchXMLImport
& i_rImport
,
114 sal_Int32 i_nElement
,
115 const uno::Reference
<document::XDocumentProperties
>& i_xDocProps
) :
116 SvXMLImportContext(i_rImport
),
117 SchXMLDocContext(i_rImpHelper
, i_rImport
, i_nElement
),
118 SvXMLMetaDocumentContext(i_rImport
, i_xDocProps
)
122 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
SchXMLFlatDocContext_Impl::createFastChildContext(
123 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
125 // behave like meta base class iff we encounter office:meta
126 if ( nElement
== XML_ELEMENT( OFFICE
, XML_META
) ) {
127 return SvXMLMetaDocumentContext::createFastChildContext(
128 nElement
, xAttrList
);
130 return SchXMLDocContext::createFastChildContext(
131 nElement
, xAttrList
);
135 SchXMLBodyContext::SchXMLBodyContext( SchXMLImportHelper
& rImpHelper
,
136 SvXMLImport
& rImport
,
137 sal_Int32 nElement
) :
138 SvXMLImportContext( rImport
),
139 mrImportHelper( rImpHelper
)
141 SAL_WARN_IF( nElement
!= XML_ELEMENT(OFFICE
, XML_CHART
), "xmloff.chart", "SchXMLBodyContext instantiated with no <office:chart> element" );
144 SchXMLBodyContext::~SchXMLBodyContext()
147 css::uno::Reference
< css::xml::sax::XFastContextHandler
> SchXMLBodyContext::createFastChildContext(
149 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
151 css::uno::Reference
< css::xml::sax::XFastContextHandler
> xContext
;
153 // <chart:chart> element
154 if( nElement
== XML_ELEMENT(CHART
, XML_CHART
) )
156 xContext
= mrImportHelper
.CreateChartContext( GetImport(), GetImport().GetModel() );
158 else if(nElement
== XML_ELEMENT(TABLE
, XML_CALCULATION_SETTINGS
))
160 // i99104 handle null date correctly
161 xContext
= new SchXMLCalculationSettingsContext ( GetImport(), xAttrList
);
164 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement
);
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */