diff options
author | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2013-04-18 18:26:28 +0200 |
---|---|---|
committer | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2013-04-23 22:20:31 +0200 |
commit | b9337e22ce1dbf2eba0e8c8db294ae99f4111f91 (patch) | |
tree | 53ee1bd3dfd213815a21579151983cb997922b05 /include/sax | |
parent | f4e1642a1761d5eab6ccdd89928869c2b2f1528a (diff) |
execute move of global headers
see https://gerrit.libreoffice.org/#/c/3367/
and Change-Id: I00c96fa77d04b33a6f8c8cd3490dfcd9bdc9e84a for details
Change-Id: I199a75bc4042af20817265d5ef85b1134a96ff5a
Diffstat (limited to 'include/sax')
-rw-r--r-- | include/sax/fastattribs.hxx | 85 | ||||
-rw-r--r-- | include/sax/fshelper.hxx | 199 | ||||
-rw-r--r-- | include/sax/saxdllapi.h | 33 | ||||
-rw-r--r-- | include/sax/tools/converter.hxx | 206 | ||||
-rw-r--r-- | include/sax/tools/documenthandleradapter.hxx | 254 |
5 files changed, 777 insertions, 0 deletions
diff --git a/include/sax/fastattribs.hxx b/include/sax/fastattribs.hxx new file mode 100644 index 000000000000..f31be4b142f6 --- /dev/null +++ b/include/sax/fastattribs.hxx @@ -0,0 +1,85 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef _SAX_FASTATTRIBS_HXX_ +#define _SAX_FASTATTRIBS_HXX_ + +#include <com/sun/star/xml/sax/XFastAttributeList.hpp> +#include <com/sun/star/xml/sax/XFastTokenHandler.hpp> +#include <com/sun/star/xml/Attribute.hpp> +#include <com/sun/star/xml/FastAttribute.hpp> + +#include <cppuhelper/implbase1.hxx> +#include "sax/saxdllapi.h" + +#include <map> +#include <vector> + +namespace sax_fastparser +{ + +struct UnknownAttribute +{ + OUString maNamespaceURL; + OString maName; + OString maValue; + + UnknownAttribute( const OUString& rNamespaceURL, const OString& rName, const OString& rValue ); + + UnknownAttribute( const OString& rName, const OString& rValue ); + + void FillAttribute( ::com::sun::star::xml::Attribute* pAttrib ) const; +}; + +typedef std::map< sal_Int32, OString > FastAttributeMap; +typedef std::vector< UnknownAttribute > UnknownAttributeList; + +class SAX_DLLPUBLIC FastAttributeList : public ::cppu::WeakImplHelper1< ::com::sun::star::xml::sax::XFastAttributeList > +{ +public: + FastAttributeList( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler >& xTokenHandler ); + virtual ~FastAttributeList(); + + void clear(); + void add( sal_Int32 nToken, const OString& rValue ); + void addUnknown( const OUString& rNamespaceURL, const OString& rName, const OString& rValue ); + void addUnknown( const OString& rName, const OString& rValue ); + + // XFastAttributeList + virtual ::sal_Bool SAL_CALL hasAttribute( ::sal_Int32 Token ) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getValueToken( ::sal_Int32 Token ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getOptionalValueToken( ::sal_Int32 Token, ::sal_Int32 Default ) throw (::com::sun::star::uno::RuntimeException); + virtual OUString SAL_CALL getValue( ::sal_Int32 Token ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + virtual OUString SAL_CALL getOptionalValue( ::sal_Int32 Token ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::xml::Attribute > SAL_CALL getUnknownAttributes( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::xml::FastAttribute > SAL_CALL getFastAttributes() throw (::com::sun::star::uno::RuntimeException); + +private: + FastAttributeMap maAttributes; + UnknownAttributeList maUnknownAttributes; + FastAttributeMap::iterator maLastIter; + ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler > mxTokenHandler; + +}; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/sax/fshelper.hxx b/include/sax/fshelper.hxx new file mode 100644 index 000000000000..e0945fc07ddf --- /dev/null +++ b/include/sax/fshelper.hxx @@ -0,0 +1,199 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef _SAX_FS_HELPER_HXX_ +#define _SAX_FS_HELPER_HXX_ + +#include <com/sun/star/uno/XReference.hpp> +#include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/xml/sax/XFastTokenHandler.hpp> +#include <stdarg.h> +#include <boost/shared_ptr.hpp> +#include <sax/fastattribs.hxx> + +#define FSNS(namespc, element) ((namespc << 16) | element) +// Backwards compatibility for code that used FSEND to terminate the vararg. +// As soon as no supported LO version has the varargs code, this can be removed entirely +// (otherwise backports might break silently if people didn't add FSEND). +// Ctor is there to get an error when trying to pass it to a vararg by accident. +struct FSEND_t { FSEND_t() {}; }; +static const FSEND_t FSEND = FSEND_t(); +const sal_Int32 FSEND_internal = -1; // same as XML_TOKEN_INVALID + +#define SAX_ARGS_ARG( arg1, arg2, convert, num ) arg1##num, arg2##num convert +#define SAX_ARGS_ARG1( arg1, arg2, convert ) SAX_ARGS_ARG( arg1, arg2, convert, 1 ) +#define SAX_ARGS_ARG2( arg1, arg2, convert ) SAX_ARGS_ARG1( arg1, arg2, convert ), SAX_ARGS_ARG( arg1, arg2, convert, 2 ) +#define SAX_ARGS_ARG3( arg1, arg2, convert ) SAX_ARGS_ARG2( arg1, arg2, convert ), SAX_ARGS_ARG( arg1, arg2, convert, 3 ) +#define SAX_ARGS_ARG4( arg1, arg2, convert ) SAX_ARGS_ARG3( arg1, arg2, convert ), SAX_ARGS_ARG( arg1, arg2, convert, 4 ) +#define SAX_ARGS_ARG5( arg1, arg2, convert ) SAX_ARGS_ARG4( arg1, arg2, convert ), SAX_ARGS_ARG( arg1, arg2, convert, 5 ) +#define SAX_ARGS_ARG6( arg1, arg2, convert ) SAX_ARGS_ARG5( arg1, arg2, convert ), SAX_ARGS_ARG( arg1, arg2, convert, 6 ) +#define SAX_ARGS_ARG7( arg1, arg2, convert ) SAX_ARGS_ARG6( arg1, arg2, convert ), SAX_ARGS_ARG( arg1, arg2, convert, 7 ) +#define SAX_ARGS_ARG8( arg1, arg2, convert ) SAX_ARGS_ARG7( arg1, arg2, convert ), SAX_ARGS_ARG( arg1, arg2, convert, 8 ) +#define SAX_ARGS_ARG9( arg1, arg2, convert ) SAX_ARGS_ARG8( arg1, arg2, convert ), SAX_ARGS_ARG( arg1, arg2, convert, 9 ) +#define SAX_ARGS_ARG10( arg1, arg2, convert ) SAX_ARGS_ARG9( arg1, arg2, convert ), SAX_ARGS_ARG( arg1, arg2, convert, 10 ) +#define SAX_ARGS_ARG11( arg1, arg2, convert ) SAX_ARGS_ARG10( arg1, arg2, convert ), SAX_ARGS_ARG( arg1, arg2, convert, 11 ) +#define SAX_ARGS_ARG12( arg1, arg2, convert ) SAX_ARGS_ARG11( arg1, arg2, convert ), SAX_ARGS_ARG( arg1, arg2, convert, 12 ) +#define SAX_ARGS_ARG13( arg1, arg2, convert ) SAX_ARGS_ARG12( arg1, arg2, convert ), SAX_ARGS_ARG( arg1, arg2, convert, 13 ) +#define SAX_ARGS_ARG14( arg1, arg2, convert ) SAX_ARGS_ARG13( arg1, arg2, convert ), SAX_ARGS_ARG( arg1, arg2, convert, 14 ) +#define SAX_ARGS_ARG15( arg1, arg2, convert ) SAX_ARGS_ARG14( arg1, arg2, convert ), SAX_ARGS_ARG( arg1, arg2, convert, 15 ) +#define SAX_ARGS_ARG16( arg1, arg2, convert ) SAX_ARGS_ARG15( arg1, arg2, convert ), SAX_ARGS_ARG( arg1, arg2, convert, 16 ) +#define SAX_ARGS_ARG17( arg1, arg2, convert ) SAX_ARGS_ARG16( arg1, arg2, convert ), SAX_ARGS_ARG( arg1, arg2, convert, 17 ) +#define SAX_ARGS_ARG18( arg1, arg2, convert ) SAX_ARGS_ARG17( arg1, arg2, convert ), SAX_ARGS_ARG( arg1, arg2, convert, 18 ) +#define SAX_ARGS_ARG19( arg1, arg2, convert ) SAX_ARGS_ARG18( arg1, arg2, convert ), SAX_ARGS_ARG( arg1, arg2, convert, 19 ) +#define SAX_ARGS_ARG20( arg1, arg2, convert ) SAX_ARGS_ARG19( arg1, arg2, convert ), SAX_ARGS_ARG( arg1, arg2, convert, 20 ) +#define SAX_ARGS_ARG21( arg1, arg2, convert ) SAX_ARGS_ARG20( arg1, arg2, convert ), SAX_ARGS_ARG( arg1, arg2, convert, 21 ) +#define SAX_ARGS_ARG22( arg1, arg2, convert ) SAX_ARGS_ARG21( arg1, arg2, convert ), SAX_ARGS_ARG( arg1, arg2, convert, 22 ) + +namespace sax_fastparser { + +enum MergeMarksEnum { MERGE_MARKS_APPEND = 0, MERGE_MARKS_PREPEND = 1, MERGE_MARKS_POSTPONE = 2 }; + +typedef ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList > XFastAttributeListRef; + +class FastSaxSerializer; + +class SAX_DLLPUBLIC FastSerializerHelper +{ +public: + + FastSerializerHelper( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutputStream, bool bWriteHeader = true ); + + ~FastSerializerHelper(); + + /// Start an element. After the first argument there can be a number of (attribute, value) pairs. + void startElement(sal_Int32 elementTokenId, FSEND_t) + { startElementInternal( elementTokenId, FSEND_internal ); } + /// overload + void startElement(sal_Int32 elementTokenId, sal_Int32 attribute, const char* value, FSEND_t) + { startElementInternal( elementTokenId, attribute, value, FSEND_internal ); } + /// overload + void startElement(sal_Int32 elementTokenId, sal_Int32 attribute, const OString& value, FSEND_t) + { startElementInternal( elementTokenId, attribute, value.getStr(), FSEND_internal ); } + /// Create a single element. After the first argument there can be a number of (attribute, value) pairs. + void singleElement(sal_Int32 elementTokenId, FSEND_t) + { singleElementInternal( elementTokenId, FSEND_internal ); } + /// overload + void singleElement(sal_Int32 elementTokenId, sal_Int32 attribute, const char* value, FSEND_t) + { singleElementInternal( elementTokenId, attribute, value, FSEND_internal ); } + /// overload + void singleElement(sal_Int32 elementTokenId, sal_Int32 attribute, const OString& value, FSEND_t) + { singleElementInternal( elementTokenId, attribute, value.getStr(), FSEND_internal ); } + /// Start an element. After the first two arguments there can be a number of (attribute, value) pairs. + void startElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId, FSEND_t) + { startElementInternal( FSNS( namespaceTokenId, elementTokenId), FSEND_internal ); } + /// overload + void startElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId, sal_Int32 attribute, const char* value, FSEND_t) + { startElementInternal( FSNS( namespaceTokenId, elementTokenId), attribute, value, FSEND_internal ); } + /// overload + void startElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId, sal_Int32 attribute, const OString& value, FSEND_t) + { startElementInternal( FSNS( namespaceTokenId, elementTokenId), attribute, value.getStr(), FSEND_internal ); } + /// Create a single element. After the first two arguments there can be a number of (attribute, value) pairs. + void singleElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId, FSEND_t) + { singleElementInternal( FSNS( namespaceTokenId, elementTokenId), FSEND_internal ); } + /// overload + void singleElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId, sal_Int32 attribute, const char* value, FSEND_t) + { singleElementInternal( FSNS( namespaceTokenId, elementTokenId), attribute, value, FSEND_internal ); } + /// overload + void singleElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId, sal_Int32 attribute, const OString& value, FSEND_t) + { singleElementInternal( FSNS( namespaceTokenId, elementTokenId), attribute, value.getStr(), FSEND_internal ); } + void endElement(sal_Int32 elementTokenId); + inline void endElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId) + { endElement( FSNS( namespaceTokenId, elementTokenId ) ); } + + void singleElement(sal_Int32 elementTokenId, XFastAttributeListRef xAttrList); + inline void singleElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId, XFastAttributeListRef xAttrList) + { singleElement(FSNS( namespaceTokenId, elementTokenId), xAttrList); } + + void startElement(sal_Int32 elementTokenId, XFastAttributeListRef xAttrList); + inline void startElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId, XFastAttributeListRef xAttrList) + { startElement( FSNS( namespaceTokenId, elementTokenId ), xAttrList ); } + + FastSerializerHelper* write(const char* value); + FastSerializerHelper* write(const OUString& value); + FastSerializerHelper* write(sal_Int32 value); + FastSerializerHelper* write(sal_Int64 value); + FastSerializerHelper* write(double value); + + FastSerializerHelper* writeEscaped(const char* value); + FastSerializerHelper* writeEscaped(const OUString& value); + + FastSerializerHelper* writeId(sal_Int32 tokenId); + + ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > getOutputStream(); + + FastAttributeList *createAttrList(); + + void mark( ::com::sun::star::uno::Sequence< sal_Int32 > aOrder = + ::com::sun::star::uno::Sequence< sal_Int32 >() ); + void mergeTopMarks( MergeMarksEnum eMergeType = MERGE_MARKS_APPEND ); + void copyTopMarkPush(); + void copyTopMarkPop(); + + /* + Now create all the overloads in a typesafe way (i.e. without varargs) by creating a number of overloads + up to a certain reasonable limit (feel free to raise it). This would be a lot easier with C++11 vararg templates. + */ + // now overloads for 2 and more pairs + #define SAX_ARGS_FUNC_DECL( argsdecl, argsuse ) \ + void startElement(sal_Int32 elementTokenId, argsdecl, FSEND_t) \ + { startElementInternal( elementTokenId, argsuse, FSEND_internal ); } \ + void singleElement(sal_Int32 elementTokenId, argsdecl, FSEND_t) \ + { singleElementInternal( elementTokenId, argsuse, FSEND_internal ); } \ + void startElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId, argsdecl, FSEND_t) \ + { startElementInternal( FSNS( namespaceTokenId, elementTokenId), argsuse, FSEND_internal ); } \ + void singleElementNS(sal_Int32 namespaceTokenId, sal_Int32 elementTokenId, argsdecl, FSEND_t) \ + { singleElementInternal( FSNS( namespaceTokenId, elementTokenId), argsuse, FSEND_internal ); } + #define SAX_ARGS_FUNC_NUM( decl1, decl2, use1, use2, convert, num ) \ + SAX_ARGS_FUNC_DECL( SAX_ARGS_ARG##num( decl1, decl2, ), SAX_ARGS_ARG##num( use1, use2, convert )) + #define SAX_ARGS_FUNC_SUBST( type, convert, num ) \ + SAX_ARGS_FUNC_NUM( sal_Int32 attribute, type value, attribute, value, convert, num ) + #define SAX_ARGS_FUNC( arg, convert ) SAX_ARGS_FUNC_SUBST( arg, convert, 2 ) \ + SAX_ARGS_FUNC_SUBST( arg, convert, 3 ) SAX_ARGS_FUNC_SUBST( arg, convert, 4 ) \ + SAX_ARGS_FUNC_SUBST( arg, convert, 5 ) SAX_ARGS_FUNC_SUBST( arg, convert, 6 ) \ + SAX_ARGS_FUNC_SUBST( arg, convert, 7 ) SAX_ARGS_FUNC_SUBST( arg, convert, 8 ) \ + SAX_ARGS_FUNC_SUBST( arg, convert, 9 ) SAX_ARGS_FUNC_SUBST( arg, convert, 10 ) \ + SAX_ARGS_FUNC_SUBST( arg, convert, 11 ) SAX_ARGS_FUNC_SUBST( arg, convert, 12 ) \ + SAX_ARGS_FUNC_SUBST( arg, convert, 13 ) SAX_ARGS_FUNC_SUBST( arg, convert, 14 ) \ + SAX_ARGS_FUNC_SUBST( arg, convert, 15 ) SAX_ARGS_FUNC_SUBST( arg, convert, 16 ) \ + SAX_ARGS_FUNC_SUBST( arg, convert, 17 ) SAX_ARGS_FUNC_SUBST( arg, convert, 18 ) \ + SAX_ARGS_FUNC_SUBST( arg, convert, 19 ) SAX_ARGS_FUNC_SUBST( arg, convert, 20 ) \ + SAX_ARGS_FUNC_SUBST( arg, convert, 21 ) SAX_ARGS_FUNC_SUBST( arg, convert, 22 ) + SAX_ARGS_FUNC( const char*, ) + SAX_ARGS_FUNC( const OString&, .getStr() ) + #undef SAX_ARGS_FUNC_DECL + #undef SAX_ARGS_FUNC_NUM + #undef SAX_ARGS_FUNC_SUBST + #undef SAX_ARGS_FUNC + +private: + void startElementInternal(sal_Int32 elementTokenId, ...); + void singleElementInternal(sal_Int32 elementTokenId, ...); + + FastSaxSerializer* mpSerializer; + com::sun::star::uno::Reference<com::sun::star::xml::sax::XFastTokenHandler> mxTokenHandler; + +}; + +typedef boost::shared_ptr< FastSerializerHelper > FSHelperPtr; + +} + +#endif // _SAX_FS_HELPER_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/sax/saxdllapi.h b/include/sax/saxdllapi.h new file mode 100644 index 000000000000..e4716975bec7 --- /dev/null +++ b/include/sax/saxdllapi.h @@ -0,0 +1,33 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_SAX_DLLAPI_H +#define INCLUDED_SAX_DLLAPI_H + +#include <sal/types.h> + +#if defined SAX_DLLIMPLEMENTATION +#define SAX_DLLPUBLIC SAL_DLLPUBLIC_EXPORT +#else +#define SAX_DLLPUBLIC SAL_DLLPUBLIC_IMPORT +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/sax/tools/converter.hxx b/include/sax/tools/converter.hxx new file mode 100644 index 000000000000..615308c9e418 --- /dev/null +++ b/include/sax/tools/converter.hxx @@ -0,0 +1,206 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef _SAX_CONVERTER_HXX +#define _SAX_CONVERTER_HXX + +#include "sax/saxdllapi.h" + +#include <sal/types.h> +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/uno/Sequence.h> +#include <com/sun/star/util/MeasureUnit.hpp> + + +namespace com { namespace sun { namespace star { + namespace uno { + class Any; + } + namespace util { + struct Date; + struct DateTime; + struct Duration; + } +} } } + +namespace sax { + +/** the Converter converts values of various types from + their internal represantation to the textual form used in xml + and back. + + All unit types are expressed as com::sun::star::util::MeasureUnit +*/ + + +class SAX_DLLPUBLIC Converter +{ +public: + /** convert string to measure using optional min and max values*/ + static bool convertMeasure( sal_Int32& rValue, + const OUString& rString, + sal_Int16 nTargetUnit = ::com::sun::star::util::MeasureUnit::MM_100TH, + sal_Int32 nMin = SAL_MIN_INT32, + sal_Int32 nMax = SAL_MAX_INT32 ); + + /** convert measure to string */ + static void convertMeasure( OUStringBuffer& rBuffer, + sal_Int32 nMeasure, + sal_Int16 SourceUnit = ::com::sun::star::util::MeasureUnit::MM_100TH, + sal_Int16 nTargetUnit = ::com::sun::star::util::MeasureUnit::INCH ); + + /** convert string to boolean */ + static bool convertBool( bool& rBool, + const OUString& rString ); + + /** convert boolean to string */ + static void convertBool( OUStringBuffer& rBuffer, + bool bValue ); + + /** convert string to percent */ + static bool convertPercent( sal_Int32& rValue, + const OUString& rString ); + + /** convert percent to string */ + static void convertPercent( OUStringBuffer& rBuffer, + sal_Int32 nValue ); + + /** convert string to pixel measure unite */ + static bool convertMeasurePx( sal_Int32& rValue, + const OUString& rString ); + + /** convert pixel measure unit to string */ + static void convertMeasurePx( OUStringBuffer& rBuffer, + sal_Int32 nValue ); + + /** convert string to rgb color */ + static bool convertColor( sal_Int32& rColor, + const OUString&rValue ); + + /** convert color to string */ + static void convertColor( OUStringBuffer &rBuffer, + sal_Int32 nColor ); + + /** convert number to string */ + static void convertNumber( OUStringBuffer& rBuffer, + sal_Int32 nNumber ); + + /** convert string to number with optional min and max values */ + static bool convertNumber( sal_Int32& rValue, + const OUString& rString, + sal_Int32 nMin = SAL_MIN_INT32, + sal_Int32 nMax = SAL_MAX_INT32 ); + + /** convert string to number with optional min and max values */ + static bool convertNumber64(sal_Int64& rValue, + const OUString& rString, + sal_Int64 nMin = SAL_MIN_INT64, + sal_Int64 nMax = SAL_MAX_INT64); + + /** convert double number to string (using ::rtl::math) and + DO convert from source unit to target unit */ + static void convertDouble( OUStringBuffer& rBuffer, + double fNumber, + bool bWriteUnits, + sal_Int16 nSourceUnit, + sal_Int16 nTargetUnit ); + + /** convert double number to string (using ::rtl::math) without unit conversion */ + static void convertDouble( OUStringBuffer& rBuffer, double fNumber); + + /** convert string to double number (using ::rtl::math) and DO convert from + source unit to target unit. */ + static bool convertDouble( double& rValue, + const OUString& rString, + sal_Int16 nSourceUnit, + sal_Int16 nTargetUnit ); + + /** convert string to double number (using ::rtl::math) without unit conversion */ + static bool convertDouble(double& rValue, const OUString& rString); + + /** convert double to ISO "duration" string; negative durations allowed */ + static void convertDuration(OUStringBuffer& rBuffer, + const double fTime); + + /** convert util::Duration to ISO "duration" string */ + static void convertDuration(OUStringBuffer& rBuffer, + const ::com::sun::star::util::Duration& rDuration); + + /** convert ISO "duration" string to double; negative durations allowed */ + static bool convertDuration(double & rfTime, + const OUString& rString); + + /** convert ISO "duration" string to util::Duration */ + static bool convertDuration(::com::sun::star::util::Duration& rDuration, + const OUString& rString); + + /** convert util::Date to ISO "date" string */ + static void convertDate( OUStringBuffer& rBuffer, + const com::sun::star::util::Date& rDate ); + + /** convert util::DateTime to ISO "date" or "dateTime" string */ + static void convertDateTime( OUStringBuffer& rBuffer, + const com::sun::star::util::DateTime& rDateTime, + bool bAddTimeIf0AM = false ); + + /** convert ISO "date" or "dateTime" string to util::DateTime */ + static bool convertDateTime( com::sun::star::util::DateTime& rDateTime, + const OUString& rString ); + + /** convert ISO "date" or "dateTime" string to util::DateTime or + util::Date */ + static bool convertDateOrDateTime( + com::sun::star::util::Date & rDate, + com::sun::star::util::DateTime & rDateTime, + bool & rbDateTime, + const OUString & rString ); + + /** gets the position of the first comma after npos in the string + rStr. Commas inside '"' pairs are not matched */ + static sal_Int32 indexOfComma( const OUString& rStr, + sal_Int32 nPos ); + + /** encodes the given byte sequence into Base64 */ + static void encodeBase64(OUStringBuffer& aStrBuffer, const com::sun::star::uno::Sequence<sal_Int8>& aPass); + + // Decode a base 64 encoded string into a sequence of bytes. The first + // version can be used for attribute values only, bacause it does not + // return any chars left from conversion. + // For text submitted throgh the SAX characters call, the later method + // must be used! + static void decodeBase64(com::sun::star::uno::Sequence<sal_Int8>& aPass, const OUString& sBuffer); + + static sal_Int32 decodeBase64SomeChars(com::sun::star::uno::Sequence<sal_Int8>& aPass, const OUString& sBuffer); + + static double GetConversionFactor(OUStringBuffer& rUnit, sal_Int16 nSourceUnit, sal_Int16 nTargetUnit); + static sal_Int16 GetUnitFromString(const OUString& rString, sal_Int16 nDefaultUnit); + + /** convert an Any to string (typesafe) */ + static bool convertAny(OUStringBuffer& rsValue, + OUStringBuffer& rsType , + const ::com::sun::star::uno::Any& rValue); + +}; + +} + +#endif // _SAX_CONVERTER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/sax/tools/documenthandleradapter.hxx b/include/sax/tools/documenthandleradapter.hxx new file mode 100644 index 000000000000..5867bbbb9cac --- /dev/null +++ b/include/sax/tools/documenthandleradapter.hxx @@ -0,0 +1,254 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Initial Developer of the Original Code is + * [ Peter Jentsch <pjotr@guineapics.de> ] + * + * Portions created by the Initial Developer are Copyright (C) 2010 the + * Initial Developer. All Rights Reserved. + * + * Contributor(s): Peter Jentsch <pjotr@guineapics.de> + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ + +#ifndef _DOCUMENTHANDLERADAPTER_H_ +#define _DOCUMENTHANDLERADAPTER_H_ + +#include <com/sun/star/xml/sax/SAXException.hpp> +#include <com/sun/star/xml/sax/XDocumentHandler.hpp> +#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp> + +namespace sax +{ + /** + * DocumentHandlerAdapter provides a base class for simple decorators to XDocumentHandlers. + * It forwards all method calls to a delegate. An inheriting class only needs to override the + * methods it actually wants to modify. + * + * See filters/source/odfflatxml/FlatXml.cxx for an example. + */ + class DocumentHandlerAdapter : public ::com::sun::star::xml::sax::XDocumentHandler + { + public: + // XDocumentHandler + virtual void SAL_CALL + startDocument(void) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) + { + m_handler->startDocument(); + } + + virtual void SAL_CALL + endDocument(void) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) + { + m_handler->endDocument(); + } + + virtual void SAL_CALL + startElement(const OUString& aName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttribs) + throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) + { + m_handler->startElement(aName, xAttribs); + } + + virtual void SAL_CALL + endElement(const OUString& aName) throw (::com::sun::star::xml::sax::SAXException, + ::com::sun::star::uno::RuntimeException) + { + m_handler->endElement(aName); + } + + virtual void SAL_CALL + characters(const OUString& aChars) throw (::com::sun::star::xml::sax::SAXException, + ::com::sun::star::uno::RuntimeException) + { + m_handler->characters(aChars); + } + + virtual void SAL_CALL + ignorableWhitespace(const OUString& aWhitespaces) throw (::com::sun::star::xml::sax::SAXException, + ::com::sun::star::uno::RuntimeException) + { + m_handler->ignorableWhitespace(aWhitespaces); + } + virtual void SAL_CALL + processingInstruction(const OUString& aTarget, const OUString& aData) + throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) + { + m_handler->processingInstruction(aTarget, aData); + } + virtual void SAL_CALL + setDocumentLocator(const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator > & xLocator) + throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) + { + m_handler->setDocumentLocator(xLocator); + } + DocumentHandlerAdapter(const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler >& delegate); + DocumentHandlerAdapter() : + m_handler(::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > (0, ::com::sun::star::uno::UNO_QUERY)) + { + } + ; + + protected: + virtual void SAL_CALL + setDelegate(const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler >& delegate) + { + m_handler = delegate; + } + virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > SAL_CALL + getDelegate() + { + return m_handler; + } + virtual + ~DocumentHandlerAdapter() + { + + } + + private: + ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > m_handler; + + }; + + /** + * ExtendedDocumentHandlerAdapter provides a base class for simple decorators to XExtendedDocumentHandlers. + * It forwards all method calls to a delegate. An inheriting class only needs to override the + * methods it actually wants to modify. + */ + class ExtendedDocumentHandlerAdapter : public ::com::sun::star::xml::sax::XExtendedDocumentHandler + + { + + public: + // XDocumentHandler + virtual void SAL_CALL + startDocument(void) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) + { + m_handler->startDocument(); + } + + virtual void SAL_CALL + endDocument(void) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) + { + m_handler->endDocument(); + } + + virtual void SAL_CALL + startElement(const OUString& aName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttribs) + throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) + { + m_handler->startElement(aName, xAttribs); + } + + virtual void SAL_CALL + endElement(const OUString& aName) throw (::com::sun::star::xml::sax::SAXException, + ::com::sun::star::uno::RuntimeException) + { + m_handler->endElement(aName); + } + + virtual void SAL_CALL + characters(const OUString& aChars) throw (::com::sun::star::xml::sax::SAXException, + ::com::sun::star::uno::RuntimeException) + { + m_handler->characters(aChars); + } + + virtual void SAL_CALL + ignorableWhitespace(const OUString& aWhitespaces) throw (::com::sun::star::xml::sax::SAXException, + ::com::sun::star::uno::RuntimeException) + { + m_handler->ignorableWhitespace(aWhitespaces); + } + virtual void SAL_CALL + processingInstruction(const OUString& aTarget, const OUString& aData) + throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) + { + m_handler->processingInstruction(aTarget, aData); + } + virtual void SAL_CALL + setDocumentLocator(const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator > & xLocator) + throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) + { + m_handler->setDocumentLocator(xLocator); + } + // XExtendedDocumentHandler + virtual void SAL_CALL + startCDATA(void) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) + { + m_handler->startCDATA(); + } + virtual void SAL_CALL + endCDATA(void) throw (::com::sun::star::uno::RuntimeException) + { + m_handler->endCDATA(); + } + virtual void SAL_CALL + comment(const OUString& sComment) throw (::com::sun::star::xml::sax::SAXException, + ::com::sun::star::uno::RuntimeException) + { + m_handler->comment(sComment); + } + virtual void SAL_CALL + unknown(const OUString& sString) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) + { + m_handler->unknown(sString); + } + virtual void SAL_CALL + allowLineBreak(void) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) + { + m_handler->allowLineBreak(); + } + protected: + ExtendedDocumentHandlerAdapter() : + m_handler(::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XExtendedDocumentHandler > (0, ::com::sun::star::uno::UNO_QUERY)) + { + } + ExtendedDocumentHandlerAdapter( + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XExtendedDocumentHandler > delegate) : + m_handler(delegate) + { + } + + virtual void SAL_CALL + setDelegate(const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XExtendedDocumentHandler >& delegate) + { + m_handler = delegate; + } + virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XExtendedDocumentHandler > SAL_CALL + getDelegate() + { + return m_handler; + } + virtual + ~ExtendedDocumentHandlerAdapter() + { + + } + + private: + ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XExtendedDocumentHandler > m_handler; + }; +} +#endif /* _DOCUMENTHANDLERADAPTER_H_ */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |