xref: /aoo4110/main/sax/inc/sax/fshelper.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SAX_FS_HELPER_HXX_
25 #define _SAX_FS_HELPER_HXX_
26 
27 #include <com/sun/star/uno/XReference.hpp>
28 #include <com/sun/star/io/XOutputStream.hpp>
29 #include <com/sun/star/xml/sax/XFastTokenHandler.hpp>
30 #include <stdarg.h>
31 #include <boost/shared_ptr.hpp>
32 #include <sax/fastattribs.hxx>
33 #include "sax/dllapi.h"
34 
35 #define FSNS(namespc, element) ((namespc << 16) | element)
36 const sal_Int32 FSEND = -1; // same as XML_TOKEN_INVALID
37 
38 namespace sax_fastparser {
39 
40 enum MergeMarksEnum { MERGE_MARKS_APPEND = 0, MERGE_MARKS_PREPEND = 1, MERGE_MARKS_POSTPONE = 2 };
41 
42 typedef ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList > XFastAttributeListRef;
43 
44 class FastSaxSerializer;
45 
46 class SAX_DLLPUBLIC FastSerializerHelper
47 {
48 public:
49 
50     FastSerializerHelper( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutputStream );
51 
52 	~FastSerializerHelper();
53 
54 	void startElement(const char* elementName, ...);
55 	void singleElement(const char* elementName, ...);
56 	void endElement(const char* elementName);
57 
58 	void startElementV(sal_Int32 elementTokenId, va_list args);
59 	void singleElementV(sal_Int32 elementTokenId, va_list args);
60 
startElement(sal_Int32 elementTokenId,...)61 	inline void startElement(sal_Int32 elementTokenId, ...)
62 		{ va_list args; va_start( args, elementTokenId ); startElementV( elementTokenId, args ); va_end( args ); }
singleElement(sal_Int32 elementTokenId,...)63 	inline void singleElement(sal_Int32 elementTokenId, ...)
64 		{ va_list args; va_start( args, elementTokenId ); singleElementV( elementTokenId, args ); va_end( args ); }
startElementNS(sal_Int32 namespaceTokenId,sal_Int32 elementTokenId,...)65 	inline void startElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId, ...)
66 		{ va_list args; va_start( args, elementTokenId ); startElementV( FSNS( namespaceTokenId, elementTokenId), args ); va_end( args ); }
singleElementNS(sal_Int32 namespaceTokenId,sal_Int32 elementTokenId,...)67 	inline void singleElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId, ...)
68 		{ va_list args; va_start( args, elementTokenId ); singleElementV( FSNS( namespaceTokenId, elementTokenId), args ); va_end( args ); }
69 	void endElement(sal_Int32 elementTokenId);
endElementNS(sal_Int32 namespaceTokenId,sal_Int32 elementTokenId)70 	inline void endElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId)
71 		{ endElement( FSNS( namespaceTokenId, elementTokenId ) ); }
72 
73 	void singleElement(const char* elementName, XFastAttributeListRef xAttrList);
singleElement(sal_Int32 elementTokenId,XFastAttributeListRef xAttrList)74 	inline void singleElement(sal_Int32 elementTokenId, XFastAttributeListRef xAttrList)
75 		{ singleElementV(elementTokenId, xAttrList); }
76 	void singleElementV(sal_Int32 elementTokenId, XFastAttributeListRef xAttrList);
singleElementNS(sal_Int32 namespaceTokenId,sal_Int32 elementTokenId,XFastAttributeListRef xAttrList)77 	inline void singleElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId, XFastAttributeListRef xAttrList)
78 		{ singleElementV(FSNS( namespaceTokenId, elementTokenId), xAttrList); }
79 
80     void startElementV(sal_Int32 elementTokenId, XFastAttributeListRef xAttrList);
startElementNS(sal_Int32 namespaceTokenId,sal_Int32 elementTokenId,XFastAttributeListRef xAttrList)81     inline void startElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId, XFastAttributeListRef xAttrList)
82         { startElementV( FSNS( namespaceTokenId, elementTokenId ), xAttrList ); }
83 
84 	FastSerializerHelper* write(const char* value);
85 	FastSerializerHelper* write(const rtl::OUString& value);
86 	FastSerializerHelper* write(sal_Int32 value);
87 	FastSerializerHelper* write(sal_Int64 value);
88 	FastSerializerHelper* write(float value);
89 	FastSerializerHelper* write(double value);
90 
91 	FastSerializerHelper* writeEscaped(const char* value);
92 	FastSerializerHelper* writeEscaped(const rtl::OUString& value);
93 
94 	FastSerializerHelper* writeId(sal_Int32 tokenId);
95 
96 	::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > getOutputStream();
97 
98 	FastAttributeList *createAttrList();
99 
100     void mark();
101     void mergeTopMarks( MergeMarksEnum eMergeType = MERGE_MARKS_APPEND );
102 
103 private:
104 
105     FastSaxSerializer* mpSerializer;
106 	com::sun::star::uno::Reference<com::sun::star::xml::sax::XFastTokenHandler> mxTokenHandler;
107 
108 };
109 
110 typedef boost::shared_ptr< FastSerializerHelper > FSHelperPtr;
111 
112 }
113 
114 #endif // _SAX_FS_HELPER_HXX_
115