1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20 #include "SvXMLAutoCorrectExport.hxx"
21
22 #include <com/sun/star/util/MeasureUnit.hpp>
23 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
24 #include <xmloff/xmltoken.hxx>
25
26 using namespace ::com::sun::star::uno;
27 using namespace ::com::sun::star;
28 using namespace ::xmloff::token;
29
SvXMLAutoCorrectExport(const css::uno::Reference<css::uno::XComponentContext> & xContext,const SvxAutocorrWordList * pNewAutocorr_List,const OUString & rFileName,css::uno::Reference<css::xml::sax::XDocumentHandler> const & rHandler)30 SvXMLAutoCorrectExport::SvXMLAutoCorrectExport(
31 const css::uno::Reference< css::uno::XComponentContext > & xContext,
32 const SvxAutocorrWordList * pNewAutocorr_List,
33 const OUString &rFileName,
34 css::uno::Reference< css::xml::sax::XDocumentHandler> const &rHandler)
35 : SvXMLExport( xContext, "", rFileName, util::MeasureUnit::CM, rHandler ),
36 pAutocorr_List( pNewAutocorr_List )
37 {
38 GetNamespaceMap_().Add( GetXMLToken ( XML_NP_BLOCK_LIST),
39 GetXMLToken ( XML_N_BLOCK_LIST ),
40 XML_NAMESPACE_BLOCKLIST );
41 }
42
exportDoc(enum XMLTokenEnum)43 ErrCode SvXMLAutoCorrectExport::exportDoc(enum XMLTokenEnum /*eClass*/)
44 {
45 GetDocHandler()->startDocument();
46
47 addChaffWhenEncryptedStorage();
48
49 AddAttribute ( XML_NAMESPACE_NONE,
50 GetNamespaceMap_().GetAttrNameByKey ( XML_NAMESPACE_BLOCKLIST ),
51 GetNamespaceMap_().GetNameByKey ( XML_NAMESPACE_BLOCKLIST ) );
52 {
53 SvXMLElementExport aRoot (*this, XML_NAMESPACE_BLOCKLIST, XML_BLOCK_LIST, true, true);
54 const SvxAutocorrWordList::AutocorrWordSetType& rContent = pAutocorr_List->getSortedContent();
55 for (auto const& content : rContent)
56 {
57 AddAttribute( XML_NAMESPACE_BLOCKLIST,
58 XML_ABBREVIATED_NAME,
59 content.GetShort());
60 AddAttribute( XML_NAMESPACE_BLOCKLIST,
61 XML_NAME,
62 content.IsTextOnly() ? content.GetLong() : content.GetShort());
63
64 SvXMLElementExport aBlock( *this, XML_NAMESPACE_BLOCKLIST, XML_BLOCK, true, true);
65 }
66 }
67 GetDocHandler()->endDocument();
68 return ERRCODE_NONE;
69 }
70
SvXMLExceptionListExport(const css::uno::Reference<css::uno::XComponentContext> & xContext,const SvStringsISortDtor & rNewList,const OUString & rFileName,css::uno::Reference<css::xml::sax::XDocumentHandler> const & rHandler)71 SvXMLExceptionListExport::SvXMLExceptionListExport(
72 const css::uno::Reference< css::uno::XComponentContext > & xContext,
73 const SvStringsISortDtor &rNewList,
74 const OUString &rFileName,
75 css::uno::Reference< css::xml::sax::XDocumentHandler> const &rHandler)
76 : SvXMLExport( xContext, "", rFileName, util::MeasureUnit::CM, rHandler ),
77 rList( rNewList )
78 {
79 GetNamespaceMap_().Add( GetXMLToken ( XML_NP_BLOCK_LIST ),
80 GetXMLToken ( XML_N_BLOCK_LIST ),
81 XML_NAMESPACE_BLOCKLIST );
82 }
83
exportDoc(enum XMLTokenEnum)84 ErrCode SvXMLExceptionListExport::exportDoc(enum XMLTokenEnum /*eClass*/)
85 {
86 GetDocHandler()->startDocument();
87
88 addChaffWhenEncryptedStorage();
89
90 AddAttribute ( XML_NAMESPACE_NONE,
91 GetNamespaceMap_().GetAttrNameByKey ( XML_NAMESPACE_BLOCKLIST ),
92 GetNamespaceMap_().GetNameByKey ( XML_NAMESPACE_BLOCKLIST ) );
93 {
94 SvXMLElementExport aRoot (*this, XML_NAMESPACE_BLOCKLIST, XML_BLOCK_LIST, true, true);
95 sal_uInt16 nBlocks= rList.size();
96 for ( sal_uInt16 i = 0; i < nBlocks; i++)
97 {
98 AddAttribute( XML_NAMESPACE_BLOCKLIST,
99 XML_ABBREVIATED_NAME,
100 rList[i] );
101 SvXMLElementExport aBlock( *this, XML_NAMESPACE_BLOCKLIST, XML_BLOCK, true, true);
102 }
103 }
104 GetDocHandler()->endDocument();
105 return ERRCODE_NONE;
106 }
107
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
109