1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SvXMLAutoCorrectImport.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <SvXMLAutoCorrectImport.hxx>
34 #ifndef _APP_HXX //autogen
35 #include <vcl/svapp.hxx>
38 #define _SVSTDARR_STRINGSISORTDTOR
39 #define _SVSTDARR_STRINGSDTOR
40 #include <svtools/svstdarr.hxx>
41 #include <xmloff/xmltoken.hxx>
43 using namespace ::com::sun::star
;
44 using namespace ::xmloff::token
;
45 using namespace ::rtl
;
48 static OUString
sBlockList ( RTL_CONSTASCII_USTRINGPARAM ( "_block-list" ) );
51 SvXMLAutoCorrectImport::SvXMLAutoCorrectImport(
52 const uno::Reference
< lang::XMultiServiceFactory
> xServiceFactory
,
53 SvxAutocorrWordList
*pNewAutocorr_List
,
54 SvxAutoCorrect
&rNewAutoCorrect
,
55 const com::sun::star::uno::Reference
< com::sun::star::embed::XStorage
>& rNewStorage
)
56 : SvXMLImport( xServiceFactory
),
57 pAutocorr_List (pNewAutocorr_List
),
58 rAutoCorrect ( rNewAutoCorrect
),
59 xStorage ( rNewStorage
)
61 GetNamespaceMap().Add(
63 GetXMLToken ( XML_N_BLOCK_LIST
),
64 XML_NAMESPACE_BLOCKLIST
);
67 SvXMLAutoCorrectImport::~SvXMLAutoCorrectImport ( void ) throw ()
71 SvXMLImportContext
*SvXMLAutoCorrectImport::CreateContext(
73 const OUString
& rLocalName
,
74 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
76 SvXMLImportContext
*pContext
= 0;
78 if( XML_NAMESPACE_BLOCKLIST
== nPrefix
&&
79 IsXMLToken ( rLocalName
, XML_BLOCK_LIST
) )
80 pContext
= new SvXMLWordListContext( *this, nPrefix
, rLocalName
, xAttrList
);
82 pContext
= SvXMLImport::CreateContext( nPrefix
, rLocalName
, xAttrList
);
86 SvXMLWordListContext::SvXMLWordListContext(
87 SvXMLAutoCorrectImport
& rImport
,
89 const OUString
& rLocalName
,
90 const com::sun::star::uno::Reference
<
91 com::sun::star::xml::sax::XAttributeList
> & /*xAttrList*/ ) :
92 SvXMLImportContext ( rImport
, nPrefix
, rLocalName
),
97 SvXMLImportContext
*SvXMLWordListContext::CreateChildContext(
99 const OUString
& rLocalName
,
100 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
102 SvXMLImportContext
*pContext
= 0;
104 if (nPrefix
== XML_NAMESPACE_BLOCKLIST
&&
105 IsXMLToken ( rLocalName
, XML_BLOCK
) )
106 pContext
= new SvXMLWordContext (rLocalRef
, nPrefix
, rLocalName
, xAttrList
);
108 pContext
= new SvXMLImportContext( rLocalRef
, nPrefix
, rLocalName
);
111 SvXMLWordListContext::~SvXMLWordListContext ( void )
115 SvXMLWordContext::SvXMLWordContext(
116 SvXMLAutoCorrectImport
& rImport
,
118 const OUString
& rLocalName
,
119 const com::sun::star::uno::Reference
<
120 com::sun::star::xml::sax::XAttributeList
> & xAttrList
) :
121 SvXMLImportContext ( rImport
, nPrefix
, rLocalName
),
124 String sRight
, sWrong
;
125 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
127 for (sal_Int16 i
=0; i
< nAttrCount
; i
++)
129 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
131 sal_uInt16 nAttrPrefix
= rImport
.GetNamespaceMap().GetKeyByAttrName( rAttrName
, &aLocalName
);
132 const OUString
& rAttrValue
= xAttrList
->getValueByIndex( i
);
133 if (XML_NAMESPACE_BLOCKLIST
== nAttrPrefix
)
135 if ( IsXMLToken ( aLocalName
, XML_ABBREVIATED_NAME
) )
139 else if ( IsXMLToken ( aLocalName
, XML_NAME
) )
145 if (!sWrong
.Len() || !sRight
.Len() )
148 // const International& rInter = Application::GetAppInternational();
149 // BOOL bOnlyTxt = COMPARE_EQUAL != rInter.Compare( sRight, sWrong, INTN_COMPARE_IGNORECASE );
150 BOOL bOnlyTxt
= sRight
!= sWrong
;
153 String
sLongSave( sRight
);
154 if( !rLocalRef
.rAutoCorrect
.GetLongText( rLocalRef
.xStorage
, String(), sWrong
, sRight
) &&
161 SvxAutocorrWordPtr pNew
= new SvxAutocorrWord( sWrong
, sRight
, bOnlyTxt
);
163 if( !rLocalRef
.pAutocorr_List
->Insert( pNew
) )
167 SvXMLWordContext::~SvXMLWordContext ( void )
172 SvXMLExceptionListImport::SvXMLExceptionListImport(
173 const uno::Reference
< lang::XMultiServiceFactory
> xServiceFactory
,
174 SvStringsISortDtor
& rNewList
)
175 : SvXMLImport( xServiceFactory
),
178 GetNamespaceMap().Add(
180 GetXMLToken ( XML_N_BLOCK_LIST
),
181 XML_NAMESPACE_BLOCKLIST
);
184 SvXMLExceptionListImport::~SvXMLExceptionListImport ( void ) throw ()
188 SvXMLImportContext
*SvXMLExceptionListImport::CreateContext(
190 const OUString
& rLocalName
,
191 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
193 SvXMLImportContext
*pContext
= 0;
195 if( XML_NAMESPACE_BLOCKLIST
==nPrefix
&&
196 IsXMLToken ( rLocalName
, XML_BLOCK_LIST
) )
197 pContext
= new SvXMLExceptionListContext( *this, nPrefix
, rLocalName
, xAttrList
);
199 pContext
= SvXMLImport::CreateContext( nPrefix
, rLocalName
, xAttrList
);
203 SvXMLExceptionListContext::SvXMLExceptionListContext(
204 SvXMLExceptionListImport
& rImport
,
206 const OUString
& rLocalName
,
207 const com::sun::star::uno::Reference
<
208 com::sun::star::xml::sax::XAttributeList
> & /* xAttrList */ ) :
209 SvXMLImportContext ( rImport
, nPrefix
, rLocalName
),
214 SvXMLImportContext
*SvXMLExceptionListContext::CreateChildContext(
216 const OUString
& rLocalName
,
217 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
219 SvXMLImportContext
*pContext
= 0;
221 if (nPrefix
== XML_NAMESPACE_BLOCKLIST
&&
222 IsXMLToken ( rLocalName
, XML_BLOCK
) )
223 pContext
= new SvXMLExceptionContext (rLocalRef
, nPrefix
, rLocalName
, xAttrList
);
225 pContext
= new SvXMLImportContext( rLocalRef
, nPrefix
, rLocalName
);
228 SvXMLExceptionListContext::~SvXMLExceptionListContext ( void )
232 SvXMLExceptionContext::SvXMLExceptionContext(
233 SvXMLExceptionListImport
& rImport
,
235 const OUString
& rLocalName
,
236 const com::sun::star::uno::Reference
<
237 com::sun::star::xml::sax::XAttributeList
> & xAttrList
) :
238 SvXMLImportContext ( rImport
, nPrefix
, rLocalName
),
242 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
244 for (sal_Int16 i
=0; i
< nAttrCount
; i
++)
246 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
248 sal_uInt16 nAttrPrefix
= rImport
.GetNamespaceMap().GetKeyByAttrName( rAttrName
, &aLocalName
);
249 const OUString
& rAttrValue
= xAttrList
->getValueByIndex( i
);
250 if (XML_NAMESPACE_BLOCKLIST
== nAttrPrefix
)
252 if ( IsXMLToken ( aLocalName
, XML_ABBREVIATED_NAME
) )
261 String
* pNew
= new String( sWord
);
263 if( !rLocalRef
.rList
.Insert( pNew
) )
267 SvXMLExceptionContext::~SvXMLExceptionContext ( void )