LibreOffice Module reportdesign (master)  1
xmlGroup.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 "xmlGroup.hxx"
20 #include "xmlSection.hxx"
21 #include "xmlFunction.hxx"
22 #include "xmlfilter.hxx"
23 #include <xmloff/xmltoken.hxx>
24 #include <xmloff/xmlnamespace.hxx>
25 #include <xmloff/xmluconv.hxx>
27 #include "xmlHelper.hxx"
28 #include "xmlEnums.hxx"
29 #include <com/sun/star/report/GroupOn.hpp>
30 #include <com/sun/star/report/KeepTogether.hpp>
31 #include <osl/diagnose.h>
32 #include <sal/log.hxx>
33 #include <tools/diagnose_ex.h>
34 
35 namespace rptxml
36 {
37  using namespace ::com::sun::star;
38  using namespace ::com::sun::star::uno;
39  using namespace ::com::sun::star::report;
40  using namespace ::com::sun::star::xml::sax;
41 
42  static sal_Int16 lcl_getKeepTogetherOption(std::string_view _sValue)
43  {
44  sal_Int16 nRet = report::KeepTogether::NO;
46  (void)SvXMLUnitConverter::convertEnum( nRet, _sValue, aXML_EnumMap );
47  return nRet;
48  }
49 
50 OXMLGroup::OXMLGroup( ORptFilter& _rImport
51  ,const Reference< XFastAttributeList > & _xAttrList
52  ) :
53  SvXMLImportContext( _rImport )
54 {
55 
56  m_xGroups = _rImport.getReportDefinition()->getGroups();
57  OSL_ENSURE(m_xGroups.is(),"Groups is NULL!");
58  m_xGroup = m_xGroups->createGroup();
59 
60  m_xGroup->setSortAscending(false);// the default value has to be set
61  for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList ))
62  {
63  try
64  {
65  switch( aIter.getToken() )
66  {
67  case XML_ELEMENT(REPORT, XML_START_NEW_COLUMN):
68  m_xGroup->setStartNewColumn(IsXMLToken(aIter, XML_TRUE));
69  break;
70  case XML_ELEMENT(REPORT, XML_RESET_PAGE_NUMBER):
71  m_xGroup->setResetPageNumber(IsXMLToken(aIter, XML_TRUE));
72  break;
73  case XML_ELEMENT(REPORT, XML_SORT_ASCENDING):
74  m_xGroup->setSortAscending(IsXMLToken(aIter, XML_TRUE));
75  break;
76  case XML_ELEMENT(REPORT, XML_GROUP_EXPRESSION):
77  {
78  OUString sValue = aIter.toString();
79  sal_Int32 nLen = sValue.getLength();
80  if ( nLen )
81  {
82 
83  static const char s_sChanged[] = "rpt:HASCHANGED(\"";
84  sal_Int32 nPos = sValue.indexOf(s_sChanged);
85  if ( nPos == -1 )
86  nPos = 5;
87  else
88  {
89  nPos = strlen(s_sChanged);
90  static const char s_sQuote[] = "\"\"";
91  sal_Int32 nIndex = sValue.indexOf(s_sQuote,nPos);
92  while ( nIndex > -1 )
93  {
94  sValue = sValue.replaceAt(nIndex,2, u"\"");
95  nIndex = sValue.indexOf(s_sQuote,nIndex+2);
96  }
97  nLen = sValue.getLength() - 1;
98  }
99  sValue = sValue.copy(nPos,nLen-nPos-1);
100  const ORptFilter::TGroupFunctionMap& aFunctions = _rImport.getFunctions();
101  ORptFilter::TGroupFunctionMap::const_iterator aFind = aFunctions.find(sValue);
102  if ( aFind != aFunctions.end() )
103  {
104  const OUString sCompleteFormula = aFind->second->getFormula();
105  OUString sExpression = sCompleteFormula.getToken(1,'[');
106  sExpression = sExpression.getToken(0,']');
107  sal_Int32 nIndex = 0;
108  const OUString sFormula = sCompleteFormula.getToken(0,'(',nIndex);
109  ::sal_Int16 nGroupOn = report::GroupOn::DEFAULT;
110 
111  if ( sFormula == "rpt:LEFT")
112  {
113  nGroupOn = report::GroupOn::PREFIX_CHARACTERS;
114  OUString sInterval = sCompleteFormula.getToken(1,';',nIndex);
115  sInterval = sInterval.getToken(0,')');
116  m_xGroup->setGroupInterval(sInterval.toInt32());
117  }
118  else if ( sFormula == "rpt:YEAR")
119  nGroupOn = report::GroupOn::YEAR;
120  else if ( sFormula == "rpt:MONTH")
121  {
122  nGroupOn = report::GroupOn::MONTH;
123  }
124  else if ( sCompleteFormula.matchIgnoreAsciiCase("rpt:INT((MONTH",0)
125  && sCompleteFormula.endsWithIgnoreAsciiCase("-1)/3)+1") )
126  {
127  nGroupOn = report::GroupOn::QUARTAL;
128  }
129  else if ( sFormula == "rpt:WEEK")
130  nGroupOn = report::GroupOn::WEEK;
131  else if ( sFormula == "rpt:DAY")
132  nGroupOn = report::GroupOn::DAY;
133  else if ( sFormula == "rpt:HOUR")
134  nGroupOn = report::GroupOn::HOUR;
135  else if ( sFormula == "rpt:MINUTE")
136  nGroupOn = report::GroupOn::MINUTE;
137  else if ( sFormula == "rpt:INT")
138  {
139  nGroupOn = report::GroupOn::INTERVAL;
140  _rImport.removeFunction(sExpression);
141  sExpression = sExpression.copy(OUString("INT_count_").getLength());
142  OUString sInterval = sCompleteFormula.getToken(1,'/');
143  sInterval = sInterval.getToken(0,')');
144  m_xGroup->setGroupInterval(sInterval.toInt32());
145  }
146 
147  m_xGroup->setGroupOn(nGroupOn);
148 
149  _rImport.removeFunction(sValue);
150  sValue = sExpression;
151  }
152  m_xGroup->setExpression(sValue);
153  }
154  }
155  break;
156  case XML_ELEMENT(REPORT, XML_KEEP_TOGETHER):
157  m_xGroup->setKeepTogether(lcl_getKeepTogetherOption(aIter.toView()));
158  break;
159  default:
160  XMLOFF_WARN_UNKNOWN("reportdesign", aIter);
161  break;
162  }
163  }
164  catch(const Exception&)
165  {
166  TOOLS_WARN_EXCEPTION( "reportdesign", "Exception caught while putting group props!");
167  }
168  }
169 }
170 
171 
172 OXMLGroup::~OXMLGroup()
173 {
174 
175 }
176 
177 css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLGroup::createFastChildContext(
178  sal_Int32 nElement,
179  const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
180 {
181  css::uno::Reference< css::xml::sax::XFastContextHandler > xContext;
182  ORptFilter& rImport = GetOwnImport();
183 
184  switch( nElement )
185  {
187  {
189  xContext = new OXMLFunction( rImport,xAttrList,m_xGroup);
190  }
191  break;
193  {
195  m_xGroup->setHeaderOn(true);
196  xContext = new OXMLSection( rImport,xAttrList,m_xGroup->getHeader());
197  }
198  break;
201  xContext = new OXMLGroup( rImport,xAttrList);
202  break;
204  {
206  Reference<XReportDefinition> xComponent = rImport.getReportDefinition();
207  xContext = new OXMLSection( rImport,xAttrList, xComponent->getDetail());
208  }
209  break;
210 
212  {
214  m_xGroup->setFooterOn(true);
215  xContext = new OXMLSection( rImport,xAttrList,m_xGroup->getFooter());
216  }
217  break;
218  default:
219  break;
220  }
221 
222  return xContext;
223 }
224 
225 ORptFilter& OXMLGroup::GetOwnImport()
226 {
227  return static_cast<ORptFilter&>(GetImport());
228 }
229 
230 void OXMLGroup::endFastElement(sal_Int32 )
231 {
232  try
233  {
234  // the group elements end in the reverse order
235  m_xGroups->insertByIndex(0,uno::makeAny(m_xGroup));
236  }catch(uno::Exception&)
237  {
238  TOOLS_WARN_EXCEPTION( "reportdesign", "");
239  }
240 }
241 
242 
243 } // namespace rptxml
244 
245 
246 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XML_GROUP
sal_Int32 nIndex
XML_GROUP_HEADER
const Reference< XReportDefinition > & getReportDefinition() const
Definition: xmlfilter.hxx:92
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
XML_GROUP_FOOTER
#define XMLOFF_WARN_UNKNOWN(area, rIter)
XML_FUNCTION
static sal_Int16 lcl_getKeepTogetherOption(std::string_view _sValue)
Definition: xmlGroup.cxx:42
void Increment(sal_Int32 nInc=1)
#define TOOLS_WARN_EXCEPTION(area, stream)
OXMLGroup(const OXMLGroup &)
ProgressBarHelper * GetProgressBarHelper()
XML_DETAIL
XML_TRUE
#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
static const SvXMLEnumMapEntry< sal_Int16 > * GetKeepTogetherOptions()
Definition: xmlHelper.cxx:210
double getLength(const B2DPolygon &rCandidate)
std::map< OUString, Reference< XFunction > > TGroupFunctionMap
Definition: xmlfilter.hxx:56
REPORT
sal_uInt16 nPos
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo