1*190118d0SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*190118d0SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*190118d0SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*190118d0SAndrew Rist  * distributed with this work for additional information
6*190118d0SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*190118d0SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*190118d0SAndrew Rist  * "License"); you may not use this file except in compliance
9*190118d0SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*190118d0SAndrew Rist  *
11*190118d0SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*190118d0SAndrew Rist  *
13*190118d0SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*190118d0SAndrew Rist  * software distributed under the License is distributed on an
15*190118d0SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*190118d0SAndrew Rist  * KIND, either express or implied.  See the License for the
17*190118d0SAndrew Rist  * specific language governing permissions and limitations
18*190118d0SAndrew Rist  * under the License.
19*190118d0SAndrew Rist  *
20*190118d0SAndrew Rist  *************************************************************/
21*190118d0SAndrew Rist 
22*190118d0SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_editeng.hxx"
26cdf0e10cSrcweir #include <SvXMLAutoCorrectImport.hxx>
27cdf0e10cSrcweir #ifndef _APP_HXX //autogen
28cdf0e10cSrcweir #include <vcl/svapp.hxx>
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #define _SVSTDARR_STRINGSISORTDTOR
32cdf0e10cSrcweir #define _SVSTDARR_STRINGSDTOR
33cdf0e10cSrcweir #include <svl/svstdarr.hxx>
34cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir using namespace ::com::sun::star;
37cdf0e10cSrcweir using namespace ::xmloff::token;
38cdf0e10cSrcweir using namespace ::rtl;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir 
41cdf0e10cSrcweir static OUString sBlockList ( RTL_CONSTASCII_USTRINGPARAM ( "_block-list" ) );
42cdf0e10cSrcweir 
43cdf0e10cSrcweir // #110680#
SvXMLAutoCorrectImport(const uno::Reference<lang::XMultiServiceFactory> xServiceFactory,SvxAutocorrWordList * pNewAutocorr_List,SvxAutoCorrect & rNewAutoCorrect,const com::sun::star::uno::Reference<com::sun::star::embed::XStorage> & rNewStorage)44cdf0e10cSrcweir SvXMLAutoCorrectImport::SvXMLAutoCorrectImport(
45cdf0e10cSrcweir 	const uno::Reference< lang::XMultiServiceFactory > xServiceFactory,
46cdf0e10cSrcweir 	SvxAutocorrWordList *pNewAutocorr_List,
47cdf0e10cSrcweir 	SvxAutoCorrect &rNewAutoCorrect,
48cdf0e10cSrcweir     const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& rNewStorage)
49cdf0e10cSrcweir :	SvXMLImport( xServiceFactory ),
50cdf0e10cSrcweir 	pAutocorr_List (pNewAutocorr_List),
51cdf0e10cSrcweir 	rAutoCorrect ( rNewAutoCorrect ),
52cdf0e10cSrcweir     xStorage ( rNewStorage )
53cdf0e10cSrcweir {
54cdf0e10cSrcweir 	GetNamespaceMap().Add(
55cdf0e10cSrcweir 			sBlockList,
56cdf0e10cSrcweir 			GetXMLToken ( XML_N_BLOCK_LIST),
57cdf0e10cSrcweir 			XML_NAMESPACE_BLOCKLIST );
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
~SvXMLAutoCorrectImport(void)60cdf0e10cSrcweir SvXMLAutoCorrectImport::~SvXMLAutoCorrectImport ( void ) throw ()
61cdf0e10cSrcweir {
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
CreateContext(sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)64cdf0e10cSrcweir SvXMLImportContext *SvXMLAutoCorrectImport::CreateContext(
65cdf0e10cSrcweir 		sal_uInt16 nPrefix,
66cdf0e10cSrcweir 		const OUString& rLocalName,
67cdf0e10cSrcweir 		const uno::Reference< xml::sax::XAttributeList > & xAttrList )
68cdf0e10cSrcweir {
69cdf0e10cSrcweir 	SvXMLImportContext *pContext = 0;
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 	if( XML_NAMESPACE_BLOCKLIST == nPrefix &&
72cdf0e10cSrcweir 		IsXMLToken ( rLocalName, XML_BLOCK_LIST ) )
73cdf0e10cSrcweir 		pContext = new SvXMLWordListContext( *this, nPrefix, rLocalName, xAttrList );
74cdf0e10cSrcweir 	else
75cdf0e10cSrcweir 		pContext = SvXMLImport::CreateContext( nPrefix, rLocalName, xAttrList );
76cdf0e10cSrcweir 	return pContext;
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
SvXMLWordListContext(SvXMLAutoCorrectImport & rImport,sal_uInt16 nPrefix,const OUString & rLocalName,const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList> &)79cdf0e10cSrcweir SvXMLWordListContext::SvXMLWordListContext(
80cdf0e10cSrcweir    SvXMLAutoCorrectImport& rImport,
81cdf0e10cSrcweir    sal_uInt16 nPrefix,
82cdf0e10cSrcweir    const OUString& rLocalName,
83cdf0e10cSrcweir    const com::sun::star::uno::Reference<
84cdf0e10cSrcweir    com::sun::star::xml::sax::XAttributeList > & /*xAttrList*/ ) :
85cdf0e10cSrcweir    SvXMLImportContext ( rImport, nPrefix, rLocalName ),
86cdf0e10cSrcweir    rLocalRef(rImport)
87cdf0e10cSrcweir {
88cdf0e10cSrcweir }
89cdf0e10cSrcweir 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)90cdf0e10cSrcweir SvXMLImportContext *SvXMLWordListContext::CreateChildContext(
91cdf0e10cSrcweir 	sal_uInt16 nPrefix,
92cdf0e10cSrcweir 	const OUString& rLocalName,
93cdf0e10cSrcweir 	const uno::Reference< xml::sax::XAttributeList > & xAttrList )
94cdf0e10cSrcweir {
95cdf0e10cSrcweir 	SvXMLImportContext *pContext = 0;
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 	if (nPrefix == XML_NAMESPACE_BLOCKLIST &&
98cdf0e10cSrcweir 		IsXMLToken ( rLocalName, XML_BLOCK ) )
99cdf0e10cSrcweir 		pContext = new SvXMLWordContext (rLocalRef, nPrefix, rLocalName, xAttrList);
100cdf0e10cSrcweir 	else
101cdf0e10cSrcweir 		pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
102cdf0e10cSrcweir 	return pContext;
103cdf0e10cSrcweir }
~SvXMLWordListContext(void)104cdf0e10cSrcweir SvXMLWordListContext::~SvXMLWordListContext ( void )
105cdf0e10cSrcweir {
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
SvXMLWordContext(SvXMLAutoCorrectImport & rImport,sal_uInt16 nPrefix,const OUString & rLocalName,const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList> & xAttrList)108cdf0e10cSrcweir SvXMLWordContext::SvXMLWordContext(
109cdf0e10cSrcweir    SvXMLAutoCorrectImport& rImport,
110cdf0e10cSrcweir    sal_uInt16 nPrefix,
111cdf0e10cSrcweir    const OUString& rLocalName,
112cdf0e10cSrcweir    const com::sun::star::uno::Reference<
113cdf0e10cSrcweir    com::sun::star::xml::sax::XAttributeList > & xAttrList ) :
114cdf0e10cSrcweir    SvXMLImportContext ( rImport, nPrefix, rLocalName ),
115cdf0e10cSrcweir    rLocalRef(rImport)
116cdf0e10cSrcweir {
117cdf0e10cSrcweir 	String sRight, sWrong;
118cdf0e10cSrcweir 	sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 	for (sal_Int16 i=0; i < nAttrCount; i++)
121cdf0e10cSrcweir 	{
122cdf0e10cSrcweir 		const OUString& rAttrName = xAttrList->getNameByIndex( i );
123cdf0e10cSrcweir 		OUString aLocalName;
124cdf0e10cSrcweir 		sal_uInt16 nAttrPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName);
125cdf0e10cSrcweir 		const OUString& rAttrValue = xAttrList->getValueByIndex( i );
126cdf0e10cSrcweir 		if (XML_NAMESPACE_BLOCKLIST == nAttrPrefix)
127cdf0e10cSrcweir 		{
128cdf0e10cSrcweir 			if ( IsXMLToken ( aLocalName, XML_ABBREVIATED_NAME ) )
129cdf0e10cSrcweir 			{
130cdf0e10cSrcweir 				sWrong = rAttrValue;
131cdf0e10cSrcweir 			}
132cdf0e10cSrcweir 			else if ( IsXMLToken ( aLocalName, XML_NAME ) )
133cdf0e10cSrcweir 			{
134cdf0e10cSrcweir 				sRight = rAttrValue;
135cdf0e10cSrcweir 			}
136cdf0e10cSrcweir 		}
137cdf0e10cSrcweir 	}
138cdf0e10cSrcweir 	if (!sWrong.Len() || !sRight.Len() )
139cdf0e10cSrcweir 		return;
140cdf0e10cSrcweir 
141cdf0e10cSrcweir //	const International& rInter = Application::GetAppInternational();
142cdf0e10cSrcweir //	sal_Bool bOnlyTxt = COMPARE_EQUAL != rInter.Compare( sRight, sWrong, INTN_COMPARE_IGNORECASE );
143cdf0e10cSrcweir 	sal_Bool bOnlyTxt = sRight != sWrong;
144cdf0e10cSrcweir 	if( !bOnlyTxt )
145cdf0e10cSrcweir 	{
146cdf0e10cSrcweir 		String sLongSave( sRight );
147cdf0e10cSrcweir         if( !rLocalRef.rAutoCorrect.GetLongText( rLocalRef.xStorage, String(), sWrong, sRight ) &&
148cdf0e10cSrcweir             sLongSave.Len() )
149cdf0e10cSrcweir 		{
150cdf0e10cSrcweir 			sRight = sLongSave;
151cdf0e10cSrcweir 			bOnlyTxt = sal_True;
152cdf0e10cSrcweir 		}
153cdf0e10cSrcweir 	}
154cdf0e10cSrcweir 	SvxAutocorrWordPtr pNew = new SvxAutocorrWord( sWrong, sRight, bOnlyTxt );
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 	if( !rLocalRef.pAutocorr_List->Insert( pNew ) )
157cdf0e10cSrcweir 		delete pNew;
158cdf0e10cSrcweir }
159cdf0e10cSrcweir 
~SvXMLWordContext(void)160cdf0e10cSrcweir SvXMLWordContext::~SvXMLWordContext ( void )
161cdf0e10cSrcweir {
162cdf0e10cSrcweir }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir // #110680#
SvXMLExceptionListImport(const uno::Reference<lang::XMultiServiceFactory> xServiceFactory,SvStringsISortDtor & rNewList)165cdf0e10cSrcweir SvXMLExceptionListImport::SvXMLExceptionListImport(
166cdf0e10cSrcweir 	const uno::Reference< lang::XMultiServiceFactory > xServiceFactory,
167cdf0e10cSrcweir 	SvStringsISortDtor & rNewList )
168cdf0e10cSrcweir :	SvXMLImport( xServiceFactory ),
169cdf0e10cSrcweir 	rList (rNewList)
170cdf0e10cSrcweir {
171cdf0e10cSrcweir 	GetNamespaceMap().Add(
172cdf0e10cSrcweir 			sBlockList,
173cdf0e10cSrcweir 			GetXMLToken ( XML_N_BLOCK_LIST),
174cdf0e10cSrcweir 			XML_NAMESPACE_BLOCKLIST );
175cdf0e10cSrcweir }
176cdf0e10cSrcweir 
~SvXMLExceptionListImport(void)177cdf0e10cSrcweir SvXMLExceptionListImport::~SvXMLExceptionListImport ( void ) throw ()
178cdf0e10cSrcweir {
179cdf0e10cSrcweir }
180cdf0e10cSrcweir 
CreateContext(sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)181cdf0e10cSrcweir SvXMLImportContext *SvXMLExceptionListImport::CreateContext(
182cdf0e10cSrcweir 		sal_uInt16 nPrefix,
183cdf0e10cSrcweir 		const OUString& rLocalName,
184cdf0e10cSrcweir 		const uno::Reference< xml::sax::XAttributeList > & xAttrList )
185cdf0e10cSrcweir {
186cdf0e10cSrcweir 	SvXMLImportContext *pContext = 0;
187cdf0e10cSrcweir 
188cdf0e10cSrcweir 	if( XML_NAMESPACE_BLOCKLIST==nPrefix &&
189cdf0e10cSrcweir 		IsXMLToken ( rLocalName, XML_BLOCK_LIST ) )
190cdf0e10cSrcweir 		pContext = new SvXMLExceptionListContext( *this, nPrefix, rLocalName, xAttrList );
191cdf0e10cSrcweir 	else
192cdf0e10cSrcweir 		pContext = SvXMLImport::CreateContext( nPrefix, rLocalName, xAttrList );
193cdf0e10cSrcweir 	return pContext;
194cdf0e10cSrcweir }
195cdf0e10cSrcweir 
SvXMLExceptionListContext(SvXMLExceptionListImport & rImport,sal_uInt16 nPrefix,const OUString & rLocalName,const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList> &)196cdf0e10cSrcweir SvXMLExceptionListContext::SvXMLExceptionListContext(
197cdf0e10cSrcweir    SvXMLExceptionListImport& rImport,
198cdf0e10cSrcweir    sal_uInt16 nPrefix,
199cdf0e10cSrcweir    const OUString& rLocalName,
200cdf0e10cSrcweir    const com::sun::star::uno::Reference<
201cdf0e10cSrcweir    com::sun::star::xml::sax::XAttributeList > & /* xAttrList */ ) :
202cdf0e10cSrcweir    SvXMLImportContext ( rImport, nPrefix, rLocalName ),
203cdf0e10cSrcweir    rLocalRef(rImport)
204cdf0e10cSrcweir {
205cdf0e10cSrcweir }
206cdf0e10cSrcweir 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)207cdf0e10cSrcweir SvXMLImportContext *SvXMLExceptionListContext::CreateChildContext(
208cdf0e10cSrcweir 	sal_uInt16 nPrefix,
209cdf0e10cSrcweir 	const OUString& rLocalName,
210cdf0e10cSrcweir 	const uno::Reference< xml::sax::XAttributeList > & xAttrList )
211cdf0e10cSrcweir {
212cdf0e10cSrcweir 	SvXMLImportContext *pContext = 0;
213cdf0e10cSrcweir 
214cdf0e10cSrcweir 	if (nPrefix == XML_NAMESPACE_BLOCKLIST &&
215cdf0e10cSrcweir 		IsXMLToken ( rLocalName, XML_BLOCK ) )
216cdf0e10cSrcweir 		pContext = new SvXMLExceptionContext (rLocalRef, nPrefix, rLocalName, xAttrList);
217cdf0e10cSrcweir 	else
218cdf0e10cSrcweir 		pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
219cdf0e10cSrcweir 	return pContext;
220cdf0e10cSrcweir }
~SvXMLExceptionListContext(void)221cdf0e10cSrcweir SvXMLExceptionListContext::~SvXMLExceptionListContext ( void )
222cdf0e10cSrcweir {
223cdf0e10cSrcweir }
224cdf0e10cSrcweir 
SvXMLExceptionContext(SvXMLExceptionListImport & rImport,sal_uInt16 nPrefix,const OUString & rLocalName,const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList> & xAttrList)225cdf0e10cSrcweir SvXMLExceptionContext::SvXMLExceptionContext(
226cdf0e10cSrcweir    SvXMLExceptionListImport& rImport,
227cdf0e10cSrcweir    sal_uInt16 nPrefix,
228cdf0e10cSrcweir    const OUString& rLocalName,
229cdf0e10cSrcweir    const com::sun::star::uno::Reference<
230cdf0e10cSrcweir    com::sun::star::xml::sax::XAttributeList > & xAttrList ) :
231cdf0e10cSrcweir    SvXMLImportContext ( rImport, nPrefix, rLocalName ),
232cdf0e10cSrcweir    rLocalRef(rImport)
233cdf0e10cSrcweir {
234cdf0e10cSrcweir 	String sWord;
235cdf0e10cSrcweir 	sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
236cdf0e10cSrcweir 
237cdf0e10cSrcweir 	for (sal_Int16 i=0; i < nAttrCount; i++)
238cdf0e10cSrcweir 	{
239cdf0e10cSrcweir 		const OUString& rAttrName = xAttrList->getNameByIndex( i );
240cdf0e10cSrcweir 		OUString aLocalName;
241cdf0e10cSrcweir 		sal_uInt16 nAttrPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName);
242cdf0e10cSrcweir 		const OUString& rAttrValue = xAttrList->getValueByIndex( i );
243cdf0e10cSrcweir 		if (XML_NAMESPACE_BLOCKLIST == nAttrPrefix)
244cdf0e10cSrcweir 		{
245cdf0e10cSrcweir 			if ( IsXMLToken ( aLocalName, XML_ABBREVIATED_NAME ) )
246cdf0e10cSrcweir 			{
247cdf0e10cSrcweir 				sWord = rAttrValue;
248cdf0e10cSrcweir 			}
249cdf0e10cSrcweir 		}
250cdf0e10cSrcweir 	}
251cdf0e10cSrcweir 	if (!sWord.Len() )
252cdf0e10cSrcweir 		return;
253cdf0e10cSrcweir 
254cdf0e10cSrcweir 	String * pNew = new String( sWord );
255cdf0e10cSrcweir 
256cdf0e10cSrcweir 	if( !rLocalRef.rList.Insert( pNew ) )
257cdf0e10cSrcweir 		delete pNew;
258cdf0e10cSrcweir }
259cdf0e10cSrcweir 
~SvXMLExceptionContext(void)260cdf0e10cSrcweir SvXMLExceptionContext::~SvXMLExceptionContext ( void )
261cdf0e10cSrcweir {
262cdf0e10cSrcweir }
263