2001-02-09 16:58:43 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2005-09-08 21:24:45 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2001-02-09 16:58:43 +00:00
|
|
|
*
|
2005-09-08 21:24:45 +00:00
|
|
|
* $RCSfile: SvXMLAutoCorrectImport.cxx,v $
|
2001-02-09 16:58:43 +00:00
|
|
|
*
|
2007-06-05 13:34:28 +00:00
|
|
|
* $Revision: 1.13 $
|
2001-02-09 16:58:43 +00:00
|
|
|
*
|
2007-06-05 13:34:28 +00:00
|
|
|
* last change: $Author: ihi $ $Date: 2007-06-05 14:34:28 $
|
2001-02-09 16:58:43 +00:00
|
|
|
*
|
2005-09-08 21:24:45 +00:00
|
|
|
* The Contents of this file are made available subject to
|
|
|
|
* the terms of GNU Lesser General Public License Version 2.1.
|
2001-02-09 16:58:43 +00:00
|
|
|
*
|
|
|
|
*
|
2005-09-08 21:24:45 +00:00
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2005 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
2001-02-09 16:58:43 +00:00
|
|
|
*
|
2005-09-08 21:24:45 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
2001-02-09 16:58:43 +00:00
|
|
|
*
|
2005-09-08 21:24:45 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2001-02-09 16:58:43 +00:00
|
|
|
*
|
2005-09-08 21:24:45 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
2001-02-09 16:58:43 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
2006-09-17 03:47:40 +00:00
|
|
|
|
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_svx.hxx"
|
2001-02-09 16:58:43 +00:00
|
|
|
#ifndef _SV_XMLAUTOCORRECTIMPORT_HXX
|
|
|
|
#include <SvXMLAutoCorrectImport.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _APP_HXX //autogen
|
|
|
|
#include <vcl/svapp.hxx>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define _SVSTDARR_STRINGSISORTDTOR
|
|
|
|
#define _SVSTDARR_STRINGSDTOR
|
|
|
|
#include <svtools/svstdarr.hxx>
|
2001-07-05 12:54:07 +00:00
|
|
|
#ifndef _XMLOFF_XMLTOKEN_HXX
|
|
|
|
#include <xmloff/xmltoken.hxx>
|
|
|
|
#endif
|
2001-02-09 16:58:43 +00:00
|
|
|
|
|
|
|
using namespace ::com::sun::star;
|
2001-07-05 12:54:07 +00:00
|
|
|
using namespace ::xmloff::token;
|
2001-02-09 16:58:43 +00:00
|
|
|
using namespace ::rtl;
|
|
|
|
|
2007-06-05 13:34:28 +00:00
|
|
|
|
2001-07-10 15:46:53 +00:00
|
|
|
static OUString sBlockList ( RTL_CONSTASCII_USTRINGPARAM ( "_block-list" ) );
|
2001-02-09 16:58:43 +00:00
|
|
|
|
2004-05-03 12:27:01 +00:00
|
|
|
// #110680#
|
|
|
|
SvXMLAutoCorrectImport::SvXMLAutoCorrectImport(
|
2007-06-05 13:34:28 +00:00
|
|
|
const uno::Reference< lang::XMultiServiceFactory > xServiceFactory,
|
2004-05-03 12:27:01 +00:00
|
|
|
SvxAutocorrWordList *pNewAutocorr_List,
|
|
|
|
SvxAutoCorrect &rNewAutoCorrect,
|
2005-01-11 11:57:22 +00:00
|
|
|
const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& rNewStorage)
|
2004-05-03 12:27:01 +00:00
|
|
|
: SvXMLImport( xServiceFactory ),
|
|
|
|
pAutocorr_List (pNewAutocorr_List),
|
|
|
|
rAutoCorrect ( rNewAutoCorrect ),
|
2005-01-11 11:57:22 +00:00
|
|
|
xStorage ( rNewStorage )
|
2001-02-09 16:58:43 +00:00
|
|
|
{
|
2001-07-10 15:46:53 +00:00
|
|
|
GetNamespaceMap().Add(
|
|
|
|
sBlockList,
|
|
|
|
GetXMLToken ( XML_N_BLOCK_LIST),
|
|
|
|
XML_NAMESPACE_BLOCKLIST );
|
2001-02-09 16:58:43 +00:00
|
|
|
}
|
|
|
|
|
2001-09-12 12:20:00 +00:00
|
|
|
SvXMLAutoCorrectImport::~SvXMLAutoCorrectImport ( void ) throw ()
|
2001-02-09 16:58:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SvXMLImportContext *SvXMLAutoCorrectImport::CreateContext(
|
|
|
|
sal_uInt16 nPrefix,
|
|
|
|
const OUString& rLocalName,
|
2007-06-05 13:34:28 +00:00
|
|
|
const uno::Reference< xml::sax::XAttributeList > & xAttrList )
|
2001-02-09 16:58:43 +00:00
|
|
|
{
|
|
|
|
SvXMLImportContext *pContext = 0;
|
|
|
|
|
2001-07-05 12:54:07 +00:00
|
|
|
if( XML_NAMESPACE_BLOCKLIST == nPrefix &&
|
|
|
|
IsXMLToken ( rLocalName, XML_BLOCK_LIST ) )
|
2001-02-09 16:58:43 +00:00
|
|
|
pContext = new SvXMLWordListContext( *this, nPrefix, rLocalName, xAttrList );
|
|
|
|
else
|
|
|
|
pContext = SvXMLImport::CreateContext( nPrefix, rLocalName, xAttrList );
|
|
|
|
return pContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
SvXMLWordListContext::SvXMLWordListContext(
|
|
|
|
SvXMLAutoCorrectImport& rImport,
|
|
|
|
sal_uInt16 nPrefix,
|
|
|
|
const OUString& rLocalName,
|
|
|
|
const com::sun::star::uno::Reference<
|
2006-10-12 11:33:46 +00:00
|
|
|
com::sun::star::xml::sax::XAttributeList > & /*xAttrList*/ ) :
|
|
|
|
SvXMLImportContext ( rImport, nPrefix, rLocalName ),
|
|
|
|
rLocalRef(rImport)
|
2001-02-09 16:58:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SvXMLImportContext *SvXMLWordListContext::CreateChildContext(
|
|
|
|
sal_uInt16 nPrefix,
|
|
|
|
const OUString& rLocalName,
|
2007-06-05 13:34:28 +00:00
|
|
|
const uno::Reference< xml::sax::XAttributeList > & xAttrList )
|
2001-02-09 16:58:43 +00:00
|
|
|
{
|
|
|
|
SvXMLImportContext *pContext = 0;
|
|
|
|
|
|
|
|
if (nPrefix == XML_NAMESPACE_BLOCKLIST &&
|
2001-07-05 12:54:07 +00:00
|
|
|
IsXMLToken ( rLocalName, XML_BLOCK ) )
|
2001-02-09 16:58:43 +00:00
|
|
|
pContext = new SvXMLWordContext (rLocalRef, nPrefix, rLocalName, xAttrList);
|
|
|
|
else
|
|
|
|
pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
|
|
|
|
return pContext;
|
|
|
|
}
|
|
|
|
SvXMLWordListContext::~SvXMLWordListContext ( void )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SvXMLWordContext::SvXMLWordContext(
|
|
|
|
SvXMLAutoCorrectImport& rImport,
|
|
|
|
sal_uInt16 nPrefix,
|
|
|
|
const OUString& rLocalName,
|
|
|
|
const com::sun::star::uno::Reference<
|
|
|
|
com::sun::star::xml::sax::XAttributeList > & xAttrList ) :
|
2006-10-12 11:33:46 +00:00
|
|
|
SvXMLImportContext ( rImport, nPrefix, rLocalName ),
|
|
|
|
rLocalRef(rImport)
|
2001-02-09 16:58:43 +00:00
|
|
|
{
|
|
|
|
String sRight, sWrong;
|
|
|
|
sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
|
|
|
|
|
|
|
|
for (sal_Int16 i=0; i < nAttrCount; i++)
|
|
|
|
{
|
|
|
|
const OUString& rAttrName = xAttrList->getNameByIndex( i );
|
|
|
|
OUString aLocalName;
|
2006-10-12 11:33:46 +00:00
|
|
|
sal_uInt16 nAttrPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName);
|
2001-02-09 16:58:43 +00:00
|
|
|
const OUString& rAttrValue = xAttrList->getValueByIndex( i );
|
2006-10-12 11:33:46 +00:00
|
|
|
if (XML_NAMESPACE_BLOCKLIST == nAttrPrefix)
|
2001-02-09 16:58:43 +00:00
|
|
|
{
|
2001-07-05 12:54:07 +00:00
|
|
|
if ( IsXMLToken ( aLocalName, XML_ABBREVIATED_NAME ) )
|
2001-02-09 16:58:43 +00:00
|
|
|
{
|
|
|
|
sWrong = rAttrValue;
|
|
|
|
}
|
2001-07-05 12:54:07 +00:00
|
|
|
else if ( IsXMLToken ( aLocalName, XML_NAME ) )
|
2001-02-09 16:58:43 +00:00
|
|
|
{
|
|
|
|
sRight = rAttrValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!sWrong.Len() || !sRight.Len() )
|
|
|
|
return;
|
2001-05-02 15:16:53 +00:00
|
|
|
|
2001-07-06 13:44:25 +00:00
|
|
|
// const International& rInter = Application::GetAppInternational();
|
|
|
|
// BOOL bOnlyTxt = COMPARE_EQUAL != rInter.Compare( sRight, sWrong, INTN_COMPARE_IGNORECASE );
|
|
|
|
BOOL bOnlyTxt = sRight != sWrong;
|
2001-02-09 16:58:43 +00:00
|
|
|
if( !bOnlyTxt )
|
|
|
|
{
|
|
|
|
String sLongSave( sRight );
|
2005-01-11 11:57:22 +00:00
|
|
|
if( !rLocalRef.rAutoCorrect.GetLongText( rLocalRef.xStorage, String(), sWrong, sRight ) &&
|
2001-02-09 16:58:43 +00:00
|
|
|
sLongSave.Len() )
|
|
|
|
{
|
|
|
|
sRight = sLongSave;
|
|
|
|
bOnlyTxt = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SvxAutocorrWordPtr pNew = new SvxAutocorrWord( sWrong, sRight, bOnlyTxt );
|
|
|
|
|
|
|
|
if( !rLocalRef.pAutocorr_List->Insert( pNew ) )
|
|
|
|
delete pNew;
|
|
|
|
}
|
|
|
|
|
|
|
|
SvXMLWordContext::~SvXMLWordContext ( void )
|
|
|
|
{
|
|
|
|
}
|
2004-05-03 12:27:01 +00:00
|
|
|
|
|
|
|
// #110680#
|
|
|
|
SvXMLExceptionListImport::SvXMLExceptionListImport(
|
2007-06-05 13:34:28 +00:00
|
|
|
const uno::Reference< lang::XMultiServiceFactory > xServiceFactory,
|
2004-05-03 12:27:01 +00:00
|
|
|
SvStringsISortDtor & rNewList )
|
|
|
|
: SvXMLImport( xServiceFactory ),
|
|
|
|
rList (rNewList)
|
2001-02-09 16:58:43 +00:00
|
|
|
{
|
2001-07-10 15:46:53 +00:00
|
|
|
GetNamespaceMap().Add(
|
|
|
|
sBlockList,
|
|
|
|
GetXMLToken ( XML_N_BLOCK_LIST),
|
|
|
|
XML_NAMESPACE_BLOCKLIST );
|
2001-02-09 16:58:43 +00:00
|
|
|
}
|
|
|
|
|
2001-09-12 12:20:00 +00:00
|
|
|
SvXMLExceptionListImport::~SvXMLExceptionListImport ( void ) throw ()
|
2001-02-09 16:58:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SvXMLImportContext *SvXMLExceptionListImport::CreateContext(
|
|
|
|
sal_uInt16 nPrefix,
|
|
|
|
const OUString& rLocalName,
|
2007-06-05 13:34:28 +00:00
|
|
|
const uno::Reference< xml::sax::XAttributeList > & xAttrList )
|
2001-02-09 16:58:43 +00:00
|
|
|
{
|
|
|
|
SvXMLImportContext *pContext = 0;
|
|
|
|
|
|
|
|
if( XML_NAMESPACE_BLOCKLIST==nPrefix &&
|
2001-07-05 12:54:07 +00:00
|
|
|
IsXMLToken ( rLocalName, XML_BLOCK_LIST ) )
|
2001-02-09 16:58:43 +00:00
|
|
|
pContext = new SvXMLExceptionListContext( *this, nPrefix, rLocalName, xAttrList );
|
|
|
|
else
|
|
|
|
pContext = SvXMLImport::CreateContext( nPrefix, rLocalName, xAttrList );
|
|
|
|
return pContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
SvXMLExceptionListContext::SvXMLExceptionListContext(
|
|
|
|
SvXMLExceptionListImport& rImport,
|
|
|
|
sal_uInt16 nPrefix,
|
|
|
|
const OUString& rLocalName,
|
|
|
|
const com::sun::star::uno::Reference<
|
2006-10-12 11:33:46 +00:00
|
|
|
com::sun::star::xml::sax::XAttributeList > & /* xAttrList */ ) :
|
|
|
|
SvXMLImportContext ( rImport, nPrefix, rLocalName ),
|
|
|
|
rLocalRef(rImport)
|
2001-02-09 16:58:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SvXMLImportContext *SvXMLExceptionListContext::CreateChildContext(
|
|
|
|
sal_uInt16 nPrefix,
|
|
|
|
const OUString& rLocalName,
|
2007-06-05 13:34:28 +00:00
|
|
|
const uno::Reference< xml::sax::XAttributeList > & xAttrList )
|
2001-02-09 16:58:43 +00:00
|
|
|
{
|
|
|
|
SvXMLImportContext *pContext = 0;
|
|
|
|
|
|
|
|
if (nPrefix == XML_NAMESPACE_BLOCKLIST &&
|
2001-07-05 12:54:07 +00:00
|
|
|
IsXMLToken ( rLocalName, XML_BLOCK ) )
|
2001-02-09 16:58:43 +00:00
|
|
|
pContext = new SvXMLExceptionContext (rLocalRef, nPrefix, rLocalName, xAttrList);
|
|
|
|
else
|
|
|
|
pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
|
|
|
|
return pContext;
|
|
|
|
}
|
|
|
|
SvXMLExceptionListContext::~SvXMLExceptionListContext ( void )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SvXMLExceptionContext::SvXMLExceptionContext(
|
|
|
|
SvXMLExceptionListImport& rImport,
|
|
|
|
sal_uInt16 nPrefix,
|
|
|
|
const OUString& rLocalName,
|
|
|
|
const com::sun::star::uno::Reference<
|
|
|
|
com::sun::star::xml::sax::XAttributeList > & xAttrList ) :
|
2006-10-12 11:33:46 +00:00
|
|
|
SvXMLImportContext ( rImport, nPrefix, rLocalName ),
|
|
|
|
rLocalRef(rImport)
|
2001-02-09 16:58:43 +00:00
|
|
|
{
|
|
|
|
String sWord;
|
|
|
|
sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
|
|
|
|
|
|
|
|
for (sal_Int16 i=0; i < nAttrCount; i++)
|
|
|
|
{
|
|
|
|
const OUString& rAttrName = xAttrList->getNameByIndex( i );
|
|
|
|
OUString aLocalName;
|
2006-10-12 11:33:46 +00:00
|
|
|
sal_uInt16 nAttrPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName);
|
2001-02-09 16:58:43 +00:00
|
|
|
const OUString& rAttrValue = xAttrList->getValueByIndex( i );
|
2006-10-12 11:33:46 +00:00
|
|
|
if (XML_NAMESPACE_BLOCKLIST == nAttrPrefix)
|
2001-02-09 16:58:43 +00:00
|
|
|
{
|
2001-07-05 12:54:07 +00:00
|
|
|
if ( IsXMLToken ( aLocalName, XML_ABBREVIATED_NAME ) )
|
2001-02-09 16:58:43 +00:00
|
|
|
{
|
|
|
|
sWord = rAttrValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!sWord.Len() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
String * pNew = new String( sWord );
|
|
|
|
|
|
|
|
if( !rLocalRef.rList.Insert( pNew ) )
|
|
|
|
delete pNew;
|
|
|
|
}
|
|
|
|
|
|
|
|
SvXMLExceptionContext::~SvXMLExceptionContext ( void )
|
|
|
|
{
|
|
|
|
}
|