1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_sw.hxx" 26 #include <SwXMLBlockExport.hxx> 27 #include <SwXMLTextBlocks.hxx> 28 #include <xmloff/nmspmap.hxx> 29 #include <xmloff/xmlnmspe.hxx> 30 using namespace ::com::sun::star::uno; 31 using namespace ::com::sun::star; 32 using namespace ::xmloff::token; 33 using ::rtl::OUString; 34 35 // #110680# 36 SwXMLBlockListExport::SwXMLBlockListExport( 37 const uno::Reference< lang::XMultiServiceFactory > xServiceFactory, 38 SwXMLTextBlocks & rBlocks, 39 const rtl::OUString &rFileName, 40 uno::Reference< xml::sax::XDocumentHandler> &rHandler) 41 : SvXMLExport( xServiceFactory, rFileName, rHandler ), 42 rBlockList(rBlocks) 43 { 44 _GetNamespaceMap().Add( GetXMLToken ( XML_NP_BLOCK_LIST ), 45 GetXMLToken ( XML_N_BLOCK_LIST ), 46 XML_NAMESPACE_BLOCKLIST ); 47 } 48 49 sal_uInt32 SwXMLBlockListExport::exportDoc(enum XMLTokenEnum ) 50 { 51 GetDocHandler()->startDocument(); 52 53 AddAttribute ( XML_NAMESPACE_NONE, 54 _GetNamespaceMap().GetAttrNameByKey ( XML_NAMESPACE_BLOCKLIST ), 55 _GetNamespaceMap().GetNameByKey ( XML_NAMESPACE_BLOCKLIST ) ); 56 AddAttribute( XML_NAMESPACE_BLOCKLIST, 57 XML_LIST_NAME, 58 OUString (rBlockList.GetName())); 59 { 60 SvXMLElementExport pRoot (*this, XML_NAMESPACE_BLOCKLIST, XML_BLOCK_LIST, sal_True, sal_True); 61 sal_uInt16 nBlocks= rBlockList.GetCount(); 62 for ( sal_uInt16 i = 0; i < nBlocks; i++) 63 { 64 AddAttribute( XML_NAMESPACE_BLOCKLIST, 65 XML_ABBREVIATED_NAME, 66 OUString(rBlockList.GetShortName(i))); 67 AddAttribute( XML_NAMESPACE_BLOCKLIST, 68 XML_PACKAGE_NAME, 69 OUString(rBlockList.GetPackageName(i))); 70 AddAttribute( XML_NAMESPACE_BLOCKLIST, 71 XML_NAME, 72 OUString(rBlockList.GetLongName(i))); 73 AddAttribute( XML_NAMESPACE_BLOCKLIST, 74 XML_UNFORMATTED_TEXT, 75 rBlockList.IsOnlyTextBlock(i) ? XML_TRUE : XML_FALSE ); 76 77 SvXMLElementExport aBlock( *this, XML_NAMESPACE_BLOCKLIST, XML_BLOCK, sal_True, sal_True); 78 } 79 } 80 GetDocHandler()->endDocument(); 81 return 0; 82 } 83 84 // #110680# 85 SwXMLTextBlockExport::SwXMLTextBlockExport( 86 const uno::Reference< lang::XMultiServiceFactory > xServiceFactory, 87 SwXMLTextBlocks & rBlocks, 88 const rtl::OUString &rFileName, 89 uno::Reference< xml::sax::XDocumentHandler> &rHandler) 90 : SvXMLExport( xServiceFactory, rFileName, rHandler ), 91 rBlockList(rBlocks) 92 { 93 _GetNamespaceMap().Add( GetXMLToken ( XML_NP_BLOCK_LIST ), 94 GetXMLToken ( XML_N_BLOCK_LIST ), 95 XML_NAMESPACE_BLOCKLIST ); 96 _GetNamespaceMap().Add( GetXMLToken ( XML_NP_OFFICE ), 97 GetXMLToken(XML_N_OFFICE_OOO), 98 XML_NAMESPACE_OFFICE ); 99 _GetNamespaceMap().Add( GetXMLToken ( XML_NP_TEXT ), 100 GetXMLToken(XML_N_TEXT_OOO), 101 XML_NAMESPACE_TEXT ); 102 } 103 104 sal_uInt32 SwXMLTextBlockExport::exportDoc(const String &rText) 105 { 106 GetDocHandler()->startDocument(); 107 108 AddAttribute ( XML_NAMESPACE_NONE, 109 _GetNamespaceMap().GetAttrNameByKey ( XML_NAMESPACE_BLOCKLIST ), 110 _GetNamespaceMap().GetNameByKey ( XML_NAMESPACE_BLOCKLIST ) ); 111 AddAttribute ( XML_NAMESPACE_NONE, 112 _GetNamespaceMap().GetAttrNameByKey ( XML_NAMESPACE_TEXT ), 113 _GetNamespaceMap().GetNameByKey ( XML_NAMESPACE_TEXT ) ); 114 AddAttribute ( XML_NAMESPACE_NONE, 115 _GetNamespaceMap().GetAttrNameByKey ( XML_NAMESPACE_OFFICE ), 116 _GetNamespaceMap().GetNameByKey ( XML_NAMESPACE_OFFICE ) ); 117 AddAttribute( XML_NAMESPACE_BLOCKLIST, 118 XML_LIST_NAME, 119 OUString (rBlockList.GetName())); 120 { 121 SvXMLElementExport aDocument (*this, XML_NAMESPACE_OFFICE, XML_DOCUMENT, sal_True, sal_True); 122 { 123 SvXMLElementExport aBody (*this, XML_NAMESPACE_OFFICE, XML_BODY, sal_True, sal_True); 124 { 125 xub_StrLen nPos = 0; 126 do 127 { 128 String sTemp ( rText.GetToken( 0, '\015', nPos ) ); 129 SvXMLElementExport aPara (*this, XML_NAMESPACE_TEXT, XML_P, sal_True, sal_False); 130 GetDocHandler()->characters(sTemp); 131 } while (STRING_NOTFOUND != nPos ); 132 } 133 134 } 135 } 136 GetDocHandler()->endDocument(); 137 return 0; 138 } 139