xref: /trunk/main/sw/source/core/swg/SwXMLBlockExport.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 #include <SwXMLBlockExport.hxx>
31 #include <SwXMLTextBlocks.hxx>
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 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, rHandler ),
46     rBlockList(rBlocks)
47 {
48     _GetNamespaceMap().Add( GetXMLToken ( XML_NP_BLOCK_LIST ),
49                             GetXMLToken ( XML_N_BLOCK_LIST ),
50                             XML_NAMESPACE_BLOCKLIST );
51 }
52 
53 sal_uInt32 SwXMLBlockListExport::exportDoc(enum XMLTokenEnum )
54 {
55     GetDocHandler()->startDocument();
56 
57     AddAttribute ( XML_NAMESPACE_NONE,
58                    _GetNamespaceMap().GetAttrNameByKey ( XML_NAMESPACE_BLOCKLIST ),
59                    _GetNamespaceMap().GetNameByKey ( XML_NAMESPACE_BLOCKLIST ) );
60     AddAttribute( XML_NAMESPACE_BLOCKLIST,
61                   XML_LIST_NAME,
62                   OUString (rBlockList.GetName()));
63     {
64         SvXMLElementExport pRoot (*this, XML_NAMESPACE_BLOCKLIST, XML_BLOCK_LIST, sal_True, sal_True);
65         sal_uInt16 nBlocks= rBlockList.GetCount();
66         for ( sal_uInt16 i = 0; i < nBlocks; i++)
67         {
68             AddAttribute( XML_NAMESPACE_BLOCKLIST,
69                           XML_ABBREVIATED_NAME,
70                           OUString(rBlockList.GetShortName(i)));
71             AddAttribute( XML_NAMESPACE_BLOCKLIST,
72                           XML_PACKAGE_NAME,
73                           OUString(rBlockList.GetPackageName(i)));
74             AddAttribute( XML_NAMESPACE_BLOCKLIST,
75                           XML_NAME,
76                           OUString(rBlockList.GetLongName(i)));
77             AddAttribute( XML_NAMESPACE_BLOCKLIST,
78                           XML_UNFORMATTED_TEXT,
79                           rBlockList.IsOnlyTextBlock(i) ? XML_TRUE : XML_FALSE );
80 
81             SvXMLElementExport aBlock( *this, XML_NAMESPACE_BLOCKLIST, XML_BLOCK, sal_True, sal_True);
82         }
83     }
84     GetDocHandler()->endDocument();
85     return 0;
86 }
87 
88 // #110680#
89 SwXMLTextBlockExport::SwXMLTextBlockExport(
90     const uno::Reference< lang::XMultiServiceFactory > xServiceFactory,
91     SwXMLTextBlocks & rBlocks,
92     const rtl::OUString &rFileName,
93     uno::Reference< xml::sax::XDocumentHandler> &rHandler)
94 :   SvXMLExport( xServiceFactory, rFileName, rHandler ),
95     rBlockList(rBlocks)
96 {
97     _GetNamespaceMap().Add( GetXMLToken ( XML_NP_BLOCK_LIST ),
98                             GetXMLToken ( XML_N_BLOCK_LIST ),
99                             XML_NAMESPACE_BLOCKLIST );
100     _GetNamespaceMap().Add( GetXMLToken ( XML_NP_OFFICE ),
101                             GetXMLToken(XML_N_OFFICE_OOO),
102                             XML_NAMESPACE_OFFICE );
103     _GetNamespaceMap().Add( GetXMLToken ( XML_NP_TEXT ),
104                             GetXMLToken(XML_N_TEXT_OOO),
105                             XML_NAMESPACE_TEXT );
106 }
107 
108 sal_uInt32 SwXMLTextBlockExport::exportDoc(const String &rText)
109 {
110     GetDocHandler()->startDocument();
111 
112     AddAttribute ( XML_NAMESPACE_NONE,
113                    _GetNamespaceMap().GetAttrNameByKey ( XML_NAMESPACE_BLOCKLIST ),
114                    _GetNamespaceMap().GetNameByKey ( XML_NAMESPACE_BLOCKLIST ) );
115     AddAttribute ( XML_NAMESPACE_NONE,
116                    _GetNamespaceMap().GetAttrNameByKey ( XML_NAMESPACE_TEXT ),
117                    _GetNamespaceMap().GetNameByKey ( XML_NAMESPACE_TEXT ) );
118     AddAttribute ( XML_NAMESPACE_NONE,
119                    _GetNamespaceMap().GetAttrNameByKey ( XML_NAMESPACE_OFFICE ),
120                    _GetNamespaceMap().GetNameByKey ( XML_NAMESPACE_OFFICE ) );
121     AddAttribute( XML_NAMESPACE_BLOCKLIST,
122                   XML_LIST_NAME,
123                   OUString (rBlockList.GetName()));
124     {
125         SvXMLElementExport aDocument (*this, XML_NAMESPACE_OFFICE, XML_DOCUMENT, sal_True, sal_True);
126         {
127             SvXMLElementExport aBody (*this, XML_NAMESPACE_OFFICE, XML_BODY, sal_True, sal_True);
128             {
129                 xub_StrLen nPos = 0;
130                 do
131                 {
132                     String sTemp ( rText.GetToken( 0, '\015', nPos ) );
133                     SvXMLElementExport aPara (*this, XML_NAMESPACE_TEXT, XML_P, sal_True, sal_False);
134                     GetDocHandler()->characters(sTemp);
135                 } while (STRING_NOTFOUND != nPos );
136             }
137 
138         }
139     }
140     GetDocHandler()->endDocument();
141     return 0;
142 }
143