LibreOffice Module reportdesign (master)  1
xmlFunction.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 "xmlFunction.hxx"
20 #include "xmlfilter.hxx"
21 #include <xmloff/xmltoken.hxx>
22 #include <xmloff/xmlnamespace.hxx>
23 #include <osl/diagnose.h>
24 #include <tools/diagnose_ex.h>
25 
26 namespace rptxml
27 {
28  using namespace ::com::sun::star;
29  using namespace ::com::sun::star::uno;
30  using namespace ::com::sun::star::report;
31  using namespace ::com::sun::star::xml::sax;
32 
33 
34 OXMLFunction::OXMLFunction( ORptFilter& _rImport
35  ,const Reference< XFastAttributeList > & _xAttrList
36  ,const Reference< XFunctionsSupplier >& _xFunctions
37  ,bool _bAddToReport
38  ) :
39  SvXMLImportContext( _rImport )
40  ,m_xFunctions(_xFunctions->getFunctions())
41  ,m_bAddToReport(_bAddToReport)
42 {
43 
44  OSL_ENSURE(m_xFunctions.is(),"Functions is NULL!");
45  m_xFunction = m_xFunctions->createFunction();
46 
47  for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList ))
48  {
49  try
50  {
51  switch( aIter.getToken() )
52  {
53  case XML_ELEMENT(REPORT, XML_NAME):
54  m_xFunction->setName(aIter.toString());
55  break;
56  case XML_ELEMENT(REPORT, XML_FORMULA):
57  m_xFunction->setFormula(ORptFilter::convertFormula(aIter.toString()));
58  break;
59  case XML_ELEMENT(REPORT, XML_PRE_EVALUATED):
60  m_xFunction->setPreEvaluated(IsXMLToken(aIter, XML_TRUE));
61  break;
62  case XML_ELEMENT(REPORT, XML_INITIAL_FORMULA):
63  if ( !aIter.isEmpty() )
64  m_xFunction->setInitialFormula(beans::Optional< OUString>(true,ORptFilter::convertFormula(aIter.toString())));
65  break;
66  case XML_ELEMENT(REPORT, XML_DEEP_TRAVERSING):
67  m_xFunction->setDeepTraversing(IsXMLToken(aIter, XML_TRUE));
68  break;
69  default:
70  XMLOFF_WARN_UNKNOWN("reportdesign", aIter);
71  break;
72  }
73  }
74  catch(const Exception&)
75  {
76  TOOLS_WARN_EXCEPTION( "reportdesign", "Exception caught while putting Function props!");
77  }
78  }
79 }
80 
81 
83 {
84 }
85 
87 {
88  return static_cast<ORptFilter&>(GetImport());
89 }
90 
92 {
93  if ( m_bAddToReport )
94  {
95  GetOwnImport().insertFunction(m_xFunction);
96  m_xFunction.clear();
97  }
98  else
99  {
100  try
101  {
102  m_xFunctions->insertByIndex(m_xFunctions->getCount(),uno::Any(m_xFunction));
103  m_xFunction.clear();
104  }catch(uno::Exception&)
105  {
106  TOOLS_WARN_EXCEPTION( "reportdesign", "");
107  }
108  }
109 }
110 
111 
112 } // namespace rptxml
113 
114 
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
Definition: xmlFunction.cxx:91
OXMLFunction(const OXMLFunction &)
SvXMLImport & GetImport()
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
#define XMLOFF_WARN_UNKNOWN(area, rIter)
#define TOOLS_WARN_EXCEPTION(area, stream)
virtual ~OXMLFunction() override
Definition: xmlFunction.cxx:82
void insertFunction(const css::uno::Reference< css::report::XFunction > &_xFunction)
inserts a new function
Definition: xmlfilter.cxx:729
ORptFilter & GetOwnImport()
Definition: xmlFunction.cxx:86
XML_TRUE
css::uno::Reference< css::report::XFunctions > m_xFunctions
Definition: xmlFunction.hxx:32
if(aStr!=aBuf) UpdateName_Impl(m_xFollowLb.get()
#define XML_ELEMENT(prefix, name)
OUString toString(OptionInfo const *info)