Bump for 3.6-28
[LibreOffice.git] / editeng / source / misc / SvXMLAutoCorrectImport.cxx
blob16b604d00f7679c50317eb78924b3c17bc75e38d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <SvXMLAutoCorrectImport.hxx>
30 #include <vcl/svapp.hxx>
31 #include <svl/svstdarr.hxx>
32 #include <xmloff/xmltoken.hxx>
34 using namespace ::com::sun::star;
35 using namespace ::xmloff::token;
36 using namespace ::rtl;
38 const char aBlockList[] = "_block-list";
40 SvXMLAutoCorrectImport::SvXMLAutoCorrectImport(
41 const uno::Reference< lang::XMultiServiceFactory > xServiceFactory,
42 SvxAutocorrWordList *pNewAutocorr_List,
43 SvxAutoCorrect &rNewAutoCorrect,
44 const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& rNewStorage)
45 : SvXMLImport( xServiceFactory ),
46 pAutocorr_List (pNewAutocorr_List),
47 rAutoCorrect ( rNewAutoCorrect ),
48 xStorage ( rNewStorage )
50 GetNamespaceMap().Add(
51 rtl::OUString(aBlockList),
52 GetXMLToken ( XML_N_BLOCK_LIST),
53 XML_NAMESPACE_BLOCKLIST );
56 SvXMLAutoCorrectImport::~SvXMLAutoCorrectImport ( void ) throw ()
60 SvXMLImportContext *SvXMLAutoCorrectImport::CreateContext(
61 sal_uInt16 nPrefix,
62 const OUString& rLocalName,
63 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
65 SvXMLImportContext *pContext = 0;
67 if( XML_NAMESPACE_BLOCKLIST == nPrefix &&
68 IsXMLToken ( rLocalName, XML_BLOCK_LIST ) )
69 pContext = new SvXMLWordListContext( *this, nPrefix, rLocalName, xAttrList );
70 else
71 pContext = SvXMLImport::CreateContext( nPrefix, rLocalName, xAttrList );
72 return pContext;
75 SvXMLWordListContext::SvXMLWordListContext(
76 SvXMLAutoCorrectImport& rImport,
77 sal_uInt16 nPrefix,
78 const OUString& rLocalName,
79 const com::sun::star::uno::Reference<
80 com::sun::star::xml::sax::XAttributeList > & /*xAttrList*/ ) :
81 SvXMLImportContext ( rImport, nPrefix, rLocalName ),
82 rLocalRef(rImport)
86 SvXMLImportContext *SvXMLWordListContext::CreateChildContext(
87 sal_uInt16 nPrefix,
88 const OUString& rLocalName,
89 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
91 SvXMLImportContext *pContext = 0;
93 if (nPrefix == XML_NAMESPACE_BLOCKLIST &&
94 IsXMLToken ( rLocalName, XML_BLOCK ) )
95 pContext = new SvXMLWordContext (rLocalRef, nPrefix, rLocalName, xAttrList);
96 else
97 pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
98 return pContext;
100 SvXMLWordListContext::~SvXMLWordListContext ( void )
104 SvXMLWordContext::SvXMLWordContext(
105 SvXMLAutoCorrectImport& rImport,
106 sal_uInt16 nPrefix,
107 const OUString& rLocalName,
108 const com::sun::star::uno::Reference<
109 com::sun::star::xml::sax::XAttributeList > & xAttrList ) :
110 SvXMLImportContext ( rImport, nPrefix, rLocalName ),
111 rLocalRef(rImport)
113 String sRight, sWrong;
114 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
116 for (sal_Int16 i=0; i < nAttrCount; i++)
118 const OUString& rAttrName = xAttrList->getNameByIndex( i );
119 OUString aLocalName;
120 sal_uInt16 nAttrPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName);
121 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
122 if (XML_NAMESPACE_BLOCKLIST == nAttrPrefix)
124 if ( IsXMLToken ( aLocalName, XML_ABBREVIATED_NAME ) )
126 sWrong = rAttrValue;
128 else if ( IsXMLToken ( aLocalName, XML_NAME ) )
130 sRight = rAttrValue;
134 if (!sWrong.Len() || !sRight.Len() )
135 return;
137 sal_Bool bOnlyTxt = sRight != sWrong;
138 if( !bOnlyTxt )
140 String sLongSave( sRight );
141 if( !rLocalRef.rAutoCorrect.GetLongText( rLocalRef.xStorage, String(), sWrong, sRight ) &&
142 sLongSave.Len() )
144 sRight = sLongSave;
145 bOnlyTxt = sal_True;
148 SvxAutocorrWordPtr pNew = new SvxAutocorrWord( sWrong, sRight, bOnlyTxt );
150 if( !rLocalRef.pAutocorr_List->Insert( pNew ) )
151 delete pNew;
154 SvXMLWordContext::~SvXMLWordContext ( void )
158 SvXMLExceptionListImport::SvXMLExceptionListImport(
159 const uno::Reference< lang::XMultiServiceFactory > xServiceFactory,
160 SvStringsISortDtor & rNewList )
161 : SvXMLImport( xServiceFactory ),
162 rList (rNewList)
164 GetNamespaceMap().Add(
165 rtl::OUString(aBlockList),
166 GetXMLToken ( XML_N_BLOCK_LIST),
167 XML_NAMESPACE_BLOCKLIST );
170 SvXMLExceptionListImport::~SvXMLExceptionListImport ( void ) throw ()
174 SvXMLImportContext *SvXMLExceptionListImport::CreateContext(
175 sal_uInt16 nPrefix,
176 const OUString& rLocalName,
177 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
179 SvXMLImportContext *pContext = 0;
181 if( XML_NAMESPACE_BLOCKLIST==nPrefix &&
182 IsXMLToken ( rLocalName, XML_BLOCK_LIST ) )
183 pContext = new SvXMLExceptionListContext( *this, nPrefix, rLocalName, xAttrList );
184 else
185 pContext = SvXMLImport::CreateContext( nPrefix, rLocalName, xAttrList );
186 return pContext;
189 SvXMLExceptionListContext::SvXMLExceptionListContext(
190 SvXMLExceptionListImport& rImport,
191 sal_uInt16 nPrefix,
192 const OUString& rLocalName,
193 const com::sun::star::uno::Reference<
194 com::sun::star::xml::sax::XAttributeList > & /* xAttrList */ ) :
195 SvXMLImportContext ( rImport, nPrefix, rLocalName ),
196 rLocalRef(rImport)
200 SvXMLImportContext *SvXMLExceptionListContext::CreateChildContext(
201 sal_uInt16 nPrefix,
202 const OUString& rLocalName,
203 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
205 SvXMLImportContext *pContext = 0;
207 if (nPrefix == XML_NAMESPACE_BLOCKLIST &&
208 IsXMLToken ( rLocalName, XML_BLOCK ) )
209 pContext = new SvXMLExceptionContext (rLocalRef, nPrefix, rLocalName, xAttrList);
210 else
211 pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
212 return pContext;
214 SvXMLExceptionListContext::~SvXMLExceptionListContext ( void )
218 SvXMLExceptionContext::SvXMLExceptionContext(
219 SvXMLExceptionListImport& rImport,
220 sal_uInt16 nPrefix,
221 const OUString& rLocalName,
222 const com::sun::star::uno::Reference<
223 com::sun::star::xml::sax::XAttributeList > & xAttrList ) :
224 SvXMLImportContext ( rImport, nPrefix, rLocalName ),
225 rLocalRef(rImport)
227 String sWord;
228 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
230 for (sal_Int16 i=0; i < nAttrCount; i++)
232 const OUString& rAttrName = xAttrList->getNameByIndex( i );
233 OUString aLocalName;
234 sal_uInt16 nAttrPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName);
235 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
236 if (XML_NAMESPACE_BLOCKLIST == nAttrPrefix)
238 if ( IsXMLToken ( aLocalName, XML_ABBREVIATED_NAME ) )
240 sWord = rAttrValue;
244 if (!sWord.Len() )
245 return;
247 String * pNew = new String( sWord );
249 if( !rLocalRef.rList.Insert( pNew ) )
250 delete pNew;
253 SvXMLExceptionContext::~SvXMLExceptionContext ( void )
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */