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 "xmlReport.hxx"
25 #include "xmlfilter.hxx"
26 #include <xmloff/xmltoken.hxx>
27 #include <xmloff/xmlnmspe.hxx>
28 #include <xmloff/nmspmap.hxx>
29 #include <xmloff/xmluconv.hxx>
30 #include "xmlHelper.hxx"
31 #include "xmlGroup.hxx"
32 #include "xmlSection.hxx"
33 #include "xmlEnums.hxx"
34 #include "xmlFunction.hxx"
35 #include <tools/diagnose_ex.h>
36 #include <com/sun/star/sdb/CommandType.hpp>
37 #include "xmlMasterFields.hxx"
38 
39 namespace rptxml
40 {
41 	using namespace ::com::sun::star;
42 	using namespace uno;
43 	using namespace xml::sax;
44 
DBG_NAME(rpt_OXMLReport)45 DBG_NAME( rpt_OXMLReport )
46 
47 OXMLReport::OXMLReport( ORptFilter& rImport,
48 				sal_uInt16 nPrfx, const ::rtl::OUString& rLName,
49 				const Reference< XAttributeList > & _xAttrList
50                 ,const uno::Reference< report::XReportDefinition >& _xComponent
51 				,OXMLTable* _pContainer) :
52 	OXMLReportElementBase( rImport, nPrfx, rLName,_xComponent.get(),_pContainer)
53     ,m_xComponent(_xComponent)
54 {
55     DBG_CTOR( rpt_OXMLReport,NULL);
56     OSL_ENSURE(m_xComponent.is(),"No Report definition!");
57 
58     impl_initRuntimeDefaults();
59 
60     const SvXMLNamespaceMap& rMap = m_rImport.GetNamespaceMap();
61 	const SvXMLTokenMap& rTokenMap = m_rImport.GetReportElemTokenMap();
62 
63 	const sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
64     static const ::rtl::OUString s_sTRUE = ::xmloff::token::GetXMLToken(XML_TRUE);
65 	try
66 	{
67 		for(sal_Int16 i = 0; i < nLength; ++i)
68 		{
69 		 ::rtl::OUString sLocalName;
70 			const rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
71 			const sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
72 			const rtl::OUString sValue = _xAttrList->getValueByIndex( i );
73 
74 			switch( rTokenMap.Get( nPrefix, sLocalName ) )
75 			{
76 				case XML_TOK_COMMAND_TYPE:
77                     {
78                         sal_uInt16 nRet = static_cast<sal_uInt16>(sdb::CommandType::COMMAND);
79 		                const SvXMLEnumMapEntry* aXML_EnumMap = OXMLHelper::GetCommandTypeOptions();
80 		                SvXMLUnitConverter::convertEnum( nRet, sValue, aXML_EnumMap );
81 					    m_xComponent->setCommandType(nRet);
82                     }
83 					break;
84 				case XML_TOK_COMMAND:
85 					m_xComponent->setCommand(sValue);
86 					break;
87                 case XML_TOK_FILTER:
88 					m_xComponent->setFilter(sValue);
89 					break;
90                 case XML_TOK_CAPTION:
91 					m_xComponent->setCaption(sValue);
92 					break;
93                 case XML_TOK_ESCAPE_PROCESSING:
94 					m_xComponent->setEscapeProcessing(sValue == s_sTRUE);
95 					break;
96                 case XML_TOK_REPORT_MIMETYPE:
97                     m_xComponent->setMimeType(sValue);
98                     break;
99                 case XML_TOK_REPORT_NAME:
100                     m_xComponent->setName(sValue);
101                     break;
102                 default:
103                     break;
104 			}
105 		}
106 	}
107 	catch(Exception&)
108 	{
109 		OSL_ENSURE(0,"Exception catched while filling the report definition props");
110 	}
111 }
112 // -----------------------------------------------------------------------------
113 
~OXMLReport()114 OXMLReport::~OXMLReport()
115 {
116     DBG_DTOR( rpt_OXMLReport,NULL);
117 }
118 
119 // -----------------------------------------------------------------------------
120 
impl_initRuntimeDefaults() const121 void OXMLReport::impl_initRuntimeDefaults() const
122 {
123     OSL_PRECOND( m_xComponent.is(), "OXMLReport::impl_initRuntimeDefaults: no component!" );
124     if ( !m_xComponent.is() )
125         return;
126 
127     try
128     {
129         m_xComponent->setCommandType( sdb::CommandType::COMMAND );
130     }
131     catch( const Exception& )
132     {
133     	DBG_UNHANDLED_EXCEPTION();
134     }
135 }
136 
137 // -----------------------------------------------------------------------------
138 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const Reference<XAttributeList> & xAttrList)139 SvXMLImportContext* OXMLReport::CreateChildContext(
140 		sal_uInt16 nPrefix,
141 		const ::rtl::OUString& rLocalName,
142 		const Reference< XAttributeList > & xAttrList )
143 {
144 	SvXMLImportContext *pContext = _CreateChildContext(nPrefix,rLocalName,xAttrList);
145     if ( pContext )
146         return pContext;
147 	const SvXMLTokenMap&	rTokenMap	= m_rImport.GetReportElemTokenMap();
148 
149 	switch( rTokenMap.Get( nPrefix, rLocalName ) )
150 	{
151 		case XML_TOK_REPORT_FUNCTION:
152 			{
153 				m_rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
154 				pContext = new OXMLFunction( m_rImport, nPrefix, rLocalName,xAttrList,m_xComponent.get(),true);
155 			}
156 			break;
157         case XML_TOK_MASTER_DETAIL_FIELDS:
158                 m_rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
159                 pContext = new OXMLMasterFields(m_rImport, nPrefix, rLocalName,xAttrList ,this);
160             break;
161 		case XML_TOK_REPORT_HEADER:
162 			{
163 				m_rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
164 				m_xComponent->setReportHeaderOn(sal_True);
165 				pContext = new OXMLSection( m_rImport, nPrefix, rLocalName,xAttrList ,m_xComponent->getReportHeader());
166 			}
167 			break;
168 		case XML_TOK_PAGE_HEADER:
169 			{
170 				m_rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
171 				m_xComponent->setPageHeaderOn(sal_True);
172 				pContext = new OXMLSection( m_rImport, nPrefix, rLocalName,xAttrList ,m_xComponent->getPageHeader());
173 			}
174 			break;
175         case XML_TOK_GROUP:
176 			m_rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
177 			pContext = new OXMLGroup( m_rImport, nPrefix, rLocalName,xAttrList);
178 			break;
179 		case XML_TOK_DETAIL:
180 			{
181 				m_rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
182 				pContext = new OXMLSection( m_rImport, nPrefix, rLocalName,xAttrList ,m_xComponent->getDetail());
183 			}
184 			break;
185 		case XML_TOK_PAGE_FOOTER:
186 			{
187 				m_rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
188 				m_xComponent->setPageFooterOn(sal_True);
189 				pContext = new OXMLSection( m_rImport, nPrefix, rLocalName,xAttrList ,m_xComponent->getPageFooter(),sal_False);
190 			}
191 			break;
192 		case XML_TOK_REPORT_FOOTER:
193 			{
194 				m_rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
195 				m_xComponent->setReportFooterOn(sal_True);
196 				pContext = new OXMLSection( m_rImport, nPrefix, rLocalName,xAttrList ,m_xComponent->getReportFooter());
197 			}
198 			break;
199         default:
200             break;
201 	}
202 
203 	if( !pContext )
204 		pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
205 
206 
207 	return pContext;
208 }
209 // -----------------------------------------------------------------------------
EndElement()210 void OXMLReport::EndElement()
211 {
212     Reference< XFunctions > xFunctions = m_xComponent->getFunctions();
213     const ORptFilter::TGroupFunctionMap& aFunctions = m_rImport.getFunctions();
214     ORptFilter::TGroupFunctionMap::const_iterator aIter = aFunctions.begin();
215     const ORptFilter::TGroupFunctionMap::const_iterator aEnd = aFunctions.end();
216     for (; aIter != aEnd; ++aIter)
217         xFunctions->insertByIndex(xFunctions->getCount(),uno::makeAny(aIter->second));
218 
219     if ( !m_aMasterFields.empty() )
220         m_xComponent->setMasterFields(Sequence< ::rtl::OUString>(&*m_aMasterFields.begin(),m_aMasterFields.size()));
221     if ( !m_aDetailFields.empty() )
222         m_xComponent->setDetailFields(Sequence< ::rtl::OUString>(&*m_aDetailFields.begin(),m_aDetailFields.size()));
223 }
224 // -----------------------------------------------------------------------------
addMasterDetailPair(const::std::pair<::rtl::OUString,::rtl::OUString> & _aPair)225 void OXMLReport::addMasterDetailPair(const ::std::pair< ::rtl::OUString,::rtl::OUString >& _aPair)
226 {
227     m_aMasterFields.push_back(_aPair.first);
228     m_aDetailFields.push_back(_aPair.second);
229 }
230 //----------------------------------------------------------------------------
231 } // namespace rptxml
232 // -----------------------------------------------------------------------------
233