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

Generated by: LCOV version 1.10