Line data Source code
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 <sax/fshelper.hxx>
21 : #include "fastserializer.hxx"
22 : #include <com/sun/star/xml/sax/XFastTokenHandler.hpp>
23 : #include <rtl/ustrbuf.hxx>
24 :
25 : using namespace ::com::sun::star;
26 : using namespace ::com::sun::star::uno;
27 :
28 : namespace sax_fastparser {
29 :
30 4656 : FastSerializerHelper::FastSerializerHelper(const Reference< io::XOutputStream >& xOutputStream, bool bWriteHeader ) :
31 4656 : mpSerializer(new FastSaxSerializer(xOutputStream))
32 : {
33 4656 : if( bWriteHeader )
34 4656 : mpSerializer->startDocument();
35 4656 : }
36 :
37 4656 : FastSerializerHelper::~FastSerializerHelper()
38 : {
39 4656 : mpSerializer->endDocument();
40 4656 : delete mpSerializer;
41 4656 : }
42 :
43 163508 : void FastSerializerHelper::startElementInternal(sal_Int32 elementTokenId, ...)
44 : {
45 : va_list args;
46 163508 : va_start( args, elementTokenId );
47 163508 : TokenValueList& rAttrList = mpSerializer->getTokenValueList();
48 :
49 : while (true)
50 : {
51 247983 : sal_Int32 nName = va_arg(args, sal_Int32);
52 247983 : if (nName == FSEND_internal)
53 163508 : break;
54 84475 : const char* pValue = va_arg(args, const char*);
55 84475 : if (pValue)
56 66235 : rAttrList.push_back(TokenValue(nName, pValue));
57 : }
58 :
59 163508 : mpSerializer->startFastElement(elementTokenId);
60 247983 : va_end( args );
61 163508 : }
62 :
63 196523 : void FastSerializerHelper::singleElementInternal(sal_Int32 elementTokenId, ...)
64 : {
65 : va_list args;
66 196523 : va_start( args, elementTokenId );
67 196523 : TokenValueList& rAttrList = mpSerializer->getTokenValueList();
68 :
69 : while (true)
70 : {
71 382731 : sal_Int32 nName = va_arg(args, sal_Int32);
72 382731 : if (nName == FSEND_internal)
73 196523 : break;
74 186208 : const char* pValue = va_arg(args, const char*);
75 186208 : if (pValue)
76 185089 : rAttrList.push_back(TokenValue(nName, pValue));
77 : }
78 :
79 196523 : mpSerializer->singleFastElement(elementTokenId);
80 382731 : va_end( args );
81 196523 : }
82 :
83 183441 : void FastSerializerHelper::endElement(sal_Int32 elementTokenId)
84 : {
85 183441 : mpSerializer->endFastElement(elementTokenId);
86 183441 : }
87 :
88 19933 : void FastSerializerHelper::startElement(sal_Int32 elementTokenId, XFastAttributeListRef xAttrList)
89 : {
90 19933 : FastAttributeList* pAttrList = dynamic_cast< FastAttributeList* >(xAttrList.get());
91 : assert(pAttrList);
92 19933 : mpSerializer->startFastElement(elementTokenId, pAttrList);
93 19933 : }
94 :
95 121543 : void FastSerializerHelper::singleElement(sal_Int32 elementTokenId, XFastAttributeListRef xAttrList)
96 : {
97 121543 : FastAttributeList* pAttrList = dynamic_cast< FastAttributeList* >(xAttrList.get());
98 : assert(pAttrList);
99 121543 : mpSerializer->singleFastElement(elementTokenId, pAttrList);
100 121543 : }
101 :
102 7099 : FastSerializerHelper* FastSerializerHelper::write(const char* value)
103 : {
104 7099 : mpSerializer->write(value, -1, false);
105 7099 : return this;
106 : }
107 :
108 0 : FastSerializerHelper* FastSerializerHelper::write(const OUString& value)
109 : {
110 0 : mpSerializer->write(value);
111 0 : return this;
112 : }
113 :
114 4396 : FastSerializerHelper* FastSerializerHelper::write(sal_Int32 value)
115 : {
116 4396 : mpSerializer->write(OString::number(value));
117 4396 : return this;
118 : }
119 :
120 848 : FastSerializerHelper* FastSerializerHelper::write(sal_Int64 value)
121 : {
122 848 : mpSerializer->write(OString::number(value));
123 848 : return this;
124 : }
125 :
126 1407 : FastSerializerHelper* FastSerializerHelper::write(double value)
127 : {
128 1407 : mpSerializer->write(value);
129 1407 : return this;
130 : }
131 :
132 144 : FastSerializerHelper* FastSerializerHelper::writeEscaped(const char* value)
133 : {
134 144 : mpSerializer->write(value, -1, true);
135 144 : return this;
136 : }
137 :
138 16522 : FastSerializerHelper* FastSerializerHelper::writeEscaped(const OUString& value)
139 : {
140 16522 : if (!value.isEmpty())
141 16350 : mpSerializer->write(value, true);
142 16522 : return this;
143 : }
144 :
145 1940 : FastSerializerHelper* FastSerializerHelper::writeId(sal_Int32 tokenId)
146 : {
147 1940 : mpSerializer->writeId(tokenId);
148 1940 : return this;
149 : }
150 :
151 4385 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > FastSerializerHelper::getOutputStream()
152 : {
153 4385 : return mpSerializer->getOutputStream();
154 : }
155 :
156 121899 : void FastSerializerHelper::mark( const Sequence< sal_Int32 >& aOrder )
157 : {
158 121899 : mpSerializer->mark( aOrder );
159 121899 : }
160 :
161 121899 : void FastSerializerHelper::mergeTopMarks( MergeMarksEnum eMergeType )
162 : {
163 121899 : mpSerializer->mergeTopMarks( eMergeType );
164 121899 : }
165 :
166 141843 : FastAttributeList * FastSerializerHelper::createAttrList()
167 : {
168 141843 : return new FastAttributeList( Reference< xml::sax::XFastTokenHandler >() );
169 : }
170 :
171 :
172 2841 : }
173 :
174 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|