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>
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"
31#include <sal/log.hxx>
32#include <com/sun/star/sdb/CommandType.hpp>
33#include "xmlMasterFields.hxx"
34
35namespace rptxml
36{
37 using namespace ::com::sun::star;
38 using namespace uno;
39 using namespace xml::sax;
40
41
42OXMLReport::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;
61 const SvXMLEnumMapEntry<sal_Int32>* aXML_EnumMap = OXMLHelper::GetCommandTypeOptions();
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
99OXMLReport::~OXMLReport()
100{
101}
102
103
104void OXMLReport::impl_initRuntimeDefaults() const
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
121css::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 {
133 m_rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
134 xContext = new OXMLFunction( m_rImport,xAttrList,m_xReportDefinition,true);
135 }
136 break;
138 m_rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
139 xContext = new OXMLMasterFields(m_rImport,xAttrList ,this);
140 break;
142 {
143 m_rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
144 m_xReportDefinition->setReportHeaderOn(true);
145 xContext = new OXMLSection( m_rImport,xAttrList, m_xReportDefinition->getReportHeader());
146 }
147 break;
149 {
150 m_rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
151 m_xReportDefinition->setPageHeaderOn(true);
152 xContext = new OXMLSection( m_rImport,xAttrList, m_xReportDefinition->getPageHeader());
153 }
154 break;
156 m_rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
157 xContext = new OXMLGroup( m_rImport,xAttrList);
158 break;
160 {
161 m_rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
162 xContext = new OXMLSection( m_rImport,xAttrList, m_xReportDefinition->getDetail());
163 }
164 break;
166 {
167 m_rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
168 m_xReportDefinition->setPageFooterOn(true);
169 xContext = new OXMLSection( m_rImport,xAttrList, m_xReportDefinition->getPageFooter(),false);
170 }
171 break;
173 {
174 m_rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
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
186void OXMLReport::endFastElement(sal_Int32)
187{
188 Reference< XFunctions > xFunctions = m_xReportDefinition->getFunctions();
189 const ORptFilter::TGroupFunctionMap& aFunctions = m_rImport.getFunctions();
190 for (const auto& rEntry : aFunctions)
191 xFunctions->insertByIndex(xFunctions->getCount(),uno::Any(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
199void 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: */
const SvXMLImport & m_rImport
static bool convertEnum(EnumT &rEnum, std::u16string_view rValue, const SvXMLEnumMapEntry< EnumT > *pMap)
std::map< OUString, Reference< XFunction > > TGroupFunctionMap
Definition: xmlfilter.hxx:56
OXMLReport(const OXMLReport &)=delete
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
#define SAL_WARN_IF(condition, area, stream)
@ Exception
REPORT
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
OUString toString(OptionInfo const *info)
XML_MASTER_DETAIL_FIELDS
XML_TRUE
XML_FUNCTION
XML_REPORT_FOOTER
XML_PAGE_HEADER
XML_CAPTION
XML_GROUP
XML_DETAIL
XML_PAGE_FOOTER
XML_REPORT_HEADER
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
#define PROGRESS_BAR_STEP
Definition: xmlEnums.hxx:22
#define XMLOFF_WARN_UNKNOWN(area, rIter)
#define XML_ELEMENT(prefix, name)