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 "xmlGroup.hxx"
20 : #include "xmlSection.hxx"
21 : #include "xmlFunction.hxx"
22 : #include "xmlfilter.hxx"
23 : #include <xmloff/xmltoken.hxx>
24 : #include <xmloff/xmlnmspe.hxx>
25 : #include <xmloff/nmspmap.hxx>
26 : #include <xmloff/xmluconv.hxx>
27 : #include "xmlHelper.hxx"
28 : #include "xmlEnums.hxx"
29 : #include <ucbhelper/content.hxx>
30 : #include <comphelper/namecontainer.hxx>
31 : #include <com/sun/star/report/GroupOn.hpp>
32 : #include <com/sun/star/report/KeepTogether.hpp>
33 : #include <tools/debug.hxx>
34 :
35 : namespace rptxml
36 : {
37 : using namespace ::com::sun::star;
38 : using namespace ::com::sun::star::uno;
39 : using namespace ::com::sun::star::report;
40 : using namespace ::com::sun::star::xml::sax;
41 :
42 0 : sal_uInt16 lcl_getKeepTogetherOption(const OUString& _sValue)
43 : {
44 0 : sal_uInt16 nRet = report::KeepTogether::NO;
45 0 : const SvXMLEnumMapEntry* aXML_EnumMap = OXMLHelper::GetKeepTogetherOptions();
46 0 : (void)SvXMLUnitConverter::convertEnum( nRet, _sValue, aXML_EnumMap );
47 0 : return nRet;
48 : }
49 :
50 0 : OXMLGroup::OXMLGroup( ORptFilter& _rImport
51 : ,sal_uInt16 nPrfx
52 : ,const OUString& _sLocalName
53 : ,const Reference< XAttributeList > & _xAttrList
54 : ) :
55 0 : SvXMLImportContext( _rImport, nPrfx, _sLocalName )
56 : {
57 :
58 0 : m_xGroups = _rImport.getReportDefinition()->getGroups();
59 : OSL_ENSURE(m_xGroups.is(),"Groups is NULL!");
60 0 : m_xGroup = m_xGroups->createGroup();
61 :
62 : OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
63 :
64 0 : const SvXMLNamespaceMap& rMap = _rImport.GetNamespaceMap();
65 0 : const SvXMLTokenMap& rTokenMap = _rImport.GetGroupElemTokenMap();
66 0 : m_xGroup->setSortAscending(sal_False);// the default value has to be set
67 0 : const sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
68 0 : static const OUString s_sTRUE = ::xmloff::token::GetXMLToken(XML_TRUE);
69 0 : for(sal_Int16 i = 0; i < nLength; ++i)
70 : {
71 0 : OUString sLocalName;
72 0 : const OUString sAttrName = _xAttrList->getNameByIndex( i );
73 0 : const sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
74 0 : OUString sValue = _xAttrList->getValueByIndex( i );
75 :
76 : try
77 : {
78 0 : switch( rTokenMap.Get( nPrefix, sLocalName ) )
79 : {
80 : case XML_TOK_START_NEW_COLUMN:
81 0 : m_xGroup->setStartNewColumn(sValue == s_sTRUE);
82 0 : break;
83 : case XML_TOK_RESET_PAGE_NUMBER:
84 0 : m_xGroup->setResetPageNumber(sValue == s_sTRUE);
85 0 : break;
86 : case XML_TOK_SORT_ASCENDING:
87 0 : m_xGroup->setSortAscending(sValue == s_sTRUE);
88 0 : break;
89 : case XML_TOK_GROUP_EXPRESSION:
90 : {
91 0 : sal_Int32 nLen = sValue.getLength();
92 0 : if ( nLen )
93 : {
94 :
95 : static const char s_sChanged[] = "rpt:HASCHANGED(\"";
96 0 : sal_Int32 nPos = sValue.indexOf(s_sChanged);
97 0 : if ( nPos == -1 )
98 0 : nPos = 5;
99 : else
100 : {
101 0 : nPos = strlen(s_sChanged);
102 : static const char s_sQuote[] = "\"\"";
103 : static const char s_sSingleQuote[] = "\"";
104 0 : sal_Int32 nIndex = sValue.indexOf(s_sQuote,nPos);
105 0 : while ( nIndex > -1 )
106 : {
107 0 : sValue = sValue.replaceAt(nIndex,2,s_sSingleQuote);
108 0 : nIndex = sValue.indexOf(s_sQuote,nIndex+2);
109 : }
110 0 : nLen = sValue.getLength() - 1;
111 : }
112 0 : sValue = sValue.copy(nPos,nLen-nPos-1);
113 0 : const ORptFilter::TGroupFunctionMap& aFunctions = _rImport.getFunctions();
114 0 : ORptFilter::TGroupFunctionMap::const_iterator aFind = aFunctions.find(sValue);
115 0 : if ( aFind != aFunctions.end() )
116 : {
117 0 : sal_Int32 nIndex = 0;
118 0 : const OUString sCompleteFormula = aFind->second->getFormula();
119 0 : OUString sExpression = sCompleteFormula.getToken(1,'[',nIndex);
120 0 : nIndex = 0;
121 0 : sExpression = sExpression.getToken(0,']',nIndex);
122 0 : nIndex = 0;
123 0 : const OUString sFormula = sCompleteFormula.getToken(0,'(',nIndex);
124 0 : ::sal_Int16 nGroupOn = report::GroupOn::DEFAULT;
125 :
126 0 : if ( sFormula == "rpt:LEFT")
127 : {
128 0 : nGroupOn = report::GroupOn::PREFIX_CHARACTERS;
129 0 : OUString sInterval = sCompleteFormula.getToken(1,';',nIndex);
130 0 : nIndex = 0;
131 0 : sInterval = sInterval.getToken(0,')',nIndex);
132 0 : m_xGroup->setGroupInterval(sInterval.toInt32());
133 : }
134 0 : else if ( sFormula == "rpt:YEAR")
135 0 : nGroupOn = report::GroupOn::YEAR;
136 0 : else if ( sFormula == "rpt:MONTH")
137 : {
138 0 : nGroupOn = report::GroupOn::MONTH;
139 : }
140 0 : else if ( sCompleteFormula.matchIgnoreAsciiCase("rpt:INT((MONTH",0)
141 0 : && sCompleteFormula.endsWithIgnoreAsciiCase("-1)/3)+1") )
142 : {
143 0 : nGroupOn = report::GroupOn::QUARTAL;
144 : }
145 0 : else if ( sFormula == "rpt:WEEK")
146 0 : nGroupOn = report::GroupOn::WEEK;
147 0 : else if ( sFormula == "rpt:DAY")
148 0 : nGroupOn = report::GroupOn::DAY;
149 0 : else if ( sFormula == "rpt:HOUR")
150 0 : nGroupOn = report::GroupOn::HOUR;
151 0 : else if ( sFormula == "rpt:MINUTE")
152 0 : nGroupOn = report::GroupOn::MINUTE;
153 0 : else if ( sFormula == "rpt:INT")
154 : {
155 0 : nGroupOn = report::GroupOn::INTERVAL;
156 0 : _rImport.removeFunction(sExpression);
157 0 : sExpression = sExpression.copy(OUString("INT_count_").getLength());
158 :
159 0 : nIndex = 0;
160 0 : OUString sInterval = sCompleteFormula.getToken(1,'/',nIndex);
161 0 : nIndex = 0;
162 0 : sInterval = sInterval.getToken(0,')',nIndex);
163 0 : m_xGroup->setGroupInterval(sInterval.toInt32());
164 : }
165 :
166 0 : m_xGroup->setGroupOn(nGroupOn);
167 :
168 0 : _rImport.removeFunction(sValue);
169 0 : sValue = sExpression;
170 : }
171 0 : m_xGroup->setExpression(sValue);
172 : }
173 : }
174 0 : break;
175 : case XML_TOK_GROUP_KEEP_TOGETHER:
176 0 : m_xGroup->setKeepTogether(lcl_getKeepTogetherOption(sValue));
177 0 : break;
178 : default:
179 0 : break;
180 : }
181 : }
182 0 : catch(const Exception&)
183 : {
184 : OSL_FAIL("Exception catched while putting group props!");
185 : }
186 0 : }
187 0 : }
188 :
189 :
190 0 : OXMLGroup::~OXMLGroup()
191 : {
192 :
193 0 : }
194 :
195 0 : SvXMLImportContext* OXMLGroup::CreateChildContext(
196 : sal_uInt16 nPrefix,
197 : const OUString& rLocalName,
198 : const Reference< XAttributeList > & xAttrList )
199 : {
200 0 : SvXMLImportContext *pContext = 0;
201 0 : ORptFilter& rImport = GetOwnImport();
202 0 : const SvXMLTokenMap& rTokenMap = rImport.GetGroupElemTokenMap();
203 :
204 0 : switch( rTokenMap.Get( nPrefix, rLocalName ) )
205 : {
206 : case XML_TOK_GROUP_FUNCTION:
207 : {
208 0 : rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
209 0 : pContext = new OXMLFunction( rImport, nPrefix, rLocalName,xAttrList,m_xGroup.get());
210 : }
211 0 : break;
212 : case XML_TOK_GROUP_HEADER:
213 : {
214 0 : rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
215 0 : m_xGroup->setHeaderOn(sal_True);
216 0 : pContext = new OXMLSection( rImport, nPrefix, rLocalName,xAttrList,m_xGroup->getHeader());
217 : }
218 0 : break;
219 : case XML_TOK_GROUP_GROUP:
220 0 : rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
221 0 : pContext = new OXMLGroup( rImport, nPrefix, rLocalName,xAttrList);
222 0 : break;
223 : case XML_TOK_GROUP_DETAIL:
224 : {
225 0 : rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
226 0 : Reference<XReportDefinition> m_xComponent = rImport.getReportDefinition();
227 0 : pContext = new OXMLSection( rImport, nPrefix, rLocalName,xAttrList ,m_xComponent->getDetail());
228 : }
229 0 : break;
230 :
231 : case XML_TOK_GROUP_FOOTER:
232 : {
233 0 : rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
234 0 : m_xGroup->setFooterOn(sal_True);
235 0 : pContext = new OXMLSection( rImport, nPrefix, rLocalName,xAttrList,m_xGroup->getFooter());
236 : }
237 0 : break;
238 : default:
239 0 : break;
240 : }
241 :
242 0 : if( !pContext )
243 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
244 :
245 0 : return pContext;
246 : }
247 :
248 0 : ORptFilter& OXMLGroup::GetOwnImport()
249 : {
250 0 : return static_cast<ORptFilter&>(GetImport());
251 : }
252 :
253 0 : void OXMLGroup::EndElement()
254 : {
255 : try
256 : {
257 : // the group elements end in the reverse order
258 0 : m_xGroups->insertByIndex(0,uno::makeAny(m_xGroup));
259 0 : }catch(uno::Exception&)
260 : {
261 : OSL_FAIL("Exception catched!");
262 : }
263 0 : }
264 :
265 :
266 : } // namespace rptxml
267 :
268 :
269 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|