Line data Source code
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 <SwXMLBlockExport.hxx>
21 : #include <SwXMLTextBlocks.hxx>
22 : #include <com/sun/star/util/MeasureUnit.hpp>
23 : #include <xmloff/nmspmap.hxx>
24 : #include <xmloff/xmlnmspe.hxx>
25 : using namespace ::com::sun::star::uno;
26 : using namespace ::com::sun::star;
27 : using namespace ::xmloff::token;
28 : using ::rtl::OUString;
29 :
30 : // #110680#
31 0 : SwXMLBlockListExport::SwXMLBlockListExport(
32 : const uno::Reference< lang::XMultiServiceFactory > xServiceFactory,
33 : SwXMLTextBlocks & rBlocks,
34 : const rtl::OUString &rFileName,
35 : uno::Reference< xml::sax::XDocumentHandler> &rHandler)
36 : : SvXMLExport( xServiceFactory, rFileName, util::MeasureUnit::CM, rHandler ),
37 0 : rBlockList(rBlocks)
38 : {
39 0 : _GetNamespaceMap().Add( GetXMLToken ( XML_NP_BLOCK_LIST ),
40 0 : GetXMLToken ( XML_N_BLOCK_LIST ),
41 0 : XML_NAMESPACE_BLOCKLIST );
42 0 : }
43 :
44 0 : sal_uInt32 SwXMLBlockListExport::exportDoc(enum XMLTokenEnum )
45 : {
46 0 : GetDocHandler()->startDocument();
47 :
48 0 : addChaffWhenEncryptedStorage();
49 :
50 : AddAttribute ( XML_NAMESPACE_NONE,
51 0 : _GetNamespaceMap().GetAttrNameByKey ( XML_NAMESPACE_BLOCKLIST ),
52 0 : _GetNamespaceMap().GetNameByKey ( XML_NAMESPACE_BLOCKLIST ) );
53 : AddAttribute( XML_NAMESPACE_BLOCKLIST,
54 : XML_LIST_NAME,
55 0 : OUString (rBlockList.GetName()));
56 : {
57 0 : SvXMLElementExport pRoot (*this, XML_NAMESPACE_BLOCKLIST, XML_BLOCK_LIST, sal_True, sal_True);
58 0 : sal_uInt16 nBlocks= rBlockList.GetCount();
59 0 : for ( sal_uInt16 i = 0; i < nBlocks; i++)
60 : {
61 : AddAttribute( XML_NAMESPACE_BLOCKLIST,
62 : XML_ABBREVIATED_NAME,
63 0 : OUString(rBlockList.GetShortName(i)));
64 : AddAttribute( XML_NAMESPACE_BLOCKLIST,
65 : XML_PACKAGE_NAME,
66 0 : OUString(rBlockList.GetPackageName(i)));
67 : AddAttribute( XML_NAMESPACE_BLOCKLIST,
68 : XML_NAME,
69 0 : OUString(rBlockList.GetLongName(i)));
70 : AddAttribute( XML_NAMESPACE_BLOCKLIST,
71 : XML_UNFORMATTED_TEXT,
72 0 : rBlockList.IsOnlyTextBlock(i) ? XML_TRUE : XML_FALSE );
73 :
74 0 : SvXMLElementExport aBlock( *this, XML_NAMESPACE_BLOCKLIST, XML_BLOCK, sal_True, sal_True);
75 0 : }
76 : }
77 0 : GetDocHandler()->endDocument();
78 0 : return 0;
79 : }
80 :
81 : // #110680#
82 0 : SwXMLTextBlockExport::SwXMLTextBlockExport(
83 : const uno::Reference< lang::XMultiServiceFactory > xServiceFactory,
84 : SwXMLTextBlocks & rBlocks,
85 : const rtl::OUString &rFileName,
86 : uno::Reference< xml::sax::XDocumentHandler> &rHandler)
87 : : SvXMLExport( xServiceFactory, rFileName, util::MeasureUnit::CM, rHandler ),
88 0 : rBlockList(rBlocks)
89 : {
90 0 : _GetNamespaceMap().Add( GetXMLToken ( XML_NP_BLOCK_LIST ),
91 0 : GetXMLToken ( XML_N_BLOCK_LIST ),
92 0 : XML_NAMESPACE_BLOCKLIST );
93 0 : _GetNamespaceMap().Add( GetXMLToken ( XML_NP_OFFICE ),
94 0 : GetXMLToken(XML_N_OFFICE_OOO),
95 0 : XML_NAMESPACE_OFFICE );
96 0 : _GetNamespaceMap().Add( GetXMLToken ( XML_NP_TEXT ),
97 0 : GetXMLToken(XML_N_TEXT_OOO),
98 0 : XML_NAMESPACE_TEXT );
99 0 : }
100 :
101 0 : sal_uInt32 SwXMLTextBlockExport::exportDoc(const String &rText)
102 : {
103 0 : GetDocHandler()->startDocument();
104 :
105 0 : addChaffWhenEncryptedStorage();
106 :
107 : AddAttribute ( XML_NAMESPACE_NONE,
108 0 : _GetNamespaceMap().GetAttrNameByKey ( XML_NAMESPACE_BLOCKLIST ),
109 0 : _GetNamespaceMap().GetNameByKey ( XML_NAMESPACE_BLOCKLIST ) );
110 : AddAttribute ( XML_NAMESPACE_NONE,
111 0 : _GetNamespaceMap().GetAttrNameByKey ( XML_NAMESPACE_TEXT ),
112 0 : _GetNamespaceMap().GetNameByKey ( XML_NAMESPACE_TEXT ) );
113 : AddAttribute ( XML_NAMESPACE_NONE,
114 0 : _GetNamespaceMap().GetAttrNameByKey ( XML_NAMESPACE_OFFICE ),
115 0 : _GetNamespaceMap().GetNameByKey ( XML_NAMESPACE_OFFICE ) );
116 : AddAttribute( XML_NAMESPACE_BLOCKLIST,
117 : XML_LIST_NAME,
118 0 : OUString (rBlockList.GetName()));
119 : {
120 0 : SvXMLElementExport aDocument (*this, XML_NAMESPACE_OFFICE, XML_DOCUMENT, sal_True, sal_True);
121 : {
122 0 : SvXMLElementExport aBody (*this, XML_NAMESPACE_OFFICE, XML_BODY, sal_True, sal_True);
123 : {
124 0 : xub_StrLen nPos = 0;
125 0 : do
126 : {
127 0 : String sTemp ( rText.GetToken( 0, '\015', nPos ) );
128 0 : SvXMLElementExport aPara (*this, XML_NAMESPACE_TEXT, XML_P, sal_True, sal_False);
129 0 : GetDocHandler()->characters(sTemp);
130 : } while (STRING_NOTFOUND != nPos );
131 0 : }
132 :
133 0 : }
134 : }
135 0 : GetDocHandler()->endDocument();
136 0 : return 0;
137 : }
138 :
139 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|