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/FastTokenHandler.hpp>
23 : #include <comphelper/processfactory.hxx>
24 : #include <rtl/ustrbuf.hxx>
25 :
26 : using namespace ::com::sun::star;
27 : using namespace ::com::sun::star::uno;
28 :
29 : namespace sax_fastparser {
30 :
31 2014 : FastSerializerHelper::FastSerializerHelper(const Reference< io::XOutputStream >& xOutputStream, bool bWriteHeader ) :
32 2014 : mpSerializer(new FastSaxSerializer())
33 : {
34 2014 : Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext(), UNO_SET_THROW );
35 2014 : mxTokenHandler = css::xml::sax::FastTokenHandler::create(xContext);
36 :
37 2014 : mpSerializer->setFastTokenHandler( mxTokenHandler );
38 2014 : mpSerializer->setOutputStream( xOutputStream );
39 2014 : if( bWriteHeader )
40 2014 : mpSerializer->startDocument();
41 2014 : }
42 :
43 4028 : FastSerializerHelper::~FastSerializerHelper()
44 : {
45 2014 : mpSerializer->endDocument();
46 2014 : delete mpSerializer;
47 2014 : }
48 :
49 82853 : void FastSerializerHelper::startElementInternal(sal_Int32 elementTokenId, ...)
50 : {
51 : va_list args;
52 82853 : va_start( args, elementTokenId );
53 82853 : FastAttributeList* pAttrList = new FastAttributeList( mxTokenHandler );
54 :
55 : while (true)
56 : {
57 106784 : sal_Int32 nName = va_arg(args, sal_Int32);
58 106784 : if (nName == FSEND_internal)
59 82853 : break;
60 23931 : const char* pValue = va_arg(args, const char*);
61 23931 : if (pValue)
62 20440 : pAttrList->add(nName, pValue);
63 : }
64 :
65 82853 : const com::sun::star::uno::Reference<com::sun::star::xml::sax::XFastAttributeList> xAttrList(pAttrList);
66 82853 : mpSerializer->startFastElement(elementTokenId, xAttrList);
67 106784 : va_end( args );
68 82853 : }
69 :
70 112426 : void FastSerializerHelper::singleElementInternal(sal_Int32 elementTokenId, ...)
71 : {
72 : va_list args;
73 112426 : va_start( args, elementTokenId );
74 112426 : FastAttributeList* pAttrList = new FastAttributeList( mxTokenHandler );
75 :
76 : while (true)
77 : {
78 219261 : sal_Int32 nName = va_arg(args, sal_Int32);
79 219261 : if (nName == FSEND_internal)
80 112426 : break;
81 106835 : const char* pValue = va_arg(args, const char*);
82 106835 : if (pValue)
83 105604 : pAttrList->add(nName, pValue);
84 : }
85 :
86 112426 : const com::sun::star::uno::Reference<com::sun::star::xml::sax::XFastAttributeList> xAttrList(pAttrList);
87 112426 : mpSerializer->singleFastElement(elementTokenId, xAttrList);
88 219261 : va_end( args );
89 112426 : }
90 :
91 94565 : void FastSerializerHelper::endElement(sal_Int32 elementTokenId)
92 : {
93 94565 : mpSerializer->endFastElement(elementTokenId);
94 94565 : }
95 :
96 11712 : void FastSerializerHelper::startElement(sal_Int32 elementTokenId, XFastAttributeListRef xAttrList)
97 : {
98 11712 : mpSerializer->startFastElement(elementTokenId, xAttrList);
99 11712 : }
100 :
101 :
102 74465 : void FastSerializerHelper::singleElement(sal_Int32 elementTokenId, XFastAttributeListRef xAttrList)
103 : {
104 74465 : mpSerializer->singleFastElement(elementTokenId, xAttrList);
105 74465 : }
106 :
107 2024 : FastSerializerHelper* FastSerializerHelper::write(const char* value)
108 : {
109 2024 : return write(OUString::createFromAscii(value));
110 : }
111 :
112 12304 : FastSerializerHelper* FastSerializerHelper::write(const OUString& value)
113 : {
114 12304 : mpSerializer->characters(value);
115 12304 : return this;
116 : }
117 :
118 89 : FastSerializerHelper* FastSerializerHelper::write(sal_Int32 value)
119 : {
120 89 : return write(OUString::number(value));
121 : }
122 :
123 455 : FastSerializerHelper* FastSerializerHelper::write(sal_Int64 value)
124 : {
125 455 : return write(OUString::number(value));
126 : }
127 :
128 597 : FastSerializerHelper* FastSerializerHelper::write(double value)
129 : {
130 597 : return write(OUString::number(value));
131 : }
132 :
133 65 : FastSerializerHelper* FastSerializerHelper::writeEscaped(const char* value)
134 : {
135 65 : return writeEscaped(OUString::createFromAscii(value));
136 : }
137 :
138 8563 : FastSerializerHelper* FastSerializerHelper::writeEscaped(const OUString& value)
139 : {
140 8563 : return write(FastSaxSerializer::escapeXml(value));
141 : }
142 :
143 473 : FastSerializerHelper* FastSerializerHelper::writeId(sal_Int32 tokenId)
144 : {
145 473 : mpSerializer->writeId(tokenId);
146 473 : return this;
147 : }
148 :
149 2341 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > FastSerializerHelper::getOutputStream()
150 : {
151 2341 : return mpSerializer->getOutputStream();
152 : }
153 :
154 70700 : void FastSerializerHelper::mark( Sequence< sal_Int32 > aOrder )
155 : {
156 70700 : mpSerializer->mark( aOrder );
157 70700 : }
158 :
159 70700 : void FastSerializerHelper::mergeTopMarks( MergeMarksEnum eMergeType )
160 : {
161 70700 : mpSerializer->mergeTopMarks( eMergeType );
162 70700 : }
163 :
164 92811 : FastAttributeList * FastSerializerHelper::createAttrList()
165 : {
166 92811 : return new FastAttributeList( mxTokenHandler );
167 : }
168 :
169 :
170 1167 : }
171 :
172 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|