LCOV - code coverage report
Current view: top level - reportdesign/source/filter/xml - xmlGroup.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 128 0.0 %
Date: 2012-08-25 Functions: 0 7 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 234 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : #include "xmlGroup.hxx"
      29                 :            : #include "xmlSection.hxx"
      30                 :            : #include "xmlFunction.hxx"
      31                 :            : #include "xmlfilter.hxx"
      32                 :            : #include <xmloff/xmltoken.hxx>
      33                 :            : #include <xmloff/xmlnmspe.hxx>
      34                 :            : #include <xmloff/nmspmap.hxx>
      35                 :            : #include <xmloff/xmluconv.hxx>
      36                 :            : #include "xmlHelper.hxx"
      37                 :            : #include "xmlEnums.hxx"
      38                 :            : #include <ucbhelper/content.hxx>
      39                 :            : #include <comphelper/namecontainer.hxx>
      40                 :            : #include <com/sun/star/report/GroupOn.hpp>
      41                 :            : #include <com/sun/star/report/KeepTogether.hpp>
      42                 :            : #include <tools/debug.hxx>
      43                 :            : 
      44                 :            : namespace rptxml
      45                 :            : {
      46                 :            :     using namespace ::com::sun::star;
      47                 :            :     using namespace ::com::sun::star::uno;
      48                 :            :     using namespace ::com::sun::star::report;
      49                 :            :     using namespace ::com::sun::star::xml::sax;
      50                 :            : 
      51                 :          0 :     sal_uInt16 lcl_getKeepTogetherOption(const ::rtl::OUString& _sValue)
      52                 :            :     {
      53                 :          0 :         sal_uInt16 nRet = report::KeepTogether::NO;
      54         [ #  # ]:          0 :         const SvXMLEnumMapEntry* aXML_EnumMap = OXMLHelper::GetKeepTogetherOptions();
      55         [ #  # ]:          0 :         SvXMLUnitConverter::convertEnum( nRet, _sValue, aXML_EnumMap );
      56                 :          0 :         return nRet;
      57                 :            :     }
      58                 :            : DBG_NAME( rpt_OXMLGroup )
      59                 :            : 
      60                 :          0 : OXMLGroup::OXMLGroup( ORptFilter& _rImport
      61                 :            :                 ,sal_uInt16 nPrfx
      62                 :            :                 ,const ::rtl::OUString& _sLocalName
      63                 :            :                 ,const Reference< XAttributeList > & _xAttrList
      64                 :            :                 ) :
      65                 :          0 :     SvXMLImportContext( _rImport, nPrfx, _sLocalName )
      66                 :            : {
      67                 :            :     DBG_CTOR( rpt_OXMLGroup,NULL);
      68                 :            : 
      69 [ #  # ][ #  # ]:          0 :     m_xGroups = _rImport.getReportDefinition()->getGroups();
         [ #  # ][ #  # ]
      70                 :            :     OSL_ENSURE(m_xGroups.is(),"Groups is NULL!");
      71 [ #  # ][ #  # ]:          0 :     m_xGroup = m_xGroups->createGroup();
                 [ #  # ]
      72                 :            : 
      73                 :            :     OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
      74                 :            : 
      75                 :          0 :     const SvXMLNamespaceMap& rMap = _rImport.GetNamespaceMap();
      76         [ #  # ]:          0 :     const SvXMLTokenMap& rTokenMap = _rImport.GetGroupElemTokenMap();
      77 [ #  # ][ #  # ]:          0 :     m_xGroup->setSortAscending(sal_False);// the default value has to be set
      78 [ #  # ][ #  # ]:          0 :     const sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
                 [ #  # ]
      79 [ #  # ][ #  # ]:          0 :     static const ::rtl::OUString s_sTRUE = ::xmloff::token::GetXMLToken(XML_TRUE);
         [ #  # ][ #  # ]
      80         [ #  # ]:          0 :     for(sal_Int16 i = 0; i < nLength; ++i)
      81                 :            :     {
      82                 :          0 :         ::rtl::OUString sLocalName;
      83 [ #  # ][ #  # ]:          0 :         const ::rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
      84         [ #  # ]:          0 :         const sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
      85 [ #  # ][ #  # ]:          0 :         ::rtl::OUString sValue = _xAttrList->getValueByIndex( i );
      86                 :            : 
      87                 :            :         try
      88                 :            :         {
      89 [ #  # ][ #  #  :          0 :             switch( rTokenMap.Get( nPrefix, sLocalName ) )
             #  #  #  # ]
      90                 :            :             {
      91                 :            :                 case XML_TOK_START_NEW_COLUMN:
      92 [ #  # ][ #  # ]:          0 :                     m_xGroup->setStartNewColumn(sValue == s_sTRUE);
      93                 :          0 :                     break;
      94                 :            :                 case XML_TOK_RESET_PAGE_NUMBER:
      95 [ #  # ][ #  # ]:          0 :                     m_xGroup->setResetPageNumber(sValue == s_sTRUE);
      96                 :          0 :                     break;
      97                 :            :                 case XML_TOK_SORT_ASCENDING:
      98 [ #  # ][ #  # ]:          0 :                     m_xGroup->setSortAscending(sValue == s_sTRUE);
      99                 :          0 :                     break;
     100                 :            :                 case XML_TOK_GROUP_EXPRESSION:
     101                 :            :                     {
     102                 :          0 :                         sal_Int32 nLen = sValue.getLength();
     103         [ #  # ]:          0 :                         if ( nLen )
     104                 :            :                         {
     105                 :            : 
     106 [ #  # ][ #  # ]:          0 :                             const static ::rtl::OUString s_sChanged(RTL_CONSTASCII_USTRINGPARAM("rpt:HASCHANGED(\""));
         [ #  # ][ #  # ]
     107                 :          0 :                             sal_Int32 nPos = sValue.indexOf(s_sChanged);
     108         [ #  # ]:          0 :                             if ( nPos == -1 )
     109                 :          0 :                                 nPos = 5;
     110                 :            :                             else
     111                 :            :                             {
     112                 :          0 :                                 nPos = s_sChanged.getLength();
     113 [ #  # ][ #  # ]:          0 :                                 static ::rtl::OUString s_sQuote(RTL_CONSTASCII_USTRINGPARAM("\"\""));
         [ #  # ][ #  # ]
     114 [ #  # ][ #  # ]:          0 :                                 static ::rtl::OUString s_sSingleQuote(RTL_CONSTASCII_USTRINGPARAM("\""));
         [ #  # ][ #  # ]
     115                 :          0 :                                 sal_Int32 nIndex = sValue.indexOf(s_sQuote,nPos);
     116         [ #  # ]:          0 :                                 while ( nIndex > -1 )
     117                 :            :                                 {
     118                 :          0 :                                     sValue = sValue.replaceAt(nIndex,2,s_sSingleQuote);
     119                 :          0 :                                     nIndex = sValue.indexOf(s_sQuote,nIndex+2);
     120                 :            :                                 }
     121                 :          0 :                                 nLen = sValue.getLength() - 1;
     122                 :            :                             }
     123                 :          0 :                             sValue = sValue.copy(nPos,nLen-nPos-1);
     124                 :          0 :                             const ORptFilter::TGroupFunctionMap& aFunctions = _rImport.getFunctions();
     125         [ #  # ]:          0 :                             ORptFilter::TGroupFunctionMap::const_iterator aFind = aFunctions.find(sValue);
     126         [ #  # ]:          0 :                             if ( aFind != aFunctions.end() )
     127                 :            :                             {
     128                 :          0 :                                 sal_Int32 nIndex = 0;
     129 [ #  # ][ #  # ]:          0 :                                 const ::rtl::OUString sCompleteFormula = aFind->second->getFormula();
     130                 :          0 :                                 ::rtl::OUString sExpression = sCompleteFormula.getToken(1,'[',nIndex);
     131                 :          0 :                                 nIndex = 0;
     132                 :          0 :                                 sExpression = sExpression.getToken(0,']',nIndex);
     133                 :          0 :                                 nIndex = 0;
     134                 :          0 :                                 const ::rtl::OUString sFormula = sCompleteFormula.getToken(0,'(',nIndex);
     135                 :          0 :                                 ::sal_Int16 nGroupOn = report::GroupOn::DEFAULT;
     136                 :            : 
     137 [ #  # ][ #  # ]:          0 :                                 if ( sFormula ==::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:LEFT")))
     138                 :            :                                 {
     139                 :          0 :                                     nGroupOn = report::GroupOn::PREFIX_CHARACTERS;
     140                 :          0 :                                     ::rtl::OUString sInterval = sCompleteFormula.getToken(1,';',nIndex);
     141                 :          0 :                                     nIndex = 0;
     142                 :          0 :                                     sInterval = sInterval.getToken(0,')',nIndex);
     143 [ #  # ][ #  # ]:          0 :                                     m_xGroup->setGroupInterval(sInterval.toInt32());
     144                 :            :                                 }
     145 [ #  # ][ #  # ]:          0 :                                 else if ( sFormula == ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:YEAR")))
     146                 :          0 :                                     nGroupOn = report::GroupOn::YEAR;
     147 [ #  # ][ #  # ]:          0 :                                 else if ( sFormula == ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:MONTH")))
     148                 :            :                                 {
     149                 :          0 :                                     nGroupOn = report::GroupOn::MONTH;
     150                 :            :                                 }
     151         [ #  # ]:          0 :                                 else if ( sCompleteFormula.matchIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:INT((MONTH")),0)
           [ #  #  #  # ]
                 [ #  # ]
           [ #  #  #  # ]
     152                 :          0 :                                        && sCompleteFormula.endsWithIgnoreAsciiCaseAsciiL("-1)/3)+1",8) )
     153                 :            :                                 {
     154                 :          0 :                                     nGroupOn = report::GroupOn::QUARTAL;
     155                 :            :                                 }
     156 [ #  # ][ #  # ]:          0 :                                 else if ( sFormula ==::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:WEEK")))
     157                 :          0 :                                     nGroupOn = report::GroupOn::WEEK;
     158 [ #  # ][ #  # ]:          0 :                                 else if ( sFormula ==::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:DAY")))
     159                 :          0 :                                     nGroupOn = report::GroupOn::DAY;
     160 [ #  # ][ #  # ]:          0 :                                 else if ( sFormula ==::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:HOUR")))
     161                 :          0 :                                     nGroupOn = report::GroupOn::HOUR;
     162 [ #  # ][ #  # ]:          0 :                                 else if ( sFormula ==::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:MINUTE")))
     163                 :          0 :                                     nGroupOn = report::GroupOn::MINUTE;
     164 [ #  # ][ #  # ]:          0 :                                 else if ( sFormula ==::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:INT")))
     165                 :            :                                 {
     166                 :          0 :                                     nGroupOn = report::GroupOn::INTERVAL;
     167         [ #  # ]:          0 :                                     _rImport.removeFunction(sExpression);
     168         [ #  # ]:          0 :                                     sExpression = sExpression.copy(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("INT_count_")).getLength());
     169                 :            : 
     170                 :          0 :                                     nIndex = 0;
     171                 :          0 :                                     ::rtl::OUString sInterval = sCompleteFormula.getToken(1,'/',nIndex);
     172                 :          0 :                                     nIndex = 0;
     173                 :          0 :                                     sInterval = sInterval.getToken(0,')',nIndex);
     174 [ #  # ][ #  # ]:          0 :                                     m_xGroup->setGroupInterval(sInterval.toInt32());
     175                 :            :                                 }
     176                 :            : 
     177 [ #  # ][ #  # ]:          0 :                                 m_xGroup->setGroupOn(nGroupOn);
     178                 :            : 
     179         [ #  # ]:          0 :                                 _rImport.removeFunction(sValue);
     180         [ #  # ]:          0 :                                 sValue = sExpression;
     181                 :            :                             }
     182 [ #  # ][ #  # ]:          0 :                             m_xGroup->setExpression(sValue);
     183                 :            :                         }
     184                 :            :                     }
     185                 :          0 :                     break;
     186                 :            :                 case XML_TOK_GROUP_KEEP_TOGETHER:
     187 [ #  # ][ #  # ]:          0 :                     m_xGroup->setKeepTogether(lcl_getKeepTogetherOption(sValue));
                 [ #  # ]
     188                 :          0 :                     break;
     189                 :            :                 default:
     190                 :          0 :                     break;
     191                 :            :             }
     192                 :            :         }
     193         [ #  # ]:          0 :         catch(const Exception&)
     194                 :            :         {
     195                 :            :             OSL_FAIL("Exception catched while putting group props!");
     196                 :            :         }
     197                 :          0 :     }
     198                 :          0 : }
     199                 :            : // -----------------------------------------------------------------------------
     200                 :            : 
     201                 :          0 : OXMLGroup::~OXMLGroup()
     202                 :            : {
     203                 :            : 
     204                 :            :     DBG_DTOR( rpt_OXMLGroup,NULL);
     205         [ #  # ]:          0 : }
     206                 :            : // -----------------------------------------------------------------------------
     207                 :          0 : SvXMLImportContext* OXMLGroup::CreateChildContext(
     208                 :            :         sal_uInt16 nPrefix,
     209                 :            :         const ::rtl::OUString& rLocalName,
     210                 :            :         const Reference< XAttributeList > & xAttrList )
     211                 :            : {
     212                 :          0 :     SvXMLImportContext *pContext = 0;
     213                 :          0 :     ORptFilter& rImport = GetOwnImport();
     214                 :          0 :     const SvXMLTokenMap&    rTokenMap   = rImport.GetGroupElemTokenMap();
     215                 :            : 
     216   [ #  #  #  #  :          0 :     switch( rTokenMap.Get( nPrefix, rLocalName ) )
                   #  # ]
     217                 :            :     {
     218                 :            :         case XML_TOK_GROUP_FUNCTION:
     219                 :            :             {
     220                 :          0 :                 rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
     221 [ #  # ][ #  # ]:          0 :                 pContext = new OXMLFunction( rImport, nPrefix, rLocalName,xAttrList,m_xGroup.get());
                 [ #  # ]
     222                 :            :             }
     223                 :          0 :             break;
     224                 :            :         case XML_TOK_GROUP_HEADER:
     225                 :            :             {
     226                 :          0 :                 rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
     227                 :          0 :                 m_xGroup->setHeaderOn(sal_True);
     228 [ #  # ][ #  # ]:          0 :                 pContext = new OXMLSection( rImport, nPrefix, rLocalName,xAttrList,m_xGroup->getHeader());
     229                 :            :             }
     230                 :          0 :             break;
     231                 :            :         case XML_TOK_GROUP_GROUP:
     232                 :          0 :             rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
     233         [ #  # ]:          0 :             pContext = new OXMLGroup( rImport, nPrefix, rLocalName,xAttrList);
     234                 :          0 :             break;
     235                 :            :         case XML_TOK_GROUP_DETAIL:
     236                 :            :             {
     237 [ #  # ][ #  # ]:          0 :                 rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
     238         [ #  # ]:          0 :                 Reference<XReportDefinition> m_xComponent = rImport.getReportDefinition();
     239 [ #  # ][ #  # ]:          0 :                 pContext = new OXMLSection( rImport, nPrefix, rLocalName,xAttrList ,m_xComponent->getDetail());
         [ #  # ][ #  # ]
     240                 :            :             }
     241                 :          0 :             break;
     242                 :            : 
     243                 :            :         case XML_TOK_GROUP_FOOTER:
     244                 :            :             {
     245                 :          0 :                 rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
     246                 :          0 :                 m_xGroup->setFooterOn(sal_True);
     247 [ #  # ][ #  # ]:          0 :                 pContext = new OXMLSection( rImport, nPrefix, rLocalName,xAttrList,m_xGroup->getFooter());
     248                 :            :             }
     249                 :          0 :             break;
     250                 :            :         default:
     251                 :          0 :             break;
     252                 :            :     }
     253                 :            : 
     254         [ #  # ]:          0 :     if( !pContext )
     255         [ #  # ]:          0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     256                 :            : 
     257                 :          0 :     return pContext;
     258                 :            : }
     259                 :            : // -----------------------------------------------------------------------------
     260                 :          0 : ORptFilter& OXMLGroup::GetOwnImport()
     261                 :            : {
     262                 :          0 :     return static_cast<ORptFilter&>(GetImport());
     263                 :            : }
     264                 :            : // -----------------------------------------------------------------------------
     265                 :          0 : void OXMLGroup::EndElement()
     266                 :            : {
     267                 :            :     try
     268                 :            :     {
     269                 :            :         // the group elements end in the reverse order
     270 [ #  # ][ #  # ]:          0 :         m_xGroups->insertByIndex(0,uno::makeAny(m_xGroup));
         [ #  # ][ #  # ]
     271                 :          0 :     }catch(uno::Exception&)
     272                 :            :     {
     273                 :            :         OSL_FAIL("Exception catched!");
     274                 :            :     }
     275                 :          0 : }
     276                 :            : // -----------------------------------------------------------------------------
     277                 :            : //----------------------------------------------------------------------------
     278                 :            : } // namespace rptxml
     279                 :            : // -----------------------------------------------------------------------------
     280                 :            : 
     281                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10