LibreOffice Module sax (master) 1
fshelper.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 <sal/log.hxx>
21#include <sax/fshelper.hxx>
22#include "fastserializer.hxx"
23
24using namespace ::com::sun::star;
25using namespace ::com::sun::star::uno;
26
27namespace sax_fastparser {
28
29FastSerializerHelper::FastSerializerHelper(const Reference< io::XOutputStream >& xOutputStream, bool bWriteHeader ) :
30 mpSerializer(new FastSaxSerializer(xOutputStream))
31{
32 if( bWriteHeader )
34}
35
37{
38 mpSerializer->startDocument();
39}
40
42{
43 std::unique_ptr<FastSaxSerializer> xSerializer(std::move(mpSerializer));
44 xSerializer->endDocument();
45}
46
48{
49 if (mpSerializer)
50 {
51 assert(false && "call endDocument explicitly before dtor to avoid potential exceptions during dtor");
53 }
54}
55
56void FastSerializerHelper::startElement(sal_Int32 elementTokenId)
57{
58 mpSerializer->startFastElement(elementTokenId);
59}
60void FastSerializerHelper::pushAttributeValue(sal_Int32 attribute, const char* value)
61{
62 mpSerializer->getTokenValueList().emplace_back(attribute, value);
63}
64void FastSerializerHelper::pushAttributeValue(sal_Int32 attribute, const OString& value)
65{
66 mpSerializer->getTokenValueList().emplace_back(attribute, value.getStr());
67}
68void FastSerializerHelper::singleElement(sal_Int32 elementTokenId)
69{
70 mpSerializer->singleFastElement(elementTokenId);
71}
72
73void FastSerializerHelper::endElement(sal_Int32 elementTokenId)
74{
75 mpSerializer->endFastElement(elementTokenId);
76}
77
78void FastSerializerHelper::startElement(sal_Int32 elementTokenId, const rtl::Reference<FastAttributeList>& xAttrList)
79{
80 assert(xAttrList);
81 mpSerializer->startFastElement(elementTokenId, xAttrList.get());
82}
83
84void FastSerializerHelper::singleElement(sal_Int32 elementTokenId, const rtl::Reference<FastAttributeList>& xAttrList)
85{
86 assert(xAttrList);
87 mpSerializer->singleFastElement(elementTokenId, xAttrList.get());
88}
89
91{
92 mpSerializer->write(value, -1);
93 return this;
94}
95
97{
98 mpSerializer->write(value);
99 return this;
100}
101
103{
104 mpSerializer->write(value);
105 return this;
106}
107
109{
110 mpSerializer->write(OString::number(value));
111 return this;
112}
113
115{
116 mpSerializer->write(OString::number(value));
117 return this;
118}
119
121{
122 mpSerializer->write(value);
123 return this;
124}
125
127{
128 mpSerializer->write(value, -1, true);
129 return this;
130}
131
133{
134 if (!value.empty())
135 mpSerializer->write(value, true);
136 return this;
137}
138
140{
141 mpSerializer->writeId(tokenId);
142 return this;
143}
144
145css::uno::Reference< css::io::XOutputStream > const & FastSerializerHelper::getOutputStream() const
146{
147 return mpSerializer->getOutputStream();
148}
149
151 sal_Int32 const nTag, const Sequence<sal_Int32>& rOrder)
152{
153 mpSerializer->mark(nTag, rOrder);
154}
155
157 sal_Int32 const nTag, MergeMarks const eMergeType)
158{
159 mpSerializer->mergeTopMarks(nTag, eMergeType);
160}
161
163{
164 return new FastAttributeList( nullptr );
165}
166
168{
169 mpSerializer->setAllowXEscape(bSet);
170}
171
172}
173
174/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Receives notification of sax document events to write into an XOutputStream.
void endElement(sal_Int32 elementTokenId)
Definition: fshelper.cxx:73
FastSerializerHelper * writeEscaped(const char *value)
Definition: fshelper.cxx:126
void singleElement(sal_Int32 elementTokenId, sal_Int32 attribute, const char *value, Args &&... args)
Create a single element. After the first argument there can be a number of (attribute,...
Definition: fshelper.hxx:92
void pushAttributeValue(sal_Int32 attribute, const char *value)
Definition: fshelper.cxx:60
void mergeTopMarks(sal_Int32 nTag, MergeMarks eMergeType=MergeMarks::APPEND)
Definition: fshelper.cxx:156
std::unique_ptr< FastSaxSerializer > mpSerializer
Definition: fshelper.hxx:160
void startElement(sal_Int32 elementTokenId, sal_Int32 attribute, const char *value, Args &&... args)
Start an element. After the first argument there can be a number of (attribute, value) pairs.
Definition: fshelper.hxx:58
FastSerializerHelper * write(const char *value)
Definition: fshelper.cxx:90
static rtl::Reference< FastAttributeList > createAttrList()
Definition: fshelper.cxx:162
FastSerializerHelper(const css::uno::Reference< css::io::XOutputStream > &xOutputStream, bool bWriteHeader)
Definition: fshelper.cxx:29
void mark(sal_Int32 nTag, const css::uno::Sequence< sal_Int32 > &rOrder=css::uno::Sequence< sal_Int32 >())
Definition: fshelper.cxx:150
css::uno::Reference< css::io::XOutputStream > const & getOutputStream() const
Definition: fshelper.cxx:145
FastSerializerHelper * writeId(sal_Int32 tokenId)
Definition: fshelper.cxx:139
Any value
sal_Int32 attribute