1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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/namespacemap.hxx>
25 #include <xmloff/xmlnamespace.hxx>
26 #include <o3tl/string_view.hxx>
28 using namespace ::com::sun::star::uno
;
29 using namespace ::com::sun::star
;
30 using namespace ::xmloff::token
;
32 SwXMLBlockListExport::SwXMLBlockListExport(
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
),
40 GetNamespaceMap_().Add( GetXMLToken ( XML_NP_BLOCK_LIST
),
41 GetXMLToken ( XML_N_BLOCK_LIST
),
42 XML_NAMESPACE_BLOCKLIST
);
45 ErrCode
SwXMLBlockListExport::exportDoc(enum XMLTokenEnum
)
47 GetDocHandler()->startDocument();
49 addChaffWhenEncryptedStorage();
51 AddAttribute ( XML_NAMESPACE_NONE
,
52 GetNamespaceMap_().GetAttrNameByKey ( XML_NAMESPACE_BLOCKLIST
),
53 GetNamespaceMap_().GetNameByKey ( XML_NAMESPACE_BLOCKLIST
) );
54 AddAttribute( XML_NAMESPACE_BLOCKLIST
,
56 m_rBlockList
.GetName());
58 SvXMLElementExport
aRoot (*this, XML_NAMESPACE_BLOCKLIST
, XML_BLOCK_LIST
, true, true);
59 sal_uInt16 nBlocks
= m_rBlockList
.GetCount();
60 for ( sal_uInt16 i
= 0; i
< nBlocks
; i
++)
62 AddAttribute( XML_NAMESPACE_BLOCKLIST
,
64 m_rBlockList
.GetShortName(i
));
65 AddAttribute( XML_NAMESPACE_BLOCKLIST
,
67 m_rBlockList
.GetPackageName(i
));
68 AddAttribute( XML_NAMESPACE_BLOCKLIST
,
70 m_rBlockList
.GetLongName(i
));
71 AddAttribute( XML_NAMESPACE_BLOCKLIST
,
73 m_rBlockList
.IsOnlyTextBlock(i
) ? XML_TRUE
: XML_FALSE
);
75 SvXMLElementExport
aBlock( *this, XML_NAMESPACE_BLOCKLIST
, XML_BLOCK
, true, true);
78 GetDocHandler()->endDocument();
82 SwXMLTextBlockExport::SwXMLTextBlockExport(
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
),
90 GetNamespaceMap_().Add( GetXMLToken ( XML_NP_BLOCK_LIST
),
91 GetXMLToken ( XML_N_BLOCK_LIST
),
92 XML_NAMESPACE_BLOCKLIST
);
93 GetNamespaceMap_().Add( GetXMLToken ( XML_NP_OFFICE
),
94 GetXMLToken(XML_N_OFFICE_OOO
),
95 XML_NAMESPACE_OFFICE
);
96 GetNamespaceMap_().Add( GetXMLToken ( XML_NP_TEXT
),
97 GetXMLToken(XML_N_TEXT_OOO
),
101 void SwXMLTextBlockExport::exportDoc(std::u16string_view rText
)
103 GetDocHandler()->startDocument();
105 addChaffWhenEncryptedStorage();
107 AddAttribute ( XML_NAMESPACE_NONE
,
108 GetNamespaceMap_().GetAttrNameByKey ( XML_NAMESPACE_BLOCKLIST
),
109 GetNamespaceMap_().GetNameByKey ( XML_NAMESPACE_BLOCKLIST
) );
110 AddAttribute ( XML_NAMESPACE_NONE
,
111 GetNamespaceMap_().GetAttrNameByKey ( XML_NAMESPACE_TEXT
),
112 GetNamespaceMap_().GetNameByKey ( XML_NAMESPACE_TEXT
) );
113 AddAttribute ( XML_NAMESPACE_NONE
,
114 GetNamespaceMap_().GetAttrNameByKey ( XML_NAMESPACE_OFFICE
),
115 GetNamespaceMap_().GetNameByKey ( XML_NAMESPACE_OFFICE
) );
116 AddAttribute( XML_NAMESPACE_BLOCKLIST
,
118 m_rBlockList
.GetName());
120 SvXMLElementExport
aDocument (*this, XML_NAMESPACE_OFFICE
, XML_DOCUMENT
, true, true);
122 SvXMLElementExport
aBody (*this, XML_NAMESPACE_OFFICE
, XML_BODY
, true, true);
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
);
135 GetDocHandler()->endDocument();
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */