tdf#156769 - Escape the question mark in the storage name
[LibreOffice.git] / editeng / source / misc / SvXMLAutoCorrectImport.cxx
blobbaeef8861289272e94a22c24c83ef9f1a6cd85c0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <utility>
22 #include "SvXMLAutoCorrectImport.hxx"
23 #include "SvXMLAutoCorrectTokenHandler.hxx"
25 using namespace css;
26 using namespace css::xml::sax;
28 SvXMLAutoCorrectImport::SvXMLAutoCorrectImport(
29 const uno::Reference< uno::XComponentContext > & xContext,
30 SvxAutocorrWordList *pNewAutocorr_List,
31 SvxAutoCorrect &rNewAutoCorrect,
32 css::uno::Reference < css::embed::XStorage > xNewStorage)
33 : SvXMLImport( xContext, "" ),
34 pAutocorr_List (pNewAutocorr_List),
35 rAutoCorrect ( rNewAutoCorrect ),
36 xStorage (std::move( xNewStorage ))
40 SvXMLAutoCorrectImport::~SvXMLAutoCorrectImport() noexcept
44 SvXMLImportContext *SvXMLAutoCorrectImport::CreateFastContext( sal_Int32 Element,
45 const uno::Reference< xml::sax::XFastAttributeList > & /*xAttrList*/ )
47 if( Element == SvXMLAutoCorrectToken::BLOCKLIST )
48 return new SvXMLWordListContext( *this );
49 return nullptr;
52 SvXMLWordListContext::SvXMLWordListContext(
53 SvXMLAutoCorrectImport& rImport ) :
54 SvXMLImportContext ( rImport ),
55 rLocalRef(rImport)
57 rLocalRef.rAutoCorrect.refreshBlockList( rLocalRef.xStorage );
60 css::uno::Reference<XFastContextHandler> SAL_CALL SvXMLWordListContext::createFastChildContext(
61 sal_Int32 Element, const uno::Reference< xml::sax::XFastAttributeList > & xAttrList )
63 if ( Element == SvXMLAutoCorrectToken::BLOCK )
64 return new SvXMLWordContext (rLocalRef, xAttrList);
65 return nullptr;
68 SvXMLWordListContext::~SvXMLWordListContext()
72 SvXMLWordContext::SvXMLWordContext(
73 SvXMLAutoCorrectImport& rImport,
74 const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList ) :
75 SvXMLImportContext ( rImport )
77 OUString sWrong, sRight;
78 if ( xAttrList.is() && xAttrList->hasAttribute( SvXMLAutoCorrectToken::ABBREVIATED_NAME ) )
79 sWrong = xAttrList->getValue( SvXMLAutoCorrectToken::ABBREVIATED_NAME );
81 if ( xAttrList.is() && xAttrList->hasAttribute( SvXMLAutoCorrectToken::NAME ) )
82 sRight = xAttrList->getValue( SvXMLAutoCorrectToken::NAME );
84 if ( sWrong.isEmpty() || sRight.isEmpty())
85 return;
87 bool bOnlyTxt = sRight != sWrong;
88 if( !bOnlyTxt )
90 const OUString sLongSave( sRight );
91 if( !rImport.rAutoCorrect.GetLongText( sWrong, sRight ) &&
92 !sLongSave.isEmpty() )
94 sRight = sLongSave;
95 bOnlyTxt = true;
98 rImport.pAutocorr_List->LoadEntry( sWrong, sRight, bOnlyTxt );
101 SvXMLWordContext::~SvXMLWordContext()
105 SvXMLExceptionListImport::SvXMLExceptionListImport(
106 const uno::Reference< uno::XComponentContext > & xContext,
107 SvStringsISortDtor & rNewList )
108 : SvXMLImport( xContext, "" ),
109 rList (rNewList)
113 SvXMLExceptionListImport::~SvXMLExceptionListImport() noexcept
117 SvXMLImportContext *SvXMLExceptionListImport::CreateFastContext(sal_Int32 Element,
118 const uno::Reference< xml::sax::XFastAttributeList > & /*xAttrList*/ )
120 if( Element == SvXMLAutoCorrectToken::BLOCKLIST )
121 return new SvXMLExceptionListContext( *this );
122 return nullptr;
125 SvXMLExceptionListContext::SvXMLExceptionListContext(
126 SvXMLExceptionListImport& rImport ) :
127 SvXMLImportContext ( rImport ),
128 rLocalRef(rImport)
132 css::uno::Reference<xml::sax::XFastContextHandler> SAL_CALL SvXMLExceptionListContext::createFastChildContext(
133 sal_Int32 Element, const uno::Reference< xml::sax::XFastAttributeList > & xAttrList )
135 if ( Element == SvXMLAutoCorrectToken::BLOCK )
136 return new SvXMLExceptionContext (rLocalRef, xAttrList);
137 return nullptr;
140 SvXMLExceptionListContext::~SvXMLExceptionListContext()
144 SvXMLExceptionContext::SvXMLExceptionContext(
145 SvXMLExceptionListImport& rImport,
146 const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList ) :
147 SvXMLImportContext ( rImport )
149 OUString sWord;
150 if( xAttrList.is() && xAttrList->hasAttribute( SvXMLAutoCorrectToken::ABBREVIATED_NAME ) )
151 sWord = xAttrList->getValue( SvXMLAutoCorrectToken::ABBREVIATED_NAME );
153 if (sWord.isEmpty())
154 return;
156 rImport.rList.insert( sWord );
159 SvXMLExceptionContext::~SvXMLExceptionContext()
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */