merge the formfield patch from ooo-build
[ooovba.git] / sax / source / tools / fastserializer.hxx
blobfe986f127b282c334d57b641f987e94969613b28
1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: serializer.hxx,v $
7 * $Revision: 1.2.4.1 $
9 * last change: $Author: dr $ $Date: 2008/02/15 12:56:11 $
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 * MA 02111-1307 USA
34 ************************************************************************/
36 #ifndef SAX_FASTSERIALIZER_HXX
37 #define SAX_FASTSERIALIZER_HXX
39 #include <com/sun/star/xml/sax/XFastSerializer.hpp>
40 #include <com/sun/star/xml/sax/XFastTokenHandler.hpp>
41 #include <com/sun/star/lang/XServiceInfo.hpp>
42 #include <com/sun/star/io/XOutputStream.hpp>
43 #include <cppuhelper/implbase2.hxx>
45 #include <stack>
47 #include "sax/dllapi.h"
48 #include "sax/fshelper.hxx"
50 #define SERIALIZER_IMPLEMENTATION_NAME "com.sun.star.comp.extensions.xml.sax.FastSerializer"
51 #define SERIALIZER_SERVICE_NAME "com.sun.star.xml.sax.FastSerializer"
53 namespace sax_fastparser {
55 class SAX_DLLPUBLIC FastSaxSerializer : public ::cppu::WeakImplHelper2< ::com::sun::star::xml::sax::XFastSerializer, ::com::sun::star::lang::XServiceInfo >
57 public:
58 explicit FastSaxSerializer( );
59 virtual ~FastSaxSerializer();
61 ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > getOutputStream() {return mxOutputStream;}
63 // The implementation details
64 static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static(void);
65 static ::rtl::OUString getImplementationName_Static();
67 // XFastSerializer
68 virtual void SAL_CALL startDocument( ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
69 virtual void SAL_CALL endDocument( ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
70 virtual void SAL_CALL startFastElement( ::sal_Int32 Element, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& Attribs )
71 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
72 virtual void SAL_CALL startUnknownElement( const ::rtl::OUString& Namespace, const ::rtl::OUString& Name, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& Attribs )
73 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
74 virtual void SAL_CALL endFastElement( ::sal_Int32 Element )
75 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
76 virtual void SAL_CALL endUnknownElement( const ::rtl::OUString& Namespace, const ::rtl::OUString& Name )
77 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
78 virtual void SAL_CALL singleFastElement( ::sal_Int32 Element, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& Attribs )
79 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
80 virtual void SAL_CALL singleUnknownElement( const ::rtl::OUString& Namespace, const ::rtl::OUString& Name, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& Attribs )
81 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
82 virtual void SAL_CALL characters( const ::rtl::OUString& aChars )
83 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
84 virtual void SAL_CALL setOutputStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutputStream )
85 throw (::com::sun::star::uno::RuntimeException);
86 virtual void SAL_CALL setFastTokenHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler >& xFastTokenHandler )
87 throw (::com::sun::star::uno::RuntimeException);
89 // XServiceInfo
90 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw ( ::com::sun::star::uno::RuntimeException );
91 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw ( ::com::sun::star::uno::RuntimeException );
92 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw ( ::com::sun::star::uno::RuntimeException );
94 // C++ helpers
95 virtual void SAL_CALL writeId( ::sal_Int32 Element );
97 static ::rtl::OUString escapeXml( const ::rtl::OUString& s );
99 public:
100 /** From now on, don't write directly to the stream, but to top of a stack.
102 This is to be able to change the order of the data being written.
103 If you need to write eg.
104 p, r, rPr, [something], /rPr, t, [text], /r, /p,
105 but get it in order
106 p, r, t, [text], /t, rPr, [something], /rPr, /r, /p,
107 simply do
108 p, r, mark(), t, [text], /t, mark(), rPr, [something], /rPr,
109 mergeTopMarks( true ), mergeTopMarks(), /r, /p
110 and you are done.
112 void mark();
114 /** Merge 2 topmost marks.
116 There are 3 possibilities - prepend the top before the second top-most
117 mark, append it, or append it later; prepending brings the possibility
118 to switch parts of the output, appending later allows to write some
119 output in advance.
121 Writes the result to the output stream if the mark stack becomes empty
122 by the operation.
124 When the MERGE_MARKS_POSTPONE is specified, the merge happens just
125 before the next merge.
127 @see mark()
129 void mergeTopMarks( sax_fastparser::MergeMarksEnum eMergeType = sax_fastparser::MERGE_MARKS_APPEND );
131 private:
132 ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > mxOutputStream;
133 ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler > mxFastTokenHandler;
135 typedef ::com::sun::star::uno::Sequence< ::sal_Int8 > Int8Sequence;
136 class ForMerge
138 Int8Sequence maData;
139 Int8Sequence maPostponed;
141 public:
142 ForMerge() : maData(), maPostponed() {}
144 Int8Sequence& getData();
146 void prepend( const Int8Sequence &rWhat );
147 void append( const Int8Sequence &rWhat );
148 void postpone( const Int8Sequence &rWhat );
150 private:
151 static void merge( Int8Sequence &rTop, const Int8Sequence &rMerge, bool bAppend );
154 ::std::stack< ForMerge > maMarkStack;
156 void writeFastAttributeList( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& Attribs );
157 void write( const ::rtl::OUString& s );
159 protected:
160 /** Forward the call to the output stream, or write to the stack.
162 The latter in the case that we are inside a mark().
164 void writeBytes( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
167 } // namespace sax_fastparser
169 #endif