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 "xmlSection.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 "xmlEnums.hxx"
32 #ifndef RPT_XMLCOLUMN_HXX
33 #include "xmlColumn.hxx"
34 #endif
35 #ifndef RPT_XMLCondPrtExpr_HXX
36 #include "xmlCondPrtExpr.hxx"
37 #endif
38 #include "xmlStyleImport.hxx"
39 #include <connectivity/dbtools.hxx>
40 #include <tools/debug.hxx>
41 #include <com/sun/star/report/ReportPrintOption.hpp>
42 #ifndef REPORTDESIGN_SHARED_XMLSTRINGS_HRC
43 #include "xmlstrings.hrc"
44 #endif
45 #include "xmlTable.hxx"
46 
47 
48 namespace rptxml
49 {
50 	using namespace ::xmloff;
51 	using namespace ::com::sun::star;
52 	using namespace ::com::sun::star::uno;
53 	using namespace ::com::sun::star::xml::sax;
54 
lcl_getReportPrintOption(const::rtl::OUString & _sValue)55   	sal_uInt16 lcl_getReportPrintOption(const ::rtl::OUString& _sValue)
56 	{
57 		sal_uInt16 nRet = report::ReportPrintOption::ALL_PAGES;
58 		const SvXMLEnumMapEntry* aXML_EnumMap = OXMLHelper::GetReportPrintOptions();
59 		SvXMLUnitConverter::convertEnum( nRet, _sValue, aXML_EnumMap );
60 		return nRet;
61 	}
62 
63 
DBG_NAME(rpt_OXMLSection)64 DBG_NAME( rpt_OXMLSection )
65 
66 OXMLSection::OXMLSection( ORptFilter& rImport,
67 				sal_uInt16 nPrfx, const ::rtl::OUString& _sLocalName,
68 				const uno::Reference< xml::sax::XAttributeList > & _xAttrList
69 				,const uno::Reference< report::XSection >& _xSection
70                 ,sal_Bool _bPageHeader)
71 :SvXMLImportContext( rImport, nPrfx, _sLocalName )
72 ,m_xSection(_xSection)
73 ,m_bPageHeader(_bPageHeader)
74 {
75     DBG_CTOR( rpt_OXMLSection,NULL);
76 
77 	OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
78 	const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
79 	const SvXMLTokenMap& rTokenMap = rImport.GetSectionElemTokenMap();
80 
81 	const sal_Int16 nLength = (m_xSection.is() && _xAttrList.is()) ? _xAttrList->getLength() : 0;
82     static const ::rtl::OUString s_sTRUE = ::xmloff::token::GetXMLToken(XML_TRUE);
83     try
84 	{
85 	    for(sal_Int16 i = 0; i < nLength; ++i)
86 	    {
87 		    rtl::OUString sLocalName;
88 		    const rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
89 		    const sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
90 		    const rtl::OUString sValue = _xAttrList->getValueByIndex( i );
91 
92 		    switch( rTokenMap.Get( nPrefix, sLocalName ) )
93 		    {
94 
95             	case XML_TOK_PAGE_PRINT_OPTION:
96                     if ( _bPageHeader )
97             		    m_xSection->getReportDefinition()->setPageHeaderOption(lcl_getReportPrintOption(sValue));
98                     else
99 					    m_xSection->getReportDefinition()->setPageFooterOption(lcl_getReportPrintOption(sValue));
100 					break;
101                 case XML_TOK_REPEAT_SECTION:
102 				    m_xSection->setRepeatSection(sValue == s_sTRUE );
103 				    break;
104 
105                 default:
106                     OSL_ENSURE(0,"OXMLSection: Unknown attribute!");
107 		    }
108 	    }
109     }
110 	catch(Exception&)
111 	{
112 		OSL_ENSURE(0,"Exception catched while filling the section props");
113 	}
114 }
115 // -----------------------------------------------------------------------------
~OXMLSection()116 OXMLSection::~OXMLSection()
117 {
118     DBG_DTOR( rpt_OXMLSection,NULL);
119 }
120 // -----------------------------------------------------------------------------
121 
CreateChildContext(sal_uInt16 _nPrefix,const::rtl::OUString & _rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)122 SvXMLImportContext* OXMLSection::CreateChildContext(
123 		sal_uInt16 _nPrefix,
124 		const ::rtl::OUString& _rLocalName,
125 		const uno::Reference< xml::sax::XAttributeList > & xAttrList )
126 {
127 	SvXMLImportContext *pContext = 0;
128     ORptFilter& rImport = GetOwnImport();
129 	const SvXMLTokenMap&	rTokenMap	= rImport.GetSectionElemTokenMap();
130     uno::Reference<lang::XMultiServiceFactory> xFactor = rImport.getServiceFactory();
131 
132 	switch( rTokenMap.Get( _nPrefix, _rLocalName ) )
133 	{
134         case XML_TOK_TABLE:
135 			pContext = new OXMLTable( rImport, _nPrefix, _rLocalName,xAttrList,m_xSection);
136 			break;
137         default:
138             break;
139 	}
140 
141 	if( !pContext )
142 		pContext = new SvXMLImportContext( rImport, _nPrefix, _rLocalName );
143 
144 	return pContext;
145 }
146 // -----------------------------------------------------------------------------
GetOwnImport()147 ORptFilter& OXMLSection::GetOwnImport()
148 {
149 	return static_cast<ORptFilter&>(GetImport());
150 }
151 // -----------------------------------------------------------------------------
152 // -----------------------------------------------------------------------------
153 } // namespace rptxml
154 // -----------------------------------------------------------------------------
155