Update ooo320-m1
[ooovba.git] / svx / source / editeng / SvXMLAutoCorrectImport.cxx
blob692557307d284d25c7339b970fb83af89b8eb875
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SvXMLAutoCorrectImport.cxx,v $
10 * $Revision: 1.14 $
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>
36 #endif
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" ) );
50 // #110680#
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(
62 sBlockList,
63 GetXMLToken ( XML_N_BLOCK_LIST),
64 XML_NAMESPACE_BLOCKLIST );
67 SvXMLAutoCorrectImport::~SvXMLAutoCorrectImport ( void ) throw ()
71 SvXMLImportContext *SvXMLAutoCorrectImport::CreateContext(
72 sal_uInt16 nPrefix,
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 );
81 else
82 pContext = SvXMLImport::CreateContext( nPrefix, rLocalName, xAttrList );
83 return pContext;
86 SvXMLWordListContext::SvXMLWordListContext(
87 SvXMLAutoCorrectImport& rImport,
88 sal_uInt16 nPrefix,
89 const OUString& rLocalName,
90 const com::sun::star::uno::Reference<
91 com::sun::star::xml::sax::XAttributeList > & /*xAttrList*/ ) :
92 SvXMLImportContext ( rImport, nPrefix, rLocalName ),
93 rLocalRef(rImport)
97 SvXMLImportContext *SvXMLWordListContext::CreateChildContext(
98 sal_uInt16 nPrefix,
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);
107 else
108 pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
109 return pContext;
111 SvXMLWordListContext::~SvXMLWordListContext ( void )
115 SvXMLWordContext::SvXMLWordContext(
116 SvXMLAutoCorrectImport& rImport,
117 sal_uInt16 nPrefix,
118 const OUString& rLocalName,
119 const com::sun::star::uno::Reference<
120 com::sun::star::xml::sax::XAttributeList > & xAttrList ) :
121 SvXMLImportContext ( rImport, nPrefix, rLocalName ),
122 rLocalRef(rImport)
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 );
130 OUString aLocalName;
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 ) )
137 sWrong = rAttrValue;
139 else if ( IsXMLToken ( aLocalName, XML_NAME ) )
141 sRight = rAttrValue;
145 if (!sWrong.Len() || !sRight.Len() )
146 return;
148 // const International& rInter = Application::GetAppInternational();
149 // BOOL bOnlyTxt = COMPARE_EQUAL != rInter.Compare( sRight, sWrong, INTN_COMPARE_IGNORECASE );
150 BOOL bOnlyTxt = sRight != sWrong;
151 if( !bOnlyTxt )
153 String sLongSave( sRight );
154 if( !rLocalRef.rAutoCorrect.GetLongText( rLocalRef.xStorage, String(), sWrong, sRight ) &&
155 sLongSave.Len() )
157 sRight = sLongSave;
158 bOnlyTxt = TRUE;
161 SvxAutocorrWordPtr pNew = new SvxAutocorrWord( sWrong, sRight, bOnlyTxt );
163 if( !rLocalRef.pAutocorr_List->Insert( pNew ) )
164 delete pNew;
167 SvXMLWordContext::~SvXMLWordContext ( void )
171 // #110680#
172 SvXMLExceptionListImport::SvXMLExceptionListImport(
173 const uno::Reference< lang::XMultiServiceFactory > xServiceFactory,
174 SvStringsISortDtor & rNewList )
175 : SvXMLImport( xServiceFactory ),
176 rList (rNewList)
178 GetNamespaceMap().Add(
179 sBlockList,
180 GetXMLToken ( XML_N_BLOCK_LIST),
181 XML_NAMESPACE_BLOCKLIST );
184 SvXMLExceptionListImport::~SvXMLExceptionListImport ( void ) throw ()
188 SvXMLImportContext *SvXMLExceptionListImport::CreateContext(
189 sal_uInt16 nPrefix,
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 );
198 else
199 pContext = SvXMLImport::CreateContext( nPrefix, rLocalName, xAttrList );
200 return pContext;
203 SvXMLExceptionListContext::SvXMLExceptionListContext(
204 SvXMLExceptionListImport& rImport,
205 sal_uInt16 nPrefix,
206 const OUString& rLocalName,
207 const com::sun::star::uno::Reference<
208 com::sun::star::xml::sax::XAttributeList > & /* xAttrList */ ) :
209 SvXMLImportContext ( rImport, nPrefix, rLocalName ),
210 rLocalRef(rImport)
214 SvXMLImportContext *SvXMLExceptionListContext::CreateChildContext(
215 sal_uInt16 nPrefix,
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);
224 else
225 pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
226 return pContext;
228 SvXMLExceptionListContext::~SvXMLExceptionListContext ( void )
232 SvXMLExceptionContext::SvXMLExceptionContext(
233 SvXMLExceptionListImport& rImport,
234 sal_uInt16 nPrefix,
235 const OUString& rLocalName,
236 const com::sun::star::uno::Reference<
237 com::sun::star::xml::sax::XAttributeList > & xAttrList ) :
238 SvXMLImportContext ( rImport, nPrefix, rLocalName ),
239 rLocalRef(rImport)
241 String sWord;
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 );
247 OUString aLocalName;
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 ) )
254 sWord = rAttrValue;
258 if (!sWord.Len() )
259 return;
261 String * pNew = new String( sWord );
263 if( !rLocalRef.rList.Insert( pNew ) )
264 delete pNew;
267 SvXMLExceptionContext::~SvXMLExceptionContext ( void )