Update ooo320-m1
[ooovba.git] / sax / source / tools / fshelper.cxx
blob035382858da1883d50d067e9630fddd59689a149
1 #include <sax/fshelper.hxx>
2 #include "fastserializer.hxx"
3 #include <com/sun/star/xml/sax/XFastTokenHandler.hpp>
4 #include <comphelper/processfactory.hxx>
5 #include <rtl/ustrbuf.hxx>
7 using namespace ::com::sun::star;
8 using namespace ::com::sun::star::uno;
10 namespace sax_fastparser {
12 FastSerializerHelper::FastSerializerHelper(const Reference< io::XOutputStream >& xOutputStream ) :
13 mpSerializer(new FastSaxSerializer())
15 Reference< lang::XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory();
16 mxTokenHandler = Reference<xml::sax::XFastTokenHandler> ( xFactory->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.sax.FastTokenHandler") ) ), UNO_QUERY_THROW );
18 mpSerializer->setFastTokenHandler( mxTokenHandler );
19 mpSerializer->setOutputStream( xOutputStream );
20 mpSerializer->startDocument();
23 FastSerializerHelper::~FastSerializerHelper()
25 mpSerializer->endDocument();
27 if (mpSerializer) {
28 delete mpSerializer;
29 mpSerializer = NULL;
33 void FastSerializerHelper::startElement(const char* elementName, ...)
35 FastAttributeList* pAttrList = new FastAttributeList( mxTokenHandler );
36 va_list args;
37 va_start(args, elementName);
38 while (true)
40 const char* pName = va_arg(args, const char*);
41 if (!pName)
42 break;
43 const char* pValue = va_arg(args, const char*);
44 if (pValue)
45 pAttrList->addUnknown(pName, pValue);
47 va_end(args);
48 const com::sun::star::uno::Reference<com::sun::star::xml::sax::XFastAttributeList> xAttrList(pAttrList);
49 mpSerializer->startUnknownElement(::rtl::OUString(), ::rtl::OUString::createFromAscii(elementName), xAttrList);
52 void FastSerializerHelper::singleElement(const char* elementName, ...)
54 FastAttributeList* pAttrList = new FastAttributeList( mxTokenHandler );
55 va_list args;
56 va_start(args, elementName);
57 while (true)
59 const char* pName = va_arg(args, const char*);
60 if (!pName)
61 break;
62 const char* pValue = va_arg(args, const char*);
63 if (pValue)
64 pAttrList->addUnknown(pName, pValue);
66 va_end(args);
67 const com::sun::star::uno::Reference<com::sun::star::xml::sax::XFastAttributeList> xAttrList(pAttrList);
68 mpSerializer->singleUnknownElement(::rtl::OUString(), ::rtl::OUString::createFromAscii(elementName), xAttrList);
71 void FastSerializerHelper::endElement(const char* elementName)
73 mpSerializer->endUnknownElement(::rtl::OUString(), ::rtl::OUString::createFromAscii(elementName));
76 void FastSerializerHelper::startElementV(sal_Int32 elementTokenId, va_list args)
78 FastAttributeList* pAttrList = new FastAttributeList( mxTokenHandler );
80 while (true)
82 sal_Int32 nName = va_arg(args, sal_Int32);
83 if (nName == FSEND)
84 break;
85 const char* pValue = va_arg(args, const char*);
86 if (pValue)
87 pAttrList->add(nName, pValue);
90 const com::sun::star::uno::Reference<com::sun::star::xml::sax::XFastAttributeList> xAttrList(pAttrList);
91 mpSerializer->startFastElement(elementTokenId, xAttrList);
94 void FastSerializerHelper::singleElementV(sal_Int32 elementTokenId, va_list args)
96 FastAttributeList* pAttrList = new FastAttributeList( mxTokenHandler );
98 while (true)
100 sal_Int32 nName = va_arg(args, sal_Int32);
101 if (nName == FSEND)
102 break;
103 const char* pValue = va_arg(args, const char*);
104 if (pValue)
105 pAttrList->add(nName, pValue);
108 const com::sun::star::uno::Reference<com::sun::star::xml::sax::XFastAttributeList> xAttrList(pAttrList);
109 mpSerializer->singleFastElement(elementTokenId, xAttrList);
112 void FastSerializerHelper::endElement(sal_Int32 elementTokenId)
114 mpSerializer->endFastElement(elementTokenId);
117 void FastSerializerHelper::startElementV(sal_Int32 elementTokenId, XFastAttributeListRef xAttrList)
119 mpSerializer->startFastElement(elementTokenId, xAttrList);
123 void FastSerializerHelper::singleElement(const char* elementName, XFastAttributeListRef xAttrList)
125 mpSerializer->singleUnknownElement(::rtl::OUString(), ::rtl::OUString::createFromAscii(elementName), xAttrList);
128 void FastSerializerHelper::singleElementV(sal_Int32 elementTokenId, XFastAttributeListRef xAttrList)
130 mpSerializer->singleFastElement(elementTokenId, xAttrList);
133 FastSerializerHelper* FastSerializerHelper::write(const char* value)
135 return write(rtl::OUString::createFromAscii(value));
138 FastSerializerHelper* FastSerializerHelper::write(const rtl::OUString& value)
140 mpSerializer->characters(value);
141 return this;
144 FastSerializerHelper* FastSerializerHelper::write(sal_Int32 value)
146 return write(::rtl::OUString::valueOf(value));
149 FastSerializerHelper* FastSerializerHelper::write(sal_Int64 value)
151 return write(::rtl::OUString::valueOf(value));
154 FastSerializerHelper* FastSerializerHelper::write(float value)
156 return write(::rtl::OUString::valueOf(value));
159 FastSerializerHelper* FastSerializerHelper::write(double value)
161 return write(::rtl::OUString::valueOf(value));
164 FastSerializerHelper* FastSerializerHelper::writeEscaped(const char* value)
166 return writeEscaped(::rtl::OUString::createFromAscii(value));
169 FastSerializerHelper* FastSerializerHelper::writeEscaped(const ::rtl::OUString& value)
171 return write(FastSaxSerializer::escapeXml(value));
174 FastSerializerHelper* FastSerializerHelper::writeId(sal_Int32 tokenId)
176 mpSerializer->writeId(tokenId);
177 return this;
180 ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > FastSerializerHelper::getOutputStream()
182 return mpSerializer->getOutputStream();
185 void FastSerializerHelper::mark()
187 mpSerializer->mark();
190 void FastSerializerHelper::mergeTopMarks( MergeMarksEnum eMergeType )
192 mpSerializer->mergeTopMarks( eMergeType );
195 FastAttributeList * FastSerializerHelper::createAttrList()
197 return new FastAttributeList( mxTokenHandler );