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