LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLTextListBlockContext.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 107 116 92.2 %
Date: 2014-11-03 Functions: 5 10 50.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             : 
      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         164 : 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 bool bRestartNumberingAtSubList )
      53             : :   SvXMLImportContext( rImport, nPrfx, rLName )
      54             : ,   mrTxtImport( rTxtImp )
      55             : ,   msListStyleName()
      56             : ,   mxParentListBlock( )
      57             : ,   mnLevel( 0 )
      58             : ,   mbRestartNumbering( false )
      59             : ,   mbSetDefaults( false )
      60             : ,   msListId()
      61         164 : ,   msContinueListId()
      62             : {
      63         164 :     static OUString s_PropNameDefaultListId("DefaultListId");
      64             :     {
      65             :         // get the parent list block context (if any); this is a bit ugly...
      66         164 :         XMLTextListBlockContext * pLB(0);
      67         164 :         XMLTextListItemContext  * pLI(0);
      68         164 :         XMLNumberedParaContext  * pNP(0);
      69         164 :         rTxtImp.GetTextListHelper().ListContextTop(pLB, pLI, pNP);
      70         164 :         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         164 :     OUString sParentListStyleName;
      75         164 :     if( mxParentListBlock.Is() )
      76             :     {
      77             :         XMLTextListBlockContext *pParent =
      78          68 :                                 static_cast<XMLTextListBlockContext *>(&mxParentListBlock);
      79          68 :         msListStyleName = pParent->GetListStyleName();
      80          68 :         sParentListStyleName = msListStyleName;
      81          68 :         mxNumRules = pParent->GetNumRules();
      82          68 :         mnLevel = pParent->GetLevel() + 1;
      83          68 :         mbRestartNumbering = pParent->IsRestartNumbering() ||
      84          68 :                              bRestartNumberingAtSubList;
      85          68 :         mbSetDefaults = pParent->mbSetDefaults;
      86          68 :         msListId = pParent->GetListId();
      87          68 :         msContinueListId = pParent->GetContinueListId();
      88             :     }
      89             : 
      90         164 :     const SvXMLTokenMap& rTokenMap = mrTxtImport.GetTextListBlockAttrTokenMap();
      91             : 
      92         164 :     bool bIsContinueNumberingAttributePresent( false );
      93         164 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      94         298 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
      95             :     {
      96         134 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
      97         268 :         const OUString& rValue = xAttrList->getValueByIndex( i );
      98             : 
      99         268 :         OUString aLocalName;
     100             :         sal_uInt16 nPrefix =
     101         134 :             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
     102         134 :                                                             &aLocalName );
     103         134 :         switch( rTokenMap.Get( nPrefix, aLocalName ) )
     104             :         {
     105             :         case XML_TOK_TEXT_LIST_BLOCK_XMLID:
     106          26 :             sXmlId = rValue;
     107             : //FIXME: there is no UNO API for lists
     108             :             // xml:id is also the list ID (#i92221#)
     109          26 :             if ( mnLevel == 0 ) // root <list> element
     110             :             {
     111          26 :                 msListId = rValue;
     112             :             }
     113          26 :             break;
     114             :         case XML_TOK_TEXT_LIST_BLOCK_CONTINUE_NUMBERING:
     115           8 :             mbRestartNumbering = !IsXMLToken(rValue, XML_TRUE);
     116           8 :             bIsContinueNumberingAttributePresent = true;
     117           8 :             break;
     118             :         case XML_TOK_TEXT_LIST_BLOCK_STYLE_NAME:
     119          96 :             msListStyleName = rValue;
     120          96 :             break;
     121             :         case XML_TOK_TEXT_LIST_BLOCK_CONTINUE_LIST:
     122           4 :             if ( mnLevel == 0 ) // root <list> element
     123             :             {
     124           4 :                 msContinueListId = rValue;
     125             :             }
     126           4 :             break;
     127             :         }
     128         134 :     }
     129             : 
     130         328 :     mxNumRules = XMLTextListsHelper::MakeNumRule(GetImport(), mxNumRules,
     131             :         sParentListStyleName, msListStyleName,
     132         164 :         mnLevel, &mbRestartNumbering, &mbSetDefaults );
     133         164 :     if( !mxNumRules.is() )
     134         164 :         return;
     135             : 
     136         164 :     if ( mnLevel == 0 ) // root <list> element
     137             :     {
     138          96 :         XMLTextListsHelper& rTextListsHelper( mrTxtImport.GetTextListHelper() );
     139             :         // Inconsistent behavior regarding lists (#i92811#)
     140          96 :         OUString sListStyleDefaultListId;
     141             :         {
     142          96 :             uno::Reference< beans::XPropertySet > xNumRuleProps( mxNumRules, UNO_QUERY );
     143          96 :             if ( xNumRuleProps.is() )
     144             :             {
     145             :                 uno::Reference< beans::XPropertySetInfo > xNumRulePropSetInfo(
     146          56 :                                             xNumRuleProps->getPropertySetInfo());
     147         112 :                 if (xNumRulePropSetInfo.is() &&
     148          56 :                     xNumRulePropSetInfo->hasPropertyByName(
     149          56 :                          s_PropNameDefaultListId))
     150             :                 {
     151          56 :                     xNumRuleProps->getPropertyValue(s_PropNameDefaultListId)
     152          56 :                         >>= sListStyleDefaultListId;
     153             :                     DBG_ASSERT( !sListStyleDefaultListId.isEmpty(),
     154             :                                 "no default list id found at numbering rules instance. Serious defect -> please inform OD." );
     155          56 :                 }
     156          96 :             }
     157             :         }
     158          96 :         if ( msListId.isEmpty() )  // no text:id property found
     159             :         {
     160          70 :             sal_Int32 nUPD( 0 );
     161          70 :             sal_Int32 nBuild( 0 );
     162          70 :             const bool bBuildIdFound = GetImport().getBuildIds( nUPD, nBuild );
     163          70 :             if ( rImport.IsTextDocInOOoFileFormat() ||
     164          24 :                  ( 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           0 :                 if ( !sListStyleDefaultListId.isEmpty() )
     171             :                 {
     172           0 :                     msListId = sListStyleDefaultListId;
     173           0 :                     if ( !bIsContinueNumberingAttributePresent &&
     174           0 :                          !mbRestartNumbering &&
     175           0 :                          rTextListsHelper.IsListProcessed( msListId ) )
     176             :                     {
     177           0 :                         mbRestartNumbering = true;
     178             :                     }
     179             :                 }
     180             :             }
     181          70 :             if ( msListId.isEmpty() )
     182             :             {
     183             :                 // generate a new list id for the list
     184          70 :                 msListId = rTextListsHelper.GenerateNewListId();
     185             :             }
     186             :         }
     187             : 
     188         102 :         if ( bIsContinueNumberingAttributePresent && !mbRestartNumbering &&
     189           6 :              msContinueListId.isEmpty() )
     190             :         {
     191           6 :             OUString Last( rTextListsHelper.GetLastProcessedListId() );
     192          12 :             if ( rTextListsHelper.GetListStyleOfLastProcessedList() == msListStyleName
     193           6 :                  && Last != msListId )
     194             :             {
     195           6 :                 msContinueListId = Last;
     196           6 :             }
     197             :         }
     198             : 
     199          96 :         if ( !msContinueListId.isEmpty() )
     200             :         {
     201          10 :             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          10 :                     rTextListsHelper.GetContinueListIdOfProcessedList( msContinueListId );
     211          22 :                 while ( !sTmpStr.isEmpty() )
     212             :                 {
     213           2 :                     msContinueListId = sTmpStr;
     214             : 
     215           4 :                     sTmpStr =
     216           2 :                         rTextListsHelper.GetContinueListIdOfProcessedList( msContinueListId );
     217          10 :                 }
     218             :             }
     219             :         }
     220             : 
     221          96 :         if ( !rTextListsHelper.IsListProcessed( msListId ) )
     222             :         {
     223             :             // Inconsistent behavior regarding lists (#i92811#)
     224             :             rTextListsHelper.KeepListAsProcessed(
     225             :                 msListId, msListStyleName, msContinueListId,
     226          96 :                 sListStyleDefaultListId );
     227          96 :         }
     228             :     }
     229             : 
     230             :     // Remember this list block.
     231         164 :     mrTxtImport.GetTextListHelper().PushListContext( this );
     232             : }
     233             : 
     234         328 : XMLTextListBlockContext::~XMLTextListBlockContext()
     235             : {
     236         328 : }
     237             : 
     238         164 : 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         164 :                                 static_cast<XMLTextListBlockContext *>(&mxParentListBlock);
     244         164 :     if( pParent )
     245             :     {
     246          68 :         pParent->mbRestartNumbering = mbRestartNumbering;
     247             :     }
     248             : 
     249             :     // Restore current list block.
     250         164 :     mrTxtImport.GetTextListHelper().PopListContext();
     251             : 
     252             :     // Any paragraph following the list within the same list item must not
     253             :     // be numbered.
     254         164 :     mrTxtImport.GetTextListHelper().SetListItem( 0 );
     255         164 : }
     256             : 
     257         284 : SvXMLImportContext *XMLTextListBlockContext::CreateChildContext(
     258             :         sal_uInt16 nPrefix,
     259             :         const OUString& rLocalName,
     260             :         const Reference< xml::sax::XAttributeList > & xAttrList )
     261             : {
     262         284 :     SvXMLImportContext *pContext = 0;
     263             : 
     264             :     const SvXMLTokenMap& rTokenMap =
     265         284 :                         mrTxtImport.GetTextListBlockElemTokenMap();
     266         284 :     bool bHeader = false;
     267         284 :     switch( rTokenMap.Get( nPrefix, rLocalName ) )
     268             :     {
     269             :     case XML_TOK_TEXT_LIST_HEADER:
     270          36 :         bHeader = true;
     271             :         //fall-through
     272             :     case XML_TOK_TEXT_LIST_ITEM:
     273         284 :         pContext = new XMLTextListItemContext( GetImport(), mrTxtImport,
     274             :                                                 nPrefix, rLocalName,
     275         284 :                                               xAttrList, bHeader );
     276         284 :         break;
     277             :     }
     278             : 
     279         284 :     if( !pContext )
     280           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     281             : 
     282         284 :     return pContext;
     283             : }
     284             : 
     285             : 
     286             : 
     287             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10