LibreOffice Module xmloff (master)  1
XMLChartStyleContext.cxx
Go to the documentation of this file.
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 <XMLChartStyleContext.hxx>
21 #include <xmloff/xmltoken.hxx>
22 #include <xmloff/xmlnamespace.hxx>
23 #include <xmloff/xmlnumfi.hxx>
24 #include <xmloff/families.hxx>
25 #include <xmloff/xmltypes.hxx>
26 #include <xmloff/xmlimp.hxx>
27 #include <xmloff/xmlimppr.hxx>
28 
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <tools/diagnose_ex.h>
31 
33 
34 using namespace com::sun::star;
42 
43 
45  sal_uInt16 nPrefixKey,
46  const OUString& rLocalName,
47  const OUString& rValue )
48 {
49  if( IsXMLToken( rLocalName, XML_DATA_STYLE_NAME ) )
50  {
51  msDataStyleName =rValue;
52  }
53  else if( IsXMLToken( rLocalName, XML_PERCENTAGE_DATA_STYLE_NAME ) )
54  {
55  msPercentageDataStyleName =rValue;
56  }
57  else
58  {
59  XMLShapeStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
60  }
61 }
62 
64  SvXMLImport& rImport,
65  SvXMLStylesContext& rStyles, XmlStyleFamily nFamily ) :
66  XMLShapeStyleContext( rImport, rStyles, nFamily ),
67  mrStyles( rStyles )
68 {}
69 
71 {}
72 
73 namespace
74 {
75 
76 void lcl_NumberFormatStyleToProperty( const OUString& rStyleName, const OUString& rPropertyName,
77  const SvXMLStylesContext& rStylesContext,
78  const uno::Reference< beans::XPropertySet >& rPropSet )
79 {
80  if( !rStyleName.isEmpty())
81  {
82  const SvXMLNumFormatContext* pStyle = static_cast<const SvXMLNumFormatContext *>(rStylesContext.FindStyleChildContext(
83  XmlStyleFamily::DATA_STYLE, rStyleName, true ));
84  if( pStyle )
85  {
86  sal_Int32 nNumberFormat = const_cast<SvXMLNumFormatContext*>(pStyle)->GetKey();
87  rPropSet->setPropertyValue( rPropertyName, uno::Any(nNumberFormat) );
88  }
89  }
90 }
91 
92 }
93 
95  const uno::Reference< beans::XPropertySet > & rPropSet )
96 {
97  try
98  {
100  }
101  catch( beans::UnknownPropertyException& )
102  {
103  TOOLS_WARN_EXCEPTION( "xmloff", "unknown property exception -> shape style not completely imported for chart style" );
104  }
105 
106  lcl_NumberFormatStyleToProperty( msDataStyleName, "NumberFormat", mrStyles, rPropSet );
107  lcl_NumberFormatStyleToProperty( msPercentageDataStyleName, "PercentageNumberFormat", mrStyles, rPropSet );
108 }
109 
110 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLChartStyleContext::createFastChildContext(
111  sal_Int32 nElement,
112  const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
113 {
114  SvXMLImportContextRef xContext;
115 
116  if( IsTokenInNamespace(nElement, XML_NAMESPACE_STYLE) ||
118  {
119  sal_Int32 nLocalName = nElement & TOKEN_MASK;
120  sal_uInt32 nFamily = 0;
121  if( nLocalName == XML_TEXT_PROPERTIES )
122  nFamily = XML_TYPE_PROP_TEXT;
123  else if( nLocalName == XML_PARAGRAPH_PROPERTIES )
124  nFamily = XML_TYPE_PROP_PARAGRAPH;
125  else if( nLocalName == XML_GRAPHIC_PROPERTIES )
126  nFamily = XML_TYPE_PROP_GRAPHIC;
127  else if( nLocalName == XML_CHART_PROPERTIES )
128  nFamily = XML_TYPE_PROP_CHART;
129  if( nFamily )
130  {
133  if( xImpPrMap.is() )
134  return new XMLChartPropertyContext(
135  GetImport(), nElement, xAttrList, nFamily,
136  GetProperties(), xImpPrMap );
137  }
138  }
139 
140  return XMLShapeStyleContext::createFastChildContext( nElement, xAttrList );
141 }
142 
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XmlStyleFamily GetFamily() const
Definition: xmlstyle.hxx:104
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3434
virtual void SetAttribute(sal_uInt16 nPrefixKey, const OUString &rLocalName, const OUString &rValue) override
is called when an attribute at the (auto)style element is found
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
constexpr sal_uInt16 XML_NAMESPACE_LO_EXT
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
void FillPropertySet(const css::uno::Reference< css::beans::XPropertySet > &rPropSet) override
is called after all styles have been read to apply styles
css::uno::Any const & rValue
Definition: ImageStyle.hxx:38
XmlStyleFamily
Definition: families.hxx:47
#define XML_TYPE_PROP_PARAGRAPH
Definition: xmltypes.hxx:99
virtual rtl::Reference< SvXMLImportPropertyMapper > GetImportPropertyMapper(XmlStyleFamily nFamily) const
Definition: xmlstyle.cxx:530
#define TOOLS_WARN_EXCEPTION(area, stream)
SvXMLStylesContext & mrStyles
::std::vector< XMLPropertyState > & GetProperties()
Definition: prstylei.hxx:81
#define XML_TYPE_PROP_TEXT
Definition: xmltypes.hxx:98
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
necessary for property context (element-property symbol-image)
#define XML_TYPE_PROP_CHART
Definition: xmltypes.hxx:107
virtual void SetAttribute(sal_uInt16 nPrefixKey, const OUString &rLocalName, const OUString &rValue) override
constexpr bool IsTokenInNamespace(sal_Int32 nToken, sal_uInt16 nNamespacePrefix)
Definition: xmlimp.hxx:101
virtual ~XMLChartStyleContext() override
#define XML_TYPE_PROP_GRAPHIC
Definition: xmltypes.hxx:94
SvXMLStylesContext * GetStyles()
Definition: prstylei.hxx:80
const SvXMLStyleContext * FindStyleChildContext(XmlStyleFamily nFamily, const OUString &rName, bool bCreateIndex=false) const
Definition: xmlstyle.cxx:809
constexpr sal_Int32 TOKEN_MASK
Definition: xmlimp.hxx:91
XMLChartStyleContext(SvXMLImport &rImport, SvXMLStylesContext &rStyles, XmlStyleFamily nFamily)
virtual void FillPropertySet(const css::uno::Reference< css::beans::XPropertySet > &rPropSet) override
constexpr sal_uInt16 XML_NAMESPACE_STYLE