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();
33 void FastSerializerHelper::startElement(const char* elementName
, ...)
35 FastAttributeList
* pAttrList
= new FastAttributeList( mxTokenHandler
);
37 va_start(args
, elementName
);
40 const char* pName
= va_arg(args
, const char*);
43 const char* pValue
= va_arg(args
, const char*);
45 pAttrList
->addUnknown(pName
, pValue
);
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
);
56 va_start(args
, elementName
);
59 const char* pName
= va_arg(args
, const char*);
62 const char* pValue
= va_arg(args
, const char*);
64 pAttrList
->addUnknown(pName
, pValue
);
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
);
82 sal_Int32 nName
= va_arg(args
, sal_Int32
);
85 const char* pValue
= va_arg(args
, const char*);
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
);
100 sal_Int32 nName
= va_arg(args
, sal_Int32
);
103 const char* pValue
= va_arg(args
, const char*);
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
);
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
);
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
);