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