LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/core/swg - SwXMLBlockListContext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 82 101 81.2 %
Date: 2013-07-09 Functions: 21 25 84.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 <SwXMLBlockListContext.hxx>
      21             : #include <SwXMLBlockImport.hxx>
      22             : #include <SwXMLTextBlocks.hxx>
      23             : #include <xmloff/nmspmap.hxx>
      24             : #include <xmloff/xmlnmspe.hxx>
      25             : #include <unotools/charclass.hxx>
      26             : #include <swtypes.hxx>
      27             : 
      28             : using namespace ::com::sun::star::uno;
      29             : using namespace ::com::sun::star;
      30             : using namespace ::xmloff::token;
      31             : 
      32          57 : SwXMLBlockListContext::SwXMLBlockListContext(
      33             :    SwXMLBlockListImport& rImport,
      34             :    sal_uInt16 nPrefix,
      35             :    const OUString& rLocalName,
      36             :    const uno::Reference<
      37             :    xml::sax::XAttributeList > & xAttrList ) :
      38             :     SvXMLImportContext ( rImport, nPrefix, rLocalName ),
      39          57 :     rLocalRef (rImport)
      40             : {
      41          57 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      42         114 :     for (sal_Int16 i=0; i < nAttrCount; i++)
      43             :     {
      44         114 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
      45         171 :         OUString aLocalName;
      46         114 :         sal_uInt16 nPrefx = rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName);
      47         171 :         const OUString& rAttrValue = xAttrList->getValueByIndex( i );
      48         114 :         if ( XML_NAMESPACE_BLOCKLIST == nPrefx )
      49             :         {
      50          57 :             if ( IsXMLToken ( aLocalName, XML_LIST_NAME ) )
      51             :             {
      52          57 :                 rImport.getBlockList().SetName(rAttrValue);
      53          57 :                 break;
      54             :             }
      55             :         }
      56          57 :     }
      57          57 : }
      58             : 
      59         114 : SwXMLBlockListContext::~SwXMLBlockListContext ( void )
      60             : {
      61         114 : }
      62             : 
      63          34 : SvXMLImportContext *SwXMLBlockListContext::CreateChildContext(
      64             :     sal_uInt16 nPrefix,
      65             :     const OUString& rLocalName,
      66             :     const uno::Reference< xml::sax::XAttributeList > & xAttrList )
      67             : {
      68          34 :     SvXMLImportContext *pContext = 0;
      69          68 :     if (nPrefix == XML_NAMESPACE_BLOCKLIST &&
      70          34 :         IsXMLToken ( rLocalName, XML_BLOCK ) )
      71          34 :         pContext = new SwXMLBlockContext (rLocalRef, nPrefix, rLocalName, xAttrList);
      72             :     else
      73           0 :         pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
      74          34 :     return pContext;
      75             : }
      76             : 
      77          34 : SwXMLBlockContext::SwXMLBlockContext(
      78             :    SwXMLBlockListImport& rImport,
      79             :    sal_uInt16 nPrefix,
      80             :    const OUString& rLocalName,
      81             :    const uno::Reference<
      82             :    xml::sax::XAttributeList > & xAttrList ) :
      83          34 :     SvXMLImportContext ( rImport, nPrefix, rLocalName )
      84             : {
      85          34 :     static const CharClass & rCC = GetAppCharClass();
      86          68 :     String aShort, aLong, aPackageName;
      87          34 :     sal_Bool bTextOnly = sal_False;
      88             : 
      89          34 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      90         170 :     for (sal_Int16 i=0; i < nAttrCount; i++)
      91             :     {
      92         136 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
      93         272 :         OUString aLocalName;
      94         136 :         sal_uInt16 nPrefx = rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName);
      95         272 :         const OUString& rAttrValue = xAttrList->getValueByIndex( i );
      96         136 :         if (XML_NAMESPACE_BLOCKLIST == nPrefx)
      97             :         {
      98         136 :             if ( IsXMLToken ( aLocalName, XML_ABBREVIATED_NAME ) )
      99             :             {
     100          34 :                 aShort = rCC.uppercase(rAttrValue);
     101             :             }
     102         102 :             else if ( IsXMLToken ( aLocalName, XML_NAME ) )
     103             :             {
     104          34 :                 aLong = rAttrValue;
     105             :             }
     106          68 :             else if ( IsXMLToken ( aLocalName, XML_PACKAGE_NAME ) )
     107             :             {
     108          34 :                 aPackageName = rAttrValue;
     109             :             }
     110          34 :             else if ( IsXMLToken ( aLocalName, XML_UNFORMATTED_TEXT ) )
     111             :             {
     112          34 :                 if ( IsXMLToken ( rAttrValue, XML_TRUE ) )
     113          34 :                     bTextOnly = sal_True;
     114             :             }
     115             :         }
     116         136 :     }
     117          34 :     if (!aShort.Len() || !aLong.Len() || !aPackageName.Len())
     118          34 :         return;
     119          68 :     rImport.getBlockList().AddName( aShort, aLong, aPackageName, bTextOnly);
     120             : }
     121             : 
     122          68 : SwXMLBlockContext::~SwXMLBlockContext ( void )
     123             : {
     124          68 : }
     125             : 
     126           4 : SwXMLTextBlockDocumentContext::SwXMLTextBlockDocumentContext(
     127             :    SwXMLTextBlockImport& rImport,
     128             :    sal_uInt16 nPrefix,
     129             :    const OUString& rLocalName,
     130             :    const uno::Reference<
     131             :    xml::sax::XAttributeList > & ) :
     132             :     SvXMLImportContext ( rImport, nPrefix, rLocalName ),
     133           4 :     rLocalRef(rImport)
     134             : {
     135           4 : }
     136             : 
     137           4 : SvXMLImportContext *SwXMLTextBlockDocumentContext::CreateChildContext(
     138             :     sal_uInt16 nPrefix,
     139             :     const OUString& rLocalName,
     140             :     const uno::Reference< xml::sax::XAttributeList > & xAttrList )
     141             : {
     142           4 :     SvXMLImportContext *pContext = 0;
     143           8 :     if (nPrefix == XML_NAMESPACE_OFFICE &&
     144           4 :         IsXMLToken ( rLocalName, XML_BODY ) )
     145           4 :         pContext = new SwXMLTextBlockBodyContext (rLocalRef, nPrefix, rLocalName, xAttrList);
     146             :     else
     147           0 :         pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
     148           4 :     return pContext;
     149             : }
     150           8 : SwXMLTextBlockDocumentContext::~SwXMLTextBlockDocumentContext ( void )
     151             : {
     152           8 : }
     153             : 
     154             : 
     155           0 : SwXMLTextBlockTextContext::SwXMLTextBlockTextContext(
     156             :    SwXMLTextBlockImport& rImport,
     157             :    sal_uInt16 nPrefix,
     158             :    const OUString& rLocalName,
     159             :    const uno::Reference<
     160             :    xml::sax::XAttributeList > & ) :
     161             :     SvXMLImportContext ( rImport, nPrefix, rLocalName ),
     162           0 :     rLocalRef(rImport)
     163             : {
     164           0 : }
     165             : 
     166           0 : SvXMLImportContext *SwXMLTextBlockTextContext::CreateChildContext(
     167             :     sal_uInt16 nPrefix,
     168             :     const OUString& rLocalName,
     169             :     const uno::Reference< xml::sax::XAttributeList > & xAttrList )
     170             : {
     171           0 :     SvXMLImportContext *pContext = 0;
     172           0 :     if (nPrefix == XML_NAMESPACE_TEXT &&
     173           0 :         IsXMLToken ( rLocalName, XML_P ) )
     174           0 :         pContext = new SwXMLTextBlockParContext (rLocalRef, nPrefix, rLocalName, xAttrList);
     175             :     else
     176           0 :         pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
     177           0 :     return pContext;
     178             : }
     179           0 : SwXMLTextBlockTextContext::~SwXMLTextBlockTextContext ( void )
     180             : {
     181           0 : }
     182             : 
     183             : 
     184           4 : SwXMLTextBlockBodyContext::SwXMLTextBlockBodyContext(
     185             :    SwXMLTextBlockImport& rImport,
     186             :    sal_uInt16 nPrefix,
     187             :    const OUString& rLocalName,
     188             :    const uno::Reference<
     189             :    xml::sax::XAttributeList > & ) :
     190             :     SvXMLImportContext ( rImport, nPrefix, rLocalName ),
     191           4 :     rLocalRef(rImport)
     192             : {
     193           4 : }
     194             : 
     195           6 : SvXMLImportContext *SwXMLTextBlockBodyContext::CreateChildContext(
     196             :     sal_uInt16 nPrefix,
     197             :     const OUString& rLocalName,
     198             :     const uno::Reference< xml::sax::XAttributeList > & xAttrList )
     199             : {
     200           6 :     SvXMLImportContext *pContext = 0;
     201           6 :     if (nPrefix == XML_NAMESPACE_OFFICE &&
     202           0 :         IsXMLToken ( rLocalName, XML_TEXT ) )
     203           0 :         pContext = new SwXMLTextBlockTextContext (rLocalRef, nPrefix, rLocalName, xAttrList);
     204          12 :     else if (nPrefix == XML_NAMESPACE_TEXT &&
     205           6 :         IsXMLToken ( rLocalName, XML_P ) )
     206           6 :         pContext = new SwXMLTextBlockParContext (rLocalRef, nPrefix, rLocalName, xAttrList);
     207             :     else
     208           0 :         pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
     209           6 :     return pContext;
     210             : }
     211           8 : SwXMLTextBlockBodyContext::~SwXMLTextBlockBodyContext ( void )
     212             : {
     213           8 : }
     214           6 : SwXMLTextBlockParContext::SwXMLTextBlockParContext(
     215             :    SwXMLTextBlockImport& rImport,
     216             :    sal_uInt16 nPrefix,
     217             :    const OUString& rLocalName,
     218             :    const uno::Reference<
     219             :    xml::sax::XAttributeList > & ) :
     220             :     SvXMLImportContext ( rImport, nPrefix, rLocalName ),
     221           6 :     rLocalRef(rImport)
     222             : {
     223           6 : }
     224             : 
     225           6 : void SwXMLTextBlockParContext::Characters( const OUString& rChars )
     226             : {
     227           6 :     rLocalRef.m_rText.Append ( rChars.getStr());
     228           6 : }
     229          18 : SwXMLTextBlockParContext::~SwXMLTextBlockParContext ( void )
     230             : {
     231           6 :     if (rLocalRef.bTextOnly)
     232           6 :         rLocalRef.m_rText.AppendAscii( "\015" );
     233             :     else
     234             :     {
     235           0 :         if (rLocalRef.m_rText.GetChar ( rLocalRef.m_rText.Len()) != ' ' )
     236           0 :             rLocalRef.m_rText.AppendAscii( " " );
     237             :     }
     238         111 : }
     239             : 
     240             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10