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