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 : #ifndef _SAX_FS_HELPER_HXX_
21 : #define _SAX_FS_HELPER_HXX_
22 :
23 : #include <com/sun/star/uno/XReference.hpp>
24 : #include <com/sun/star/io/XOutputStream.hpp>
25 : #include <com/sun/star/xml/sax/XFastTokenHandler.hpp>
26 : #include <stdarg.h>
27 : #include <boost/shared_ptr.hpp>
28 : #include <sax/fastattribs.hxx>
29 :
30 : #define FSNS(namespc, element) ((namespc << 16) | element)
31 : const sal_Int32 FSEND = -1; // same as XML_TOKEN_INVALID
32 :
33 : namespace sax_fastparser {
34 :
35 : enum MergeMarksEnum { MERGE_MARKS_APPEND = 0, MERGE_MARKS_PREPEND = 1, MERGE_MARKS_POSTPONE = 2 };
36 :
37 : typedef ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList > XFastAttributeListRef;
38 :
39 : class FastSaxSerializer;
40 :
41 : class SAX_DLLPUBLIC FastSerializerHelper
42 : {
43 : public:
44 :
45 : FastSerializerHelper( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutputStream, bool bWriteHeader = true );
46 :
47 : ~FastSerializerHelper();
48 :
49 : void startElementV(sal_Int32 elementTokenId, va_list args);
50 : void singleElementV(sal_Int32 elementTokenId, va_list args);
51 :
52 1268 : inline void startElement(sal_Int32 elementTokenId, ...)
53 1268 : { va_list args; va_start( args, elementTokenId ); startElementV( elementTokenId, args ); va_end( args ); }
54 198 : inline void singleElement(sal_Int32 elementTokenId, ...)
55 198 : { va_list args; va_start( args, elementTokenId ); singleElementV( elementTokenId, args ); va_end( args ); }
56 4524 : inline void startElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId, ...)
57 4524 : { va_list args; va_start( args, elementTokenId ); startElementV( FSNS( namespaceTokenId, elementTokenId), args ); va_end( args ); }
58 3596 : inline void singleElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId, ...)
59 3596 : { va_list args; va_start( args, elementTokenId ); singleElementV( FSNS( namespaceTokenId, elementTokenId), args ); va_end( args ); }
60 : void endElement(sal_Int32 elementTokenId);
61 4582 : inline void endElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId)
62 4582 : { endElement( FSNS( namespaceTokenId, elementTokenId ) ); }
63 :
64 2 : inline void singleElement(sal_Int32 elementTokenId, XFastAttributeListRef xAttrList)
65 2 : { singleElementV(elementTokenId, xAttrList); }
66 : void singleElementV(sal_Int32 elementTokenId, XFastAttributeListRef xAttrList);
67 1310 : inline void singleElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId, XFastAttributeListRef xAttrList)
68 1310 : { singleElementV(FSNS( namespaceTokenId, elementTokenId), xAttrList); }
69 :
70 : void startElementV(sal_Int32 elementTokenId, XFastAttributeListRef xAttrList);
71 58 : inline void startElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId, XFastAttributeListRef xAttrList)
72 58 : { startElementV( FSNS( namespaceTokenId, elementTokenId ), xAttrList ); }
73 :
74 : FastSerializerHelper* write(const char* value);
75 : FastSerializerHelper* write(const rtl::OUString& value);
76 : FastSerializerHelper* write(sal_Int32 value);
77 : FastSerializerHelper* write(sal_Int64 value);
78 : FastSerializerHelper* write(double value);
79 :
80 : FastSerializerHelper* writeEscaped(const char* value);
81 : FastSerializerHelper* writeEscaped(const rtl::OUString& value);
82 :
83 : FastSerializerHelper* writeId(sal_Int32 tokenId);
84 :
85 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > getOutputStream();
86 :
87 : FastAttributeList *createAttrList();
88 :
89 : void mark( ::com::sun::star::uno::Sequence< sal_Int32 > aOrder =
90 : ::com::sun::star::uno::Sequence< sal_Int32 >() );
91 : void mergeTopMarks( MergeMarksEnum eMergeType = MERGE_MARKS_APPEND );
92 :
93 : private:
94 :
95 : FastSaxSerializer* mpSerializer;
96 : com::sun::star::uno::Reference<com::sun::star::xml::sax::XFastTokenHandler> mxTokenHandler;
97 :
98 : };
99 :
100 : typedef boost::shared_ptr< FastSerializerHelper > FSHelperPtr;
101 :
102 : }
103 :
104 : #endif // _SAX_FS_HELPER_HXX_
105 :
106 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|