LCOV - code coverage report
Current view: top level - xmloff/source/text - txtparai.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 471 828 56.9 %
Date: 2014-04-11 Functions: 56 175 32.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 <xmloff/unointerfacetouniqueidentifiermapper.hxx>
      21             : #include <rtl/ustring.hxx>
      22             : #include <rtl/ustrbuf.hxx>
      23             : #include <tools/debug.hxx>
      24             : #include <boost/ptr_container/ptr_vector.hpp>
      25             : 
      26             : #include <com/sun/star/text/XTextFrame.hpp>
      27             : #include <com/sun/star/text/XTextCursor.hpp>
      28             : #include <com/sun/star/beans/XPropertySet.hpp>
      29             : #include <com/sun/star/beans/XPropertySetInfo.hpp>
      30             : #include <com/sun/star/text/ControlCharacter.hpp>
      31             : #include <com/sun/star/container/XIndexReplace.hpp>
      32             : #include <com/sun/star/drawing/XShapes.hpp>
      33             : #include <com/sun/star/container/XEnumerationAccess.hpp>
      34             : #include <com/sun/star/rdf/XMetadatable.hpp>
      35             : 
      36             : #include <sax/tools/converter.hxx>
      37             : 
      38             : #include <xmloff/xmlictxt.hxx>
      39             : #include <xmloff/xmlimp.hxx>
      40             : #include <xmloff/xmltoken.hxx>
      41             : #include <xmloff/nmspmap.hxx>
      42             : #include <xmloff/xmlnmspe.hxx>
      43             : #include <xmloff/txtimp.hxx>
      44             : #include "txtparai.hxx"
      45             : #include "txtfldi.hxx"
      46             : #include "XMLFootnoteImportContext.hxx"
      47             : #include "XMLTextMarkImportContext.hxx"
      48             : #include "XMLTextFrameContext.hxx"
      49             : #include <xmloff/XMLCharContext.hxx>
      50             : #include "XMLTextFrameHyperlinkContext.hxx"
      51             : #include <xmloff/XMLEventsImportContext.hxx>
      52             : #include "XMLChangeImportContext.hxx"
      53             : #include "txtlists.hxx"
      54             : 
      55             : // OD 2004-04-21 #i26791#
      56             : #include <txtparaimphint.hxx>
      57        5409 : class XMLHints_Impl : public boost::ptr_vector<XMLHint_Impl> {};
      58             : // OD 2004-04-21 #i26791#
      59             : 
      60             : using namespace ::com::sun::star;
      61             : using namespace ::com::sun::star::uno;
      62             : using namespace ::com::sun::star::text;
      63             : using namespace ::com::sun::star::drawing;
      64             : using namespace ::com::sun::star::beans;
      65             : using namespace ::xmloff::token;
      66             : using ::com::sun::star::container::XEnumerationAccess;
      67             : using ::com::sun::star::container::XEnumeration;
      68             : 
      69           0 : TYPEINIT1( XMLCharContext, SvXMLImportContext );
      70             : 
      71        1922 : XMLCharContext::XMLCharContext(
      72             :         SvXMLImport& rImport,
      73             :         sal_uInt16 nPrfx,
      74             :         const OUString& rLName,
      75             :         const Reference< xml::sax::XAttributeList > & xAttrList,
      76             :         sal_Unicode c,
      77             :         bool bCount ) :
      78             :     SvXMLImportContext( rImport, nPrfx, rLName )
      79             :     ,m_nControl(0)
      80             :     ,m_nCount(1)
      81        1922 :     ,m_c(c)
      82             : {
      83        1922 :     if( bCount )
      84             :     {
      85         686 :         const SvXMLNamespaceMap& rMap = GetImport().GetNamespaceMap();
      86         686 :         sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      87         723 :         for( sal_Int16 i=0; i < nAttrCount; i++ )
      88             :         {
      89          37 :             const OUString& rAttrName = xAttrList->getNameByIndex( i );
      90             : 
      91          74 :             OUString aLocalName;
      92          37 :             sal_uInt16 nPrefix =rMap.GetKeyByAttrName( rAttrName,&aLocalName );
      93          74 :             if( XML_NAMESPACE_TEXT == nPrefix &&
      94          37 :                 IsXMLToken( aLocalName, XML_C ) )
      95             :             {
      96          37 :                 sal_Int32 nTmp = xAttrList->getValueByIndex(i).toInt32();
      97          37 :                 if( nTmp > 0L )
      98             :                 {
      99          37 :                     if( nTmp > USHRT_MAX )
     100           0 :                         m_nCount = USHRT_MAX;
     101             :                     else
     102          37 :                         m_nCount = (sal_uInt16)nTmp;
     103             :                 }
     104             :             }
     105          37 :         }
     106             :     }
     107        1922 : }
     108             : 
     109           6 : XMLCharContext::XMLCharContext(
     110             :         SvXMLImport& rImp,
     111             :         sal_uInt16 nPrfx,
     112             :         const OUString& rLName,
     113             :         const Reference< xml::sax::XAttributeList > &,
     114             :         sal_Int16 nControl ) :
     115             :     SvXMLImportContext( rImp, nPrfx, rLName )
     116             :     ,m_nControl(nControl)
     117             :     ,m_nCount(0)
     118           6 :     ,m_c(0)
     119             : {
     120           6 : }
     121             : 
     122        3856 : XMLCharContext::~XMLCharContext()
     123             : {
     124        3856 : }
     125        1928 : void XMLCharContext::EndElement()
     126             : {
     127        1928 :     if ( !m_nCount )
     128           6 :         InsertControlCharacter( m_nControl );
     129             :     else
     130             :     {
     131        1922 :         if( 1U == m_nCount )
     132             :         {
     133        1885 :             OUString sBuff( &m_c, 1 );
     134        1885 :             InsertString(sBuff);
     135             :         }
     136             :         else
     137             :         {
     138          37 :             OUStringBuffer sBuff( m_nCount );
     139         211 :             while( m_nCount-- )
     140         137 :                 sBuff.append( &m_c, 1 );
     141             : 
     142          37 :             InsertString(sBuff.makeStringAndClear() );
     143             :         }
     144             :     }
     145        1928 : }
     146           6 : void XMLCharContext::InsertControlCharacter(sal_Int16   _nControl)
     147             : {
     148           6 :     GetImport().GetTextImport()->InsertControlCharacter( _nControl );
     149           6 : }
     150        1922 : void XMLCharContext::InsertString(const OUString& _sString)
     151             : {
     152        1922 :     GetImport().GetTextImport()->InsertString( _sString );
     153        1922 : }
     154             : 
     155             : /** import start of reference (<text:reference-start>) */
     156           0 : class XMLStartReferenceContext_Impl : public SvXMLImportContext
     157             : {
     158             : public:
     159             :     TYPEINFO_OVERRIDE();
     160             : 
     161             :     // Do everything in constructor. Well ...
     162             :     XMLStartReferenceContext_Impl (
     163             :         SvXMLImport& rImport,
     164             :         sal_uInt16 nPrefix,
     165             :         const OUString& rLocalName,
     166             :         XMLHints_Impl& rHnts,
     167             :         const Reference<xml::sax::XAttributeList> & xAttrList);
     168             : 
     169             :     static sal_Bool FindName(
     170             :         SvXMLImport& rImport,
     171             :         const Reference<xml::sax::XAttributeList> & xAttrList,
     172             :         OUString& rName);
     173             : };
     174             : 
     175           0 : TYPEINIT1( XMLStartReferenceContext_Impl, SvXMLImportContext );
     176             : 
     177           0 : XMLStartReferenceContext_Impl::XMLStartReferenceContext_Impl(
     178             :     SvXMLImport& rImport,
     179             :     sal_uInt16 nPrefix,
     180             :     const OUString& rLocalName,
     181             :     XMLHints_Impl& rHints,
     182             :     const Reference<xml::sax::XAttributeList> & xAttrList) :
     183           0 :         SvXMLImportContext(rImport, nPrefix, rLocalName)
     184             : {
     185           0 :     OUString sName;
     186             : 
     187           0 :     if (FindName(GetImport(), xAttrList, sName))
     188             :     {
     189             :         XMLHint_Impl* pHint = new XMLReferenceHint_Impl(
     190           0 :             sName, rImport.GetTextImport()->GetCursor()->getStart() );
     191             : 
     192             :         // degenerates to point reference, if no end is found!
     193           0 :         pHint->SetEnd(rImport.GetTextImport()->GetCursor()->getStart() );
     194             : 
     195           0 :         rHints.push_back(pHint);
     196           0 :     }
     197           0 : }
     198             : 
     199           0 : sal_Bool XMLStartReferenceContext_Impl::FindName(
     200             :     SvXMLImport& rImport,
     201             :     const Reference<xml::sax::XAttributeList> & xAttrList,
     202             :     OUString& rName)
     203             : {
     204           0 :     sal_Bool bNameOK( sal_False );
     205             : 
     206             :     // find name attribute first
     207           0 :     const sal_Int16 nLength( xAttrList->getLength() );
     208           0 :     for (sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
     209             :     {
     210           0 :         OUString sLocalName;
     211           0 :         const sal_uInt16 nPrefix = rImport.GetNamespaceMap().
     212           0 :             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
     213           0 :                               &sLocalName );
     214             : 
     215           0 :         if ( (XML_NAMESPACE_TEXT == nPrefix) &&
     216           0 :              IsXMLToken(sLocalName, XML_NAME)   )
     217             :         {
     218           0 :             rName = xAttrList->getValueByIndex(nAttr);
     219           0 :             bNameOK = sal_True;
     220             :         }
     221           0 :     }
     222             : 
     223           0 :     return bNameOK;
     224             : }
     225             : 
     226             : /** import end of reference (<text:reference-end>) */
     227           0 : class XMLEndReferenceContext_Impl : public SvXMLImportContext
     228             : {
     229             : public:
     230             :     TYPEINFO_OVERRIDE();
     231             : 
     232             :     // Do everything in constructor. Well ...
     233             :     XMLEndReferenceContext_Impl(
     234             :         SvXMLImport& rImport,
     235             :         sal_uInt16 nPrefix,
     236             :         const OUString& rLocalName,
     237             :         XMLHints_Impl& rHnts,
     238             :         const Reference<xml::sax::XAttributeList> & xAttrList);
     239             : };
     240             : 
     241           0 : TYPEINIT1( XMLEndReferenceContext_Impl, SvXMLImportContext );
     242             : 
     243           0 : XMLEndReferenceContext_Impl::XMLEndReferenceContext_Impl(
     244             :     SvXMLImport& rImport,
     245             :     sal_uInt16 nPrefix,
     246             :     const OUString& rLocalName,
     247             :     XMLHints_Impl& rHints,
     248             :     const Reference<xml::sax::XAttributeList> & xAttrList) :
     249           0 :         SvXMLImportContext(rImport, nPrefix, rLocalName)
     250             : {
     251           0 :     OUString sName;
     252             : 
     253             :     // borrow from XMLStartReferenceContext_Impl
     254           0 :     if (XMLStartReferenceContext_Impl::FindName(GetImport(), xAttrList, sName))
     255             :     {
     256             :         // search for reference start
     257           0 :         sal_uInt16 nCount = rHints.size();
     258           0 :         for(sal_uInt16 nPos = 0; nPos < nCount; nPos++)
     259             :         {
     260           0 :             XMLHint_Impl *pHint = &rHints[nPos];
     261           0 :             if ( pHint->IsReference() &&
     262           0 :                  sName.equals( ((XMLReferenceHint_Impl *)pHint)->GetRefName()) )
     263             :             {
     264             :                 // set end and stop searching
     265           0 :                 pHint->SetEnd(GetImport().GetTextImport()->
     266           0 :                                      GetCursor()->getStart() );
     267           0 :                 break;
     268             :             }
     269             :         }
     270             :         // else: no start (in this paragraph) -> ignore
     271           0 :     }
     272           0 : }
     273             : 
     274             : class XMLImpSpanContext_Impl : public SvXMLImportContext
     275             : {
     276             :     const OUString sTextFrame;
     277             : 
     278             :     XMLHints_Impl&      rHints;
     279             :     XMLStyleHint_Impl   *pHint;
     280             : 
     281             :     bool&                rIgnoreLeadingSpace;
     282             : 
     283             :     sal_uInt8            nStarFontsConvFlags;
     284             : 
     285             : public:
     286             : 
     287             :     TYPEINFO_OVERRIDE();
     288             : 
     289             :     XMLImpSpanContext_Impl(
     290             :             SvXMLImport& rImport,
     291             :             sal_uInt16 nPrfx,
     292             :             const OUString& rLName,
     293             :             const Reference< xml::sax::XAttributeList > & xAttrList,
     294             :             XMLHints_Impl& rHnts,
     295             :             bool& rIgnLeadSpace,
     296             :             sal_uInt8 nSFConvFlags
     297             :                           );
     298             : 
     299             :     virtual ~XMLImpSpanContext_Impl();
     300             : 
     301             :     static SvXMLImportContext *CreateChildContext(
     302             :             SvXMLImport& rImport,
     303             :             sal_uInt16 nPrefix, const OUString& rLocalName,
     304             :             const Reference< xml::sax::XAttributeList > & xAttrList,
     305             :             sal_uInt16 nToken, XMLHints_Impl& rHnts,
     306             :             bool& rIgnLeadSpace,
     307             :             sal_uInt8 nStarFontsConvFlags = 0
     308             :              );
     309             :     virtual SvXMLImportContext *CreateChildContext(
     310             :             sal_uInt16 nPrefix, const OUString& rLocalName,
     311             :             const Reference< xml::sax::XAttributeList > & xAttrList ) SAL_OVERRIDE;
     312             : 
     313             :     virtual void Characters( const OUString& rChars ) SAL_OVERRIDE;
     314             : };
     315             : 
     316             : class XMLImpHyperlinkContext_Impl : public SvXMLImportContext
     317             : {
     318             :     XMLHints_Impl&  mrHints;
     319             :     XMLHyperlinkHint_Impl   *mpHint;
     320             : 
     321             :     bool&       mrbIgnoreLeadingSpace;
     322             : 
     323             : public:
     324             : 
     325             :     TYPEINFO_OVERRIDE();
     326             : 
     327             :     XMLImpHyperlinkContext_Impl(
     328             :             SvXMLImport& rImport,
     329             :             sal_uInt16 nPrfx,
     330             :             const OUString& rLName,
     331             :             const Reference< xml::sax::XAttributeList > & xAttrList,
     332             :             XMLHints_Impl& rHnts,
     333             :             bool& rIgnLeadSpace );
     334             : 
     335             :     virtual ~XMLImpHyperlinkContext_Impl();
     336             : 
     337             :     virtual SvXMLImportContext *CreateChildContext(
     338             :             sal_uInt16 nPrefix, const OUString& rLocalName,
     339             :             const Reference< xml::sax::XAttributeList > & xAttrList ) SAL_OVERRIDE;
     340             : 
     341             :     virtual void Characters( const OUString& rChars ) SAL_OVERRIDE;
     342             : };
     343             : 
     344           0 : TYPEINIT1( XMLImpHyperlinkContext_Impl, SvXMLImportContext );
     345             : 
     346           4 : XMLImpHyperlinkContext_Impl::XMLImpHyperlinkContext_Impl(
     347             :     SvXMLImport& rImport,
     348             :     sal_uInt16 nPrfx,
     349             :     const OUString& rLName,
     350             :     const Reference< xml::sax::XAttributeList > & xAttrList,
     351             :     XMLHints_Impl& rHnts,
     352             :     bool& rIgnLeadSpace )
     353             :     : SvXMLImportContext( rImport, nPrfx, rLName )
     354             :     , mrHints( rHnts )
     355          12 :     , mpHint( new XMLHyperlinkHint_Impl( GetImport().GetTextImport()->GetCursorAsRange()->getStart() ) )
     356          16 :     , mrbIgnoreLeadingSpace( rIgnLeadSpace )
     357             : {
     358           4 :     OUString sShow;
     359           4 :     const SvXMLTokenMap& rTokenMap = GetImport().GetTextImport()->GetTextHyperlinkAttrTokenMap();
     360             : 
     361           4 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     362          16 :     for ( sal_Int16 i = 0; i < nAttrCount; i++ )
     363             :     {
     364          12 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
     365          24 :         const OUString& rValue = xAttrList->getValueByIndex( i );
     366             : 
     367          24 :         OUString aLocalName;
     368          12 :         const sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
     369          12 :         switch (rTokenMap.Get( nPrefix, aLocalName ))
     370             :         {
     371             :         case XML_TOK_TEXT_HYPERLINK_HREF:
     372           4 :             mpHint->SetHRef( GetImport().GetAbsoluteReference( rValue ) );
     373           4 :             break;
     374             :         case XML_TOK_TEXT_HYPERLINK_NAME:
     375           0 :             mpHint->SetName( rValue );
     376           0 :             break;
     377             :         case XML_TOK_TEXT_HYPERLINK_TARGET_FRAME:
     378           0 :             mpHint->SetTargetFrameName( rValue );
     379           0 :             break;
     380             :         case XML_TOK_TEXT_HYPERLINK_SHOW:
     381           0 :             sShow = rValue;
     382           0 :             break;
     383             :         case XML_TOK_TEXT_HYPERLINK_STYLE_NAME:
     384           2 :             mpHint->SetStyleName( rValue );
     385           2 :             break;
     386             :         case XML_TOK_TEXT_HYPERLINK_VIS_STYLE_NAME:
     387           2 :             mpHint->SetVisitedStyleName( rValue );
     388           2 :             break;
     389             :         }
     390          12 :     }
     391             : 
     392           4 :     if( !sShow.isEmpty() && mpHint->GetTargetFrameName().isEmpty() )
     393             :     {
     394           0 :         if( IsXMLToken( sShow, XML_NEW ) )
     395             :             mpHint->SetTargetFrameName(
     396           0 :                     OUString( "_blank"  ) );
     397           0 :         else if( IsXMLToken( sShow, XML_REPLACE ) )
     398             :             mpHint->SetTargetFrameName(
     399           0 :                     OUString( "_self"  ) );
     400             :     }
     401             : 
     402           4 :     if ( mpHint->GetHRef().isEmpty() )
     403             :     {
     404             :         // hyperlink without an URL is not imported.
     405           0 :         delete mpHint;
     406           0 :         mpHint = NULL;
     407             :     }
     408             :     else
     409             :     {
     410           4 :         mrHints.push_back( mpHint );
     411           4 :     }
     412           4 : }
     413             : 
     414          12 : XMLImpHyperlinkContext_Impl::~XMLImpHyperlinkContext_Impl()
     415             : {
     416           4 :     if( mpHint != NULL )
     417           4 :         mpHint->SetEnd( GetImport().GetTextImport()
     418           4 :                             ->GetCursorAsRange()->getStart() );
     419           8 : }
     420             : 
     421           2 : SvXMLImportContext *XMLImpHyperlinkContext_Impl::CreateChildContext(
     422             :         sal_uInt16 nPrefix, const OUString& rLocalName,
     423             :         const Reference< xml::sax::XAttributeList > & xAttrList )
     424             : {
     425           2 :     if ( (nPrefix == XML_NAMESPACE_OFFICE) &&
     426           0 :          IsXMLToken(rLocalName, XML_EVENT_LISTENERS) )
     427             :     {
     428             :         XMLEventsImportContext* pCtxt = new XMLEventsImportContext(
     429           0 :             GetImport(), nPrefix, rLocalName);
     430           0 :         mpHint->SetEventsContext(pCtxt);
     431           0 :         return pCtxt;
     432             :     }
     433             :     else
     434             :     {
     435             :         const SvXMLTokenMap& rTokenMap =
     436           2 :             GetImport().GetTextImport()->GetTextPElemTokenMap();
     437           2 :         sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName );
     438             : 
     439             :         return XMLImpSpanContext_Impl::CreateChildContext(
     440           2 :             GetImport(), nPrefix, rLocalName, xAttrList,
     441           4 :             nToken, mrHints, mrbIgnoreLeadingSpace );
     442             :     }
     443             : }
     444             : 
     445           6 : void XMLImpHyperlinkContext_Impl::Characters( const OUString& rChars )
     446             : {
     447           6 :     GetImport().GetTextImport()->InsertString( rChars, mrbIgnoreLeadingSpace );
     448           6 : }
     449             : 
     450             : class XMLImpRubyBaseContext_Impl : public SvXMLImportContext
     451             : {
     452             :     XMLHints_Impl&  rHints;
     453             : 
     454             :     bool&       rIgnoreLeadingSpace;
     455             : 
     456             : public:
     457             : 
     458             :     TYPEINFO_OVERRIDE();
     459             : 
     460             :     XMLImpRubyBaseContext_Impl(
     461             :             SvXMLImport& rImport,
     462             :             sal_uInt16 nPrfx,
     463             :             const OUString& rLName,
     464             :             const Reference< xml::sax::XAttributeList > & xAttrList,
     465             :             XMLHints_Impl& rHnts,
     466             :             bool& rIgnLeadSpace );
     467             : 
     468             :     virtual ~XMLImpRubyBaseContext_Impl();
     469             : 
     470             :     virtual SvXMLImportContext *CreateChildContext(
     471             :             sal_uInt16 nPrefix, const OUString& rLocalName,
     472             :             const Reference< xml::sax::XAttributeList > & xAttrList ) SAL_OVERRIDE;
     473             : 
     474             :     virtual void Characters( const OUString& rChars ) SAL_OVERRIDE;
     475             : };
     476             : 
     477           0 : TYPEINIT1( XMLImpRubyBaseContext_Impl, SvXMLImportContext );
     478             : 
     479          12 : XMLImpRubyBaseContext_Impl::XMLImpRubyBaseContext_Impl(
     480             :         SvXMLImport& rImport,
     481             :         sal_uInt16 nPrfx,
     482             :         const OUString& rLName,
     483             :         const Reference< xml::sax::XAttributeList > &,
     484             :         XMLHints_Impl& rHnts,
     485             :         bool& rIgnLeadSpace ) :
     486             :     SvXMLImportContext( rImport, nPrfx, rLName ),
     487             :     rHints( rHnts ),
     488          12 :     rIgnoreLeadingSpace( rIgnLeadSpace )
     489             : {
     490          12 : }
     491             : 
     492          24 : XMLImpRubyBaseContext_Impl::~XMLImpRubyBaseContext_Impl()
     493             : {
     494          24 : }
     495             : 
     496           6 : SvXMLImportContext *XMLImpRubyBaseContext_Impl::CreateChildContext(
     497             :         sal_uInt16 nPrefix, const OUString& rLocalName,
     498             :         const Reference< xml::sax::XAttributeList > & xAttrList )
     499             : {
     500             :     const SvXMLTokenMap& rTokenMap =
     501           6 :         GetImport().GetTextImport()->GetTextPElemTokenMap();
     502           6 :     sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName );
     503             : 
     504           6 :     return XMLImpSpanContext_Impl::CreateChildContext( GetImport(), nPrefix,
     505             :                                                        rLocalName, xAttrList,
     506          12 :                                nToken, rHints, rIgnoreLeadingSpace );
     507             : }
     508             : 
     509           6 : void XMLImpRubyBaseContext_Impl::Characters( const OUString& rChars )
     510             : {
     511           6 :     GetImport().GetTextImport()->InsertString( rChars, rIgnoreLeadingSpace );
     512           6 : }
     513             : 
     514             : class XMLImpRubyContext_Impl : public SvXMLImportContext
     515             : {
     516             :     XMLHints_Impl&  rHints;
     517             : 
     518             :     bool&       rIgnoreLeadingSpace;
     519             : 
     520             :     Reference < XTextRange > m_xStart;
     521             :     OUString        m_sStyleName;
     522             :     OUString        m_sTextStyleName;
     523             :     OUString        m_sText;
     524             : 
     525             : public:
     526             : 
     527             :     TYPEINFO_OVERRIDE();
     528             : 
     529             :     XMLImpRubyContext_Impl(
     530             :             SvXMLImport& rImport,
     531             :             sal_uInt16 nPrfx,
     532             :             const OUString& rLName,
     533             :             const Reference< xml::sax::XAttributeList > & xAttrList,
     534             :             XMLHints_Impl& rHnts,
     535             :             bool& rIgnLeadSpace );
     536             : 
     537             :     virtual ~XMLImpRubyContext_Impl();
     538             : 
     539             :     virtual SvXMLImportContext *CreateChildContext(
     540             :             sal_uInt16 nPrefix, const OUString& rLocalName,
     541             :             const Reference< xml::sax::XAttributeList > & xAttrList ) SAL_OVERRIDE;
     542             : 
     543           0 :     void SetTextStyleName( const OUString& s ) { m_sTextStyleName = s; }
     544          12 :     void AppendText( const OUString& s ) { m_sText += s; }
     545             : };
     546             : 
     547             : class XMLImpRubyTextContext_Impl : public SvXMLImportContext
     548             : {
     549             :     XMLImpRubyContext_Impl & m_rRubyContext;
     550             : 
     551             : public:
     552             : 
     553             :     TYPEINFO_OVERRIDE();
     554             : 
     555             :     XMLImpRubyTextContext_Impl(
     556             :             SvXMLImport& rImport,
     557             :             sal_uInt16 nPrfx,
     558             :             const OUString& rLName,
     559             :             const Reference< xml::sax::XAttributeList > & xAttrList,
     560             :             XMLImpRubyContext_Impl & rParent );
     561             : 
     562             :     virtual ~XMLImpRubyTextContext_Impl();
     563             : 
     564             :     virtual void Characters( const OUString& rChars ) SAL_OVERRIDE;
     565             : };
     566             : 
     567           0 : TYPEINIT1( XMLImpRubyTextContext_Impl, SvXMLImportContext );
     568             : 
     569          12 : XMLImpRubyTextContext_Impl::XMLImpRubyTextContext_Impl(
     570             :         SvXMLImport& rImport,
     571             :         sal_uInt16 nPrfx,
     572             :         const OUString& rLName,
     573             :         const Reference< xml::sax::XAttributeList > & xAttrList,
     574             :         XMLImpRubyContext_Impl & rParent )
     575             :     : SvXMLImportContext( rImport, nPrfx, rLName )
     576          12 :     , m_rRubyContext( rParent )
     577             : {
     578          12 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     579          12 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
     580             :     {
     581           0 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
     582           0 :         const OUString& rValue = xAttrList->getValueByIndex( i );
     583             : 
     584           0 :         OUString aLocalName;
     585             :         sal_uInt16 nPrefix =
     586           0 :             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
     587           0 :                                                             &aLocalName );
     588           0 :         if( XML_NAMESPACE_TEXT == nPrefix &&
     589           0 :             IsXMLToken( aLocalName, XML_STYLE_NAME ) )
     590             :         {
     591           0 :             m_rRubyContext.SetTextStyleName( rValue );
     592           0 :             break;
     593             :         }
     594           0 :     }
     595          12 : }
     596             : 
     597          24 : XMLImpRubyTextContext_Impl::~XMLImpRubyTextContext_Impl()
     598             : {
     599          24 : }
     600             : 
     601          12 : void XMLImpRubyTextContext_Impl::Characters( const OUString& rChars )
     602             : {
     603          12 :     m_rRubyContext.AppendText( rChars );
     604          12 : }
     605             : 
     606           0 : TYPEINIT1( XMLImpRubyContext_Impl, SvXMLImportContext );
     607             : 
     608          12 : XMLImpRubyContext_Impl::XMLImpRubyContext_Impl(
     609             :         SvXMLImport& rImport,
     610             :         sal_uInt16 nPrfx,
     611             :         const OUString& rLName,
     612             :         const Reference< xml::sax::XAttributeList > & xAttrList,
     613             :         XMLHints_Impl& rHnts,
     614             :         bool& rIgnLeadSpace ) :
     615             :     SvXMLImportContext( rImport, nPrfx, rLName ),
     616             :     rHints( rHnts ),
     617             :     rIgnoreLeadingSpace( rIgnLeadSpace )
     618          12 :     , m_xStart( GetImport().GetTextImport()->GetCursorAsRange()->getStart() )
     619             : {
     620          12 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     621          12 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
     622             :     {
     623          12 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
     624          12 :         const OUString& rValue = xAttrList->getValueByIndex( i );
     625             : 
     626          12 :         OUString aLocalName;
     627             :         sal_uInt16 nPrefix =
     628          12 :             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
     629          12 :                                                             &aLocalName );
     630          24 :         if( XML_NAMESPACE_TEXT == nPrefix &&
     631          12 :             IsXMLToken( aLocalName, XML_STYLE_NAME ) )
     632             :         {
     633          12 :             m_sStyleName = rValue;
     634          12 :             break;
     635             :         }
     636           0 :     }
     637          12 : }
     638             : 
     639          36 : XMLImpRubyContext_Impl::~XMLImpRubyContext_Impl()
     640             : {
     641             :     const UniReference < XMLTextImportHelper > xTextImport(
     642          12 :         GetImport().GetTextImport());
     643             :     const Reference < XTextCursor > xAttrCursor(
     644          24 :         xTextImport->GetText()->createTextCursorByRange( m_xStart ));
     645          24 :     xAttrCursor->gotoRange(xTextImport->GetCursorAsRange()->getStart(),
     646          24 :             sal_True);
     647          12 :     xTextImport->SetRuby( GetImport(), xAttrCursor,
     648          36 :          m_sStyleName, m_sTextStyleName, m_sText );
     649          24 : }
     650             : 
     651          24 : SvXMLImportContext *XMLImpRubyContext_Impl::CreateChildContext(
     652             :         sal_uInt16 nPrefix, const OUString& rLocalName,
     653             :         const Reference< xml::sax::XAttributeList > & xAttrList )
     654             : {
     655             :     SvXMLImportContext *pContext;
     656          24 :     if( XML_NAMESPACE_TEXT == nPrefix )
     657             :     {
     658          24 :         if( IsXMLToken( rLocalName, XML_RUBY_BASE ) )
     659          12 :             pContext = new XMLImpRubyBaseContext_Impl( GetImport(), nPrefix,
     660             :                                                        rLocalName,
     661             :                                                        xAttrList,
     662             :                                                        rHints,
     663          12 :                                                        rIgnoreLeadingSpace );
     664          12 :         else if( IsXMLToken( rLocalName, XML_RUBY_TEXT ) )
     665          12 :             pContext = new XMLImpRubyTextContext_Impl( GetImport(), nPrefix,
     666             :                                                        rLocalName,
     667             :                                                        xAttrList,
     668          12 :                                                        *this );
     669             :         else
     670             :             pContext = new SvXMLImportContext(
     671           0 :                 GetImport(), nPrefix, rLocalName );
     672             :     }
     673             :     else
     674             :         pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName,
     675           0 :                                                             xAttrList );
     676             : 
     677          24 :     return pContext;
     678             : }
     679             : 
     680             : /** for text:meta and text:meta-field
     681             :  */
     682             : class XMLMetaImportContextBase : public SvXMLImportContext
     683             : {
     684             :     XMLHints_Impl&    m_rHints;
     685             : 
     686             :     bool& m_rIgnoreLeadingSpace;
     687             : 
     688             :     /// start position
     689             :     Reference<XTextRange> m_xStart;
     690             : 
     691             : protected:
     692             :     OUString m_XmlId;
     693             : 
     694             : public:
     695             :     TYPEINFO_OVERRIDE();
     696             : 
     697             :     XMLMetaImportContextBase(
     698             :         SvXMLImport& i_rImport,
     699             :         const sal_uInt16 i_nPrefix,
     700             :         const OUString& i_rLocalName,
     701             :         XMLHints_Impl& i_rHints,
     702             :         bool & i_rIgnoreLeadingSpace );
     703             : 
     704             :     virtual ~XMLMetaImportContextBase();
     705             : 
     706             :     virtual void StartElement(
     707             :             const Reference<xml::sax::XAttributeList> & i_xAttrList) SAL_OVERRIDE;
     708             : 
     709             :     virtual void EndElement() SAL_OVERRIDE;
     710             : 
     711             :     virtual SvXMLImportContext *CreateChildContext(
     712             :             sal_uInt16 i_nPrefix, const OUString& i_rLocalName,
     713             :             const Reference< xml::sax::XAttributeList > & i_xAttrList) SAL_OVERRIDE;
     714             : 
     715             :     virtual void Characters( const OUString& i_rChars ) SAL_OVERRIDE;
     716             : 
     717             :     virtual void ProcessAttribute(sal_uInt16 const i_nPrefix,
     718             :         OUString const & i_rLocalName, OUString const & i_rValue);
     719             : 
     720             :     virtual void InsertMeta(const Reference<XTextRange> & i_xInsertionRange)
     721             :         = 0;
     722             : };
     723             : 
     724           0 : TYPEINIT1( XMLMetaImportContextBase, SvXMLImportContext );
     725             : 
     726          40 : XMLMetaImportContextBase::XMLMetaImportContextBase(
     727             :         SvXMLImport& i_rImport,
     728             :         const sal_uInt16 i_nPrefix,
     729             :         const OUString& i_rLocalName,
     730             :         XMLHints_Impl& i_rHints,
     731             :         bool & i_rIgnoreLeadingSpace )
     732             :     : SvXMLImportContext( i_rImport, i_nPrefix, i_rLocalName )
     733             :     , m_rHints( i_rHints )
     734             :     , m_rIgnoreLeadingSpace( i_rIgnoreLeadingSpace )
     735          40 :     , m_xStart( GetImport().GetTextImport()->GetCursorAsRange()->getStart() )
     736             : {
     737          40 : }
     738             : 
     739          40 : XMLMetaImportContextBase::~XMLMetaImportContextBase()
     740             : {
     741          40 : }
     742             : 
     743          40 : void XMLMetaImportContextBase::StartElement(
     744             :         const Reference<xml::sax::XAttributeList> & i_xAttrList)
     745             : {
     746          40 :     const sal_Int16 nAttrCount(i_xAttrList.is() ? i_xAttrList->getLength() : 0);
     747          91 :     for ( sal_Int16 i = 0; i < nAttrCount; ++i )
     748             :     {
     749          51 :         const OUString& rAttrName( i_xAttrList->getNameByIndex( i ) );
     750         102 :         const OUString& rValue( i_xAttrList->getValueByIndex( i ) );
     751             : 
     752         102 :         OUString sLocalName;
     753             :         const sal_uInt16 nPrefix(
     754          51 :             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
     755          51 :                                                             &sLocalName ));
     756          51 :         ProcessAttribute(nPrefix, sLocalName, rValue);
     757          51 :     }
     758          40 : }
     759             : 
     760          40 : void XMLMetaImportContextBase::EndElement()
     761             : {
     762             :     SAL_WARN_IF(!m_xStart.is(), "xmloff.text", "no mxStart?");
     763          80 :     if (!m_xStart.is()) return;
     764             : 
     765             :     const Reference<XTextRange> xEndRange(
     766          40 :         GetImport().GetTextImport()->GetCursorAsRange()->getStart() );
     767             : 
     768             :     // create range for insertion
     769             :     const Reference<XTextCursor> xInsertionCursor(
     770          80 :         GetImport().GetTextImport()->GetText()->createTextCursorByRange(
     771          80 :             xEndRange) );
     772          40 :     xInsertionCursor->gotoRange(m_xStart, sal_True);
     773             : 
     774          80 :     InsertMeta(xInsertionCursor);
     775             : }
     776             : 
     777          14 : SvXMLImportContext * XMLMetaImportContextBase::CreateChildContext(
     778             :             sal_uInt16 i_nPrefix, const OUString& i_rLocalName,
     779             :             const Reference< xml::sax::XAttributeList > & i_xAttrList )
     780             : {
     781             :     const SvXMLTokenMap& rTokenMap(
     782          14 :         GetImport().GetTextImport()->GetTextPElemTokenMap() );
     783          14 :     const sal_uInt16 nToken( rTokenMap.Get( i_nPrefix, i_rLocalName ) );
     784             : 
     785          14 :     return XMLImpSpanContext_Impl::CreateChildContext( GetImport(), i_nPrefix,
     786          28 :         i_rLocalName, i_xAttrList, nToken, m_rHints, m_rIgnoreLeadingSpace );
     787             : }
     788             : 
     789          26 : void XMLMetaImportContextBase::Characters( const OUString& i_rChars )
     790             : {
     791          26 :     GetImport().GetTextImport()->InsertString(i_rChars, m_rIgnoreLeadingSpace);
     792          26 : }
     793             : 
     794          39 : void XMLMetaImportContextBase::ProcessAttribute(sal_uInt16 const i_nPrefix,
     795             :     OUString const & i_rLocalName, OUString const & i_rValue)
     796             : {
     797          39 :     if ( (XML_NAMESPACE_XML == i_nPrefix) && IsXMLToken(i_rLocalName, XML_ID) )
     798             :     {
     799          37 :         m_XmlId = i_rValue;
     800             :     }
     801          39 : }
     802             : 
     803             : /** text:meta */
     804          38 : class XMLMetaImportContext : public XMLMetaImportContextBase
     805             : {
     806             :     // RDFa
     807             :     bool m_bHaveAbout;
     808             :     OUString m_sAbout;
     809             :     OUString m_sProperty;
     810             :     OUString m_sContent;
     811             :     OUString m_sDatatype;
     812             : 
     813             : public:
     814             :     TYPEINFO_OVERRIDE();
     815             : 
     816             :     XMLMetaImportContext(
     817             :         SvXMLImport& i_rImport,
     818             :         const sal_uInt16 i_nPrefix,
     819             :         const OUString& i_rLocalName,
     820             :         XMLHints_Impl& i_rHints,
     821             :         bool & i_rIgnoreLeadingSpace );
     822             : 
     823             :     virtual void ProcessAttribute(sal_uInt16 const i_nPrefix,
     824             :         OUString const & i_rLocalName, OUString const & i_rValue) SAL_OVERRIDE;
     825             : 
     826             :     virtual void InsertMeta(const Reference<XTextRange> & i_xInsertionRange) SAL_OVERRIDE;
     827             : };
     828             : 
     829           0 : TYPEINIT1( XMLMetaImportContext, XMLMetaImportContextBase );
     830             : 
     831          19 : XMLMetaImportContext::XMLMetaImportContext(
     832             :         SvXMLImport& i_rImport,
     833             :         const sal_uInt16 i_nPrefix,
     834             :         const OUString& i_rLocalName,
     835             :         XMLHints_Impl& i_rHints,
     836             :         bool & i_rIgnoreLeadingSpace )
     837             :     : XMLMetaImportContextBase( i_rImport, i_nPrefix, i_rLocalName,
     838             :             i_rHints, i_rIgnoreLeadingSpace )
     839          19 :     , m_bHaveAbout(false)
     840             : {
     841          19 : }
     842             : 
     843          27 : void XMLMetaImportContext::ProcessAttribute(sal_uInt16 const i_nPrefix,
     844             :     OUString const & i_rLocalName, OUString const & i_rValue)
     845             : {
     846          27 :     if ( XML_NAMESPACE_XHTML == i_nPrefix )
     847             :     {
     848             :         // RDFa
     849           8 :         if ( IsXMLToken( i_rLocalName, XML_ABOUT) )
     850             :         {
     851           2 :             m_sAbout = i_rValue;
     852           2 :             m_bHaveAbout = true;
     853             :         }
     854           6 :         else if ( IsXMLToken( i_rLocalName, XML_PROPERTY) )
     855             :         {
     856           2 :             m_sProperty = i_rValue;
     857             :         }
     858           4 :         else if ( IsXMLToken( i_rLocalName, XML_CONTENT) )
     859             :         {
     860           2 :             m_sContent = i_rValue;
     861             :         }
     862           2 :         else if ( IsXMLToken( i_rLocalName, XML_DATATYPE) )
     863             :         {
     864           2 :             m_sDatatype = i_rValue;
     865             :         }
     866             :     }
     867             :     else
     868             :     {
     869             :         XMLMetaImportContextBase::ProcessAttribute(
     870          19 :             i_nPrefix, i_rLocalName, i_rValue);
     871             :     }
     872          27 : }
     873             : 
     874          19 : void XMLMetaImportContext::InsertMeta(
     875             :     const Reference<XTextRange> & i_xInsertionRange)
     876             : {
     877             :     SAL_WARN_IF(m_bHaveAbout == m_sProperty.isEmpty(), "xmloff.text", "XMLMetaImportContext::InsertMeta: invalid RDFa?");
     878          19 :     if (!m_XmlId.isEmpty() || (m_bHaveAbout && !m_sProperty.isEmpty()))
     879             :     {
     880             :         // insert mark
     881             :         const uno::Reference<rdf::XMetadatable> xMeta(
     882             :             XMLTextMarkImportContext::CreateAndInsertMark(
     883          18 :                 GetImport(),
     884             :                 OUString("com.sun.star.text.InContentMetadata"),
     885             :                 OUString(),
     886             :                 i_xInsertionRange, m_XmlId),
     887          36 :             uno::UNO_QUERY);
     888             :         SAL_WARN_IF(!xMeta.is(), "xmloff.text", "cannot insert Meta?");
     889             : 
     890          18 :         if (xMeta.is() && m_bHaveAbout)
     891             :         {
     892           2 :             GetImport().AddRDFa(xMeta,
     893           4 :                 m_sAbout, m_sProperty, m_sContent, m_sDatatype);
     894          18 :         }
     895             :     }
     896             :     else
     897             :     {
     898             :         SAL_INFO("xmloff.text", "invalid <text:meta>: no xml:id, no valid RDFa");
     899             :     }
     900          19 : }
     901             : 
     902             : /** text:meta-field */
     903          42 : class XMLMetaFieldImportContext : public XMLMetaImportContextBase
     904             : {
     905             :     OUString m_DataStyleName;
     906             : 
     907             : public:
     908             :     TYPEINFO_OVERRIDE();
     909             : 
     910             :     XMLMetaFieldImportContext(
     911             :         SvXMLImport& i_rImport,
     912             :         const sal_uInt16 i_nPrefix,
     913             :         const OUString& i_rLocalName,
     914             :         XMLHints_Impl& i_rHints,
     915             :         bool & i_rIgnoreLeadingSpace );
     916             : 
     917             :     virtual void ProcessAttribute(sal_uInt16 const i_nPrefix,
     918             :         OUString const & i_rLocalName, OUString const & i_rValue) SAL_OVERRIDE;
     919             : 
     920             :     virtual void InsertMeta(const Reference<XTextRange> & i_xInsertionRange) SAL_OVERRIDE;
     921             : };
     922             : 
     923           0 : TYPEINIT1( XMLMetaFieldImportContext, XMLMetaImportContextBase );
     924             : 
     925          21 : XMLMetaFieldImportContext::XMLMetaFieldImportContext(
     926             :         SvXMLImport& i_rImport,
     927             :         const sal_uInt16 i_nPrefix,
     928             :         const OUString& i_rLocalName,
     929             :         XMLHints_Impl& i_rHints,
     930             :         bool & i_rIgnoreLeadingSpace )
     931             :     : XMLMetaImportContextBase( i_rImport, i_nPrefix, i_rLocalName,
     932          21 :             i_rHints, i_rIgnoreLeadingSpace )
     933             : {
     934          21 : }
     935             : 
     936          24 : void XMLMetaFieldImportContext::ProcessAttribute(sal_uInt16 const i_nPrefix,
     937             :     OUString const & i_rLocalName, OUString const & i_rValue)
     938             : {
     939          28 :     if ( XML_NAMESPACE_STYLE == i_nPrefix &&
     940           4 :          IsXMLToken( i_rLocalName, XML_DATA_STYLE_NAME ) )
     941             :     {
     942           4 :         m_DataStyleName = i_rValue;
     943             :     }
     944             :     else
     945             :     {
     946             :         XMLMetaImportContextBase::ProcessAttribute(
     947          20 :             i_nPrefix, i_rLocalName, i_rValue);
     948             :     }
     949          24 : }
     950             : 
     951          21 : void XMLMetaFieldImportContext::InsertMeta(
     952             :     const Reference<XTextRange> & i_xInsertionRange)
     953             : {
     954          21 :     if (!m_XmlId.isEmpty()) // valid?
     955             :     {
     956             :         // insert mark
     957             :         const Reference<XPropertySet> xPropertySet(
     958             :             XMLTextMarkImportContext::CreateAndInsertMark(
     959          20 :                 GetImport(),
     960             :                 OUString("com.sun.star.text.textfield.MetadataField"),
     961             :                 OUString(),
     962             :                 i_xInsertionRange, m_XmlId),
     963          40 :             UNO_QUERY);
     964             :         SAL_WARN_IF(!xPropertySet.is(), "xmloff.text", "cannot insert MetaField?");
     965          41 :         if (!xPropertySet.is()) return;
     966             : 
     967          20 :         if (!m_DataStyleName.isEmpty())
     968             :         {
     969           4 :             bool isDefaultLanguage(true);
     970             : 
     971           4 :             const sal_Int32 nKey( GetImport().GetTextImport()->GetDataStyleKey(
     972           8 :                                    m_DataStyleName, & isDefaultLanguage) );
     973             : 
     974           4 :             if (-1 != nKey)
     975             :             {
     976             :                 static OUString sPropertyIsFixedLanguage(
     977           4 :                     OUString("IsFixedLanguage") );
     978           4 :                 Any any;
     979           4 :                 any <<= nKey;
     980           4 :                 xPropertySet->setPropertyValue(
     981           4 :                     OUString("NumberFormat"), any);
     982           8 :                 if ( xPropertySet->getPropertySetInfo()->
     983           4 :                         hasPropertyByName( sPropertyIsFixedLanguage ) )
     984             :                 {
     985           4 :                     any <<= static_cast<bool>(!isDefaultLanguage);
     986           4 :                     xPropertySet->setPropertyValue( sPropertyIsFixedLanguage,
     987           4 :                         any );
     988           4 :                 }
     989             :             }
     990          20 :         }
     991             :     }
     992             :     else
     993             :     {
     994             :         SAL_INFO("xmloff.text", "invalid <text:meta-field>: no xml:id");
     995             :     }
     996             : }
     997             : 
     998             : /**
     999             :  * Process index marks.
    1000             :  *
    1001             :  * All *-mark-end index marks should instantiate *this* class (because
    1002             :  * it doesn't process attributes other than ID), while the *-mark and
    1003             :  * *-mark-start classes should instantiate the apporpiate subclasses.
    1004             :  */
    1005           0 : class XMLIndexMarkImportContext_Impl : public SvXMLImportContext
    1006             : {
    1007             :     const OUString sAlternativeText;
    1008             : 
    1009             :     XMLHints_Impl& rHints;
    1010             :     const enum XMLTextPElemTokens eToken;
    1011             :     OUString sID;
    1012             : 
    1013             : public:
    1014             :     TYPEINFO_OVERRIDE();
    1015             : 
    1016             :     XMLIndexMarkImportContext_Impl(
    1017             :         SvXMLImport& rImport,
    1018             :         sal_uInt16 nPrefix,
    1019             :         const OUString& rLocalName,
    1020             :         enum XMLTextPElemTokens nTok,
    1021             :         XMLHints_Impl& rHnts);
    1022             : 
    1023             :     void StartElement(const Reference<xml::sax::XAttributeList> & xAttrList) SAL_OVERRIDE;
    1024             : 
    1025             : protected:
    1026             : 
    1027             :     /// process all attributes
    1028             :     void ProcessAttributes(const Reference<xml::sax::XAttributeList> & xAttrList,
    1029             :                            Reference<beans::XPropertySet>& rPropSet);
    1030             : 
    1031             :     /**
    1032             :      * All marks can be created immediately. Since we don't care about
    1033             :      * the element content, ProcessAttribute should set the properties
    1034             :      * immediately.
    1035             :      *
    1036             :      * This method tolerates an empty PropertySet; subclasses however
    1037             :      * are not expected to.
    1038             :      */
    1039             :     virtual void ProcessAttribute(sal_uInt16 nNamespace,
    1040             :                                   const OUString& sLocalName,
    1041             :                                   const OUString& sValue,
    1042             :                                   Reference<beans::XPropertySet>& rPropSet);
    1043             : 
    1044             :     static void GetServiceName(OUString& sServiceName,
    1045             :                                enum XMLTextPElemTokens nToken);
    1046             : 
    1047             :     sal_Bool CreateMark(Reference<beans::XPropertySet>& rPropSet,
    1048             :                         const OUString& rServiceName);
    1049             : };
    1050             : 
    1051           0 : TYPEINIT1( XMLIndexMarkImportContext_Impl, SvXMLImportContext );
    1052             : 
    1053           0 : XMLIndexMarkImportContext_Impl::XMLIndexMarkImportContext_Impl(
    1054             :     SvXMLImport& rImport,
    1055             :     sal_uInt16 nPrefix,
    1056             :     const OUString& rLocalName,
    1057             :     enum XMLTextPElemTokens eTok,
    1058             :     XMLHints_Impl& rHnts) :
    1059             :         SvXMLImportContext(rImport, nPrefix, rLocalName),
    1060             :         sAlternativeText("AlternativeText"),
    1061             :         rHints(rHnts),
    1062           0 :         eToken(eTok)
    1063             : {
    1064           0 : }
    1065             : 
    1066           0 : void XMLIndexMarkImportContext_Impl::StartElement(
    1067             :     const Reference<xml::sax::XAttributeList> & xAttrList)
    1068             : {
    1069             :     // get Cursor position (needed for all cases)
    1070             :     Reference<XTextRange> xPos(
    1071           0 :         GetImport().GetTextImport()->GetCursor()->getStart());
    1072           0 :     Reference<beans::XPropertySet> xMark;
    1073             : 
    1074           0 :     switch (eToken)
    1075             :     {
    1076             :         case XML_TOK_TEXT_TOC_MARK:
    1077             :         case XML_TOK_TEXT_USER_INDEX_MARK:
    1078             :         case XML_TOK_TEXT_ALPHA_INDEX_MARK:
    1079             :         {
    1080             :             // single mark: create mark and insert
    1081           0 :             OUString sService;
    1082           0 :             GetServiceName(sService, eToken);
    1083           0 :             if (CreateMark(xMark, sService))
    1084             :             {
    1085           0 :                 ProcessAttributes(xAttrList, xMark);
    1086           0 :                 XMLHint_Impl* pHint = new XMLIndexMarkHint_Impl(xMark, xPos);
    1087           0 :                 rHints.push_back(pHint);
    1088             :             }
    1089             :             // else: can't create mark -> ignore
    1090           0 :             break;
    1091             :         }
    1092             : 
    1093             :         case XML_TOK_TEXT_TOC_MARK_START:
    1094             :         case XML_TOK_TEXT_USER_INDEX_MARK_START:
    1095             :         case XML_TOK_TEXT_ALPHA_INDEX_MARK_START:
    1096             :         {
    1097             :             // start: create mark and insert (if ID is found)
    1098           0 :             OUString sService;
    1099           0 :             GetServiceName(sService, eToken);
    1100           0 :             if (CreateMark(xMark, sService))
    1101             :             {
    1102           0 :                 ProcessAttributes(xAttrList, xMark);
    1103           0 :                 if (!sID.isEmpty())
    1104             :                 {
    1105             :                     // process only if we find an ID
    1106             :                     XMLHint_Impl* pHint =
    1107           0 :                         new XMLIndexMarkHint_Impl(xMark, xPos, sID);
    1108           0 :                     rHints.push_back(pHint);
    1109             :                 }
    1110             :                 // else: no ID -> we'll never find the end -> ignore
    1111             :             }
    1112             :             // else: can't create mark -> ignore
    1113           0 :             break;
    1114             :         }
    1115             : 
    1116             :         case XML_TOK_TEXT_TOC_MARK_END:
    1117             :         case XML_TOK_TEXT_USER_INDEX_MARK_END:
    1118             :         case XML_TOK_TEXT_ALPHA_INDEX_MARK_END:
    1119             :         {
    1120             :             // end: search for ID and set end of mark
    1121             : 
    1122             :             // call process attributes with empty XPropertySet:
    1123           0 :             ProcessAttributes(xAttrList, xMark);
    1124           0 :             if (!sID.isEmpty())
    1125             :             {
    1126             :                 // if we have an ID, find the hint and set the end position
    1127           0 :                 sal_uInt16 nCount = rHints.size();
    1128           0 :                 for(sal_uInt16 nPos = 0; nPos < nCount; nPos++)
    1129             :                 {
    1130           0 :                     XMLHint_Impl *pHint = &rHints[nPos];
    1131           0 :                     if ( pHint->IsIndexMark() &&
    1132             :                          sID.equals(
    1133           0 :                              ((XMLIndexMarkHint_Impl *)pHint)->GetID()) )
    1134             :                     {
    1135             :                         // set end and stop searching
    1136           0 :                         pHint->SetEnd(xPos);
    1137           0 :                         break;
    1138             :                     }
    1139             :                 }
    1140             :             }
    1141             :             // else: no ID -> ignore
    1142           0 :             break;
    1143             :         }
    1144             : 
    1145             :         default:
    1146             :             SAL_WARN("xmloff.text", "unknown index mark type!");
    1147           0 :             break;
    1148           0 :     }
    1149           0 : }
    1150             : 
    1151           0 : void XMLIndexMarkImportContext_Impl::ProcessAttributes(
    1152             :     const Reference<xml::sax::XAttributeList> & xAttrList,
    1153             :     Reference<beans::XPropertySet>& rPropSet)
    1154             : {
    1155             :     // process attributes
    1156           0 :     sal_Int16 nLength = xAttrList->getLength();
    1157           0 :     for(sal_Int16 i=0; i<nLength; i++)
    1158             :     {
    1159           0 :         OUString sLocalName;
    1160           0 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
    1161           0 :             GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
    1162             : 
    1163             :         ProcessAttribute(nPrefix, sLocalName,
    1164           0 :                          xAttrList->getValueByIndex(i),
    1165           0 :                          rPropSet);
    1166           0 :     }
    1167           0 : }
    1168             : 
    1169           0 : void XMLIndexMarkImportContext_Impl::ProcessAttribute(
    1170             :     sal_uInt16 nNamespace,
    1171             :     const OUString& sLocalName,
    1172             :     const OUString& sValue,
    1173             :     Reference<beans::XPropertySet>& rPropSet)
    1174             : {
    1175             :     // we only know ID + string-value attribute;
    1176             :     // (former: marks, latter: -start + -end-marks)
    1177             :     // the remainder is handled in sub-classes
    1178           0 :     switch (eToken)
    1179             :     {
    1180             :         case XML_TOK_TEXT_TOC_MARK:
    1181             :         case XML_TOK_TEXT_USER_INDEX_MARK:
    1182             :         case XML_TOK_TEXT_ALPHA_INDEX_MARK:
    1183           0 :             if ( (XML_NAMESPACE_TEXT == nNamespace) &&
    1184           0 :                  IsXMLToken( sLocalName, XML_STRING_VALUE ) )
    1185             :             {
    1186           0 :                 rPropSet->setPropertyValue(sAlternativeText, uno::makeAny(sValue));
    1187             :             }
    1188             :             // else: ignore!
    1189           0 :             break;
    1190             : 
    1191             :         case XML_TOK_TEXT_TOC_MARK_START:
    1192             :         case XML_TOK_TEXT_USER_INDEX_MARK_START:
    1193             :         case XML_TOK_TEXT_ALPHA_INDEX_MARK_START:
    1194             :         case XML_TOK_TEXT_TOC_MARK_END:
    1195             :         case XML_TOK_TEXT_USER_INDEX_MARK_END:
    1196             :         case XML_TOK_TEXT_ALPHA_INDEX_MARK_END:
    1197           0 :             if ( (XML_NAMESPACE_TEXT == nNamespace) &&
    1198           0 :                  IsXMLToken( sLocalName, XML_ID ) )
    1199             :             {
    1200           0 :                 sID = sValue;
    1201             :             }
    1202             :             // else: ignore
    1203           0 :             break;
    1204             : 
    1205             :         default:
    1206             :             SAL_WARN("xmloff.text", "unknown index mark type!");
    1207           0 :             break;
    1208             :     }
    1209           0 : }
    1210             : 
    1211             : static const sal_Char sAPI_com_sun_star_text_ContentIndexMark[] =
    1212             :         "com.sun.star.text.ContentIndexMark";
    1213             : static const sal_Char sAPI_com_sun_star_text_UserIndexMark[] =
    1214             :         "com.sun.star.text.UserIndexMark";
    1215             : static const sal_Char sAPI_com_sun_star_text_DocumentIndexMark[] =
    1216             :         "com.sun.star.text.DocumentIndexMark";
    1217             : 
    1218           0 : void XMLIndexMarkImportContext_Impl::GetServiceName(
    1219             :     OUString& sServiceName,
    1220             :     enum XMLTextPElemTokens eToken)
    1221             : {
    1222           0 :     switch (eToken)
    1223             :     {
    1224             :         case XML_TOK_TEXT_TOC_MARK:
    1225             :         case XML_TOK_TEXT_TOC_MARK_START:
    1226             :         case XML_TOK_TEXT_TOC_MARK_END:
    1227             :         {
    1228             :             OUString sTmp(
    1229           0 :                 sAPI_com_sun_star_text_ContentIndexMark);
    1230           0 :             sServiceName = sTmp;
    1231           0 :             break;
    1232             :         }
    1233             : 
    1234             :         case XML_TOK_TEXT_USER_INDEX_MARK:
    1235             :         case XML_TOK_TEXT_USER_INDEX_MARK_START:
    1236             :         case XML_TOK_TEXT_USER_INDEX_MARK_END:
    1237             :         {
    1238             :             OUString sTmp(
    1239           0 :                 sAPI_com_sun_star_text_UserIndexMark);
    1240           0 :             sServiceName = sTmp;
    1241           0 :             break;
    1242             :         }
    1243             : 
    1244             :         case XML_TOK_TEXT_ALPHA_INDEX_MARK:
    1245             :         case XML_TOK_TEXT_ALPHA_INDEX_MARK_START:
    1246             :         case XML_TOK_TEXT_ALPHA_INDEX_MARK_END:
    1247             :         {
    1248             :             OUString sTmp(
    1249           0 :                 sAPI_com_sun_star_text_DocumentIndexMark);
    1250           0 :             sServiceName = sTmp;
    1251           0 :             break;
    1252             :         }
    1253             : 
    1254             :         default:
    1255             :         {
    1256             :             SAL_WARN("xmloff.text", "unknown index mark type!");
    1257           0 :             OUString sTmp;
    1258           0 :             sServiceName = sTmp;
    1259           0 :             break;
    1260             :         }
    1261             :     }
    1262           0 : }
    1263             : 
    1264           0 : sal_Bool XMLIndexMarkImportContext_Impl::CreateMark(
    1265             :     Reference<beans::XPropertySet>& rPropSet,
    1266             :     const OUString& rServiceName)
    1267             : {
    1268             :     Reference<lang::XMultiServiceFactory>
    1269           0 :         xFactory(GetImport().GetModel(), UNO_QUERY);
    1270             : 
    1271           0 :     if( xFactory.is() )
    1272             :     {
    1273           0 :         Reference<beans::XPropertySet> xPropSet( xFactory->createInstance(rServiceName), UNO_QUERY );
    1274           0 :         if (xPropSet.is())
    1275           0 :             rPropSet = xPropSet;
    1276           0 :         return sal_True;
    1277             :     }
    1278             : 
    1279           0 :     return sal_False;
    1280             : }
    1281             : 
    1282           0 : class XMLTOCMarkImportContext_Impl : public XMLIndexMarkImportContext_Impl
    1283             : {
    1284             :     const OUString sLevel;
    1285             : 
    1286             : public:
    1287             :     TYPEINFO_OVERRIDE();
    1288             : 
    1289             :     XMLTOCMarkImportContext_Impl(
    1290             :         SvXMLImport& rImport,
    1291             :         sal_uInt16 nPrefix,
    1292             :         const OUString& rLocalName,
    1293             :         enum XMLTextPElemTokens nTok,
    1294             :         XMLHints_Impl& rHnts);
    1295             : 
    1296             : protected:
    1297             : 
    1298             :     /** process outline level */
    1299             :     virtual void ProcessAttribute(sal_uInt16 nNamespace,
    1300             :                                   const OUString& sLocalName,
    1301             :                                   const OUString& sValue,
    1302             :                                   Reference<beans::XPropertySet>& rPropSet) SAL_OVERRIDE;
    1303             : };
    1304             : 
    1305           0 : TYPEINIT1( XMLTOCMarkImportContext_Impl, XMLIndexMarkImportContext_Impl );
    1306             : 
    1307           0 : XMLTOCMarkImportContext_Impl::XMLTOCMarkImportContext_Impl(
    1308             :     SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLocalName,
    1309             :     enum XMLTextPElemTokens nTok, XMLHints_Impl& rHnts) :
    1310             :         XMLIndexMarkImportContext_Impl(rImport, nPrefix, rLocalName,
    1311             :                                        nTok, rHnts),
    1312           0 :         sLevel("Level")
    1313             : {
    1314           0 : }
    1315             : 
    1316           0 : void XMLTOCMarkImportContext_Impl::ProcessAttribute(
    1317             :     sal_uInt16 nNamespace,
    1318             :     const OUString& sLocalName,
    1319             :     const OUString& sValue,
    1320             :     Reference<beans::XPropertySet>& rPropSet)
    1321             : {
    1322             :     SAL_WARN_IF(!rPropSet.is(), "xmloff.text", "need PropertySet");
    1323             : 
    1324           0 :     if ((XML_NAMESPACE_TEXT == nNamespace) &&
    1325           0 :         IsXMLToken( sLocalName, XML_OUTLINE_LEVEL ) )
    1326             :     {
    1327             :         // ouline level: set Level property
    1328             :         sal_Int32 nTmp;
    1329           0 :         if (::sax::Converter::convertNumber( nTmp, sValue )
    1330           0 :              && nTmp >= 1
    1331           0 :              && nTmp < GetImport().GetTextImport()->
    1332           0 :                               GetChapterNumbering()->getCount() )
    1333             :         {
    1334           0 :             rPropSet->setPropertyValue(sLevel, uno::makeAny((sal_Int16)(nTmp - 1)));
    1335             :         }
    1336             :         // else: value out of range -> ignore
    1337             :     }
    1338             :     else
    1339             :     {
    1340             :         // else: delegate to superclass
    1341             :         XMLIndexMarkImportContext_Impl::ProcessAttribute(
    1342           0 :             nNamespace, sLocalName, sValue, rPropSet);
    1343             :     }
    1344           0 : }
    1345             : 
    1346           0 : class XMLUserIndexMarkImportContext_Impl : public XMLIndexMarkImportContext_Impl
    1347             : {
    1348             :     const OUString sUserIndexName;
    1349             :     const OUString sLevel;
    1350             : 
    1351             : public:
    1352             :     TYPEINFO_OVERRIDE();
    1353             : 
    1354             :     XMLUserIndexMarkImportContext_Impl(
    1355             :         SvXMLImport& rImport,
    1356             :         sal_uInt16 nPrefix,
    1357             :         const OUString& rLocalName,
    1358             :         enum XMLTextPElemTokens nTok,
    1359             :         XMLHints_Impl& rHnts);
    1360             : 
    1361             : protected:
    1362             : 
    1363             :     /** process index name */
    1364             :     virtual void ProcessAttribute(sal_uInt16 nNamespace,
    1365             :                                   const OUString& sLocalName,
    1366             :                                   const OUString& sValue,
    1367             :                                   Reference<beans::XPropertySet>& rPropSet) SAL_OVERRIDE;
    1368             : };
    1369             : 
    1370           0 : TYPEINIT1( XMLUserIndexMarkImportContext_Impl, XMLIndexMarkImportContext_Impl);
    1371             : 
    1372           0 : XMLUserIndexMarkImportContext_Impl::XMLUserIndexMarkImportContext_Impl(
    1373             :     SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLocalName,
    1374             :     enum XMLTextPElemTokens nTok, XMLHints_Impl& rHnts) :
    1375             :         XMLIndexMarkImportContext_Impl(rImport, nPrefix, rLocalName,
    1376             :                                        nTok, rHnts),
    1377             :         sUserIndexName("UserIndexName"),
    1378           0 :         sLevel("Level")
    1379             : {
    1380           0 : }
    1381             : 
    1382           0 : void XMLUserIndexMarkImportContext_Impl::ProcessAttribute(
    1383             :     sal_uInt16 nNamespace, const OUString& sLocalName, const OUString& sValue,
    1384             :     Reference<beans::XPropertySet>& rPropSet)
    1385             : {
    1386           0 :     if ( XML_NAMESPACE_TEXT == nNamespace )
    1387             :     {
    1388           0 :         if ( IsXMLToken( sLocalName, XML_INDEX_NAME ) )
    1389             :         {
    1390           0 :             rPropSet->setPropertyValue(sUserIndexName, uno::makeAny(sValue));
    1391             :         }
    1392           0 :         else if ( IsXMLToken( sLocalName, XML_OUTLINE_LEVEL ) )
    1393             :         {
    1394             :             // ouline level: set Level property
    1395             :             sal_Int32 nTmp;
    1396           0 :             if (::sax::Converter::convertNumber(
    1397             :                 nTmp, sValue, 0,
    1398           0 :                GetImport().GetTextImport()->GetChapterNumbering()->getCount()))
    1399             :             {
    1400           0 :                 rPropSet->setPropertyValue(sLevel, uno::makeAny(static_cast<sal_Int16>(nTmp - 1)));
    1401             :             }
    1402             :             // else: value out of range -> ignore
    1403             :         }
    1404             :         else
    1405             :         {
    1406             :             // else: unknown text property: delegate to super class
    1407             :             XMLIndexMarkImportContext_Impl::ProcessAttribute(
    1408           0 :                 nNamespace, sLocalName, sValue, rPropSet);
    1409             :         }
    1410             :     }
    1411             :     else
    1412             :     {
    1413             :         // else: unknown namespace: delegate to super class
    1414             :         XMLIndexMarkImportContext_Impl::ProcessAttribute(
    1415           0 :             nNamespace, sLocalName, sValue, rPropSet);
    1416             :     }
    1417           0 : }
    1418             : 
    1419           0 : class XMLAlphaIndexMarkImportContext_Impl : public XMLIndexMarkImportContext_Impl
    1420             : {
    1421             :     const OUString sPrimaryKey;
    1422             :     const OUString sSecondaryKey;
    1423             :     const OUString sTextReading;
    1424             :     const OUString sPrimaryKeyReading;
    1425             :     const OUString sSecondaryKeyReading;
    1426             :     const OUString sMainEntry;
    1427             : 
    1428             : public:
    1429             :     TYPEINFO_OVERRIDE();
    1430             : 
    1431             :     XMLAlphaIndexMarkImportContext_Impl(
    1432             :         SvXMLImport& rImport,
    1433             :         sal_uInt16 nPrefix,
    1434             :         const OUString& rLocalName,
    1435             :         enum XMLTextPElemTokens nTok,
    1436             :         XMLHints_Impl& rHnts);
    1437             : 
    1438             : protected:
    1439             : 
    1440             :     /** process primary + secondary keys */
    1441             :     virtual void ProcessAttribute(sal_uInt16 nNamespace,
    1442             :                                   const OUString& sLocalName,
    1443             :                                   const OUString& sValue,
    1444             :                                   Reference<beans::XPropertySet>& rPropSet) SAL_OVERRIDE;
    1445             : };
    1446             : 
    1447           0 : TYPEINIT1( XMLAlphaIndexMarkImportContext_Impl,
    1448             :            XMLIndexMarkImportContext_Impl );
    1449             : 
    1450           0 : XMLAlphaIndexMarkImportContext_Impl::XMLAlphaIndexMarkImportContext_Impl(
    1451             :     SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLocalName,
    1452             :     enum XMLTextPElemTokens nTok, XMLHints_Impl& rHnts) :
    1453             :         XMLIndexMarkImportContext_Impl(rImport, nPrefix, rLocalName,
    1454             :                                        nTok, rHnts),
    1455             :         sPrimaryKey("PrimaryKey"),
    1456             :         sSecondaryKey("SecondaryKey"),
    1457             :         sTextReading("TextReading"),
    1458             :         sPrimaryKeyReading("PrimaryKeyReading"),
    1459             :         sSecondaryKeyReading("SecondaryKeyReading"),
    1460           0 :         sMainEntry("IsMainEntry")
    1461             : {
    1462           0 : }
    1463             : 
    1464           0 : void XMLAlphaIndexMarkImportContext_Impl::ProcessAttribute(
    1465             :     sal_uInt16 nNamespace, const OUString& sLocalName, const OUString& sValue,
    1466             :     Reference<beans::XPropertySet>& rPropSet)
    1467             : {
    1468           0 :     if (XML_NAMESPACE_TEXT == nNamespace)
    1469             :     {
    1470           0 :         if ( IsXMLToken( sLocalName, XML_KEY1 ) )
    1471             :         {
    1472           0 :             rPropSet->setPropertyValue(sPrimaryKey, uno::makeAny(sValue));
    1473             :         }
    1474           0 :         else if ( IsXMLToken( sLocalName, XML_KEY2 ) )
    1475             :         {
    1476           0 :             rPropSet->setPropertyValue(sSecondaryKey, uno::makeAny(sValue));
    1477             :         }
    1478           0 :         else if ( IsXMLToken( sLocalName, XML_KEY1_PHONETIC ) )
    1479             :         {
    1480           0 :             rPropSet->setPropertyValue(sPrimaryKeyReading, uno::makeAny(sValue));
    1481             :         }
    1482           0 :         else if ( IsXMLToken( sLocalName, XML_KEY2_PHONETIC ) )
    1483             :         {
    1484           0 :             rPropSet->setPropertyValue(sSecondaryKeyReading, uno::makeAny(sValue));
    1485             :         }
    1486           0 :         else if ( IsXMLToken( sLocalName, XML_STRING_VALUE_PHONETIC ) )
    1487             :         {
    1488           0 :             rPropSet->setPropertyValue(sTextReading, uno::makeAny(sValue));
    1489             :         }
    1490           0 :         else if ( IsXMLToken( sLocalName, XML_MAIN_ENTRY ) )
    1491             :         {
    1492           0 :             sal_Bool bMainEntry = sal_False;
    1493           0 :             bool bTmp(false);
    1494             : 
    1495           0 :             if (::sax::Converter::convertBool(bTmp, sValue))
    1496           0 :                 bMainEntry = bTmp;
    1497             : 
    1498           0 :             rPropSet->setPropertyValue(sMainEntry, uno::makeAny(bMainEntry));
    1499             :         }
    1500             :         else
    1501             :         {
    1502             :             XMLIndexMarkImportContext_Impl::ProcessAttribute(
    1503           0 :                 nNamespace, sLocalName, sValue, rPropSet);
    1504             :         }
    1505             :     }
    1506             :     else
    1507             :     {
    1508             :         XMLIndexMarkImportContext_Impl::ProcessAttribute(
    1509           0 :             nNamespace, sLocalName, sValue, rPropSet);
    1510             :     }
    1511           0 : }
    1512             : 
    1513           0 : TYPEINIT1( XMLImpSpanContext_Impl, SvXMLImportContext );
    1514             : 
    1515        3318 : XMLImpSpanContext_Impl::XMLImpSpanContext_Impl(
    1516             :         SvXMLImport& rImport,
    1517             :         sal_uInt16 nPrfx,
    1518             :         const OUString& rLName,
    1519             :         const Reference< xml::sax::XAttributeList > & xAttrList,
    1520             :         XMLHints_Impl& rHnts,
    1521             :         bool& rIgnLeadSpace,
    1522             :         sal_uInt8 nSFConvFlags
    1523             :                                               )
    1524             : :   SvXMLImportContext( rImport, nPrfx, rLName )
    1525             : ,   sTextFrame("TextFrame")
    1526             : ,   rHints( rHnts )
    1527             : ,   pHint( 0  )
    1528             : ,   rIgnoreLeadingSpace( rIgnLeadSpace )
    1529        3318 : ,   nStarFontsConvFlags( nSFConvFlags & (CONV_FROM_STAR_BATS|CONV_FROM_STAR_MATH) )
    1530             : {
    1531        3318 :     OUString aStyleName;
    1532             : 
    1533        3318 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
    1534        6636 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
    1535             :     {
    1536        3318 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
    1537             : 
    1538        6636 :         OUString aLocalName;
    1539             :         sal_uInt16 nPrefix =
    1540        3318 :             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
    1541        3318 :                                                             &aLocalName );
    1542        6636 :         if( XML_NAMESPACE_TEXT == nPrefix &&
    1543        3318 :             IsXMLToken( aLocalName, XML_STYLE_NAME ) )
    1544        3318 :             aStyleName = xAttrList->getValueByIndex( i );
    1545        3318 :     }
    1546             : 
    1547        3318 :     if( !aStyleName.isEmpty() )
    1548             :     {
    1549             :         pHint = new XMLStyleHint_Impl( aStyleName,
    1550        3318 :                   GetImport().GetTextImport()->GetCursorAsRange()->getStart() );
    1551        3318 :             rHints.push_back( pHint );
    1552        3318 :     }
    1553        3318 : }
    1554             : 
    1555        9954 : XMLImpSpanContext_Impl::~XMLImpSpanContext_Impl()
    1556             : {
    1557        3318 :     if( pHint )
    1558        3318 :         pHint->SetEnd( GetImport().GetTextImport()
    1559        3318 :                             ->GetCursorAsRange()->getStart() );
    1560        6636 : }
    1561             : 
    1562        8513 : SvXMLImportContext *XMLImpSpanContext_Impl::CreateChildContext(
    1563             :         SvXMLImport& rImport,
    1564             :         sal_uInt16 nPrefix, const OUString& rLocalName,
    1565             :         const Reference< xml::sax::XAttributeList > & xAttrList,
    1566             :         sal_uInt16 nToken,
    1567             :         XMLHints_Impl& rHints,
    1568             :         bool& rIgnoreLeadingSpace,
    1569             :         sal_uInt8 nStarFontsConvFlags
    1570             :      )
    1571             : {
    1572        8513 :     SvXMLImportContext *pContext = 0;
    1573             : 
    1574        8513 :     switch( nToken )
    1575             :     {
    1576             :     case XML_TOK_TEXT_SPAN:
    1577             :         pContext = new XMLImpSpanContext_Impl( rImport, nPrefix,
    1578             :                                                rLocalName, xAttrList,
    1579             :                                                rHints,
    1580             :                                                rIgnoreLeadingSpace
    1581             :                                                ,nStarFontsConvFlags
    1582        3318 :                                              );
    1583        3318 :         break;
    1584             : 
    1585             :     case XML_TOK_TEXT_TAB_STOP:
    1586             :         pContext = new XMLCharContext( rImport, nPrefix,
    1587             :                                                rLocalName, xAttrList,
    1588        1236 :                                                0x0009, false );
    1589        1236 :         rIgnoreLeadingSpace = false;
    1590        1236 :         break;
    1591             : 
    1592             :     case XML_TOK_TEXT_LINE_BREAK:
    1593             :         pContext = new XMLCharContext( rImport, nPrefix,
    1594             :                                                rLocalName, xAttrList,
    1595           6 :                                                ControlCharacter::LINE_BREAK );
    1596           6 :         rIgnoreLeadingSpace = false;
    1597           6 :         break;
    1598             : 
    1599             :     case XML_TOK_TEXT_S:
    1600             :         pContext = new XMLCharContext( rImport, nPrefix,
    1601             :                                                rLocalName, xAttrList,
    1602         686 :                                                0x0020, true );
    1603         686 :         break;
    1604             : 
    1605             :     case XML_TOK_TEXT_HYPERLINK:
    1606             :     {
    1607             :         // test for HyperLinkURL property. If present, insert link as
    1608             :         // text property (StarWriter), else try to insert as text
    1609             :         // field (StarCalc, StarDraw, ...)
    1610           5 :         Reference< beans::XPropertySet > xPropSet( rImport.GetTextImport()->GetCursor(), UNO_QUERY );
    1611             : 
    1612          10 :         const OUString sHyperLinkURL("HyperLinkURL");
    1613             : 
    1614           5 :         if ( xPropSet->getPropertySetInfo()->hasPropertyByName( sHyperLinkURL ) )
    1615             :         {
    1616             :             pContext = new XMLImpHyperlinkContext_Impl(
    1617             :                     rImport,
    1618             :                     nPrefix,
    1619             :                     rLocalName,
    1620             :                     xAttrList,
    1621             :                     rHints,
    1622           4 :                     rIgnoreLeadingSpace );
    1623             :         }
    1624             :         else
    1625             :         {
    1626           1 :             pContext = new XMLUrlFieldImportContext( rImport, *rImport.GetTextImport().get(), nPrefix, rLocalName );
    1627             :             //whitespace handling like other fields
    1628           1 :             rIgnoreLeadingSpace = false;
    1629             : 
    1630             :         }
    1631          10 :         break;
    1632             :     }
    1633             : 
    1634             :     case XML_TOK_TEXT_RUBY:
    1635             :         pContext = new XMLImpRubyContext_Impl( rImport, nPrefix,
    1636             :                                                rLocalName, xAttrList,
    1637             :                                                rHints,
    1638          12 :                                                rIgnoreLeadingSpace );
    1639          12 :         break;
    1640             : 
    1641             :     case XML_TOK_TEXT_NOTE:
    1642          17 :         if (rImport.GetTextImport()->IsInFrame())
    1643             :         {
    1644             :             // we must not insert footnotes into text frames
    1645             :             pContext = new SvXMLImportContext( rImport, nPrefix,
    1646           0 :                                                rLocalName );
    1647             :         }
    1648             :         else
    1649             :         {
    1650             :             pContext = new XMLFootnoteImportContext( rImport,
    1651          34 :                                                      *rImport.GetTextImport().get(),
    1652          17 :                                                      nPrefix, rLocalName );
    1653             :         }
    1654          17 :         rIgnoreLeadingSpace = false;
    1655          17 :         break;
    1656             : 
    1657             :     case XML_TOK_TEXT_REFERENCE:
    1658             :     case XML_TOK_TEXT_BOOKMARK:
    1659             :     case XML_TOK_TEXT_BOOKMARK_START:
    1660             :     case XML_TOK_TEXT_BOOKMARK_END:
    1661             :         pContext = new XMLTextMarkImportContext( rImport,
    1662        3890 :                                                  *rImport.GetTextImport().get(),
    1663        1945 :                                                  nPrefix, rLocalName );
    1664        1945 :         break;
    1665             : 
    1666             :     case XML_TOK_TEXT_FIELDMARK:
    1667             :     case XML_TOK_TEXT_FIELDMARK_START:
    1668             :     case XML_TOK_TEXT_FIELDMARK_END:
    1669             :         pContext = new XMLTextMarkImportContext( rImport,
    1670           0 :                                                  *rImport.GetTextImport().get(),
    1671           0 :                                                  nPrefix, rLocalName );
    1672           0 :         break;
    1673             : 
    1674             :     case XML_TOK_TEXT_REFERENCE_START:
    1675             :         pContext = new XMLStartReferenceContext_Impl( rImport,
    1676             :                                                       nPrefix, rLocalName,
    1677           0 :                                                       rHints, xAttrList );
    1678           0 :         break;
    1679             : 
    1680             :     case XML_TOK_TEXT_REFERENCE_END:
    1681             :         pContext = new XMLEndReferenceContext_Impl( rImport,
    1682             :                                                     nPrefix, rLocalName,
    1683           0 :                                                     rHints, xAttrList );
    1684           0 :         break;
    1685             : 
    1686             :     case XML_TOK_TEXT_FRAME:
    1687             :         {
    1688             :             Reference < XTextRange > xAnchorPos =
    1689         113 :                 rImport.GetTextImport()->GetCursor()->getStart();
    1690             :             XMLTextFrameContext *pTextFrameContext =
    1691             :                 new XMLTextFrameContext( rImport, nPrefix,
    1692             :                                          rLocalName, xAttrList,
    1693         113 :                                          TextContentAnchorType_AS_CHARACTER );
    1694             :             // Remove check for text content. (#i33242#)
    1695             :             // Check for text content is done on the processing of the hint
    1696         113 :             if( TextContentAnchorType_AT_CHARACTER ==
    1697         113 :                                             pTextFrameContext->GetAnchorType() )
    1698             :             {
    1699             :                 rHints.push_back( new XMLTextFrameHint_Impl(
    1700           8 :                     pTextFrameContext, xAnchorPos ) );
    1701             :             }
    1702         113 :             pContext = pTextFrameContext;
    1703         113 :             rIgnoreLeadingSpace = false;
    1704             :         }
    1705         113 :         break;
    1706             :     case XML_TOK_DRAW_A:
    1707             :         {
    1708           0 :             Reference < XTextRange > xAnchorPos(rImport.GetTextImport()->GetCursor()->getStart());
    1709             :             pContext =
    1710             :                 new XMLTextFrameHyperlinkContext( rImport, nPrefix,
    1711             :                                         rLocalName, xAttrList,
    1712           0 :                                         TextContentAnchorType_AS_CHARACTER );
    1713             :             XMLTextFrameHint_Impl *pHint =
    1714           0 :                 new XMLTextFrameHint_Impl( pContext, xAnchorPos);
    1715           0 :             rHints.push_back( pHint );
    1716             :         }
    1717           0 :         break;
    1718             : 
    1719             :     case XML_TOK_TEXT_TOC_MARK:
    1720             :     case XML_TOK_TEXT_TOC_MARK_START:
    1721             :         pContext = new XMLTOCMarkImportContext_Impl(
    1722             :             rImport, nPrefix, rLocalName,
    1723           0 :             (enum XMLTextPElemTokens)nToken, rHints);
    1724           0 :         break;
    1725             : 
    1726             :     case XML_TOK_TEXT_USER_INDEX_MARK:
    1727             :     case XML_TOK_TEXT_USER_INDEX_MARK_START:
    1728             :         pContext = new XMLUserIndexMarkImportContext_Impl(
    1729             :             rImport, nPrefix, rLocalName,
    1730           0 :             (enum XMLTextPElemTokens)nToken, rHints);
    1731           0 :         break;
    1732             : 
    1733             :     case XML_TOK_TEXT_ALPHA_INDEX_MARK:
    1734             :     case XML_TOK_TEXT_ALPHA_INDEX_MARK_START:
    1735             :         pContext = new XMLAlphaIndexMarkImportContext_Impl(
    1736             :             rImport, nPrefix, rLocalName,
    1737           0 :             (enum XMLTextPElemTokens)nToken, rHints);
    1738           0 :         break;
    1739             : 
    1740             :     case XML_TOK_TEXT_TOC_MARK_END:
    1741             :     case XML_TOK_TEXT_USER_INDEX_MARK_END:
    1742             :     case XML_TOK_TEXT_ALPHA_INDEX_MARK_END:
    1743             :         pContext = new XMLIndexMarkImportContext_Impl(
    1744             :             rImport, nPrefix, rLocalName, (enum XMLTextPElemTokens)nToken,
    1745           0 :             rHints);
    1746           0 :         break;
    1747             : 
    1748             :     case XML_TOK_TEXTP_CHANGE_START:
    1749             :     case XML_TOK_TEXTP_CHANGE_END:
    1750             :     case XML_TOK_TEXTP_CHANGE:
    1751             :         pContext = new XMLChangeImportContext(
    1752             :             rImport, nPrefix, rLocalName,
    1753             :             (nToken != XML_TOK_TEXTP_CHANGE_END),
    1754             :             (nToken != XML_TOK_TEXTP_CHANGE_START),
    1755           5 :             sal_False);
    1756           5 :         break;
    1757             : 
    1758             :     case XML_TOK_TEXT_META:
    1759             :         pContext = new XMLMetaImportContext(rImport, nPrefix, rLocalName,
    1760          19 :             rHints, rIgnoreLeadingSpace );
    1761          19 :         break;
    1762             : 
    1763             :     case XML_TOK_TEXT_META_FIELD:
    1764             :         pContext = new XMLMetaFieldImportContext(rImport, nPrefix, rLocalName,
    1765          21 :             rHints, rIgnoreLeadingSpace );
    1766          21 :         break;
    1767             : 
    1768             :     default:
    1769             :         // none of the above? then it's probably  a text field!
    1770             :         pContext =
    1771             :             XMLTextFieldImportContext::CreateTextFieldImportContext(
    1772        2260 :                 rImport, *rImport.GetTextImport().get(), nPrefix, rLocalName,
    1773        2260 :                 nToken);
    1774             :         // #108784# import draw elements (except control shapes in headers)
    1775        3446 :         if( pContext == NULL &&
    1776        1214 :             !( rImport.GetTextImport()->IsInHeaderFooter() &&
    1777             :                nPrefix == XML_NAMESPACE_DRAW &&
    1778           0 :                IsXMLToken( rLocalName, XML_CONTROL ) ) )
    1779             :         {
    1780          28 :             Reference < XShapes > xShapes;
    1781             :             SvXMLShapeContext* pShapeContext = rImport.GetShapeImport()->CreateGroupChildContext(
    1782          28 :                 rImport, nPrefix, rLocalName, xAttrList, xShapes );
    1783          28 :             pContext = pShapeContext;
    1784             :             // OD 2004-04-20 #i26791# - keep shape in a text frame hint to
    1785             :             // adjust its anchor position, if its at-character anchored
    1786             :             Reference < XTextRange > xAnchorPos =
    1787          56 :                 rImport.GetTextImport()->GetCursor()->getStart();
    1788          56 :             rHints.push_back( new XMLDrawHint_Impl( pShapeContext, xAnchorPos ) );
    1789             :         }
    1790        1130 :         if( !pContext )
    1791             :         {
    1792             :             // ignore unknown content
    1793             :             pContext =
    1794           0 :                 new SvXMLImportContext( rImport, nPrefix, rLocalName );
    1795             :         }
    1796             :         // Behind fields, shapes and any unknown content blanks aren't ignored
    1797        1130 :         rIgnoreLeadingSpace = false;
    1798             :     }
    1799             : 
    1800        8513 :     return pContext;
    1801             : }
    1802             : 
    1803        2065 : SvXMLImportContext *XMLImpSpanContext_Impl::CreateChildContext(
    1804             :         sal_uInt16 nPrefix, const OUString& rLocalName,
    1805             :         const Reference< xml::sax::XAttributeList > & xAttrList )
    1806             : {
    1807             :     const SvXMLTokenMap& rTokenMap =
    1808        2065 :         GetImport().GetTextImport()->GetTextPElemTokenMap();
    1809        2065 :     sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName );
    1810             : 
    1811        2065 :     return CreateChildContext( GetImport(), nPrefix, rLocalName, xAttrList,
    1812             :                                nToken, rHints, rIgnoreLeadingSpace
    1813             :                                ,nStarFontsConvFlags
    1814        4130 :                              );
    1815             : }
    1816             : 
    1817        2920 : void XMLImpSpanContext_Impl::Characters( const OUString& rChars )
    1818             : {
    1819        2920 :     OUString sStyleName;
    1820        2920 :     if( pHint )
    1821        2920 :         sStyleName = pHint->GetStyleName();
    1822             :     OUString sChars =
    1823        2920 :         GetImport().GetTextImport()->ConvertStarFonts( rChars, sStyleName,
    1824             :                                                        nStarFontsConvFlags,
    1825        8760 :                                                        false, GetImport() );
    1826        5840 :     GetImport().GetTextImport()->InsertString( sChars, rIgnoreLeadingSpace );
    1827        2920 : }
    1828             : 
    1829           0 : TYPEINIT1( XMLParaContext, SvXMLImportContext );
    1830             : 
    1831        3692 : XMLParaContext::XMLParaContext(
    1832             :         SvXMLImport& rImport,
    1833             :         sal_uInt16 nPrfx,
    1834             :         const OUString& rLName,
    1835             :         const Reference< xml::sax::XAttributeList > & xAttrList,
    1836             :         bool bHead ) :
    1837             :     SvXMLImportContext( rImport, nPrfx, rLName ),
    1838        7384 :     xStart( rImport.GetTextImport()->GetCursorAsRange()->getStart() ),
    1839             :     m_bHaveAbout(false),
    1840        3692 :     nOutlineLevel( IsXMLToken( rLName, XML_H ) ? 1 : -1 ),
    1841             :     pHints( 0 ),
    1842             :     // Lost outline numbering in master document (#i73509#)
    1843             :     mbOutlineLevelAttrFound( sal_False ),
    1844             :     bIgnoreLeadingSpace( true ),
    1845             :     bHeading( bHead ),
    1846             :     bIsListHeader( false ),
    1847             :     bIsRestart (false),
    1848             :     nStartValue(0),
    1849       14768 :     nStarFontsConvFlags( 0 )
    1850             : {
    1851             :     const SvXMLTokenMap& rTokenMap =
    1852        3692 :         GetImport().GetTextImport()->GetTextPAttrTokenMap();
    1853             : 
    1854        3692 :     bool bHaveXmlId( false );
    1855        7384 :     OUString aCondStyleName, sClassNames;
    1856             : 
    1857        3692 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
    1858        6785 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
    1859             :     {
    1860        3093 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
    1861        6186 :         const OUString& rValue = xAttrList->getValueByIndex( i );
    1862             : 
    1863        6186 :         OUString aLocalName;
    1864             :         sal_uInt16 nPrefix =
    1865        3093 :             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
    1866        3093 :                                                             &aLocalName );
    1867        3093 :         switch( rTokenMap.Get( nPrefix, aLocalName ) )
    1868             :         {
    1869             :         case XML_TOK_TEXT_P_XMLID:
    1870          15 :             m_sXmlId = rValue;
    1871          15 :             bHaveXmlId = true;
    1872          15 :             break;
    1873             :         case XML_TOK_TEXT_P_ABOUT:
    1874          34 :             m_sAbout = rValue;
    1875          34 :             m_bHaveAbout = true;
    1876          34 :             break;
    1877             :         case XML_TOK_TEXT_P_PROPERTY:
    1878          34 :             m_sProperty = rValue;
    1879          34 :             break;
    1880             :         case XML_TOK_TEXT_P_CONTENT:
    1881          10 :             m_sContent = rValue;
    1882          10 :             break;
    1883             :         case XML_TOK_TEXT_P_DATATYPE:
    1884           7 :             m_sDatatype = rValue;
    1885           7 :             break;
    1886             :         case XML_TOK_TEXT_P_TEXTID:
    1887           0 :             if (!bHaveXmlId) { m_sXmlId = rValue; }
    1888           0 :             break;
    1889             :         case XML_TOK_TEXT_P_STYLE_NAME:
    1890        2920 :             sStyleName = rValue;
    1891        2920 :             break;
    1892             :         case XML_TOK_TEXT_P_CLASS_NAMES:
    1893           0 :             sClassNames = rValue;
    1894           0 :             break;
    1895             :         case XML_TOK_TEXT_P_COND_STYLE_NAME:
    1896           0 :             aCondStyleName = rValue;
    1897           0 :             break;
    1898             :         case XML_TOK_TEXT_P_LEVEL:
    1899             :             {
    1900          38 :                 sal_Int32 nTmp = rValue.toInt32();
    1901          38 :                 if( nTmp > 0L )
    1902             :                 {
    1903          38 :                     if( nTmp > 127 )
    1904           0 :                         nTmp = 127;
    1905          38 :                     nOutlineLevel = (sal_Int8)nTmp;
    1906             :                 }
    1907             :                 // Lost outline numbering in master document (#i73509#)
    1908          38 :                 mbOutlineLevelAttrFound = sal_True;
    1909             :             }
    1910          38 :             break;
    1911             :         case XML_TOK_TEXT_P_IS_LIST_HEADER:
    1912             :             {
    1913           0 :                 bool bBool(false);
    1914           0 :                 if( ::sax::Converter::convertBool( bBool, rValue ) )
    1915             :                 {
    1916           0 :                     bIsListHeader = bBool;
    1917             :                 }
    1918             :             }
    1919           0 :             break;
    1920             :         case XML_TOK_TEXT_P_RESTART_NUMBERING:
    1921             :             {
    1922           1 :                 bool bBool(false);
    1923           1 :                 if (::sax::Converter::convertBool(bBool, rValue))
    1924             :                 {
    1925           1 :                     bIsRestart = bBool;
    1926             :                 }
    1927             :             }
    1928           1 :             break;
    1929             :         case XML_TOK_TEXT_P_START_VALUE:
    1930             :             {
    1931             :                 nStartValue = sal::static_int_cast< sal_Int16 >(
    1932           1 :                     rValue.toInt32());
    1933             :             }
    1934           1 :             break;
    1935             :         }
    1936        3093 :     }
    1937             : 
    1938        3692 :     if( !aCondStyleName.isEmpty() )
    1939           0 :         sStyleName = aCondStyleName;
    1940        3692 :     else if( !sClassNames.isEmpty() )
    1941             :     {
    1942           0 :         sal_Int32 nDummy = 0;
    1943           0 :         sStyleName = sClassNames.getToken( 0, ' ', nDummy );
    1944        3692 :     }
    1945        3692 : }
    1946             : 
    1947       11076 : XMLParaContext::~XMLParaContext()
    1948             : {
    1949             :     UniReference < XMLTextImportHelper > xTxtImport(
    1950        3692 :         GetImport().GetTextImport());
    1951        7383 :     Reference < XTextRange > xCrsrRange( xTxtImport->GetCursorAsRange() );
    1952        3692 :     if( !xCrsrRange.is() )
    1953           0 :         return; // Robust (defect file)
    1954        7383 :     Reference < XTextRange > xEnd(xCrsrRange->getStart());
    1955             : 
    1956             :     // if we have an id set for this paragraph, get a cursor for this
    1957             :     // paragraph and register it with the given identifier
    1958             :     // FIXME: this is just temporary, and should be removed when
    1959             :     // EditEngine paragraphs implement XMetadatable!
    1960        3692 :     if (!m_sXmlId.isEmpty())
    1961             :     {
    1962          15 :         Reference < XTextCursor > xIdCursor( xTxtImport->GetText()->createTextCursorByRange( xStart ) );
    1963          15 :         if( xIdCursor.is() )
    1964             :         {
    1965          15 :             xIdCursor->gotoRange( xEnd, sal_True );
    1966          15 :             GetImport().getInterfaceToIdentifierMapper().registerReference(
    1967          30 :                 m_sXmlId, xIdCursor);
    1968          15 :         }
    1969             :     }
    1970             : 
    1971             :     // insert a paragraph break
    1972        3692 :     xTxtImport->InsertControlCharacter( ControlCharacter::APPEND_PARAGRAPH );
    1973             : 
    1974             :     // create a cursor that select the whole last paragraph
    1975        7383 :     Reference < XTextCursor > xAttrCursor;
    1976             :     try {
    1977        3692 :         xAttrCursor = xTxtImport->GetText()->createTextCursorByRange( xStart );
    1978        3692 :         if( !xAttrCursor.is() )
    1979           1 :             return; // Robust (defect file)
    1980           0 :     } catch (const uno::Exception &) {
    1981             :         // createTextCursorByRange() likes to throw runtime exception, even
    1982             :         // though it just means 'we were unable to create the cursor'
    1983           0 :         return;
    1984             :     }
    1985        3691 :     xAttrCursor->gotoRange( xEnd, sal_True );
    1986             : 
    1987             :     // xml:id for RDF metadata
    1988        3691 :     if (!m_sXmlId.isEmpty() || m_bHaveAbout || !m_sProperty.isEmpty())
    1989             :     {
    1990             :         try {
    1991             :             const uno::Reference<container::XEnumerationAccess> xEA
    1992          36 :                 (xAttrCursor, uno::UNO_QUERY_THROW);
    1993             :             const uno::Reference<container::XEnumeration> xEnum(
    1994          72 :                 xEA->createEnumeration(), uno::UNO_QUERY_THROW);
    1995             :             SAL_WARN_IF(!xEnum->hasMoreElements(), "xmloff.text", "xml:id: no paragraph?");
    1996          36 :             if (xEnum->hasMoreElements()) {
    1997          36 :                 uno::Reference<rdf::XMetadatable> xMeta;
    1998          36 :                 xEnum->nextElement() >>= xMeta;
    1999             :                 SAL_WARN_IF(!xMeta.is(), "xmloff.text", "xml:id: not XMetadatable");
    2000          36 :                 GetImport().SetXmlId(xMeta, m_sXmlId);
    2001          36 :                 if (m_bHaveAbout)
    2002             :                 {
    2003          34 :                     GetImport().AddRDFa(xMeta,
    2004          68 :                         m_sAbout, m_sProperty, m_sContent, m_sDatatype);
    2005             :                 }
    2006          36 :                 SAL_WARN_IF(xEnum->hasMoreElements(), "xmloff.text", "xml:id: > 1 paragraph?");
    2007          36 :             }
    2008           0 :         } catch (const uno::Exception &) {
    2009             :             SAL_INFO("xmloff.text", "XMLParaContext::~XMLParaContext: exception");
    2010             :         }
    2011             :     }
    2012             : 
    2013        7382 :     OUString const sCellParaStyleName(xTxtImport->GetCellParaStyleDefault());
    2014        3691 :     if( !sCellParaStyleName.isEmpty() )
    2015             :     {
    2016             :         /* Suppress handling of outline and list attributes,
    2017             :            because of side effects of method <SetStyleAndAttrs(..)> (#i80724#)
    2018             :         */
    2019         266 :         xTxtImport->SetStyleAndAttrs( GetImport(), xAttrCursor,
    2020             :                                       sCellParaStyleName,
    2021             :                                       true,
    2022             :                                       false, -1, // suppress outline handling
    2023         266 :                                       false );   // suppress list attributes handling
    2024             :     }
    2025             : 
    2026             :     // #103445# for headings without style name, find the proper style
    2027        3691 :     if( bHeading && sStyleName.isEmpty() )
    2028           0 :         xTxtImport->FindOutlineStyleName( sStyleName, nOutlineLevel );
    2029             : 
    2030             :     // set style and hard attributes at the previous paragraph
    2031             :     // Add paramter <mbOutlineLevelAttrFound> (#i73509#)
    2032        7382 :     sStyleName = xTxtImport->SetStyleAndAttrs( GetImport(), xAttrCursor,
    2033             :                                                sStyleName,
    2034             :                                                true,
    2035             :                                                mbOutlineLevelAttrFound,
    2036        3691 :                                                bHeading ? nOutlineLevel : -1 );
    2037             : 
    2038             :     // handle list style header
    2039        3691 :     if (bHeading && (bIsListHeader || bIsRestart))
    2040             :     {
    2041           1 :         Reference<XPropertySet> xPropSet( xAttrCursor, UNO_QUERY );
    2042             : 
    2043           1 :         if (xPropSet.is())
    2044             :         {
    2045           1 :             if (bIsListHeader)
    2046             :             {
    2047             :                 OUString sNumberingIsNumber
    2048           0 :                     ("NumberingIsNumber");
    2049           0 :                 if(xPropSet->getPropertySetInfo()->
    2050           0 :                    hasPropertyByName(sNumberingIsNumber))
    2051             :                 {
    2052           0 :                     xPropSet->setPropertyValue
    2053           0 :                         (sNumberingIsNumber, makeAny( false ) );
    2054           0 :                 }
    2055             :             }
    2056           1 :             if (bIsRestart)
    2057             :             {
    2058             :                 OUString sParaIsNumberingRestart
    2059           1 :                     ("ParaIsNumberingRestart");
    2060             :                 OUString sNumberingStartValue
    2061           2 :                     ("NumberingStartValue");
    2062           2 :                 if (xPropSet->getPropertySetInfo()->
    2063           1 :                     hasPropertyByName(sParaIsNumberingRestart))
    2064             :                 {
    2065           1 :                     xPropSet->setPropertyValue
    2066           1 :                         (sParaIsNumberingRestart, makeAny(true));
    2067             :                 }
    2068             : 
    2069           2 :                 if (xPropSet->getPropertySetInfo()->
    2070           1 :                     hasPropertyByName(sNumberingStartValue))
    2071             :                 {
    2072           1 :                     xPropSet->setPropertyValue
    2073           1 :                         (sNumberingStartValue, makeAny(nStartValue));
    2074           1 :                 }
    2075             :             }
    2076             : 
    2077           1 :         }
    2078             :     }
    2079             : 
    2080        3691 :     if( pHints && !pHints->empty() )
    2081             :     {
    2082        5313 :         for( sal_uInt16 i=0; i<pHints->size(); i++ )
    2083             :         {
    2084        3357 :             XMLHint_Impl *pHint = &(*pHints)[i];
    2085        3357 :             xAttrCursor->gotoRange( pHint->GetStart(), sal_False );
    2086        3357 :             xAttrCursor->gotoRange( pHint->GetEnd(), sal_True );
    2087        3357 :             switch( pHint->GetType() )
    2088             :             {
    2089             :             case XML_HINT_STYLE:
    2090             :                 {
    2091             :                     const OUString& rStyleName =
    2092        3317 :                             ((XMLStyleHint_Impl *)pHint)->GetStyleName();
    2093        3317 :                     if( !rStyleName.isEmpty() )
    2094        3317 :                         xTxtImport->SetStyleAndAttrs( GetImport(),
    2095             :                                                       xAttrCursor, rStyleName,
    2096        3317 :                                                       false );
    2097             :                 }
    2098        3317 :                 break;
    2099             :             case XML_HINT_REFERENCE:
    2100             :                 {
    2101             :                     const OUString& rRefName =
    2102           0 :                             ((XMLReferenceHint_Impl *)pHint)->GetRefName();
    2103           0 :                     if( !rRefName.isEmpty() )
    2104             :                     {
    2105           0 :                         if( !pHint->GetEnd().is() )
    2106           0 :                             pHint->SetEnd(xEnd);
    2107             : 
    2108             :                         // reference name uses rStyleName member
    2109             :                         // borrow from XMLTextMarkImportContext
    2110             :                         XMLTextMarkImportContext::CreateAndInsertMark(
    2111           0 :                             GetImport(),
    2112             :                             OUString( "com.sun.star.text.ReferenceMark"),
    2113             :                             rRefName,
    2114           0 :                             xAttrCursor);
    2115             :                     }
    2116             :                 }
    2117           0 :                 break;
    2118             :             case XML_HINT_HYPERLINK:
    2119             :                 {
    2120             :                     const XMLHyperlinkHint_Impl *pHHint =
    2121           4 :                         (const XMLHyperlinkHint_Impl *)pHint;
    2122           4 :                     xTxtImport->SetHyperlink( GetImport(),
    2123             :                                               xAttrCursor,
    2124           4 :                                               pHHint->GetHRef(),
    2125           4 :                                               pHHint->GetName(),
    2126           4 :                                               pHHint->GetTargetFrameName(),
    2127           4 :                                               pHHint->GetStyleName(),
    2128           4 :                                               pHHint->GetVisitedStyleName(),
    2129           8 :                                               pHHint->GetEventsContext() );
    2130             :                 }
    2131           4 :                 break;
    2132             :             case XML_HINT_INDEX_MARK:
    2133             :                 {
    2134             :                     Reference<beans::XPropertySet> xMark(
    2135           0 :                         ((const XMLIndexMarkHint_Impl *)pHint)->GetMark());
    2136           0 :                     Reference<XTextContent> xContent(xMark, UNO_QUERY);
    2137           0 :                     xTxtImport->GetText()->insertTextContent(
    2138           0 :                         xAttrCursor, xContent, sal_True );
    2139             :                 }
    2140           0 :                 break;
    2141             :             case XML_HINT_TEXT_FRAME:
    2142             :                 {
    2143             :                     const XMLTextFrameHint_Impl *pFHint =
    2144           8 :                         (const XMLTextFrameHint_Impl *)pHint;
    2145             :                     // Check for text content (#i33242#)
    2146             :                     Reference < XTextContent > xTextContent =
    2147           8 :                                                     pFHint->GetTextContent();
    2148           8 :                     if ( xTextContent.is() )
    2149             :                     {
    2150             :                         /* Core impl. of the unification of drawing objects and
    2151             :                            Writer fly frames (#i26791#)
    2152             :                         */
    2153           8 :                         if ( pFHint->IsBoundAtChar() )
    2154             :                         {
    2155           8 :                             xTextContent->attach( xAttrCursor );
    2156             :                         }
    2157             :                     }
    2158             :                     /* Consider, that hint can also contain a shape -
    2159             :                        e.g. drawing object of type 'Text'. (#i33242#)
    2160             :                     */
    2161             :                     else
    2162             :                     {
    2163           0 :                         Reference < XShape > xShape = pFHint->GetShape();
    2164           0 :                         if ( xShape.is() )
    2165             :                         {
    2166             :                             // determine anchor type
    2167           0 :                             Reference < XPropertySet > xPropSet( xShape, UNO_QUERY );
    2168             :                             TextContentAnchorType eAnchorType =
    2169           0 :                                             TextContentAnchorType_AT_PARAGRAPH;
    2170             :                             {
    2171           0 :                                 OUString sAnchorType( "AnchorType"  );
    2172           0 :                                 Any aAny = xPropSet->getPropertyValue( sAnchorType );
    2173           0 :                                 aAny >>= eAnchorType;
    2174             :                             }
    2175           0 :                             if ( TextContentAnchorType_AT_CHARACTER == eAnchorType )
    2176             :                             {
    2177             :                                 // set anchor position for at-character anchored objects
    2178           0 :                                 Reference<XTextRange> xRange(xAttrCursor, UNO_QUERY);
    2179           0 :                                 Any aPos;
    2180           0 :                                 aPos <<= xRange;
    2181           0 :                                 OUString sTextRange( "TextRange"  );
    2182           0 :                                 xPropSet->setPropertyValue(sTextRange, aPos);
    2183           0 :                             }
    2184           0 :                         }
    2185           8 :                     }
    2186             :                 }
    2187           8 :                 break;
    2188             :             /* Core impl. of the unification of drawing objects and
    2189             :                Writer fly frames (#i26791#)
    2190             :             */
    2191             :             case XML_HINT_DRAW:
    2192             :                 {
    2193             :                     const XMLDrawHint_Impl *pDHint =
    2194          28 :                         static_cast<const XMLDrawHint_Impl*>(pHint);
    2195             :                     // Improvement: hint directly provides the shape. (#i33242#)
    2196          28 :                     Reference < XShape > xShape = pDHint->GetShape();
    2197          28 :                     if ( xShape.is() )
    2198             :                     {
    2199             :                         // determine anchor type
    2200          18 :                         Reference < XPropertySet > xPropSet( xShape, UNO_QUERY );
    2201          18 :                         TextContentAnchorType eAnchorType = TextContentAnchorType_AT_PARAGRAPH;
    2202             :                         {
    2203          18 :                             OUString sAnchorType( "AnchorType"  );
    2204          36 :                             Any aAny = xPropSet->getPropertyValue( sAnchorType );
    2205          36 :                             aAny >>= eAnchorType;
    2206             :                         }
    2207          18 :                         if ( TextContentAnchorType_AT_CHARACTER == eAnchorType )
    2208             :                         {
    2209             :                             // set anchor position for at-character anchored objects
    2210           0 :                             Reference<XTextRange> xRange(xAttrCursor, UNO_QUERY);
    2211           0 :                             Any aPos;
    2212           0 :                             aPos <<= xRange;
    2213           0 :                             OUString sTextRange( "TextRange"  );
    2214           0 :                             xPropSet->setPropertyValue(sTextRange, aPos);
    2215          18 :                         }
    2216          28 :                     }
    2217             :                 }
    2218          28 :                 break;
    2219             :             default:
    2220             :                 SAL_WARN( "xmloff.text", "What's this" );
    2221           0 :                 break;
    2222             :             }
    2223             :         }
    2224             :     }
    2225        7382 :     delete pHints;
    2226        7383 : }
    2227             : 
    2228        6426 : SvXMLImportContext *XMLParaContext::CreateChildContext(
    2229             :         sal_uInt16 nPrefix, const OUString& rLocalName,
    2230             :         const Reference< xml::sax::XAttributeList > & xAttrList )
    2231             : {
    2232             :     const SvXMLTokenMap& rTokenMap =
    2233        6426 :         GetImport().GetTextImport()->GetTextPElemTokenMap();
    2234        6426 :     sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName );
    2235        6426 :     if( !pHints )
    2236        2705 :         pHints = new XMLHints_Impl;
    2237             :     return XMLImpSpanContext_Impl::CreateChildContext(
    2238        6426 :                                 GetImport(), nPrefix, rLocalName, xAttrList,
    2239             :                                    nToken, *pHints, bIgnoreLeadingSpace
    2240             :                                 , nStarFontsConvFlags
    2241       12852 :                                                      );
    2242             : }
    2243             : 
    2244        3195 : void XMLParaContext::Characters( const OUString& rChars )
    2245             : {
    2246             :     OUString sChars =
    2247        3195 :         GetImport().GetTextImport()->ConvertStarFonts( rChars, sStyleName,
    2248             :                                                        nStarFontsConvFlags,
    2249        6390 :                                                        true, GetImport() );
    2250        3195 :     GetImport().GetTextImport()->InsertString( sChars, bIgnoreLeadingSpace );
    2251        3195 : }
    2252             : 
    2253           0 : TYPEINIT1( XMLNumberedParaContext, SvXMLImportContext );
    2254             : 
    2255           0 : XMLNumberedParaContext::XMLNumberedParaContext(
    2256             :         SvXMLImport& i_rImport,
    2257             :         sal_uInt16 i_nPrefix,
    2258             :         const OUString& i_rLocalName,
    2259             :         const Reference< xml::sax::XAttributeList > & i_xAttrList ) :
    2260             :     SvXMLImportContext( i_rImport, i_nPrefix, i_rLocalName ),
    2261             :     m_Level(0),
    2262             :     m_StartValue(-1),
    2263             :     m_ListId(),
    2264           0 :     m_xNumRules()
    2265             : {
    2266           0 :     OUString StyleName;
    2267             : 
    2268             :     const SvXMLTokenMap& rTokenMap(
    2269           0 :         i_rImport.GetTextImport()->GetTextNumberedParagraphAttrTokenMap() );
    2270             : 
    2271           0 :     const sal_Int16 nAttrCount( i_xAttrList.is() ?
    2272           0 :         i_xAttrList->getLength() : 0 );
    2273           0 :     for ( sal_Int16 i=0; i < nAttrCount; i++ )
    2274             :     {
    2275           0 :         const OUString& rAttrName( i_xAttrList->getNameByIndex( i )  );
    2276           0 :         const OUString& rValue   ( i_xAttrList->getValueByIndex( i ) );
    2277             : 
    2278           0 :         OUString aLocalName;
    2279             :         const sal_uInt16 nPrefix(
    2280           0 :             GetImport().GetNamespaceMap().GetKeyByAttrName(
    2281           0 :                 rAttrName, &aLocalName ) );
    2282           0 :         switch( rTokenMap.Get( nPrefix, aLocalName ) )
    2283             :         {
    2284             :             case XML_TOK_TEXT_NUMBERED_PARAGRAPH_XMLID:
    2285           0 :                 m_XmlId = rValue;
    2286             : //FIXME: there is no UNO API for lists
    2287           0 :                 break;
    2288             :             case XML_TOK_TEXT_NUMBERED_PARAGRAPH_LIST_ID:
    2289           0 :                 m_ListId = rValue;
    2290           0 :                 break;
    2291             :             case XML_TOK_TEXT_NUMBERED_PARAGRAPH_LEVEL:
    2292             :                 {
    2293           0 :                     sal_Int32 nTmp = rValue.toInt32();
    2294           0 :                     if ( nTmp >= 1 && nTmp <= SHRT_MAX ) {
    2295           0 :                         m_Level = static_cast<sal_uInt16>(nTmp) - 1;
    2296             :                     }
    2297             :                 }
    2298           0 :                 break;
    2299             :             case XML_TOK_TEXT_NUMBERED_PARAGRAPH_STYLE_NAME:
    2300           0 :                 StyleName = rValue;
    2301           0 :                 break;
    2302             :             case XML_TOK_TEXT_NUMBERED_PARAGRAPH_CONTINUE_NUMBERING:
    2303             :                 // this attribute is deprecated
    2304             : //                ContinuteNumbering = IsXMLToken(rValue, XML_TRUE);
    2305           0 :                 break;
    2306             :             case XML_TOK_TEXT_NUMBERED_PARAGRAPH_START_VALUE:
    2307             :                 {
    2308           0 :                     sal_Int32 nTmp = rValue.toInt32();
    2309           0 :                     if ( nTmp >= 0 && nTmp <= SHRT_MAX ) {
    2310           0 :                         m_StartValue = static_cast<sal_Int16>(nTmp);
    2311             :                     }
    2312             :                 }
    2313           0 :                 break;
    2314             :         }
    2315           0 :     }
    2316             : 
    2317             :     XMLTextListsHelper& rTextListsHelper(
    2318           0 :         i_rImport.GetTextImport()->GetTextListHelper() );
    2319           0 :     if (m_ListId.isEmpty())
    2320             :       {
    2321             :         SAL_WARN_IF( i_rImport.GetODFVersion() == "1.2", "xmloff.text", "invalid numbered-paragraph: no list-id (1.2)" );
    2322           0 :         m_ListId = rTextListsHelper.GetNumberedParagraphListId(m_Level,
    2323           0 :             StyleName);
    2324             :         SAL_WARN_IF(m_ListId.isEmpty(), "xmloff.text", "numbered-paragraph: no ListId");
    2325           0 :         if (m_ListId.isEmpty()) {
    2326           0 :             return;
    2327             :         }
    2328             :     }
    2329           0 :     m_xNumRules = rTextListsHelper.EnsureNumberedParagraph( i_rImport,
    2330           0 :         m_ListId, m_Level, StyleName);
    2331             : 
    2332             :     SAL_WARN_IF(!m_xNumRules.is(), "xmloff.text", "numbered-paragraph: no NumRules");
    2333             : 
    2334           0 :     i_rImport.GetTextImport()->GetTextListHelper().PushListContext( this );
    2335             : }
    2336             : 
    2337           0 : XMLNumberedParaContext::~XMLNumberedParaContext()
    2338             : {
    2339           0 : }
    2340             : 
    2341           0 : void XMLNumberedParaContext::EndElement()
    2342             : {
    2343           0 :     if (!m_ListId.isEmpty()) {
    2344           0 :         GetImport().GetTextImport()->PopListContext();
    2345             :     }
    2346           0 : }
    2347             : 
    2348           0 : SvXMLImportContext *XMLNumberedParaContext::CreateChildContext(
    2349             :     sal_uInt16 i_nPrefix, const OUString& i_rLocalName,
    2350             :     const Reference< xml::sax::XAttributeList > & i_xAttrList )
    2351             : {
    2352           0 :     SvXMLImportContext *pContext( 0 );
    2353             : 
    2354           0 :     if ( XML_NAMESPACE_TEXT == i_nPrefix )
    2355             :     {
    2356           0 :         bool bIsHeader( IsXMLToken( i_rLocalName, XML_H ) );
    2357           0 :         if ( bIsHeader || IsXMLToken( i_rLocalName, XML_P ) )
    2358             :         {
    2359           0 :             pContext = new XMLParaContext( GetImport(),
    2360           0 :                 i_nPrefix, i_rLocalName, i_xAttrList, bIsHeader );
    2361             : // ignore text:number       } else if (IsXMLToken( i_rLocalName, XML_NUMBER )) {
    2362             :         }
    2363             :     }
    2364             : 
    2365           0 :     if (!pContext) {
    2366             :         pContext = SvXMLImportContext::CreateChildContext(
    2367           0 :             i_nPrefix, i_rLocalName, i_xAttrList );
    2368             :     }
    2369             : 
    2370           0 :     return pContext;
    2371             : }
    2372             : 
    2373             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10