LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/xmloff/source/text - XMLTextListBlockContext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 105 120 87.5 %
Date: 2013-07-09 Functions: 7 12 58.3 %
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             : 
      20             : #include <tools/debug.hxx>
      21             : #include <com/sun/star/container/XNameContainer.hpp>
      22             : #include <com/sun/star/container/XIndexReplace.hpp>
      23             : #include <com/sun/star/style/XStyle.hpp>
      24             : #include <com/sun/star/beans/XPropertySet.hpp>
      25             : #include <xmloff/xmlimp.hxx>
      26             : #include <xmloff/xmlnumi.hxx>
      27             : #include <xmloff/nmspmap.hxx>
      28             : #include "xmloff/xmlnmspe.hxx"
      29             : #include <xmloff/xmltoken.hxx>
      30             : #include "XMLTextListItemContext.hxx"
      31             : #include "XMLTextListBlockContext.hxx"
      32             : #include "txtlists.hxx"
      33             : 
      34             : 
      35             : using namespace ::com::sun::star;
      36             : using namespace ::com::sun::star::uno;
      37             : using namespace ::com::sun::star::container;
      38             : using namespace ::com::sun::star::style;
      39             : using namespace ::com::sun::star::beans;
      40             : using namespace ::xmloff::token;
      41             : 
      42           0 : TYPEINIT1( XMLTextListBlockContext, SvXMLImportContext );
      43             : 
      44             : // OD 2008-05-07 #refactorlists#
      45             : // add optional parameter <bRestartNumberingAtSubList> and its handling
      46          27 : XMLTextListBlockContext::XMLTextListBlockContext(
      47             :         SvXMLImport& rImport,
      48             :         XMLTextImportHelper& rTxtImp,
      49             :         sal_uInt16 nPrfx,
      50             :         const OUString& rLName,
      51             :         const Reference< xml::sax::XAttributeList > & xAttrList,
      52             :         const sal_Bool bRestartNumberingAtSubList )
      53             : :   SvXMLImportContext( rImport, nPrfx, rLName )
      54             : ,   mrTxtImport( rTxtImp )
      55             : ,   msListStyleName()
      56             : ,   mxParentListBlock( )
      57             : ,   mnLevel( 0 )
      58             : ,   mbRestartNumbering( sal_False )
      59             : ,   mbSetDefaults( sal_False )
      60             : ,   msListId()
      61          27 : ,   msContinueListId()
      62             : {
      63          27 :     static OUString s_PropNameDefaultListId("DefaultListId");
      64             :     {
      65             :         // get the parent list block context (if any); this is a bit ugly...
      66          27 :         XMLTextListBlockContext * pLB(0);
      67          27 :         XMLTextListItemContext  * pLI(0);
      68          27 :         XMLNumberedParaContext  * pNP(0);
      69          27 :         rTxtImp.GetTextListHelper().ListContextTop(pLB, pLI, pNP);
      70          27 :         mxParentListBlock = pLB;
      71             :     }
      72             :     // Inherit style name from parent list, as well as the flags whether
      73             :     // numbering must be restarted and formats have to be created.
      74          27 :     OUString sParentListStyleName;
      75          27 :     if( mxParentListBlock.Is() )
      76             :     {
      77             :         XMLTextListBlockContext *pParent =
      78          17 :                                 (XMLTextListBlockContext *)&mxParentListBlock;
      79          17 :         msListStyleName = pParent->GetListStyleName();
      80          17 :         sParentListStyleName = msListStyleName;
      81          17 :         mxNumRules = pParent->GetNumRules();
      82          17 :         mnLevel = pParent->GetLevel() + 1;
      83          17 :         mbRestartNumbering = pParent->IsRestartNumbering() ||
      84          17 :                              bRestartNumberingAtSubList;
      85          17 :         mbSetDefaults = pParent->mbSetDefaults;
      86          17 :         msListId = pParent->GetListId();
      87          17 :         msContinueListId = pParent->GetContinueListId();
      88             :     }
      89             : 
      90          27 :     const SvXMLTokenMap& rTokenMap = mrTxtImport.GetTextListBlockAttrTokenMap();
      91             : 
      92          27 :     bool bIsContinueNumberingAttributePresent( false );
      93          27 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      94          44 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
      95             :     {
      96          17 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
      97          34 :         const OUString& rValue = xAttrList->getValueByIndex( i );
      98             : 
      99          34 :         OUString aLocalName;
     100             :         sal_uInt16 nPrefix =
     101          17 :             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
     102          17 :                                                             &aLocalName );
     103          17 :         switch( rTokenMap.Get( nPrefix, aLocalName ) )
     104             :         {
     105             :         case XML_TOK_TEXT_LIST_BLOCK_XMLID:
     106           2 :             sXmlId = rValue;
     107             : //FIXME: there is no UNO API for lists
     108             :             // xml:id is also the list ID (#i92221#)
     109           2 :             if ( mnLevel == 0 ) // root <list> element
     110             :             {
     111           2 :                 msListId = rValue;
     112             :             }
     113           2 :             break;
     114             :         case XML_TOK_TEXT_LIST_BLOCK_CONTINUE_NUMBERING:
     115           5 :             mbRestartNumbering = !IsXMLToken(rValue, XML_TRUE);
     116           5 :             bIsContinueNumberingAttributePresent = true;
     117           5 :             break;
     118             :         case XML_TOK_TEXT_LIST_BLOCK_STYLE_NAME:
     119          10 :             msListStyleName = rValue;
     120          10 :             break;
     121             :         case XML_TOK_TEXT_LIST_BLOCK_CONTINUE_LIST:
     122           0 :             if ( mnLevel == 0 ) // root <list> element
     123             :             {
     124           0 :                 msContinueListId = rValue;
     125             :             }
     126           0 :             break;
     127             :         }
     128          17 :     }
     129             : 
     130          54 :     mxNumRules = XMLTextListsHelper::MakeNumRule(GetImport(), mxNumRules,
     131             :         sParentListStyleName, msListStyleName,
     132          27 :         mnLevel, &mbRestartNumbering, &mbSetDefaults );
     133          27 :     if( !mxNumRules.is() )
     134          27 :         return;
     135             : 
     136          27 :     if ( mnLevel == 0 ) // root <list> element
     137             :     {
     138          10 :         XMLTextListsHelper& rTextListsHelper( mrTxtImport.GetTextListHelper() );
     139             :         // Inconsistent behavior regarding lists (#i92811#)
     140          10 :         OUString sListStyleDefaultListId;
     141             :         {
     142          10 :             uno::Reference< beans::XPropertySet > xNumRuleProps( mxNumRules, UNO_QUERY );
     143          10 :             if ( xNumRuleProps.is() )
     144             :             {
     145             :                 uno::Reference< beans::XPropertySetInfo > xNumRulePropSetInfo(
     146          10 :                                             xNumRuleProps->getPropertySetInfo());
     147          20 :                 if (xNumRulePropSetInfo.is() &&
     148          10 :                     xNumRulePropSetInfo->hasPropertyByName(
     149          10 :                          s_PropNameDefaultListId))
     150             :                 {
     151          10 :                     xNumRuleProps->getPropertyValue(s_PropNameDefaultListId)
     152          10 :                         >>= sListStyleDefaultListId;
     153             :                     DBG_ASSERT( !sListStyleDefaultListId.isEmpty(),
     154             :                                 "no default list id found at numbering rules instance. Serious defect -> please inform OD." );
     155          10 :                 }
     156          10 :             }
     157             :         }
     158          10 :         if ( msListId.isEmpty() )  // no text:id property found
     159             :         {
     160           8 :             sal_Int32 nUPD( 0 );
     161           8 :             sal_Int32 nBuild( 0 );
     162           8 :             const bool bBuildIdFound = GetImport().getBuildIds( nUPD, nBuild );
     163          14 :             if ( rImport.IsTextDocInOOoFileFormat() ||
     164           6 :                  ( bBuildIdFound && nUPD == 680 ) )
     165             :             {
     166             :                 /* handling former documents written by OpenOffice.org:
     167             :                    use default list id of numbering rules instance, if existing
     168             :                    (#i92811#)
     169             :                 */
     170           6 :                 if ( !sListStyleDefaultListId.isEmpty() )
     171             :                 {
     172           6 :                     msListId = sListStyleDefaultListId;
     173          24 :                     if ( !bIsContinueNumberingAttributePresent &&
     174          20 :                          !mbRestartNumbering &&
     175          18 :                          rTextListsHelper.IsListProcessed( msListId ) )
     176             :                     {
     177           1 :                         mbRestartNumbering = sal_True;
     178             :                     }
     179             :                 }
     180             :             }
     181           8 :             if ( msListId.isEmpty() )
     182             :             {
     183             :                 // generate a new list id for the list
     184           2 :                 msListId = rTextListsHelper.GenerateNewListId();
     185             :             }
     186             :         }
     187             : 
     188          12 :         if ( bIsContinueNumberingAttributePresent && !mbRestartNumbering &&
     189           2 :              msContinueListId.isEmpty() )
     190             :         {
     191           2 :             OUString Last( rTextListsHelper.GetLastProcessedListId() );
     192           4 :             if ( rTextListsHelper.GetListStyleOfLastProcessedList() == msListStyleName
     193           2 :                  && Last != msListId )
     194             :             {
     195           0 :                 msContinueListId = Last;
     196           2 :             }
     197             :         }
     198             : 
     199          10 :         if ( !msContinueListId.isEmpty() )
     200             :         {
     201           0 :             if ( !rTextListsHelper.IsListProcessed( msContinueListId ) )
     202             :             {
     203           0 :                 msContinueListId = "";
     204             :             }
     205             :             else
     206             :             {
     207             :                 // search continue list chain for master list and
     208             :                 // continue the master list.
     209             :                 OUString sTmpStr =
     210           0 :                     rTextListsHelper.GetContinueListIdOfProcessedList( msContinueListId );
     211           0 :                 while ( !sTmpStr.isEmpty() )
     212             :                 {
     213           0 :                     msContinueListId = sTmpStr;
     214             : 
     215           0 :                     sTmpStr =
     216           0 :                         rTextListsHelper.GetContinueListIdOfProcessedList( msContinueListId );
     217           0 :                 }
     218             :             }
     219             :         }
     220             : 
     221          10 :         if ( !rTextListsHelper.IsListProcessed( msListId ) )
     222             :         {
     223             :             // Inconsistent behavior regarding lists (#i92811#)
     224             :             rTextListsHelper.KeepListAsProcessed(
     225             :                 msListId, msListStyleName, msContinueListId,
     226           7 :                 sListStyleDefaultListId );
     227          10 :         }
     228             :     }
     229             : 
     230             :     // Remember this list block.
     231          27 :     mrTxtImport.GetTextListHelper().PushListContext( this );
     232             : }
     233             : 
     234          54 : XMLTextListBlockContext::~XMLTextListBlockContext()
     235             : {
     236          54 : }
     237             : 
     238          27 : void XMLTextListBlockContext::EndElement()
     239             : {
     240             :     // Numbering has not to be restarted if it has been restarted within
     241             :     // a child list.
     242             :     XMLTextListBlockContext *pParent =
     243          27 :                                 (XMLTextListBlockContext *)&mxParentListBlock;
     244          27 :     if( pParent )
     245             :     {
     246          17 :         pParent->mbRestartNumbering = mbRestartNumbering;
     247             :     }
     248             : 
     249             :     // Restore current list block.
     250          27 :     mrTxtImport.GetTextListHelper().PopListContext();
     251             : 
     252             :     // Any paragraph following the list within the same list item must not
     253             :     // be numbered.
     254          27 :     mrTxtImport.GetTextListHelper().SetListItem( 0 );
     255          27 : }
     256             : 
     257          37 : SvXMLImportContext *XMLTextListBlockContext::CreateChildContext(
     258             :         sal_uInt16 nPrefix,
     259             :         const OUString& rLocalName,
     260             :         const Reference< xml::sax::XAttributeList > & xAttrList )
     261             : {
     262          37 :     SvXMLImportContext *pContext = 0;
     263             : 
     264             :     const SvXMLTokenMap& rTokenMap =
     265          37 :                         mrTxtImport.GetTextListBlockElemTokenMap();
     266          37 :     sal_Bool bHeader = sal_False;
     267          37 :     switch( rTokenMap.Get( nPrefix, rLocalName ) )
     268             :     {
     269             :     case XML_TOK_TEXT_LIST_HEADER:
     270           0 :         bHeader = sal_True;
     271             :     case XML_TOK_TEXT_LIST_ITEM:
     272          37 :         pContext = new XMLTextListItemContext( GetImport(), mrTxtImport,
     273             :                                                 nPrefix, rLocalName,
     274          37 :                                               xAttrList, bHeader );
     275          37 :         break;
     276             :     }
     277             : 
     278          37 :     if( !pContext )
     279           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     280             : 
     281          37 :     return pContext;
     282             : }
     283             : 
     284          49 : const OUString& XMLTextListBlockContext::GetListId() const
     285             : {
     286          49 :     return msListId;
     287             : }
     288             : 
     289          49 : const OUString& XMLTextListBlockContext::GetContinueListId() const
     290             : {
     291          49 :     return msContinueListId;
     292             : }
     293             : 
     294             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10