Bump version to 5.0-14
[LibreOffice.git] / sax / source / tools / fshelper.cxx
blob438aef75c48a082c8417acf4439648f5ef1e5c9d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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))
33 if( bWriteHeader )
34 mpSerializer->startDocument();
37 FastSerializerHelper::~FastSerializerHelper()
39 mpSerializer->endDocument();
40 delete mpSerializer;
43 void FastSerializerHelper::startElementInternal(sal_Int32 elementTokenId, ...)
45 va_list args;
46 va_start( args, elementTokenId );
47 TokenValueList& rAttrList = mpSerializer->getTokenValueList();
49 while (true)
51 sal_Int32 nName = va_arg(args, sal_Int32);
52 if (nName == FSEND_internal)
53 break;
54 const char* pValue = va_arg(args, const char*);
55 if (pValue)
56 rAttrList.push_back(TokenValue(nName, pValue));
59 mpSerializer->startFastElement(elementTokenId);
60 va_end( args );
63 void FastSerializerHelper::singleElementInternal(sal_Int32 elementTokenId, ...)
65 va_list args;
66 va_start( args, elementTokenId );
67 TokenValueList& rAttrList = mpSerializer->getTokenValueList();
69 while (true)
71 sal_Int32 nName = va_arg(args, sal_Int32);
72 if (nName == FSEND_internal)
73 break;
74 const char* pValue = va_arg(args, const char*);
75 if (pValue)
76 rAttrList.push_back(TokenValue(nName, pValue));
79 mpSerializer->singleFastElement(elementTokenId);
80 va_end( args );
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());
91 assert(pAttrList);
92 mpSerializer->startFastElement(elementTokenId, pAttrList);
95 void FastSerializerHelper::singleElement(sal_Int32 elementTokenId, XFastAttributeListRef xAttrList)
97 FastAttributeList* pAttrList = dynamic_cast< FastAttributeList* >(xAttrList.get());
98 assert(pAttrList);
99 mpSerializer->singleFastElement(elementTokenId, pAttrList);
102 FastSerializerHelper* FastSerializerHelper::write(const char* value)
104 mpSerializer->write(value, -1, false);
105 return this;
108 FastSerializerHelper* FastSerializerHelper::write(const OUString& value)
110 mpSerializer->write(value);
111 return this;
114 FastSerializerHelper* FastSerializerHelper::write(sal_Int32 value)
116 mpSerializer->write(OString::number(value));
117 return this;
120 FastSerializerHelper* FastSerializerHelper::write(sal_Int64 value)
122 mpSerializer->write(OString::number(value));
123 return this;
126 FastSerializerHelper* FastSerializerHelper::write(double value)
128 mpSerializer->write(value);
129 return this;
132 FastSerializerHelper* FastSerializerHelper::writeEscaped(const char* value)
134 mpSerializer->write(value, -1, true);
135 return this;
138 FastSerializerHelper* FastSerializerHelper::writeEscaped(const OUString& value)
140 if (!value.isEmpty())
141 mpSerializer->write(value, true);
142 return this;
145 FastSerializerHelper* FastSerializerHelper::writeId(sal_Int32 tokenId)
147 mpSerializer->writeId(tokenId);
148 return this;
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: */