1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <SvXMLAutoCorrectImport.hxx>
21 #include <SvXMLAutoCorrectTokenHandler.hxx>
23 using namespace ::css
;
24 using namespace ::css::xml::sax
;
26 SvXMLAutoCorrectImport::SvXMLAutoCorrectImport(
27 const uno::Reference
< uno::XComponentContext
> xContext
,
28 SvxAutocorrWordList
*pNewAutocorr_List
,
29 SvxAutoCorrect
&rNewAutoCorrect
,
30 const com::sun::star::uno::Reference
< com::sun::star::embed::XStorage
>& rNewStorage
)
31 : SvXMLImport( xContext
, "" ),
32 pAutocorr_List (pNewAutocorr_List
),
33 rAutoCorrect ( rNewAutoCorrect
),
34 xStorage ( rNewStorage
)
38 SvXMLAutoCorrectImport::~SvXMLAutoCorrectImport() throw ()
42 SvXMLImportContext
*SvXMLAutoCorrectImport::CreateFastContext( sal_Int32 Element
,
43 const uno::Reference
< xml::sax::XFastAttributeList
> & xAttrList
)
45 if( Element
== SvXMLAutoCorrectToken::BLOCKLIST
)
46 return new SvXMLWordListContext( *this, Element
, xAttrList
);
48 return SvXMLImport::CreateFastContext( Element
, xAttrList
);
51 SvXMLWordListContext::SvXMLWordListContext(
52 SvXMLAutoCorrectImport
& rImport
,
53 sal_Int32
/*Element*/,
54 const com::sun::star::uno::Reference
<
55 com::sun::star::xml::sax::XFastAttributeList
> & /*xAttrList*/ ) :
56 SvXMLImportContext ( rImport
),
59 rLocalRef
.rAutoCorrect
.refreshBlockList( rLocalRef
.xStorage
);
62 com::sun::star::uno::Reference
<XFastContextHandler
> SAL_CALL
SvXMLWordListContext::createFastChildContext(
63 sal_Int32 Element
, const uno::Reference
< xml::sax::XFastAttributeList
> & xAttrList
)
64 throw (css::uno::RuntimeException
, css::xml::sax::SAXException
, std::exception
)
66 if ( Element
== SvXMLAutoCorrectToken::BLOCK
)
67 return new SvXMLWordContext (rLocalRef
, Element
, xAttrList
);
69 return new SvXMLImportContext( rLocalRef
);
72 SvXMLWordListContext::~SvXMLWordListContext()
76 SvXMLWordContext::SvXMLWordContext(
77 SvXMLAutoCorrectImport
& rImport
,
78 sal_Int32
/*Element*/,
79 const com::sun::star::uno::Reference
<
80 com::sun::star::xml::sax::XFastAttributeList
> & xAttrList
) :
81 SvXMLImportContext ( rImport
),
84 OUString sWrong
, sRight
;
85 if ( xAttrList
.is() && xAttrList
->hasAttribute( SvXMLAutoCorrectToken::ABBREVIATED_NAME
) )
86 sWrong
= xAttrList
->getValue( SvXMLAutoCorrectToken::ABBREVIATED_NAME
);
88 if ( xAttrList
.is() && xAttrList
->hasAttribute( SvXMLAutoCorrectToken::NAME
) )
89 sRight
= xAttrList
->getValue( SvXMLAutoCorrectToken::NAME
);
91 if ( sWrong
.isEmpty() || sRight
.isEmpty())
94 bool bOnlyTxt
= sRight
!= sWrong
;
97 const OUString
sLongSave( sRight
);
98 if( !rLocalRef
.rAutoCorrect
.GetLongText( sWrong
, sRight
) &&
99 !sLongSave
.isEmpty() )
105 rLocalRef
.pAutocorr_List
->LoadEntry( sWrong
, sRight
, bOnlyTxt
);
108 SvXMLWordContext::~SvXMLWordContext()
112 SvXMLExceptionListImport::SvXMLExceptionListImport(
113 const uno::Reference
< uno::XComponentContext
> xContext
,
114 SvStringsISortDtor
& rNewList
)
115 : SvXMLImport( xContext
, "" ),
120 SvXMLExceptionListImport::~SvXMLExceptionListImport() throw ()
124 SvXMLImportContext
*SvXMLExceptionListImport::CreateFastContext(sal_Int32 Element
,
125 const uno::Reference
< xml::sax::XFastAttributeList
> & xAttrList
)
127 if( Element
== SvXMLAutoCorrectToken::BLOCKLIST
)
128 return new SvXMLExceptionListContext( *this, Element
, xAttrList
);
130 return SvXMLImport::CreateFastContext( Element
, xAttrList
);
133 SvXMLExceptionListContext::SvXMLExceptionListContext(
134 SvXMLExceptionListImport
& rImport
,
135 sal_Int32
/*Element*/,
136 const com::sun::star::uno::Reference
<
137 com::sun::star::xml::sax::XFastAttributeList
> & /* xAttrList */ ) :
138 SvXMLImportContext ( rImport
),
143 com::sun::star::uno::Reference
<xml::sax::XFastContextHandler
> SAL_CALL
SvXMLExceptionListContext::createFastChildContext(
144 sal_Int32 Element
, const uno::Reference
< xml::sax::XFastAttributeList
> & xAttrList
)
145 throw (css::uno::RuntimeException
, css::xml::sax::SAXException
, std::exception
)
147 if ( Element
== SvXMLAutoCorrectToken::BLOCK
)
148 return new SvXMLExceptionContext (rLocalRef
, Element
, xAttrList
);
150 return new SvXMLImportContext( rLocalRef
);
153 SvXMLExceptionListContext::~SvXMLExceptionListContext()
157 SvXMLExceptionContext::SvXMLExceptionContext(
158 SvXMLExceptionListImport
& rImport
,
159 sal_Int32
/*Element*/,
160 const com::sun::star::uno::Reference
<
161 com::sun::star::xml::sax::XFastAttributeList
> & xAttrList
) :
162 SvXMLImportContext ( rImport
),
166 if( xAttrList
.is() && xAttrList
->hasAttribute( SvXMLAutoCorrectToken::ABBREVIATED_NAME
) )
167 sWord
= xAttrList
->getValue( SvXMLAutoCorrectToken::ABBREVIATED_NAME
);
172 rLocalRef
.rList
.insert( sWord
);
175 SvXMLExceptionContext::~SvXMLExceptionContext()
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */