LibreOffice Module xmloff (master)  1
SchXMLPropertyMappingContext.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 
11 #include "SchXMLTools.hxx"
12 #include <xmloff/xmlnamespace.hxx>
13 #include <xmloff/xmlimp.hxx>
14 #include <xmloff/namespacemap.hxx>
15 #include <SchXMLImport.hxx>
16 
17 #include <com/sun/star/chart2/data/XLabeledDataSequence2.hpp>
18 #include <com/sun/star/chart2/data/XDataSource.hpp>
19 #include <com/sun/star/chart2/data/XDataSink.hpp>
20 #include <com/sun/star/chart2/XChartDocument.hpp>
21 
22 using namespace com::sun::star;
23 using namespace com::sun::star::uno;
24 
25 namespace {
26 
27 Reference< chart2::data::XLabeledDataSequence2 > createAndAddSequenceToSeries( const OUString& rRole
28  , const OUString& rRange
29  , const Reference< chart2::XChartDocument >& xChartDoc
30  , const Reference< chart2::XDataSeries >& xSeries )
31 {
33 
34  Reference< chart2::data::XDataSource > xSeriesSource( xSeries,uno::UNO_QUERY );
35 
36  if( !(!rRange.isEmpty() && xChartDoc.is() && xSeriesSource.is()) )
37  return xLabeledSeq;
38 
39  // create a new sequence
41 
42  // set values at the new sequence
44  Reference< beans::XPropertySet > xSeqProp( xSeq, uno::UNO_QUERY );
45  if( xSeqProp.is())
46  xSeqProp->setPropertyValue("Role", uno::makeAny( rRole));
47  xLabeledSeq->setValues( xSeq );
48 
49  Reference< chart2::data::XDataSink > xSink( xSeriesSource, uno::UNO_QUERY );
50  if( xSink.is())
51  {
52  Sequence< Reference< chart2::data::XLabeledDataSequence > > aData( xSeriesSource->getDataSequences());
53  aData.realloc( aData.getLength() + 1 );
54  aData[ aData.getLength() - 1 ] = xLabeledSeq;
55  xSink->setData( aData );
56  }
57 
58  return xLabeledSeq;
59 }
60 
61 }
62 
64  SvXMLImport& rImport, const OUString& rLocalName,
65  tSchXMLLSequencesPerIndex & rLSequencesPerIndex,
66  uno::Reference<
67  chart2::XDataSeries > const & xSeries ):
68  SvXMLImportContext( rImport, XML_NAMESPACE_LO_EXT, rLocalName ),
69  mrImportHelper( rImpHelper ),
70  mxDataSeries(xSeries),
71  mrLSequencesPerIndex(rLSequencesPerIndex)
72 {
73 
74 }
75 
77 {
78 }
79 
80 void SchXMLPropertyMappingContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList )
81 {
82  OUString aRange;
83  OUString aRole;
84  // parse attributes
85  sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
87 
88  for( sal_Int16 i = 0; i < nAttrCount; i++ )
89  {
90  OUString sAttrName = xAttrList->getNameByIndex( i );
91  OUString aLocalName;
92  OUString aValue = xAttrList->getValueByIndex( i );
93  sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
94 
95  switch( rAttrTokenMap.Get( nPrefix, aLocalName ))
96  {
98  aRole = aValue;
99  break;
101  aRange = aValue;
102  break;
103  }
104  }
105 
106  if( !aRange.isEmpty() && !aRole.isEmpty() )
107  {
108  Reference< chart2::XChartDocument > xChartDoc( GetImport().GetModel(), uno::UNO_QUERY );
110  createAndAddSequenceToSeries(aRole, aRange, xChartDoc, mxDataSeries);
111  mrLSequencesPerIndex.emplace(
113  xSeq);
114  }
115 }
116 
117 
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
tools::SvRef< SvBaseLink > xSink
const char aData[]
css::uno::Reference< css::chart2::XDataSeries > mxDataSeries
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
SvXMLNamespaceMap & GetNamespaceMap()
Definition: xmlimp.hxx:402
constexpr sal_uInt16 XML_NAMESPACE_LO_EXT
sal_uInt16 GetKeyByAttrName(const OUString &rAttrName, OUString *pPrefix, OUString *pLocalName, OUString *pNamespace) const
::std::pair< tSchXMLIndex, SchXMLLabeledSequencePart > tSchXMLIndexWithPart
int i
Reference< chart2::data::XLabeledDataSequence2 > GetNewLabeledDataSequence()
const SvXMLTokenMap & GetPropMappingAttrTokenMap()
sal_uInt16 Get(sal_uInt16 nPrefix, const OUString &rLName) const
Definition: xmltkmap.cxx:99
With this class you can import a element containing its data as element o...
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
Any makeAny(Color const &value)
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
StartElement is called after a context has been constructed and before an elements context is parsed...
Reference< chart2::data::XDataSequence > CreateDataSequence(const OUString &rRange, const Reference< chart2::XChartDocument > &xChartDoc)
::std::multimap< tSchXMLIndexWithPart, css::uno::Reference< css::chart2::data::XLabeledDataSequence > > tSchXMLLSequencesPerIndex
tSchXMLLSequencesPerIndex & mrLSequencesPerIndex
SchXMLPropertyMappingContext(SchXMLImportHelper &rImpHelper, SvXMLImport &rImport, const OUString &rLocalName, tSchXMLLSequencesPerIndex &rLSequencesPerIndex, css::uno::Reference< css::chart2::XDataSeries > const &xSeries)