Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
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.
15 : : *
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).
21 : : *
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.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <SwXMLBlockExport.hxx>
30 : : #include <SwXMLTextBlocks.hxx>
31 : : #include <com/sun/star/util/MeasureUnit.hpp>
32 : : #include <xmloff/nmspmap.hxx>
33 : : #include <xmloff/xmlnmspe.hxx>
34 : : using namespace ::com::sun::star::uno;
35 : : using namespace ::com::sun::star;
36 : : using namespace ::xmloff::token;
37 : : using ::rtl::OUString;
38 : :
39 : : // #110680#
40 : 34 : SwXMLBlockListExport::SwXMLBlockListExport(
41 : : const uno::Reference< lang::XMultiServiceFactory > xServiceFactory,
42 : : SwXMLTextBlocks & rBlocks,
43 : : const rtl::OUString &rFileName,
44 : : uno::Reference< xml::sax::XDocumentHandler> &rHandler)
45 : : : SvXMLExport( xServiceFactory, rFileName, util::MeasureUnit::CM, rHandler ),
46 : 34 : rBlockList(rBlocks)
47 : : {
48 [ + - ]: 34 : _GetNamespaceMap().Add( GetXMLToken ( XML_NP_BLOCK_LIST ),
49 [ + - ]: 34 : GetXMLToken ( XML_N_BLOCK_LIST ),
50 [ + - ]: 34 : XML_NAMESPACE_BLOCKLIST );
51 : 34 : }
52 : :
53 : 34 : sal_uInt32 SwXMLBlockListExport::exportDoc(enum XMLTokenEnum )
54 : : {
55 : 34 : GetDocHandler()->startDocument();
56 : :
57 : 34 : addChaffWhenEncryptedStorage();
58 : :
59 : : AddAttribute ( XML_NAMESPACE_NONE,
60 : 34 : _GetNamespaceMap().GetAttrNameByKey ( XML_NAMESPACE_BLOCKLIST ),
61 [ + - ]: 68 : _GetNamespaceMap().GetNameByKey ( XML_NAMESPACE_BLOCKLIST ) );
62 : : AddAttribute( XML_NAMESPACE_BLOCKLIST,
63 : : XML_LIST_NAME,
64 [ + - ]: 34 : OUString (rBlockList.GetName()));
65 : : {
66 [ + - ]: 34 : SvXMLElementExport pRoot (*this, XML_NAMESPACE_BLOCKLIST, XML_BLOCK_LIST, sal_True, sal_True);
67 [ + - ]: 34 : sal_uInt16 nBlocks= rBlockList.GetCount();
68 [ + + ]: 54 : for ( sal_uInt16 i = 0; i < nBlocks; i++)
69 : : {
70 : : AddAttribute( XML_NAMESPACE_BLOCKLIST,
71 : : XML_ABBREVIATED_NAME,
72 [ + - ][ + - ]: 20 : OUString(rBlockList.GetShortName(i)));
[ + - ]
73 : : AddAttribute( XML_NAMESPACE_BLOCKLIST,
74 : : XML_PACKAGE_NAME,
75 [ + - ][ + - ]: 20 : OUString(rBlockList.GetPackageName(i)));
76 : : AddAttribute( XML_NAMESPACE_BLOCKLIST,
77 : : XML_NAME,
78 [ + - ][ + - ]: 20 : OUString(rBlockList.GetLongName(i)));
[ + - ]
79 : : AddAttribute( XML_NAMESPACE_BLOCKLIST,
80 : : XML_UNFORMATTED_TEXT,
81 [ + + ][ + - ]: 20 : rBlockList.IsOnlyTextBlock(i) ? XML_TRUE : XML_FALSE );
[ + - ]
82 : :
83 [ + - ]: 20 : SvXMLElementExport aBlock( *this, XML_NAMESPACE_BLOCKLIST, XML_BLOCK, sal_True, sal_True);
84 [ + - ][ + - ]: 54 : }
85 : : }
86 : 34 : GetDocHandler()->endDocument();
87 : 34 : return 0;
88 : : }
89 : :
90 : : // #110680#
91 : 12 : SwXMLTextBlockExport::SwXMLTextBlockExport(
92 : : const uno::Reference< lang::XMultiServiceFactory > xServiceFactory,
93 : : SwXMLTextBlocks & rBlocks,
94 : : const rtl::OUString &rFileName,
95 : : uno::Reference< xml::sax::XDocumentHandler> &rHandler)
96 : : : SvXMLExport( xServiceFactory, rFileName, util::MeasureUnit::CM, rHandler ),
97 : 12 : rBlockList(rBlocks)
98 : : {
99 [ + - ]: 12 : _GetNamespaceMap().Add( GetXMLToken ( XML_NP_BLOCK_LIST ),
100 [ + - ]: 12 : GetXMLToken ( XML_N_BLOCK_LIST ),
101 [ + - ]: 12 : XML_NAMESPACE_BLOCKLIST );
102 [ + - ]: 12 : _GetNamespaceMap().Add( GetXMLToken ( XML_NP_OFFICE ),
103 [ + - ]: 12 : GetXMLToken(XML_N_OFFICE_OOO),
104 [ + - ]: 12 : XML_NAMESPACE_OFFICE );
105 [ + - ]: 12 : _GetNamespaceMap().Add( GetXMLToken ( XML_NP_TEXT ),
106 [ + - ]: 12 : GetXMLToken(XML_N_TEXT_OOO),
107 [ + - ]: 12 : XML_NAMESPACE_TEXT );
108 : 12 : }
109 : :
110 : 12 : sal_uInt32 SwXMLTextBlockExport::exportDoc(const String &rText)
111 : : {
112 : 12 : GetDocHandler()->startDocument();
113 : :
114 : 12 : addChaffWhenEncryptedStorage();
115 : :
116 : : AddAttribute ( XML_NAMESPACE_NONE,
117 : 12 : _GetNamespaceMap().GetAttrNameByKey ( XML_NAMESPACE_BLOCKLIST ),
118 [ + - ]: 24 : _GetNamespaceMap().GetNameByKey ( XML_NAMESPACE_BLOCKLIST ) );
119 : : AddAttribute ( XML_NAMESPACE_NONE,
120 : 12 : _GetNamespaceMap().GetAttrNameByKey ( XML_NAMESPACE_TEXT ),
121 [ + - ]: 24 : _GetNamespaceMap().GetNameByKey ( XML_NAMESPACE_TEXT ) );
122 : : AddAttribute ( XML_NAMESPACE_NONE,
123 : 12 : _GetNamespaceMap().GetAttrNameByKey ( XML_NAMESPACE_OFFICE ),
124 [ + - ]: 24 : _GetNamespaceMap().GetNameByKey ( XML_NAMESPACE_OFFICE ) );
125 : : AddAttribute( XML_NAMESPACE_BLOCKLIST,
126 : : XML_LIST_NAME,
127 [ + - ]: 12 : OUString (rBlockList.GetName()));
128 : : {
129 [ + - ]: 12 : SvXMLElementExport aDocument (*this, XML_NAMESPACE_OFFICE, XML_DOCUMENT, sal_True, sal_True);
130 : : {
131 [ + - ]: 12 : SvXMLElementExport aBody (*this, XML_NAMESPACE_OFFICE, XML_BODY, sal_True, sal_True);
132 : : {
133 : 12 : xub_StrLen nPos = 0;
134 [ + + ]: 16 : do
135 : : {
136 [ + - ]: 16 : String sTemp ( rText.GetToken( 0, '\015', nPos ) );
137 [ + - ]: 16 : SvXMLElementExport aPara (*this, XML_NAMESPACE_TEXT, XML_P, sal_True, sal_False);
138 [ + - ][ + - ]: 16 : GetDocHandler()->characters(sTemp);
[ + - ][ + - ]
[ + - ]
139 : : } while (STRING_NOTFOUND != nPos );
140 [ + - ]: 12 : }
141 : :
142 [ + - ]: 12 : }
143 : : }
144 : 12 : GetDocHandler()->endDocument();
145 : 12 : return 0;
146 : : }
147 : :
148 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|