LibreOffice Module reportdesign (master)  1
xmlReport.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 #include "xmlReport.hxx"
20 #include "xmlfilter.hxx"
21 #include <xmloff/xmltoken.hxx>
22 #include <xmloff/xmlnamespace.hxx>
23 #include <xmloff/xmluconv.hxx>
25 #include "xmlHelper.hxx"
26 #include "xmlGroup.hxx"
27 #include "xmlSection.hxx"
28 #include "xmlEnums.hxx"
29 #include "xmlFunction.hxx"
30 #include <tools/diagnose_ex.h>
31 #include <sal/log.hxx>
32 #include <com/sun/star/sdb/CommandType.hpp>
33 #include "xmlMasterFields.hxx"
34 
35 namespace rptxml
36 {
37  using namespace ::com::sun::star;
38  using namespace uno;
39  using namespace xml::sax;
40 
41 
42 OXMLReport::OXMLReport( ORptFilter& rImport,
43  const Reference< css::xml::sax::XFastAttributeList > & _xAttrList
44  ,const uno::Reference< report::XReportDefinition >& _xComponent) :
45  OXMLReportElementBase( rImport, _xComponent,nullptr)
46  ,m_xReportDefinition(_xComponent)
47 {
48  OSL_ENSURE(m_xReportDefinition.is(),"No Report definition!");
49 
50  impl_initRuntimeDefaults();
51 
52  try
53  {
54  for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList ))
55  {
56  switch( aIter.getToken() )
57  {
58  case XML_ELEMENT(REPORT, XML_COMMAND_TYPE):
59  {
60  sal_Int32 nRet = sdb::CommandType::COMMAND;
62  bool bConvertOk = SvXMLUnitConverter::convertEnum( nRet, aIter.toView(), aXML_EnumMap );
63  SAL_WARN_IF(!bConvertOk, "reportdesign", "convertEnum failed");
64  m_xReportDefinition->setCommandType(nRet);
65  }
66  break;
67  case XML_ELEMENT(REPORT, XML_COMMAND):
68  m_xReportDefinition->setCommand(aIter.toString());
69  break;
70  case XML_ELEMENT(REPORT, XML_FILTER):
71  m_xReportDefinition->setFilter(aIter.toString());
72  break;
73  case XML_ELEMENT(REPORT, XML_CAPTION):
75  m_xReportDefinition->setCaption(aIter.toString());
76  break;
77  case XML_ELEMENT(REPORT, XML_ESCAPE_PROCESSING):
78  m_xReportDefinition->setEscapeProcessing(IsXMLToken(aIter, XML_TRUE));
79  break;
80  case XML_ELEMENT(OFFICE, XML_MIMETYPE):
81  m_xReportDefinition->setMimeType(aIter.toString());
82  break;
83  case XML_ELEMENT(DRAW, XML_NAME):
84  m_xReportDefinition->setName(aIter.toString());
85  break;
86  default:
87  XMLOFF_WARN_UNKNOWN("reportdesign", aIter);
88  break;
89  }
90  }
91  }
92  catch(Exception&)
93  {
94  TOOLS_WARN_EXCEPTION( "reportdesign", "Exception caught while filling the report definition props");
95  }
96 }
97 
98 
100 {
101 }
102 
103 
105 {
106  OSL_PRECOND( m_xReportDefinition.is(), "OXMLReport::impl_initRuntimeDefaults: no component!" );
107  if ( !m_xReportDefinition.is() )
108  return;
109 
110  try
111  {
112  m_xReportDefinition->setCommandType( sdb::CommandType::COMMAND );
113  }
114  catch( const Exception& )
115  {
116  DBG_UNHANDLED_EXCEPTION("reportdesign");
117  }
118 }
119 
120 
121 css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLReport::createFastChildContext(
122  sal_Int32 nElement,
123  const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
124 {
125  css::uno::Reference< css::xml::sax::XFastContextHandler > xContext = OXMLReportElementBase::createFastChildContext(nElement,xAttrList);
126  if (xContext)
127  return xContext;
128 
129  switch( nElement )
130  {
132  {
134  xContext = new OXMLFunction( m_rImport,xAttrList,m_xReportDefinition,true);
135  }
136  break;
139  xContext = new OXMLMasterFields(m_rImport,xAttrList ,this);
140  break;
142  {
144  m_xReportDefinition->setReportHeaderOn(true);
145  xContext = new OXMLSection( m_rImport,xAttrList, m_xReportDefinition->getReportHeader());
146  }
147  break;
149  {
151  m_xReportDefinition->setPageHeaderOn(true);
152  xContext = new OXMLSection( m_rImport,xAttrList, m_xReportDefinition->getPageHeader());
153  }
154  break;
157  xContext = new OXMLGroup( m_rImport,xAttrList);
158  break;
160  {
162  xContext = new OXMLSection( m_rImport,xAttrList, m_xReportDefinition->getDetail());
163  }
164  break;
166  {
168  m_xReportDefinition->setPageFooterOn(true);
169  xContext = new OXMLSection( m_rImport,xAttrList, m_xReportDefinition->getPageFooter(),false);
170  }
171  break;
173  {
175  m_xReportDefinition->setReportFooterOn(true);
176  xContext = new OXMLSection( m_rImport, xAttrList, m_xReportDefinition->getReportFooter());
177  }
178  break;
179  default:
180  break;
181  }
182 
183  return xContext;
184 }
185 
187 {
188  Reference< XFunctions > xFunctions = m_xReportDefinition->getFunctions();
190  for (const auto& rEntry : aFunctions)
191  xFunctions->insertByIndex(xFunctions->getCount(),uno::makeAny(rEntry.second));
192 
193  if ( !m_aMasterFields.empty() )
194  m_xReportDefinition->setMasterFields(Sequence< OUString>(&*m_aMasterFields.begin(),m_aMasterFields.size()));
195  if ( !m_aDetailFields.empty() )
196  m_xReportDefinition->setDetailFields(Sequence< OUString>(&*m_aDetailFields.begin(),m_aDetailFields.size()));
197 }
198 
199 void OXMLReport::addMasterDetailPair(const ::std::pair< OUString,OUString >& _aPair)
200 {
201  m_aMasterFields.push_back(_aPair.first);
202  m_aDetailFields.push_back(_aPair.second);
203 }
204 
205 } // namespace rptxml
206 
207 
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XML_REPORT_HEADER
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
Definition: xmlReport.cxx:121
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
virtual void addMasterDetailPair(const ::std::pair< OUString, OUString > &_aPair) override
Definition: xmlReport.cxx:199
::std::vector< OUString > m_aDetailFields
Definition: xmlReport.hxx:32
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
Definition: xmlReport.cxx:186
virtual ~OXMLReport() override
Definition: xmlReport.cxx:99
css::uno::Reference< css::report::XReportDefinition > m_xReportDefinition
Definition: xmlReport.hxx:30
#define XMLOFF_WARN_UNKNOWN(area, rIter)
XML_GROUP
void impl_initRuntimeDefaults() const
initializes our object's properties whose runtime (API) default is different from the file format def...
Definition: xmlReport.cxx:104
static const SvXMLEnumMapEntry< sal_Int32 > * GetCommandTypeOptions()
Definition: xmlHelper.cxx:221
void Increment(sal_Int32 nInc=1)
#define DBG_UNHANDLED_EXCEPTION(...)
XML_CAPTION
#define TOOLS_WARN_EXCEPTION(area, stream)
XML_REPORT_FOOTER
XML_PAGE_HEADER
XML_MASTER_DETAIL_FIELDS
XML_DETAIL
OXMLReport(const OXMLReport &)=delete
ProgressBarHelper * GetProgressBarHelper()
const TGroupFunctionMap & getFunctions() const
Definition: xmlfilter.hxx:116
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
XML_PAGE_FOOTER
::std::vector< OUString > m_aMasterFields
Definition: xmlReport.hxx:31
#define SAL_WARN_IF(condition, area, stream)
#define XML_ELEMENT(prefix, name)
static bool convertEnum(EnumT &rEnum, std::u16string_view rValue, const SvXMLEnumMapEntry< EnumT > *pMap)
#define PROGRESS_BAR_STEP
Definition: xmlEnums.hxx:22
XML_TRUE
std::map< OUString, Reference< XFunction > > TGroupFunctionMap
Definition: xmlfilter.hxx:56
XML_FUNCTION
REPORT
OUString toString(OptionInfo const *info)