LCOV - code coverage report
Current view: top level - libreoffice/reportdesign/source/filter/xml - xmlGroup.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 128 0.0 %
Date: 2012-12-27 Functions: 0 7 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10