Update ooo320-m1
[ooovba.git] / sw / source / core / swg / SwXMLBlockExport.cxx
blobc672c41a1926d338e8df14d6d116e32493c38215
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwXMLBlockExport.cxx,v $
10 * $Revision: 1.15 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
33 #include <SwXMLBlockExport.hxx>
34 #include <SwXMLTextBlocks.hxx>
35 #include <xmloff/nmspmap.hxx>
36 #include <xmloff/xmlnmspe.hxx>
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star;
39 using namespace ::xmloff::token;
40 using ::rtl::OUString;
42 // #110680#
43 SwXMLBlockListExport::SwXMLBlockListExport(
44 const uno::Reference< lang::XMultiServiceFactory > xServiceFactory,
45 SwXMLTextBlocks & rBlocks,
46 const rtl::OUString &rFileName,
47 uno::Reference< xml::sax::XDocumentHandler> &rHandler)
48 : SvXMLExport( xServiceFactory, rFileName, rHandler ),
49 rBlockList(rBlocks)
51 _GetNamespaceMap().Add( GetXMLToken ( XML_NP_BLOCK_LIST ),
52 GetXMLToken ( XML_N_BLOCK_LIST ),
53 XML_NAMESPACE_BLOCKLIST );
56 sal_uInt32 SwXMLBlockListExport::exportDoc(enum XMLTokenEnum )
58 GetDocHandler()->startDocument();
60 AddAttribute ( XML_NAMESPACE_NONE,
61 _GetNamespaceMap().GetAttrNameByKey ( XML_NAMESPACE_BLOCKLIST ),
62 _GetNamespaceMap().GetNameByKey ( XML_NAMESPACE_BLOCKLIST ) );
63 AddAttribute( XML_NAMESPACE_BLOCKLIST,
64 XML_LIST_NAME,
65 OUString (rBlockList.GetName()));
67 SvXMLElementExport pRoot (*this, XML_NAMESPACE_BLOCKLIST, XML_BLOCK_LIST, sal_True, sal_True);
68 sal_uInt16 nBlocks= rBlockList.GetCount();
69 for ( sal_uInt16 i = 0; i < nBlocks; i++)
71 AddAttribute( XML_NAMESPACE_BLOCKLIST,
72 XML_ABBREVIATED_NAME,
73 OUString(rBlockList.GetShortName(i)));
74 AddAttribute( XML_NAMESPACE_BLOCKLIST,
75 XML_PACKAGE_NAME,
76 OUString(rBlockList.GetPackageName(i)));
77 AddAttribute( XML_NAMESPACE_BLOCKLIST,
78 XML_NAME,
79 OUString(rBlockList.GetLongName(i)));
80 AddAttribute( XML_NAMESPACE_BLOCKLIST,
81 XML_UNFORMATTED_TEXT,
82 rBlockList.IsOnlyTextBlock(i) ? XML_TRUE : XML_FALSE );
84 SvXMLElementExport aBlock( *this, XML_NAMESPACE_BLOCKLIST, XML_BLOCK, sal_True, sal_True);
87 GetDocHandler()->endDocument();
88 return 0;
91 // #110680#
92 SwXMLTextBlockExport::SwXMLTextBlockExport(
93 const uno::Reference< lang::XMultiServiceFactory > xServiceFactory,
94 SwXMLTextBlocks & rBlocks,
95 const rtl::OUString &rFileName,
96 uno::Reference< xml::sax::XDocumentHandler> &rHandler)
97 : SvXMLExport( xServiceFactory, rFileName, rHandler ),
98 rBlockList(rBlocks)
100 _GetNamespaceMap().Add( GetXMLToken ( XML_NP_BLOCK_LIST ),
101 GetXMLToken ( XML_N_BLOCK_LIST ),
102 XML_NAMESPACE_BLOCKLIST );
103 _GetNamespaceMap().Add( GetXMLToken ( XML_NP_OFFICE ),
104 GetXMLToken(XML_N_OFFICE_OOO),
105 XML_NAMESPACE_OFFICE );
106 _GetNamespaceMap().Add( GetXMLToken ( XML_NP_TEXT ),
107 GetXMLToken(XML_N_TEXT_OOO),
108 XML_NAMESPACE_TEXT );
111 sal_uInt32 SwXMLTextBlockExport::exportDoc(const String &rText)
113 GetDocHandler()->startDocument();
115 AddAttribute ( XML_NAMESPACE_NONE,
116 _GetNamespaceMap().GetAttrNameByKey ( XML_NAMESPACE_BLOCKLIST ),
117 _GetNamespaceMap().GetNameByKey ( XML_NAMESPACE_BLOCKLIST ) );
118 AddAttribute ( XML_NAMESPACE_NONE,
119 _GetNamespaceMap().GetAttrNameByKey ( XML_NAMESPACE_TEXT ),
120 _GetNamespaceMap().GetNameByKey ( XML_NAMESPACE_TEXT ) );
121 AddAttribute ( XML_NAMESPACE_NONE,
122 _GetNamespaceMap().GetAttrNameByKey ( XML_NAMESPACE_OFFICE ),
123 _GetNamespaceMap().GetNameByKey ( XML_NAMESPACE_OFFICE ) );
124 AddAttribute( XML_NAMESPACE_BLOCKLIST,
125 XML_LIST_NAME,
126 OUString (rBlockList.GetName()));
128 SvXMLElementExport aDocument (*this, XML_NAMESPACE_OFFICE, XML_DOCUMENT, sal_True, sal_True);
130 SvXMLElementExport aBody (*this, XML_NAMESPACE_OFFICE, XML_BODY, sal_True, sal_True);
132 xub_StrLen nPos = 0;
135 String sTemp ( rText.GetToken( 0, '\015', nPos ) );
136 SvXMLElementExport aPara (*this, XML_NAMESPACE_TEXT, XML_P, sal_True, sal_False);
137 GetDocHandler()->characters(sTemp);
138 } while (STRING_NOTFOUND != nPos );
143 GetDocHandler()->endDocument();
144 return 0;