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 "xmlReportElement.hxx"
25 #include "xmlfilter.hxx"
26 #include <xmloff/xmltoken.hxx>
27 #include <xmloff/xmlnmspe.hxx>
28 #include <xmloff/nmspmap.hxx>
29 #include "xmlEnums.hxx"
30 #include "xmlComponent.hxx"
31 #include "xmlCondPrtExpr.hxx"
32 #include <tools/debug.hxx>
33 #include "xmlFormatCondition.hxx"
34 
35 
36 namespace rptxml
37 {
38 	using namespace ::com::sun::star;
39 	using namespace report;
40 	using namespace uno;
41 	using namespace xml::sax;
DBG_NAME(rpt_OXMLReportElement)42 DBG_NAME( rpt_OXMLReportElement )
43 
44 OXMLReportElement::OXMLReportElement( ORptFilter& rImport,
45 				sal_uInt16 nPrfx, const ::rtl::OUString& rLName,
46 				const Reference< XAttributeList > & _xAttrList
47 				,const Reference< XReportControlModel > & _xComponent) :
48 	SvXMLImportContext( rImport, nPrfx, rLName )
49 ,m_xComponent(_xComponent)
50 {
51     DBG_CTOR( rpt_OXMLReportElement,NULL);
52 
53 	OSL_ENSURE(m_xComponent.is(),"Component is NULL!");
54 	const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
55 	const SvXMLTokenMap& rTokenMap = rImport.GetReportElementElemTokenMap();
56 
57 	static const ::rtl::OUString s_sTRUE = ::xmloff::token::GetXMLToken(XML_TRUE);
58 	const sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
59 	try
60 	{
61 		for(sal_Int16 i = 0; i < nLength; ++i)
62 		{
63 		 ::rtl::OUString sLocalName;
64 			const rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
65 			const sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
66 			const rtl::OUString sValue = _xAttrList->getValueByIndex( i );
67 
68 			switch( rTokenMap.Get( nPrefix, sLocalName ) )
69 			{
70 				case XML_TOK_PRINT_ONLY_WHEN_GROUP_CHANGE:
71 					m_xComponent->setPrintWhenGroupChange(s_sTRUE == sValue);
72 					break;
73    				case XML_TOK_PRINT_REPEATED_VALUES:
74 					m_xComponent->setPrintRepeatedValues(sValue == s_sTRUE ? sal_True : sal_False);
75 					break;
76                 default:
77                     break;
78 			}
79 		}
80 	}
81 	catch(Exception&)
82 	{
83 		OSL_ENSURE(0,"Exception catched while filling the report definition props");
84 	}
85 }
86 // -----------------------------------------------------------------------------
87 
~OXMLReportElement()88 OXMLReportElement::~OXMLReportElement()
89 {
90 
91     DBG_DTOR( rpt_OXMLReportElement,NULL);
92 }
93 // -----------------------------------------------------------------------------
94 
CreateChildContext(sal_uInt16 _nPrefix,const::rtl::OUString & _rLocalName,const Reference<XAttributeList> & xAttrList)95 SvXMLImportContext* OXMLReportElement::CreateChildContext(
96 		sal_uInt16 _nPrefix,
97 		const ::rtl::OUString& _rLocalName,
98 		const Reference< XAttributeList > & xAttrList )
99 {
100 	SvXMLImportContext *pContext = 0;
101     ORptFilter& rImport = GetOwnImport();
102 	const SvXMLTokenMap&	rTokenMap	= rImport.GetReportElementElemTokenMap();
103 
104 	switch( rTokenMap.Get( _nPrefix, _rLocalName ) )
105 	{
106 		case XML_TOK_COMPONENT:
107 			rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
108 			pContext = new OXMLComponent( rImport, _nPrefix, _rLocalName,xAttrList,m_xComponent.get());
109 			break;
110 		case XML_TOK_REP_CONDITIONAL_PRINT_EXPRESSION:
111 			rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
112 			pContext = new OXMLCondPrtExpr( rImport, _nPrefix, _rLocalName,xAttrList,m_xComponent.get());
113 			break;
114         case XML_TOK_FORMATCONDITION:
115 			{
116 				uno::Reference< report::XFormatCondition > xNewCond = m_xComponent->createFormatCondition();
117 				m_xComponent->insertByIndex(m_xComponent->getCount(),uno::makeAny(xNewCond));
118 				rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
119 				pContext = new OXMLFormatCondition( rImport, _nPrefix, _rLocalName,xAttrList,xNewCond);
120 			}
121 			break;
122         default:
123             break;
124 	}
125 
126 	if( !pContext )
127 		pContext = new SvXMLImportContext( GetImport(), _nPrefix, _rLocalName );
128 
129 
130 	return pContext;
131 }
132 // -----------------------------------------------------------------------------
GetOwnImport()133 ORptFilter& OXMLReportElement::GetOwnImport()
134 {
135 	return static_cast<ORptFilter&>(GetImport());
136 }
137 //----------------------------------------------------------------------------
138 } // namespace rptxml
139 // -----------------------------------------------------------------------------
140