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