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 #ifndef INCLUDED_SAX_FSHELPER_HXX
21 #define INCLUDED_SAX_FSHELPER_HXX
23 #include <com/sun/star/xml/sax/XFastAttributeList.hpp>
24 #include <com/sun/star/uno/Reference.hxx>
25 #include <com/sun/star/uno/Sequence.hxx>
26 #include <sax/saxdllapi.h>
30 namespace com
{ namespace sun
{ namespace star
{ namespace io
{ class XOutputStream
; } } } }
31 namespace sax_fastparser
{ class FastAttributeList
; }
33 constexpr sal_Int32
FSNS(sal_Int32 namespc
, sal_Int32 element
) { return (namespc
<< 16) | element
; }
35 namespace sax_fastparser
{
37 enum class MergeMarks
{ APPEND
= 0, PREPEND
= 1, POSTPONE
= 2};
39 typedef css::uno::Reference
< css::xml::sax::XFastAttributeList
> XFastAttributeListRef
;
41 class FastSaxSerializer
;
43 class SAX_DLLPUBLIC FastSerializerHelper
47 FastSerializerHelper( const css::uno::Reference
< css::io::XOutputStream
>& xOutputStream
, bool bWriteHeader
);
49 ~FastSerializerHelper();
51 /// Start an element. After the first argument there can be a number of (attribute, value) pairs.
52 template<typename
... Args
>
53 void startElement(sal_Int32 elementTokenId
, sal_Int32 attribute
, const char* value
, Args
&&... args
)
56 pushAttributeValue(attribute
, value
);
57 startElement(elementTokenId
, std::forward
<Args
>(args
)...);
59 template<typename
... Args
>
60 void startElement(sal_Int32 elementTokenId
, sal_Int32 attribute
, const OString
& value
, Args
&&... args
)
62 pushAttributeValue(attribute
, value
);
63 startElement(elementTokenId
, std::forward
<Args
>(args
)...);
65 void startElement(sal_Int32 elementTokenId
);
67 /// Start an element. After the first two arguments there can be a number of (attribute, value) pairs.
68 template<typename
... Args
>
69 void startElementNS(sal_Int32 namespaceTokenId
, sal_Int32 elementTokenId
, sal_Int32 attribute
, const char* value
, Args
&&... args
)
72 pushAttributeValue(attribute
, value
);
73 startElementNS(namespaceTokenId
, elementTokenId
, std::forward
<Args
>(args
)...);
75 template<typename
... Args
>
76 void startElementNS(sal_Int32 namespaceTokenId
, sal_Int32 elementTokenId
, sal_Int32 attribute
, const OString
& value
, Args
&&... args
)
78 pushAttributeValue(attribute
, value
);
79 startElementNS(namespaceTokenId
, elementTokenId
, std::forward
<Args
>(args
)...);
81 void startElementNS(sal_Int32 namespaceTokenId
, sal_Int32 elementTokenId
)
83 startElement(FSNS(namespaceTokenId
, elementTokenId
));
86 /// Create a single element. After the first argument there can be a number of (attribute, value) pairs.
87 template<typename
... Args
>
88 void singleElement(sal_Int32 elementTokenId
, sal_Int32 attribute
, const char* value
, Args
&&... args
)
91 pushAttributeValue(attribute
, value
);
92 singleElement(elementTokenId
, std::forward
<Args
>(args
)...);
94 template<typename
... Args
>
95 void singleElement(sal_Int32 elementTokenId
, sal_Int32 attribute
, const OString
& value
, Args
&&... args
)
97 pushAttributeValue(attribute
, value
);
98 singleElement(elementTokenId
, std::forward
<Args
>(args
)...);
100 void singleElement(sal_Int32 elementTokenId
);
102 /// Create a single element. After the first two arguments there can be a number of (attribute, value) pairs.
103 template<typename
... Args
>
104 void singleElementNS(sal_Int32 namespaceTokenId
, sal_Int32 elementTokenId
, sal_Int32 attribute
, const char* value
, Args
&&... args
)
107 pushAttributeValue(attribute
, value
);
108 singleElementNS(namespaceTokenId
, elementTokenId
, std::forward
<Args
>(args
)...);
110 template<typename
... Args
>
111 void singleElementNS(sal_Int32 namespaceTokenId
, sal_Int32 elementTokenId
, sal_Int32 attribute
, const OString
& value
, Args
&&... args
)
113 pushAttributeValue(attribute
, value
);
114 singleElementNS(namespaceTokenId
, elementTokenId
, std::forward
<Args
>(args
)...);
116 void singleElementNS(sal_Int32 namespaceTokenId
, sal_Int32 elementTokenId
)
118 singleElement(FSNS(namespaceTokenId
, elementTokenId
));
121 void endElement(sal_Int32 elementTokenId
);
122 void endElementNS(sal_Int32 namespaceTokenId
, sal_Int32 elementTokenId
)
123 { endElement( FSNS( namespaceTokenId
, elementTokenId
) ); }
125 void singleElement(sal_Int32 elementTokenId
, const XFastAttributeListRef
& xAttrList
);
126 void singleElementNS(sal_Int32 namespaceTokenId
, sal_Int32 elementTokenId
, XFastAttributeListRef
const & xAttrList
)
127 { singleElement(FSNS( namespaceTokenId
, elementTokenId
), xAttrList
); }
129 void startElement(sal_Int32 elementTokenId
, const XFastAttributeListRef
& xAttrList
);
130 void startElementNS(sal_Int32 namespaceTokenId
, sal_Int32 elementTokenId
, XFastAttributeListRef
const & xAttrList
)
131 { startElement( FSNS( namespaceTokenId
, elementTokenId
), xAttrList
); }
133 FastSerializerHelper
* write(const char* value
);
134 FastSerializerHelper
* write(const OString
& value
);
135 FastSerializerHelper
* write(const OUString
& value
);
136 FastSerializerHelper
* write(sal_Int32 value
);
137 FastSerializerHelper
* write(sal_Int64 value
);
138 FastSerializerHelper
* write(double value
);
140 FastSerializerHelper
* writeEscaped(const char* value
);
141 FastSerializerHelper
* writeEscaped(const OUString
& value
);
143 FastSerializerHelper
* writeId(sal_Int32 tokenId
);
145 css::uno::Reference
< css::io::XOutputStream
> const & getOutputStream() const;
147 static FastAttributeList
*createAttrList();
149 void mark(sal_Int32 nTag
,
150 const css::uno::Sequence
< sal_Int32
>& rOrder
=
151 css::uno::Sequence
< sal_Int32
>() );
152 void mergeTopMarks(sal_Int32 nTag
,
153 MergeMarks eMergeType
= MergeMarks::APPEND
);
156 void pushAttributeValue( sal_Int32 attribute
, const char* value
);
157 void pushAttributeValue( sal_Int32 attribute
, const OString
& value
);
159 FastSaxSerializer
* mpSerializer
;
162 typedef std::shared_ptr
< FastSerializerHelper
> FSHelperPtr
;
166 #endif // INCLUDED_SAX_FSHELPER_HXX
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */