1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23 #include "precompiled_reportdesign.hxx"
24 #include "xmlFunction.hxx"
25 #include "xmlfilter.hxx"
26 #include <xmloff/xmltoken.hxx>
27 #include <xmloff/xmlnmspe.hxx>
28 #include <xmloff/nmspmap.hxx>
29 #include "xmlHelper.hxx"
30 #include "xmlEnums.hxx"
31 #include "xmlstrings.hrc"
32 #include <tools/debug.hxx>
33
34 namespace rptxml
35 {
36 using namespace ::com::sun::star;
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::report;
39 using namespace ::com::sun::star::xml::sax;
40
DBG_NAME(rpt_OXMLFunction)41 DBG_NAME( rpt_OXMLFunction )
42
43 OXMLFunction::OXMLFunction( ORptFilter& _rImport
44 ,sal_uInt16 nPrfx
45 ,const ::rtl::OUString& _sLocalName
46 ,const Reference< XAttributeList > & _xAttrList
47 ,const Reference< XFunctionsSupplier >& _xFunctions
48 ,bool _bAddToReport
49 ) :
50 SvXMLImportContext( _rImport, nPrfx, _sLocalName )
51 ,m_xFunctions(_xFunctions->getFunctions())
52 ,m_bAddToReport(_bAddToReport)
53 {
54 DBG_CTOR( rpt_OXMLFunction,NULL);
55
56 OSL_ENSURE(m_xFunctions.is(),"Functions is NULL!");
57 m_xFunction = m_xFunctions->createFunction();
58
59 OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
60
61 const SvXMLNamespaceMap& rMap = _rImport.GetNamespaceMap();
62 const SvXMLTokenMap& rTokenMap = _rImport.GetFunctionElemTokenMap();
63
64 const sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
65 static const ::rtl::OUString s_sTRUE = ::xmloff::token::GetXMLToken(XML_TRUE);
66 for(sal_Int16 i = 0; i < nLength; ++i)
67 {
68 ::rtl::OUString sLocalName;
69 const rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
70 const sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
71 const rtl::OUString sValue = _xAttrList->getValueByIndex( i );
72
73 try
74 {
75 switch( rTokenMap.Get( nPrefix, sLocalName ) )
76 {
77 case XML_TOK_FUNCTION_NAME:
78 m_xFunction->setName(sValue);
79 break;
80 case XML_TOK_FUNCTION_FORMULA:
81 m_xFunction->setFormula(ORptFilter::convertFormula(sValue));
82 break;
83 case XML_TOK_PRE_EVALUATED:
84 m_xFunction->setPreEvaluated(sValue == s_sTRUE);
85 break;
86 case XML_TOK_INITIAL_FORMULA:
87 if ( sValue.getLength() )
88 m_xFunction->setInitialFormula(beans::Optional< ::rtl::OUString>(sal_True,ORptFilter::convertFormula(sValue)));
89 break;
90 case XML_TOK_DEEP_TRAVERSING:
91 m_xFunction->setDeepTraversing(sValue == s_sTRUE);
92 break;
93 default:
94 break;
95 }
96 }
97 catch(const Exception&)
98 {
99 OSL_ENSURE(0,"Exception catched while putting Function props!");
100 }
101 }
102 }
103 // -----------------------------------------------------------------------------
104
~OXMLFunction()105 OXMLFunction::~OXMLFunction()
106 {
107 DBG_DTOR( rpt_OXMLFunction,NULL);
108 }
109 // -----------------------------------------------------------------------------
GetOwnImport()110 ORptFilter& OXMLFunction::GetOwnImport()
111 {
112 return static_cast<ORptFilter&>(GetImport());
113 }
114 // -----------------------------------------------------------------------------
EndElement()115 void OXMLFunction::EndElement()
116 {
117 if ( m_bAddToReport )
118 {
119 GetOwnImport().insertFunction(m_xFunction);
120 m_xFunction.clear();
121 }
122 else
123 {
124 try
125 {
126 m_xFunctions->insertByIndex(m_xFunctions->getCount(),uno::makeAny(m_xFunction));
127 m_xFunction.clear();
128 }catch(uno::Exception&)
129 {
130 OSL_ENSURE(0,"Exception catched!");
131 }
132 }
133 }
134 // -----------------------------------------------------------------------------
135 //----------------------------------------------------------------------------
136 } // namespace rptxml
137 // -----------------------------------------------------------------------------
138