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

Generated by: LCOV version 1.11