LCOV - code coverage report
Current view: top level - libreoffice/editeng/source/misc - SvXMLAutoCorrectImport.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 102 0.0 %
Date: 2012-12-27 Functions: 0 22 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <SvXMLAutoCorrectImport.hxx>
      21             : #include <vcl/svapp.hxx>
      22             : #include <xmloff/xmltoken.hxx>
      23             : 
      24             : using namespace ::com::sun::star;
      25             : using namespace ::xmloff::token;
      26             : using namespace ::rtl;
      27             : 
      28             : const char aBlockList[] =  "_block-list";
      29             : 
      30           0 : SvXMLAutoCorrectImport::SvXMLAutoCorrectImport(
      31             :     const uno::Reference< lang::XMultiServiceFactory > xServiceFactory,
      32             :     SvxAutocorrWordList *pNewAutocorr_List,
      33             :     SvxAutoCorrect &rNewAutoCorrect,
      34             :     const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& rNewStorage)
      35             : :   SvXMLImport( xServiceFactory ),
      36             :     pAutocorr_List (pNewAutocorr_List),
      37             :     rAutoCorrect ( rNewAutoCorrect ),
      38           0 :     xStorage ( rNewStorage )
      39             : {
      40           0 :     GetNamespaceMap().Add(
      41             :             rtl::OUString(aBlockList),
      42           0 :             GetXMLToken ( XML_N_BLOCK_LIST),
      43           0 :             XML_NAMESPACE_BLOCKLIST );
      44           0 : }
      45             : 
      46           0 : SvXMLAutoCorrectImport::~SvXMLAutoCorrectImport ( void ) throw ()
      47             : {
      48           0 : }
      49             : 
      50           0 : SvXMLImportContext *SvXMLAutoCorrectImport::CreateContext(
      51             :         sal_uInt16 nPrefix,
      52             :         const OUString& rLocalName,
      53             :         const uno::Reference< xml::sax::XAttributeList > & xAttrList )
      54             : {
      55           0 :     SvXMLImportContext *pContext = 0;
      56             : 
      57           0 :     if( XML_NAMESPACE_BLOCKLIST == nPrefix &&
      58           0 :         IsXMLToken ( rLocalName, XML_BLOCK_LIST ) )
      59           0 :         pContext = new SvXMLWordListContext( *this, nPrefix, rLocalName, xAttrList );
      60             :     else
      61           0 :         pContext = SvXMLImport::CreateContext( nPrefix, rLocalName, xAttrList );
      62           0 :     return pContext;
      63             : }
      64             : 
      65           0 : SvXMLWordListContext::SvXMLWordListContext(
      66             :    SvXMLAutoCorrectImport& rImport,
      67             :    sal_uInt16 nPrefix,
      68             :    const OUString& rLocalName,
      69             :    const com::sun::star::uno::Reference<
      70             :    com::sun::star::xml::sax::XAttributeList > & /*xAttrList*/ ) :
      71             :    SvXMLImportContext ( rImport, nPrefix, rLocalName ),
      72           0 :    rLocalRef(rImport)
      73             : {
      74           0 : }
      75             : 
      76           0 : SvXMLImportContext *SvXMLWordListContext::CreateChildContext(
      77             :     sal_uInt16 nPrefix,
      78             :     const OUString& rLocalName,
      79             :     const uno::Reference< xml::sax::XAttributeList > & xAttrList )
      80             : {
      81           0 :     SvXMLImportContext *pContext = 0;
      82             : 
      83           0 :     if (nPrefix == XML_NAMESPACE_BLOCKLIST &&
      84           0 :         IsXMLToken ( rLocalName, XML_BLOCK ) )
      85           0 :         pContext = new SvXMLWordContext (rLocalRef, nPrefix, rLocalName, xAttrList);
      86             :     else
      87           0 :         pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
      88           0 :     return pContext;
      89             : }
      90           0 : SvXMLWordListContext::~SvXMLWordListContext ( void )
      91             : {
      92           0 : }
      93             : 
      94           0 : SvXMLWordContext::SvXMLWordContext(
      95             :    SvXMLAutoCorrectImport& rImport,
      96             :    sal_uInt16 nPrefix,
      97             :    const OUString& rLocalName,
      98             :    const com::sun::star::uno::Reference<
      99             :    com::sun::star::xml::sax::XAttributeList > & xAttrList ) :
     100             :    SvXMLImportContext ( rImport, nPrefix, rLocalName ),
     101           0 :    rLocalRef(rImport)
     102             : {
     103           0 :     String sRight, sWrong;
     104           0 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     105             : 
     106           0 :     for (sal_Int16 i=0; i < nAttrCount; i++)
     107             :     {
     108           0 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
     109           0 :         OUString aLocalName;
     110           0 :         sal_uInt16 nAttrPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName);
     111           0 :         const OUString& rAttrValue = xAttrList->getValueByIndex( i );
     112           0 :         if (XML_NAMESPACE_BLOCKLIST == nAttrPrefix)
     113             :         {
     114           0 :             if ( IsXMLToken ( aLocalName, XML_ABBREVIATED_NAME ) )
     115             :             {
     116           0 :                 sWrong = rAttrValue;
     117             :             }
     118           0 :             else if ( IsXMLToken ( aLocalName, XML_NAME ) )
     119             :             {
     120           0 :                 sRight = rAttrValue;
     121             :             }
     122             :         }
     123           0 :     }
     124           0 :     if (!sWrong.Len() || !sRight.Len() )
     125           0 :         return;
     126             : 
     127           0 :     sal_Bool bOnlyTxt = sRight != sWrong;
     128           0 :     if( !bOnlyTxt )
     129             :     {
     130           0 :         String sLongSave( sRight );
     131           0 :         if( !rLocalRef.rAutoCorrect.GetLongText( rLocalRef.xStorage, String(), sWrong, sRight ) &&
     132           0 :             sLongSave.Len() )
     133             :         {
     134           0 :             sRight = sLongSave;
     135           0 :             bOnlyTxt = sal_True;
     136           0 :         }
     137             :     }
     138           0 :     rLocalRef.pAutocorr_List->LoadEntry( sWrong, sRight, bOnlyTxt );
     139             : }
     140             : 
     141           0 : SvXMLWordContext::~SvXMLWordContext ( void )
     142             : {
     143           0 : }
     144             : 
     145           0 : SvXMLExceptionListImport::SvXMLExceptionListImport(
     146             :     const uno::Reference< lang::XMultiServiceFactory > xServiceFactory,
     147             :     SvStringsISortDtor & rNewList )
     148             : :   SvXMLImport( xServiceFactory ),
     149           0 :     rList (rNewList)
     150             : {
     151           0 :     GetNamespaceMap().Add(
     152             :             rtl::OUString(aBlockList),
     153           0 :             GetXMLToken ( XML_N_BLOCK_LIST),
     154           0 :             XML_NAMESPACE_BLOCKLIST );
     155           0 : }
     156             : 
     157           0 : SvXMLExceptionListImport::~SvXMLExceptionListImport ( void ) throw ()
     158             : {
     159           0 : }
     160             : 
     161           0 : SvXMLImportContext *SvXMLExceptionListImport::CreateContext(
     162             :         sal_uInt16 nPrefix,
     163             :         const OUString& rLocalName,
     164             :         const uno::Reference< xml::sax::XAttributeList > & xAttrList )
     165             : {
     166           0 :     SvXMLImportContext *pContext = 0;
     167             : 
     168           0 :     if( XML_NAMESPACE_BLOCKLIST==nPrefix &&
     169           0 :         IsXMLToken ( rLocalName, XML_BLOCK_LIST ) )
     170           0 :         pContext = new SvXMLExceptionListContext( *this, nPrefix, rLocalName, xAttrList );
     171             :     else
     172           0 :         pContext = SvXMLImport::CreateContext( nPrefix, rLocalName, xAttrList );
     173           0 :     return pContext;
     174             : }
     175             : 
     176           0 : SvXMLExceptionListContext::SvXMLExceptionListContext(
     177             :    SvXMLExceptionListImport& rImport,
     178             :    sal_uInt16 nPrefix,
     179             :    const OUString& rLocalName,
     180             :    const com::sun::star::uno::Reference<
     181             :    com::sun::star::xml::sax::XAttributeList > & /* xAttrList */ ) :
     182             :    SvXMLImportContext ( rImport, nPrefix, rLocalName ),
     183           0 :    rLocalRef(rImport)
     184             : {
     185           0 : }
     186             : 
     187           0 : SvXMLImportContext *SvXMLExceptionListContext::CreateChildContext(
     188             :     sal_uInt16 nPrefix,
     189             :     const OUString& rLocalName,
     190             :     const uno::Reference< xml::sax::XAttributeList > & xAttrList )
     191             : {
     192           0 :     SvXMLImportContext *pContext = 0;
     193             : 
     194           0 :     if (nPrefix == XML_NAMESPACE_BLOCKLIST &&
     195           0 :         IsXMLToken ( rLocalName, XML_BLOCK ) )
     196           0 :         pContext = new SvXMLExceptionContext (rLocalRef, nPrefix, rLocalName, xAttrList);
     197             :     else
     198           0 :         pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
     199           0 :     return pContext;
     200             : }
     201           0 : SvXMLExceptionListContext::~SvXMLExceptionListContext ( void )
     202             : {
     203           0 : }
     204             : 
     205           0 : SvXMLExceptionContext::SvXMLExceptionContext(
     206             :    SvXMLExceptionListImport& rImport,
     207             :    sal_uInt16 nPrefix,
     208             :    const OUString& rLocalName,
     209             :    const com::sun::star::uno::Reference<
     210             :    com::sun::star::xml::sax::XAttributeList > & xAttrList ) :
     211             :    SvXMLImportContext ( rImport, nPrefix, rLocalName ),
     212           0 :    rLocalRef(rImport)
     213             : {
     214           0 :     String sWord;
     215           0 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     216             : 
     217           0 :     for (sal_Int16 i=0; i < nAttrCount; i++)
     218             :     {
     219           0 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
     220           0 :         OUString aLocalName;
     221           0 :         sal_uInt16 nAttrPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName);
     222           0 :         const OUString& rAttrValue = xAttrList->getValueByIndex( i );
     223           0 :         if (XML_NAMESPACE_BLOCKLIST == nAttrPrefix)
     224             :         {
     225           0 :             if ( IsXMLToken ( aLocalName, XML_ABBREVIATED_NAME ) )
     226             :             {
     227           0 :                 sWord = rAttrValue;
     228             :             }
     229             :         }
     230           0 :     }
     231           0 :     if (!sWord.Len() )
     232           0 :         return;
     233             : 
     234           0 :     String * pNew = new String( sWord );
     235             : 
     236           0 :     if( !rLocalRef.rList.insert( pNew ).second )
     237           0 :         delete pNew;
     238             : }
     239             : 
     240           0 : SvXMLExceptionContext::~SvXMLExceptionContext ( void )
     241             : {
     242           0 : }
     243             : 
     244             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10