LCOV - code coverage report
Current view: top level - editeng/source/misc - SvXMLAutoCorrectImport.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 101 0.0 %
Date: 2014-04-11 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< uno::XComponentContext > xContext,
      32             :     SvxAutocorrWordList *pNewAutocorr_List,
      33             :     SvxAutoCorrect &rNewAutoCorrect,
      34             :     const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& rNewStorage)
      35             : :   SvXMLImport( xContext, "" ),
      36             :     pAutocorr_List (pNewAutocorr_List),
      37             :     rAutoCorrect ( rNewAutoCorrect ),
      38           0 :     xStorage ( rNewStorage )
      39             : {
      40           0 :     GetNamespaceMap().Add(
      41             :             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 :     OUString sRight;
     104           0 :     OUString sWrong;
     105           0 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     106             : 
     107           0 :     for (sal_Int16 i=0; i < nAttrCount; i++)
     108             :     {
     109           0 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
     110           0 :         OUString aLocalName;
     111           0 :         sal_uInt16 nAttrPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName);
     112           0 :         const OUString& rAttrValue = xAttrList->getValueByIndex( i );
     113           0 :         if (XML_NAMESPACE_BLOCKLIST == nAttrPrefix)
     114             :         {
     115           0 :             if ( IsXMLToken ( aLocalName, XML_ABBREVIATED_NAME ) )
     116             :             {
     117           0 :                 sWrong = rAttrValue;
     118             :             }
     119           0 :             else if ( IsXMLToken ( aLocalName, XML_NAME ) )
     120             :             {
     121           0 :                 sRight = rAttrValue;
     122             :             }
     123             :         }
     124           0 :     }
     125           0 :     if (sWrong.isEmpty() || sRight.isEmpty())
     126           0 :         return;
     127             : 
     128           0 :     sal_Bool bOnlyTxt = sRight != sWrong;
     129           0 :     if( !bOnlyTxt )
     130             :     {
     131           0 :         const OUString sLongSave( sRight );
     132           0 :         if( !rLocalRef.rAutoCorrect.GetLongText( rLocalRef.xStorage, OUString(), sWrong, sRight ) &&
     133           0 :             !sLongSave.isEmpty() )
     134             :         {
     135           0 :             sRight = sLongSave;
     136           0 :             bOnlyTxt = sal_True;
     137           0 :         }
     138             :     }
     139           0 :     rLocalRef.pAutocorr_List->LoadEntry( sWrong, sRight, bOnlyTxt );
     140             : }
     141             : 
     142           0 : SvXMLWordContext::~SvXMLWordContext ( void )
     143             : {
     144           0 : }
     145             : 
     146           0 : SvXMLExceptionListImport::SvXMLExceptionListImport(
     147             :     const uno::Reference< uno::XComponentContext > xContext,
     148             :     SvStringsISortDtor & rNewList )
     149             : :   SvXMLImport( xContext, "" ),
     150           0 :     rList (rNewList)
     151             : {
     152           0 :     GetNamespaceMap().Add(
     153             :             OUString(aBlockList),
     154           0 :             GetXMLToken ( XML_N_BLOCK_LIST),
     155           0 :             XML_NAMESPACE_BLOCKLIST );
     156           0 : }
     157             : 
     158           0 : SvXMLExceptionListImport::~SvXMLExceptionListImport ( void ) throw ()
     159             : {
     160           0 : }
     161             : 
     162           0 : SvXMLImportContext *SvXMLExceptionListImport::CreateContext(
     163             :         sal_uInt16 nPrefix,
     164             :         const OUString& rLocalName,
     165             :         const uno::Reference< xml::sax::XAttributeList > & xAttrList )
     166             : {
     167           0 :     SvXMLImportContext *pContext = 0;
     168             : 
     169           0 :     if( XML_NAMESPACE_BLOCKLIST==nPrefix &&
     170           0 :         IsXMLToken ( rLocalName, XML_BLOCK_LIST ) )
     171           0 :         pContext = new SvXMLExceptionListContext( *this, nPrefix, rLocalName, xAttrList );
     172             :     else
     173           0 :         pContext = SvXMLImport::CreateContext( nPrefix, rLocalName, xAttrList );
     174           0 :     return pContext;
     175             : }
     176             : 
     177           0 : SvXMLExceptionListContext::SvXMLExceptionListContext(
     178             :    SvXMLExceptionListImport& rImport,
     179             :    sal_uInt16 nPrefix,
     180             :    const OUString& rLocalName,
     181             :    const com::sun::star::uno::Reference<
     182             :    com::sun::star::xml::sax::XAttributeList > & /* xAttrList */ ) :
     183             :    SvXMLImportContext ( rImport, nPrefix, rLocalName ),
     184           0 :    rLocalRef(rImport)
     185             : {
     186           0 : }
     187             : 
     188           0 : SvXMLImportContext *SvXMLExceptionListContext::CreateChildContext(
     189             :     sal_uInt16 nPrefix,
     190             :     const OUString& rLocalName,
     191             :     const uno::Reference< xml::sax::XAttributeList > & xAttrList )
     192             : {
     193           0 :     SvXMLImportContext *pContext = 0;
     194             : 
     195           0 :     if (nPrefix == XML_NAMESPACE_BLOCKLIST &&
     196           0 :         IsXMLToken ( rLocalName, XML_BLOCK ) )
     197           0 :         pContext = new SvXMLExceptionContext (rLocalRef, nPrefix, rLocalName, xAttrList);
     198             :     else
     199           0 :         pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
     200           0 :     return pContext;
     201             : }
     202           0 : SvXMLExceptionListContext::~SvXMLExceptionListContext ( void )
     203             : {
     204           0 : }
     205             : 
     206           0 : SvXMLExceptionContext::SvXMLExceptionContext(
     207             :    SvXMLExceptionListImport& rImport,
     208             :    sal_uInt16 nPrefix,
     209             :    const OUString& rLocalName,
     210             :    const com::sun::star::uno::Reference<
     211             :    com::sun::star::xml::sax::XAttributeList > & xAttrList ) :
     212             :    SvXMLImportContext ( rImport, nPrefix, rLocalName ),
     213           0 :    rLocalRef(rImport)
     214             : {
     215           0 :     OUString sWord;
     216           0 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     217             : 
     218           0 :     for (sal_Int16 i=0; i < nAttrCount; i++)
     219             :     {
     220           0 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
     221           0 :         OUString aLocalName;
     222           0 :         sal_uInt16 nAttrPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName);
     223           0 :         const OUString& rAttrValue = xAttrList->getValueByIndex( i );
     224           0 :         if (XML_NAMESPACE_BLOCKLIST == nAttrPrefix)
     225             :         {
     226           0 :             if ( IsXMLToken ( aLocalName, XML_ABBREVIATED_NAME ) )
     227             :             {
     228           0 :                 sWord = rAttrValue;
     229             :             }
     230             :         }
     231           0 :     }
     232           0 :     if (sWord.isEmpty() )
     233           0 :         return;
     234             : 
     235           0 :     rLocalRef.rList.insert( sWord );
     236             : }
     237             : 
     238           0 : SvXMLExceptionContext::~SvXMLExceptionContext ( void )
     239             : {
     240           0 : }
     241             : 
     242             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10