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(
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
);
71 pContext
= SvXMLImport::CreateContext( nPrefix
, rLocalName
, xAttrList
);
75 SvXMLWordListContext::SvXMLWordListContext(
76 SvXMLAutoCorrectImport
& rImport
,
78 const OUString
& rLocalName
,
79 const com::sun::star::uno::Reference
<
80 com::sun::star::xml::sax::XAttributeList
> & /*xAttrList*/ ) :
81 SvXMLImportContext ( rImport
, nPrefix
, rLocalName
),
86 SvXMLImportContext
*SvXMLWordListContext::CreateChildContext(
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
);
97 pContext
= new SvXMLImportContext( rLocalRef
, nPrefix
, rLocalName
);
100 SvXMLWordListContext::~SvXMLWordListContext ( void )
104 SvXMLWordContext::SvXMLWordContext(
105 SvXMLAutoCorrectImport
& rImport
,
107 const OUString
& rLocalName
,
108 const com::sun::star::uno::Reference
<
109 com::sun::star::xml::sax::XAttributeList
> & xAttrList
) :
110 SvXMLImportContext ( rImport
, nPrefix
, rLocalName
),
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
);
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
) )
128 else if ( IsXMLToken ( aLocalName
, XML_NAME
) )
134 if (!sWrong
.Len() || !sRight
.Len() )
137 sal_Bool bOnlyTxt
= sRight
!= sWrong
;
140 String
sLongSave( sRight
);
141 if( !rLocalRef
.rAutoCorrect
.GetLongText( rLocalRef
.xStorage
, String(), sWrong
, sRight
) &&
148 SvxAutocorrWordPtr pNew
= new SvxAutocorrWord( sWrong
, sRight
, bOnlyTxt
);
150 if( !rLocalRef
.pAutocorr_List
->Insert( pNew
) )
154 SvXMLWordContext::~SvXMLWordContext ( void )
158 SvXMLExceptionListImport::SvXMLExceptionListImport(
159 const uno::Reference
< lang::XMultiServiceFactory
> xServiceFactory
,
160 SvStringsISortDtor
& rNewList
)
161 : SvXMLImport( xServiceFactory
),
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(
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
);
185 pContext
= SvXMLImport::CreateContext( nPrefix
, rLocalName
, xAttrList
);
189 SvXMLExceptionListContext::SvXMLExceptionListContext(
190 SvXMLExceptionListImport
& rImport
,
192 const OUString
& rLocalName
,
193 const com::sun::star::uno::Reference
<
194 com::sun::star::xml::sax::XAttributeList
> & /* xAttrList */ ) :
195 SvXMLImportContext ( rImport
, nPrefix
, rLocalName
),
200 SvXMLImportContext
*SvXMLExceptionListContext::CreateChildContext(
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
);
211 pContext
= new SvXMLImportContext( rLocalRef
, nPrefix
, rLocalName
);
214 SvXMLExceptionListContext::~SvXMLExceptionListContext ( void )
218 SvXMLExceptionContext::SvXMLExceptionContext(
219 SvXMLExceptionListImport
& rImport
,
221 const OUString
& rLocalName
,
222 const com::sun::star::uno::Reference
<
223 com::sun::star::xml::sax::XAttributeList
> & xAttrList
) :
224 SvXMLImportContext ( rImport
, nPrefix
, rLocalName
),
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
);
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
) )
247 String
* pNew
= new String( sWord
);
249 if( !rLocalRef
.rList
.Insert( pNew
) )
253 SvXMLExceptionContext::~SvXMLExceptionContext ( void )
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */