1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SAX_FASTATTRIBS_HXX
21 #define INCLUDED_SAX_FASTATTRIBS_HXX
23 #include <com/sun/star/xml/sax/XFastAttributeList.hpp>
24 #include <com/sun/star/xml/sax/XFastTokenHandler.hpp>
25 #include <com/sun/star/xml/Attribute.hpp>
26 #include <com/sun/star/xml/FastAttribute.hpp>
28 #include <cppuhelper/implbase1.hxx>
29 #include <sax/saxdllapi.h>
34 namespace sax_fastparser
37 struct UnknownAttribute
39 OUString maNamespaceURL
;
43 UnknownAttribute( const OUString
& rNamespaceURL
, const OString
& rName
, const sal_Char
* pValue
);
45 UnknownAttribute( const OString
& rName
, const sal_Char
* pValue
);
47 void FillAttribute( ::com::sun::star::xml::Attribute
* pAttrib
) const;
50 typedef std::vector
< UnknownAttribute
> UnknownAttributeList
;
52 /// A native C++ interface to tokenisation
53 class SAX_DLLPUBLIC FastTokenHandlerBase
56 FastTokenHandlerBase();
57 virtual ~FastTokenHandlerBase();
58 virtual sal_Int32
getTokenDirect( const char *pToken
, sal_Int32 nLength
) const = 0;
61 /// avoid constantly allocating and freeing sequences.
62 class SAX_DLLPUBLIC FastTokenLookup
64 static const int mnUtf8BufferSize
= 128;
65 ::css::uno::Sequence
< sal_Int8
> maUtf8Buffer
;
68 sal_Int32
getTokenFromChars(
69 const ::css::uno::Reference
< ::css::xml::sax::XFastTokenHandler
> &mxTokenHandler
,
70 FastTokenHandlerBase
*pTokenHandler
,
71 const char *pStr
, size_t nLength
= 0 );
74 class SAX_DLLPUBLIC FastAttributeList
: public ::cppu::WeakImplHelper1
< ::com::sun::star::xml::sax::XFastAttributeList
>
77 FastAttributeList( const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XFastTokenHandler
>& xTokenHandler
,
78 FastTokenHandlerBase
*pOptHandlerBase
= NULL
);
79 virtual ~FastAttributeList();
82 void add( sal_Int32 nToken
, const sal_Char
* pValue
, size_t nValueLength
= 0 );
83 void add( sal_Int32 nToken
, const OString
& rValue
);
84 void addUnknown( const OUString
& rNamespaceURL
, const OString
& rName
, const sal_Char
* pValue
);
85 void addUnknown( const OString
& rName
, const sal_Char
* pValue
);
87 // performance sensitive shortcuts to avoid allocation ...
88 bool getAsInteger( sal_Int32 nToken
, sal_Int32
&rInt
);
89 bool getAsDouble( sal_Int32 nToken
, double &rDouble
);
90 bool getAsChar( sal_Int32 nToken
, const char*& rPos
) const;
93 virtual ::sal_Bool SAL_CALL
hasAttribute( ::sal_Int32 Token
) throw (::com::sun::star::uno::RuntimeException
);
94 virtual ::sal_Int32 SAL_CALL
getValueToken( ::sal_Int32 Token
) throw (::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
);
95 virtual ::sal_Int32 SAL_CALL
getOptionalValueToken( ::sal_Int32 Token
, ::sal_Int32 Default
) throw (::com::sun::star::uno::RuntimeException
);
96 virtual OUString SAL_CALL
getValue( ::sal_Int32 Token
) throw (::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
);
97 virtual OUString SAL_CALL
getOptionalValue( ::sal_Int32 Token
) throw (::com::sun::star::uno::RuntimeException
);
98 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::xml::Attribute
> SAL_CALL
getUnknownAttributes( ) throw (::com::sun::star::uno::RuntimeException
);
99 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::xml::FastAttribute
> SAL_CALL
getFastAttributes() throw (::com::sun::star::uno::RuntimeException
);
102 inline sal_Int32
AttributeValueLength(sal_Int32 i
);
105 sal_Char
*mpChunk
; ///< buffer to store all attribute values - null terminated strings
106 sal_Int32 mnChunkLength
; ///< size of allocated memory for mpChunk
107 // maAttributeValues stores pointers, relative to mpChunk, for each attribute value string
108 // length of the string is maAttributeValues[n+1] - maAttributeValues[n] - 1
109 // maAttributeValues[0] == 0
110 std::vector
< sal_Int32
> maAttributeValues
;
111 std::vector
< sal_Int32
> maAttributeTokens
;
112 UnknownAttributeList maUnknownAttributes
;
113 ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XFastTokenHandler
> mxTokenHandler
;
114 FastTokenHandlerBase
*mpTokenHandler
;
116 FastTokenLookup maTokenLookup
;
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */