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/xmlnmspe.hxx>
23 #include <xmloff/xmlnumfi.hxx>
24 #include <xmloff/families.hxx>
25 #include <xmloff/xmltypes.hxx>
26 #include <xmloff/xmlimppr.hxx>
27 
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <tools/diagnose_ex.h>
30 
32 
33 using namespace com::sun::star;
41 
42 
44  sal_uInt16 nPrefixKey,
45  const OUString& rLocalName,
46  const OUString& rValue )
47 {
48  if( IsXMLToken( rLocalName, XML_DATA_STYLE_NAME ) )
49  {
50  msDataStyleName =rValue;
51  }
52  else if( IsXMLToken( rLocalName, XML_PERCENTAGE_DATA_STYLE_NAME ) )
53  {
54  msPercentageDataStyleName =rValue;
55  }
56  else
57  {
58  XMLShapeStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
59  }
60 }
61 
63  SvXMLImport& rImport, sal_uInt16 nPrfx,
64  const OUString& rLName,
65  const uno::Reference< xml::sax::XAttributeList > & xAttrList,
66  SvXMLStylesContext& rStyles, XmlStyleFamily nFamily ) :
67 
68  XMLShapeStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, nFamily ),
69  mrStyles( rStyles )
70 {}
71 
73 {}
74 
75 namespace
76 {
77 
78 void lcl_NumberFormatStyleToProperty( const OUString& rStyleName, const OUString& rPropertyName,
79  const SvXMLStylesContext& rStylesContext,
80  const uno::Reference< beans::XPropertySet >& rPropSet )
81 {
82  if( !rStyleName.isEmpty())
83  {
84  const SvXMLNumFormatContext* pStyle = static_cast<const SvXMLNumFormatContext *>(rStylesContext.FindStyleChildContext(
85  XmlStyleFamily::DATA_STYLE, rStyleName, true ));
86  if( pStyle )
87  {
88  sal_Int32 nNumberFormat = const_cast<SvXMLNumFormatContext*>(pStyle)->GetKey();
89  rPropSet->setPropertyValue( rPropertyName, uno::Any(nNumberFormat) );
90  }
91  }
92 }
93 
94 }
95 
97  const uno::Reference< beans::XPropertySet > & rPropSet )
98 {
99  try
100  {
102  }
103  catch( beans::UnknownPropertyException& )
104  {
105  TOOLS_WARN_EXCEPTION( "xmloff", "unknown property exception -> shape style not completely imported for chart style" );
106  }
107 
108  lcl_NumberFormatStyleToProperty( msDataStyleName, "NumberFormat", mrStyles, rPropSet );
109  lcl_NumberFormatStyleToProperty( msPercentageDataStyleName, "PercentageNumberFormat", mrStyles, rPropSet );
110 }
111 
113  sal_uInt16 nPrefix,
114  const OUString& rLocalName,
115  const uno::Reference< xml::sax::XAttributeList > & xAttrList )
116 {
117  SvXMLImportContextRef xContext;
118 
119  if( XML_NAMESPACE_STYLE == nPrefix || XML_NAMESPACE_LO_EXT == nPrefix )
120  {
121  sal_uInt32 nFamily = 0;
122  if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
123  nFamily = XML_TYPE_PROP_TEXT;
124  else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
125  nFamily = XML_TYPE_PROP_PARAGRAPH;
126  else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) )
127  nFamily = XML_TYPE_PROP_GRAPHIC;
128  else if( IsXMLToken( rLocalName, XML_CHART_PROPERTIES ) )
129  nFamily = XML_TYPE_PROP_CHART;
130  if( nFamily )
131  {
134  if( xImpPrMap.is() )
135  xContext = new XMLChartPropertyContext(
136  GetImport(), nPrefix, rLocalName, xAttrList, nFamily,
137  GetProperties(), xImpPrMap );
138  }
139  }
140 
141  if (!xContext)
142  xContext = XMLShapeStyleContext::CreateChildContext( nPrefix, rLocalName,
143  xAttrList );
144 
145  return xContext;
146 }
147 
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr sal_uInt16 XML_NAMESPACE_LO_EXT
Definition: xmlnmspe.hxx:80
XmlStyleFamily GetFamily() const
Definition: xmlstyle.hxx:112
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3422
constexpr sal_uInt16 XML_NAMESPACE_STYLE
Definition: xmlnmspe.hxx:30
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
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
XMLChartStyleContext(SvXMLImport &rImport, sal_uInt16 nPrfx, const OUString &rLName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList, SvXMLStylesContext &rStyles, XmlStyleFamily nFamily)
virtual rtl::Reference< SvXMLImportPropertyMapper > GetImportPropertyMapper(XmlStyleFamily nFamily) const
Definition: xmlstyle.cxx:580
#define TOOLS_WARN_EXCEPTION(area, stream)
SvXMLStylesContext & mrStyles
::std::vector< XMLPropertyState > & GetProperties()
Definition: prstylei.hxx:79
virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
necessary for property context (element-property symbol-image)
#define XML_TYPE_PROP_TEXT
Definition: xmltypes.hxx:98
#define XML_TYPE_PROP_CHART
Definition: xmltypes.hxx:107
SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
Create a children element context.
virtual void SetAttribute(sal_uInt16 nPrefixKey, const OUString &rLocalName, const OUString &rValue) override
virtual ~XMLChartStyleContext() override
#define XML_TYPE_PROP_GRAPHIC
Definition: xmltypes.hxx:94
SvXMLStylesContext * GetStyles()
Definition: prstylei.hxx:78
const SvXMLStyleContext * FindStyleChildContext(XmlStyleFamily nFamily, const OUString &rName, bool bCreateIndex=false) const
Definition: xmlstyle.cxx:870
virtual void FillPropertySet(const css::uno::Reference< css::beans::XPropertySet > &rPropSet) override