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 <sax/fshelper.hxx>
21 #include "fastserializer.hxx"
22 #include <com/sun/star/xml/sax/XFastTokenHandler.hpp>
23 #include <rtl/ustrbuf.hxx>
25 using namespace ::com::sun::star
;
26 using namespace ::com::sun::star::uno
;
28 namespace sax_fastparser
{
30 FastSerializerHelper::FastSerializerHelper(const Reference
< io::XOutputStream
>& xOutputStream
, bool bWriteHeader
) :
31 mpSerializer(new FastSaxSerializer(xOutputStream
))
34 mpSerializer
->startDocument();
37 FastSerializerHelper::~FastSerializerHelper()
39 mpSerializer
->endDocument();
43 void FastSerializerHelper::startElementInternal(sal_Int32 elementTokenId
, ...)
46 va_start( args
, elementTokenId
);
47 TokenValueList
& rAttrList
= mpSerializer
->getTokenValueList();
51 sal_Int32 nName
= va_arg(args
, sal_Int32
);
52 if (nName
== FSEND_internal
)
54 const char* pValue
= va_arg(args
, const char*);
56 rAttrList
.push_back(TokenValue(nName
, pValue
));
59 mpSerializer
->startFastElement(elementTokenId
);
63 void FastSerializerHelper::singleElementInternal(sal_Int32 elementTokenId
, ...)
66 va_start( args
, elementTokenId
);
67 TokenValueList
& rAttrList
= mpSerializer
->getTokenValueList();
71 sal_Int32 nName
= va_arg(args
, sal_Int32
);
72 if (nName
== FSEND_internal
)
74 const char* pValue
= va_arg(args
, const char*);
76 rAttrList
.push_back(TokenValue(nName
, pValue
));
79 mpSerializer
->singleFastElement(elementTokenId
);
83 void FastSerializerHelper::endElement(sal_Int32 elementTokenId
)
85 mpSerializer
->endFastElement(elementTokenId
);
88 void FastSerializerHelper::startElement(sal_Int32 elementTokenId
, XFastAttributeListRef xAttrList
)
90 FastAttributeList
* pAttrList
= dynamic_cast< FastAttributeList
* >(xAttrList
.get());
92 mpSerializer
->startFastElement(elementTokenId
, pAttrList
);
95 void FastSerializerHelper::singleElement(sal_Int32 elementTokenId
, XFastAttributeListRef xAttrList
)
97 FastAttributeList
* pAttrList
= dynamic_cast< FastAttributeList
* >(xAttrList
.get());
99 mpSerializer
->singleFastElement(elementTokenId
, pAttrList
);
102 FastSerializerHelper
* FastSerializerHelper::write(const char* value
)
104 mpSerializer
->write(value
, -1, false);
108 FastSerializerHelper
* FastSerializerHelper::write(const OUString
& value
)
110 mpSerializer
->write(value
);
114 FastSerializerHelper
* FastSerializerHelper::write(sal_Int32 value
)
116 mpSerializer
->write(OString::number(value
));
120 FastSerializerHelper
* FastSerializerHelper::write(sal_Int64 value
)
122 mpSerializer
->write(OString::number(value
));
126 FastSerializerHelper
* FastSerializerHelper::write(double value
)
128 mpSerializer
->write(value
);
132 FastSerializerHelper
* FastSerializerHelper::writeEscaped(const char* value
)
134 mpSerializer
->write(value
, -1, true);
138 FastSerializerHelper
* FastSerializerHelper::writeEscaped(const OUString
& value
)
140 if (!value
.isEmpty())
141 mpSerializer
->write(value
, true);
145 FastSerializerHelper
* FastSerializerHelper::writeId(sal_Int32 tokenId
)
147 mpSerializer
->writeId(tokenId
);
151 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XOutputStream
> FastSerializerHelper::getOutputStream()
153 return mpSerializer
->getOutputStream();
156 void FastSerializerHelper::mark( const Sequence
< sal_Int32
>& aOrder
)
158 mpSerializer
->mark( aOrder
);
161 void FastSerializerHelper::mergeTopMarks( MergeMarksEnum eMergeType
)
163 mpSerializer
->mergeTopMarks( eMergeType
);
166 FastAttributeList
* FastSerializerHelper::createAttrList()
168 return new FastAttributeList( Reference
< xml::sax::XFastTokenHandler
>() );
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */