LibreOffice Module sw (master)  1
SwXMLBlockExport.cxx
Go to the documentation of this file.
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 <com/sun/star/xml/sax/XDocumentHandler.hpp>
24 #include <xmloff/nmspmap.hxx>
25 #include <xmloff/xmlnmspe.hxx>
26 using namespace ::com::sun::star::uno;
27 using namespace ::com::sun::star;
28 using namespace ::xmloff::token;
29 
31  const uno::Reference< uno::XComponentContext >& rContext,
32  SwXMLTextBlocks & rBlocks,
33  const OUString &rFileName,
34  uno::Reference< xml::sax::XDocumentHandler> const &rHandler)
35 : SvXMLExport( rContext, "", rFileName, util::MeasureUnit::CM, rHandler ),
36  rBlockList(rBlocks)
37 {
40  XML_NAMESPACE_BLOCKLIST );
41 }
42 
44 {
45  GetDocHandler()->startDocument();
46 
48 
50  GetNamespaceMap_().GetAttrNameByKey ( XML_NAMESPACE_BLOCKLIST ),
51  GetNamespaceMap_().GetNameByKey ( XML_NAMESPACE_BLOCKLIST ) );
52  AddAttribute( XML_NAMESPACE_BLOCKLIST,
55  {
56  SvXMLElementExport aRoot (*this, XML_NAMESPACE_BLOCKLIST, XML_BLOCK_LIST, true, true);
57  sal_uInt16 nBlocks= rBlockList.GetCount();
58  for ( sal_uInt16 i = 0; i < nBlocks; i++)
59  {
60  AddAttribute( XML_NAMESPACE_BLOCKLIST,
63  AddAttribute( XML_NAMESPACE_BLOCKLIST,
66  AddAttribute( XML_NAMESPACE_BLOCKLIST,
67  XML_NAME,
69  AddAttribute( XML_NAMESPACE_BLOCKLIST,
72 
73  SvXMLElementExport aBlock( *this, XML_NAMESPACE_BLOCKLIST, XML_BLOCK, true, true);
74  }
75  }
76  GetDocHandler()->endDocument();
77  return ERRCODE_NONE;
78 }
79 
81  const uno::Reference< uno::XComponentContext >& rContext,
82  SwXMLTextBlocks & rBlocks,
83  const OUString &rFileName,
84  uno::Reference< xml::sax::XDocumentHandler> const &rHandler)
85 : SvXMLExport( rContext, "", rFileName, util::MeasureUnit::CM, rHandler ),
86  rBlockList(rBlocks)
87 {
90  XML_NAMESPACE_BLOCKLIST );
93  XML_NAMESPACE_OFFICE );
96  XML_NAMESPACE_TEXT );
97 }
98 
99 void SwXMLTextBlockExport::exportDoc(const OUString &rText)
100 {
101  GetDocHandler()->startDocument();
102 
104 
106  GetNamespaceMap_().GetAttrNameByKey ( XML_NAMESPACE_BLOCKLIST ),
107  GetNamespaceMap_().GetNameByKey ( XML_NAMESPACE_BLOCKLIST ) );
109  GetNamespaceMap_().GetAttrNameByKey ( XML_NAMESPACE_TEXT ),
110  GetNamespaceMap_().GetNameByKey ( XML_NAMESPACE_TEXT ) );
112  GetNamespaceMap_().GetAttrNameByKey ( XML_NAMESPACE_OFFICE ),
113  GetNamespaceMap_().GetNameByKey ( XML_NAMESPACE_OFFICE ) );
114  AddAttribute( XML_NAMESPACE_BLOCKLIST,
116  rBlockList.GetName());
117  {
118  SvXMLElementExport aDocument (*this, XML_NAMESPACE_OFFICE, XML_DOCUMENT, true, true);
119  {
120  SvXMLElementExport aBody (*this, XML_NAMESPACE_OFFICE, XML_BODY, true, true);
121  {
122  sal_Int32 nPos = 0;
123  do
124  {
125  OUString sTemp ( rText.getToken( 0, '\015', nPos ) );
126  SvXMLElementExport aPara (*this, XML_NAMESPACE_TEXT, XML_P, true, false);
127  GetDocHandler()->characters(sTemp);
128  } while (-1 != nPos );
129  }
130 
131  }
132  }
133  GetDocHandler()->endDocument();
134 }
135 
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XML_N_BLOCK_LIST
ScriptDocument aDocument
XML_NP_BLOCK_LIST
XML_NAME
void addChaffWhenEncryptedStorage()
const sal_uInt16 XML_NAMESPACE_NONE
XML_N_TEXT_OOO
XML_UNFORMATTED_TEXT
virtual bool IsOnlyTextBlock(const OUString &rShort) const override
XML_ABBREVIATED_NAME
XML_BODY
void AddAttribute(sal_uInt16 nPrefix, const sal_Char *pName, const OUString &rValue)
SwXMLBlockListExport(const css::uno::Reference< css::uno::XComponentContext > &rContext, SwXMLTextBlocks &rBlocks, const OUString &rFileName, css::uno::Reference< css::xml::sax::XDocumentHandler > const &rHandler)
ErrCode exportDoc(enum::xmloff::token::XMLTokenEnum eClass=::xmloff::token::XML_TOKEN_INVALID) override
const css::uno::Reference< css::xml::sax::XDocumentHandler > & GetDocHandler()
sal_uInt16 GetCount() const
Hashcode for Block names.
Definition: swblocks.cxx:129
XML_NP_OFFICE
XML_FALSE
XML_PACKAGE_NAME
XMLTokenEnum
XML_LIST_NAME
int i
XML_NP_TEXT
XML_N_OFFICE_OOO
OUString GetShortName(sal_uInt16) const
Index for longnames.
Definition: swblocks.cxx:164
OUString GetLongName(sal_uInt16) const
Return shortname for index.
Definition: swblocks.cxx:171
XML_BLOCK_LIST
XML_DOCUMENT
SwXMLTextBlockExport(const css::uno::Reference< css::uno::XComponentContext > &rContext, SwXMLTextBlocks &rBlocks, const OUString &rFileName, css::uno::Reference< css::xml::sax::XDocumentHandler > const &rHandler)
SvXMLNamespaceMap & GetNamespaceMap_()
#define ERRCODE_NONE
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
const OUString & GetName()
Definition: swblocks.hxx:103
XML_BLOCK
ErrCode exportDoc(enum::xmloff::token::XMLTokenEnum) override
XML_P
sal_uInt16 Add(const OUString &rPrefix, const OUString &rName, sal_uInt16 nKey=XML_NAMESPACE_UNKNOWN)
XML_TRUE
OUString GetPackageName(sal_uInt16) const
Return longname for index.
Definition: swblocks.cxx:178
SwXMLTextBlocks & rBlockList
SwXMLTextBlocks & rBlockList
sal_Int32 nPos