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>
26#include <o3tl/string_view.hxx>
27
28using namespace ::com::sun::star::uno;
29using namespace ::com::sun::star;
30using namespace ::xmloff::token;
31
33 const uno::Reference< uno::XComponentContext >& rContext,
34 SwXMLTextBlocks & rBlocks,
35 const OUString &rFileName,
36 uno::Reference< xml::sax::XDocumentHandler> const &rHandler)
37: SvXMLExport( rContext, "", rFileName, util::MeasureUnit::CM, rHandler ),
38 m_rBlockList(rBlocks)
39{
43}
44
46{
47 GetDocHandler()->startDocument();
48
50
52 GetNamespaceMap_().GetAttrNameByKey ( XML_NAMESPACE_BLOCKLIST ),
53 GetNamespaceMap_().GetNameByKey ( XML_NAMESPACE_BLOCKLIST ) );
57 {
59 sal_uInt16 nBlocks= m_rBlockList.GetCount();
60 for ( sal_uInt16 i = 0; i < nBlocks; i++)
61 {
74
75 SvXMLElementExport aBlock( *this, XML_NAMESPACE_BLOCKLIST, XML_BLOCK, true, true);
76 }
77 }
78 GetDocHandler()->endDocument();
79 return ERRCODE_NONE;
80}
81
83 const uno::Reference< uno::XComponentContext >& rContext,
84 SwXMLTextBlocks & rBlocks,
85 const OUString &rFileName,
86 uno::Reference< xml::sax::XDocumentHandler> const &rHandler)
87: SvXMLExport( rContext, "", rFileName, util::MeasureUnit::CM, rHandler ),
88 m_rBlockList(rBlocks)
89{
99}
100
101void SwXMLTextBlockExport::exportDoc(std::u16string_view rText)
102{
103 GetDocHandler()->startDocument();
104
106
108 GetNamespaceMap_().GetAttrNameByKey ( XML_NAMESPACE_BLOCKLIST ),
109 GetNamespaceMap_().GetNameByKey ( XML_NAMESPACE_BLOCKLIST ) );
111 GetNamespaceMap_().GetAttrNameByKey ( XML_NAMESPACE_TEXT ),
112 GetNamespaceMap_().GetNameByKey ( XML_NAMESPACE_TEXT ) );
114 GetNamespaceMap_().GetAttrNameByKey ( XML_NAMESPACE_OFFICE ),
115 GetNamespaceMap_().GetNameByKey ( XML_NAMESPACE_OFFICE ) );
119 {
121 {
122 SvXMLElementExport aBody (*this, XML_NAMESPACE_OFFICE, XML_BODY, true, true);
123 {
124 sal_Int32 nPos = 0;
125 do
126 {
127 OUString sTemp ( o3tl::getToken(rText, 0, '\015', nPos ) );
128 SvXMLElementExport aPara (*this, XML_NAMESPACE_TEXT, XML_P, true, false);
129 GetDocHandler()->characters(sTemp);
130 } while (-1 != nPos );
131 }
132
133 }
134 }
135 GetDocHandler()->endDocument();
136}
137
138/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScriptDocument aDocument
void AddAttribute(sal_uInt16 nPrefix, const OUString &rName, const OUString &rValue)
SvXMLNamespaceMap & GetNamespaceMap_()
void addChaffWhenEncryptedStorage()
const css::uno::Reference< css::xml::sax::XDocumentHandler > & GetDocHandler() const
sal_uInt16 Add(const OUString &rPrefix, const OUString &rName, sal_uInt16 nKey=XML_NAMESPACE_UNKNOWN)
OUString GetLongName(sal_uInt16) const
Return shortname for index.
Definition: swblocks.cxx:161
sal_uInt16 GetCount() const
Hashcode for Block names.
Definition: swblocks.cxx:119
OUString GetPackageName(sal_uInt16) const
Return longname for index.
Definition: swblocks.cxx:168
const OUString & GetName() const
Definition: swblocks.hxx:101
OUString GetShortName(sal_uInt16) const
Index for longnames.
Definition: swblocks.cxx:154
SwXMLTextBlocks & m_rBlockList
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
SwXMLTextBlocks & m_rBlockList
ErrCode exportDoc(enum ::xmloff::token::XMLTokenEnum) override
SwXMLTextBlockExport(const css::uno::Reference< css::uno::XComponentContext > &rContext, SwXMLTextBlocks &rBlocks, const OUString &rFileName, css::uno::Reference< css::xml::sax::XDocumentHandler > const &rHandler)
virtual bool IsOnlyTextBlock(const OUString &rShort) const override
#define ERRCODE_NONE
sal_uInt16 nPos
int i
const sal_uInt16 XML_NAMESPACE_NONE
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
XMLTokenEnum
XML_BLOCK
XML_DOCUMENT
XML_TRUE
XML_NP_OFFICE
XML_PACKAGE_NAME
XML_NP_TEXT
XML_N_OFFICE_OOO
XML_FALSE
XML_N_TEXT_OOO
XML_NAME
XML_P
XML_BLOCK_LIST
XML_UNFORMATTED_TEXT
XML_N_BLOCK_LIST
XML_BODY
XML_ABBREVIATED_NAME
XML_LIST_NAME
XML_NP_BLOCK_LIST
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
constexpr sal_uInt16 XML_NAMESPACE_BLOCKLIST
constexpr sal_uInt16 XML_NAMESPACE_TEXT
constexpr sal_uInt16 XML_NAMESPACE_OFFICE