1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_editeng.hxx" 30 #include <SvXMLAutoCorrectImport.hxx> 31 #ifndef _APP_HXX //autogen 32 #include <vcl/svapp.hxx> 33 #endif 34 35 #define _SVSTDARR_STRINGSISORTDTOR 36 #define _SVSTDARR_STRINGSDTOR 37 #include <svl/svstdarr.hxx> 38 #include <xmloff/xmltoken.hxx> 39 40 using namespace ::com::sun::star; 41 using namespace ::xmloff::token; 42 using namespace ::rtl; 43 44 45 static OUString sBlockList ( RTL_CONSTASCII_USTRINGPARAM ( "_block-list" ) ); 46 47 // #110680# 48 SvXMLAutoCorrectImport::SvXMLAutoCorrectImport( 49 const uno::Reference< lang::XMultiServiceFactory > xServiceFactory, 50 SvxAutocorrWordList *pNewAutocorr_List, 51 SvxAutoCorrect &rNewAutoCorrect, 52 const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& rNewStorage) 53 : SvXMLImport( xServiceFactory ), 54 pAutocorr_List (pNewAutocorr_List), 55 rAutoCorrect ( rNewAutoCorrect ), 56 xStorage ( rNewStorage ) 57 { 58 GetNamespaceMap().Add( 59 sBlockList, 60 GetXMLToken ( XML_N_BLOCK_LIST), 61 XML_NAMESPACE_BLOCKLIST ); 62 } 63 64 SvXMLAutoCorrectImport::~SvXMLAutoCorrectImport ( void ) throw () 65 { 66 } 67 68 SvXMLImportContext *SvXMLAutoCorrectImport::CreateContext( 69 sal_uInt16 nPrefix, 70 const OUString& rLocalName, 71 const uno::Reference< xml::sax::XAttributeList > & xAttrList ) 72 { 73 SvXMLImportContext *pContext = 0; 74 75 if( XML_NAMESPACE_BLOCKLIST == nPrefix && 76 IsXMLToken ( rLocalName, XML_BLOCK_LIST ) ) 77 pContext = new SvXMLWordListContext( *this, nPrefix, rLocalName, xAttrList ); 78 else 79 pContext = SvXMLImport::CreateContext( nPrefix, rLocalName, xAttrList ); 80 return pContext; 81 } 82 83 SvXMLWordListContext::SvXMLWordListContext( 84 SvXMLAutoCorrectImport& rImport, 85 sal_uInt16 nPrefix, 86 const OUString& rLocalName, 87 const com::sun::star::uno::Reference< 88 com::sun::star::xml::sax::XAttributeList > & /*xAttrList*/ ) : 89 SvXMLImportContext ( rImport, nPrefix, rLocalName ), 90 rLocalRef(rImport) 91 { 92 } 93 94 SvXMLImportContext *SvXMLWordListContext::CreateChildContext( 95 sal_uInt16 nPrefix, 96 const OUString& rLocalName, 97 const uno::Reference< xml::sax::XAttributeList > & xAttrList ) 98 { 99 SvXMLImportContext *pContext = 0; 100 101 if (nPrefix == XML_NAMESPACE_BLOCKLIST && 102 IsXMLToken ( rLocalName, XML_BLOCK ) ) 103 pContext = new SvXMLWordContext (rLocalRef, nPrefix, rLocalName, xAttrList); 104 else 105 pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName); 106 return pContext; 107 } 108 SvXMLWordListContext::~SvXMLWordListContext ( void ) 109 { 110 } 111 112 SvXMLWordContext::SvXMLWordContext( 113 SvXMLAutoCorrectImport& rImport, 114 sal_uInt16 nPrefix, 115 const OUString& rLocalName, 116 const com::sun::star::uno::Reference< 117 com::sun::star::xml::sax::XAttributeList > & xAttrList ) : 118 SvXMLImportContext ( rImport, nPrefix, rLocalName ), 119 rLocalRef(rImport) 120 { 121 String sRight, sWrong; 122 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 123 124 for (sal_Int16 i=0; i < nAttrCount; i++) 125 { 126 const OUString& rAttrName = xAttrList->getNameByIndex( i ); 127 OUString aLocalName; 128 sal_uInt16 nAttrPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName); 129 const OUString& rAttrValue = xAttrList->getValueByIndex( i ); 130 if (XML_NAMESPACE_BLOCKLIST == nAttrPrefix) 131 { 132 if ( IsXMLToken ( aLocalName, XML_ABBREVIATED_NAME ) ) 133 { 134 sWrong = rAttrValue; 135 } 136 else if ( IsXMLToken ( aLocalName, XML_NAME ) ) 137 { 138 sRight = rAttrValue; 139 } 140 } 141 } 142 if (!sWrong.Len() || !sRight.Len() ) 143 return; 144 145 // const International& rInter = Application::GetAppInternational(); 146 // sal_Bool bOnlyTxt = COMPARE_EQUAL != rInter.Compare( sRight, sWrong, INTN_COMPARE_IGNORECASE ); 147 sal_Bool bOnlyTxt = sRight != sWrong; 148 if( !bOnlyTxt ) 149 { 150 String sLongSave( sRight ); 151 if( !rLocalRef.rAutoCorrect.GetLongText( rLocalRef.xStorage, String(), sWrong, sRight ) && 152 sLongSave.Len() ) 153 { 154 sRight = sLongSave; 155 bOnlyTxt = sal_True; 156 } 157 } 158 SvxAutocorrWordPtr pNew = new SvxAutocorrWord( sWrong, sRight, bOnlyTxt ); 159 160 if( !rLocalRef.pAutocorr_List->Insert( pNew ) ) 161 delete pNew; 162 } 163 164 SvXMLWordContext::~SvXMLWordContext ( void ) 165 { 166 } 167 168 // #110680# 169 SvXMLExceptionListImport::SvXMLExceptionListImport( 170 const uno::Reference< lang::XMultiServiceFactory > xServiceFactory, 171 SvStringsISortDtor & rNewList ) 172 : SvXMLImport( xServiceFactory ), 173 rList (rNewList) 174 { 175 GetNamespaceMap().Add( 176 sBlockList, 177 GetXMLToken ( XML_N_BLOCK_LIST), 178 XML_NAMESPACE_BLOCKLIST ); 179 } 180 181 SvXMLExceptionListImport::~SvXMLExceptionListImport ( void ) throw () 182 { 183 } 184 185 SvXMLImportContext *SvXMLExceptionListImport::CreateContext( 186 sal_uInt16 nPrefix, 187 const OUString& rLocalName, 188 const uno::Reference< xml::sax::XAttributeList > & xAttrList ) 189 { 190 SvXMLImportContext *pContext = 0; 191 192 if( XML_NAMESPACE_BLOCKLIST==nPrefix && 193 IsXMLToken ( rLocalName, XML_BLOCK_LIST ) ) 194 pContext = new SvXMLExceptionListContext( *this, nPrefix, rLocalName, xAttrList ); 195 else 196 pContext = SvXMLImport::CreateContext( nPrefix, rLocalName, xAttrList ); 197 return pContext; 198 } 199 200 SvXMLExceptionListContext::SvXMLExceptionListContext( 201 SvXMLExceptionListImport& rImport, 202 sal_uInt16 nPrefix, 203 const OUString& rLocalName, 204 const com::sun::star::uno::Reference< 205 com::sun::star::xml::sax::XAttributeList > & /* xAttrList */ ) : 206 SvXMLImportContext ( rImport, nPrefix, rLocalName ), 207 rLocalRef(rImport) 208 { 209 } 210 211 SvXMLImportContext *SvXMLExceptionListContext::CreateChildContext( 212 sal_uInt16 nPrefix, 213 const OUString& rLocalName, 214 const uno::Reference< xml::sax::XAttributeList > & xAttrList ) 215 { 216 SvXMLImportContext *pContext = 0; 217 218 if (nPrefix == XML_NAMESPACE_BLOCKLIST && 219 IsXMLToken ( rLocalName, XML_BLOCK ) ) 220 pContext = new SvXMLExceptionContext (rLocalRef, nPrefix, rLocalName, xAttrList); 221 else 222 pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName); 223 return pContext; 224 } 225 SvXMLExceptionListContext::~SvXMLExceptionListContext ( void ) 226 { 227 } 228 229 SvXMLExceptionContext::SvXMLExceptionContext( 230 SvXMLExceptionListImport& rImport, 231 sal_uInt16 nPrefix, 232 const OUString& rLocalName, 233 const com::sun::star::uno::Reference< 234 com::sun::star::xml::sax::XAttributeList > & xAttrList ) : 235 SvXMLImportContext ( rImport, nPrefix, rLocalName ), 236 rLocalRef(rImport) 237 { 238 String sWord; 239 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 240 241 for (sal_Int16 i=0; i < nAttrCount; i++) 242 { 243 const OUString& rAttrName = xAttrList->getNameByIndex( i ); 244 OUString aLocalName; 245 sal_uInt16 nAttrPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName); 246 const OUString& rAttrValue = xAttrList->getValueByIndex( i ); 247 if (XML_NAMESPACE_BLOCKLIST == nAttrPrefix) 248 { 249 if ( IsXMLToken ( aLocalName, XML_ABBREVIATED_NAME ) ) 250 { 251 sWord = rAttrValue; 252 } 253 } 254 } 255 if (!sWord.Len() ) 256 return; 257 258 String * pNew = new String( sWord ); 259 260 if( !rLocalRef.rList.Insert( pNew ) ) 261 delete pNew; 262 } 263 264 SvXMLExceptionContext::~SvXMLExceptionContext ( void ) 265 { 266 } 267