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 <sal/log.hxx>
21 #include <sax/fshelper.hxx>
22 #include "fastserializer.hxx"
24 using namespace ::com::sun::star
;
25 using namespace ::com::sun::star::uno
;
27 namespace sax_fastparser
{
29 FastSerializerHelper::FastSerializerHelper(const Reference
< io::XOutputStream
>& xOutputStream
, bool bWriteHeader
) :
30 mpSerializer(new FastSaxSerializer(xOutputStream
))
36 void FastSerializerHelper::startDocument()
38 mpSerializer
->startDocument();
41 void FastSerializerHelper::endDocument()
43 std::unique_ptr
<FastSaxSerializer
> xSerializer(std::move(mpSerializer
));
44 xSerializer
->endDocument();
47 FastSerializerHelper::~FastSerializerHelper()
51 assert(false && "call endDocument explicitly before dtor to avoid potential exceptions during dtor");
56 void FastSerializerHelper::startElement(sal_Int32 elementTokenId
)
58 mpSerializer
->startFastElement(elementTokenId
);
60 void FastSerializerHelper::pushAttributeValue(sal_Int32 attribute
, const char* value
)
62 mpSerializer
->getTokenValueList().emplace_back(attribute
, value
);
64 void FastSerializerHelper::pushAttributeValue(sal_Int32 attribute
, const OString
& value
)
66 mpSerializer
->getTokenValueList().emplace_back(attribute
, value
.getStr());
68 void FastSerializerHelper::singleElement(sal_Int32 elementTokenId
)
70 mpSerializer
->singleFastElement(elementTokenId
);
73 void FastSerializerHelper::endElement(sal_Int32 elementTokenId
)
75 mpSerializer
->endFastElement(elementTokenId
);
78 void FastSerializerHelper::startElement(sal_Int32 elementTokenId
, const rtl::Reference
<FastAttributeList
>& xAttrList
)
81 mpSerializer
->startFastElement(elementTokenId
, xAttrList
.get());
84 void FastSerializerHelper::singleElement(sal_Int32 elementTokenId
, const rtl::Reference
<FastAttributeList
>& xAttrList
)
87 mpSerializer
->singleFastElement(elementTokenId
, xAttrList
.get());
90 FastSerializerHelper
* FastSerializerHelper::write(const char* value
)
92 mpSerializer
->write(value
, -1);
96 FastSerializerHelper
* FastSerializerHelper::write(const OString
& value
)
98 mpSerializer
->write(value
);
102 FastSerializerHelper
* FastSerializerHelper::write(std::u16string_view value
)
104 mpSerializer
->write(value
);
108 FastSerializerHelper
* FastSerializerHelper::write(sal_Int32 value
)
110 mpSerializer
->write(OString::number(value
));
114 FastSerializerHelper
* FastSerializerHelper::write(sal_Int64 value
)
116 mpSerializer
->write(OString::number(value
));
120 FastSerializerHelper
* FastSerializerHelper::write(double value
)
122 mpSerializer
->write(value
);
126 FastSerializerHelper
* FastSerializerHelper::writeEscaped(const char* value
)
128 mpSerializer
->write(value
, -1, true);
132 FastSerializerHelper
* FastSerializerHelper::writeEscaped(std::u16string_view value
)
135 mpSerializer
->write(value
, true);
139 FastSerializerHelper
* FastSerializerHelper::writeId(sal_Int32 tokenId
)
141 mpSerializer
->writeId(tokenId
);
145 css::uno::Reference
< css::io::XOutputStream
> const & FastSerializerHelper::getOutputStream() const
147 return mpSerializer
->getOutputStream();
150 void FastSerializerHelper::mark(
151 sal_Int32
const nTag
, const Sequence
<sal_Int32
>& rOrder
)
153 mpSerializer
->mark(nTag
, rOrder
);
156 void FastSerializerHelper::mergeTopMarks(
157 sal_Int32
const nTag
, MergeMarks
const eMergeType
)
159 mpSerializer
->mergeTopMarks(nTag
, eMergeType
);
162 rtl::Reference
<FastAttributeList
> FastSerializerHelper::createAttrList()
164 return new FastAttributeList( nullptr );
167 void FastSerializerHelper::setAllowXEscape(bool bSet
)
169 mpSerializer
->setAllowXEscape(bSet
);
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */