summaryrefslogtreecommitdiffstats
path: root/include/sax/tools
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
commit940b4d1848e8c70ab7642901a68594e8016caffc (patch)
treeeb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /include/sax/tools
parentInitial commit. (diff)
downloadlibreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz
libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'include/sax/tools')
-rw-r--r--include/sax/tools/converter.hxx224
-rw-r--r--include/sax/tools/documenthandleradapter.hxx214
2 files changed, 438 insertions, 0 deletions
diff --git a/include/sax/tools/converter.hxx b/include/sax/tools/converter.hxx
new file mode 100644
index 000000000..e5e6d5764
--- /dev/null
+++ b/include/sax/tools/converter.hxx
@@ -0,0 +1,224 @@
+/* -*- 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_TOOLS_CONVERTER_HXX
+#define INCLUDED_SAX_TOOLS_CONVERTER_HXX
+
+#include <sal/config.h>
+
+#include <optional>
+
+#include <sax/saxdllapi.h>
+
+#include <sal/types.h>
+#include <rtl/ustring.hxx>
+#include <rtl/ustrbuf.hxx>
+#include <com/sun/star/util/MeasureUnit.hpp>
+#include <tools/color.hxx>
+#include <unotools/saveopt.hxx>
+
+namespace com::sun::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 representation to the textual form used in xml
+ and back.
+
+ All unit types are expressed as css::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 = css::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,
+ sal_Int16 nTargetUnit );
+
+ /** 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 );
+ static bool convertColor( ::Color& rColor,
+ const OUString&rValue )
+ {
+ sal_Int32 n(rColor);
+ bool b = convertColor( n, rValue );
+ if (b) rColor = n;
+ return b;
+ }
+
+ /** convert color to string */
+ static void convertColor( OUStringBuffer &rBuffer,
+ sal_Int32 nColor );
+ static void convertColor( OUStringBuffer &rBuffer,
+ ::Color nColor )
+ { convertColor( rBuffer, sal_Int32(nColor) ); }
+
+ /** convert string to number with optional min and max values */
+ static bool convertNumber( sal_Int32& rValue,
+ std::u16string_view aString,
+ 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,
+ std::u16string_view aString,
+ 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 number, 10th of degrees with range [0..3600] to SVG angle */
+ static void convertAngle(OUStringBuffer& rBuffer, sal_Int16 nAngle,
+ SvtSaveOptions::ODFSaneDefaultVersion nVersion);
+
+ /** convert SVG angle to number, 10th of degrees with range [0..3600] */
+ static bool convertAngle(sal_Int16& rAngle, OUString const& rString,
+ bool isWrongOOo10thDegAngle);
+
+ /** convert double to XMLSchema-2 "duration" string; negative durations allowed */
+ static void convertDuration(OUStringBuffer& rBuffer,
+ const double fTime);
+
+ /** convert util::Duration to XMLSchema-2 "duration" string */
+ static void convertDuration(OUStringBuffer& rBuffer,
+ const css::util::Duration& rDuration);
+
+ /** convert XMLSchema-2 "duration" string to double; negative durations allowed */
+ static bool convertDuration(double & rfTime,
+ const OUString& rString);
+
+ /** convert XMLSchema-2 "duration" string to util::Duration */
+ static bool convertDuration(css::util::Duration& rDuration,
+ const OUString& rString);
+
+ /** convert util::Date to XMLSchema-2 "date" string */
+ static void convertDate( OUStringBuffer& rBuffer,
+ const css::util::Date& rDate,
+ sal_Int16 const* pTimeZoneOffset);
+
+ /** convert util::DateTime to XMLSchema-2 "date" or "dateTime" string */
+ static void convertDateTime( OUStringBuffer& rBuffer,
+ const css::util::DateTime& rDateTime,
+ sal_Int16 const* pTimeZoneOffset,
+ bool bAddTimeIf0AM = false );
+
+ /** convert util::DateTime to XMLSchema-2 "time" or "dateTime" string */
+ static void convertTimeOrDateTime(OUStringBuffer& rBuffer,
+ const css::util::DateTime& rDateTime);
+
+ /** convert XMLSchema-2 "date" or "dateTime" string to util::DateTime */
+ static bool parseDateTime( css::util::DateTime& rDateTime,
+ const OUString& rString );
+
+ /** convert XMLSchema-2 "time" or "dateTime" string to util::DateTime */
+ static bool parseTimeOrDateTime(css::util::DateTime& rDateTime,
+ const OUString& rString);
+
+ /** convert XMLSchema-2 "date" or "dateTime" string to util::DateTime or
+ util::Date */
+ static bool parseDateOrDateTime(
+ css::util::Date * pDate,
+ css::util::DateTime & rDateTime,
+ bool & rbDateTime,
+ std::optional<sal_Int16> * pTimeZoneOffset,
+ 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 );
+
+ 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 css::uno::Any& rValue);
+
+};
+
+}
+
+#endif // INCLUDED_SAX_TOOLS_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 000000000..0296abfd6
--- /dev/null
+++ b/include/sax/tools/documenthandleradapter.hxx
@@ -0,0 +1,214 @@
+/* -*- 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/.
+ */
+
+#ifndef INCLUDED_SAX_TOOLS_DOCUMENTHANDLERADAPTER_HXX
+#define INCLUDED_SAX_TOOLS_DOCUMENTHANDLERADAPTER_HXX
+
+#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 css::xml::sax::XDocumentHandler
+ {
+ public:
+ // XDocumentHandler
+ virtual void SAL_CALL
+ startDocument() override
+ {
+ m_handler->startDocument();
+ }
+
+ virtual void SAL_CALL
+ endDocument() override
+ {
+ m_handler->endDocument();
+ }
+
+ virtual void SAL_CALL
+ startElement(const OUString& aName,
+ const css::uno::Reference< css::xml::sax::XAttributeList > & xAttribs) override
+ {
+ m_handler->startElement(aName, xAttribs);
+ }
+
+ virtual void SAL_CALL
+ endElement(const OUString& aName) override
+ {
+ m_handler->endElement(aName);
+ }
+
+ virtual void SAL_CALL
+ characters(const OUString& aChars) override
+ {
+ m_handler->characters(aChars);
+ }
+
+ virtual void SAL_CALL
+ ignorableWhitespace(const OUString& aWhitespaces) override
+ {
+ m_handler->ignorableWhitespace(aWhitespaces);
+ }
+ virtual void SAL_CALL
+ processingInstruction(const OUString& aTarget, const OUString& aData) override
+ {
+ m_handler->processingInstruction(aTarget, aData);
+ }
+ virtual void SAL_CALL
+ setDocumentLocator(const css::uno::Reference< css::xml::sax::XLocator > & xLocator) override
+ {
+ m_handler->setDocumentLocator(xLocator);
+ }
+ DocumentHandlerAdapter() :
+ m_handler(css::uno::Reference< css::xml::sax::XDocumentHandler > (nullptr, css::uno::UNO_QUERY))
+ {
+ }
+ ;
+
+ protected:
+ void
+ setDelegate(const css::uno::Reference< css::xml::sax::XDocumentHandler >& delegate)
+ {
+ m_handler = delegate;
+ }
+ const css::uno::Reference< css::xml::sax::XDocumentHandler >&
+ getDelegate() const
+ {
+ return m_handler;
+ }
+ virtual
+ ~DocumentHandlerAdapter()
+ {
+
+ }
+
+ private:
+ css::uno::Reference< css::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 css::xml::sax::XExtendedDocumentHandler
+
+ {
+
+ public:
+ // XDocumentHandler
+ virtual void SAL_CALL
+ startDocument() override
+ {
+ m_handler->startDocument();
+ }
+
+ virtual void SAL_CALL
+ endDocument() override
+ {
+ m_handler->endDocument();
+ }
+
+ virtual void SAL_CALL
+ startElement(const OUString& aName,
+ const css::uno::Reference< css::xml::sax::XAttributeList > & xAttribs) override
+ {
+ m_handler->startElement(aName, xAttribs);
+ }
+
+ virtual void SAL_CALL
+ endElement(const OUString& aName) override
+ {
+ m_handler->endElement(aName);
+ }
+
+ virtual void SAL_CALL
+ characters(const OUString& aChars) override
+ {
+ m_handler->characters(aChars);
+ }
+
+ virtual void SAL_CALL
+ ignorableWhitespace(const OUString& aWhitespaces) override
+ {
+ m_handler->ignorableWhitespace(aWhitespaces);
+ }
+ virtual void SAL_CALL
+ processingInstruction(const OUString& aTarget, const OUString& aData) override
+ {
+ m_handler->processingInstruction(aTarget, aData);
+ }
+ virtual void SAL_CALL
+ setDocumentLocator(const css::uno::Reference< css::xml::sax::XLocator > & xLocator) override
+ {
+ m_handler->setDocumentLocator(xLocator);
+ }
+ // XExtendedDocumentHandler
+ virtual void SAL_CALL
+ startCDATA() override
+ {
+ m_handler->startCDATA();
+ }
+ virtual void SAL_CALL
+ endCDATA() override
+ {
+ m_handler->endCDATA();
+ }
+ virtual void SAL_CALL
+ comment(const OUString& sComment) override
+ {
+ m_handler->comment(sComment);
+ }
+ virtual void SAL_CALL
+ unknown(const OUString& sString) override
+ {
+ m_handler->unknown(sString);
+ }
+ virtual void SAL_CALL
+ allowLineBreak() override
+ {
+ m_handler->allowLineBreak();
+ }
+ protected:
+ ExtendedDocumentHandlerAdapter() :
+ m_handler(css::uno::Reference< css::xml::sax::XExtendedDocumentHandler > (nullptr, css::uno::UNO_QUERY))
+ {
+ }
+
+ void
+ setDelegate(const css::uno::Reference< css::xml::sax::XExtendedDocumentHandler >& delegate)
+ {
+ m_handler = delegate;
+ }
+ const css::uno::Reference< css::xml::sax::XExtendedDocumentHandler >&
+ getDelegate() const
+ {
+ return m_handler;
+ }
+ virtual
+ ~ExtendedDocumentHandlerAdapter()
+ {
+
+ }
+
+ private:
+ css::uno::Reference< css::xml::sax::XExtendedDocumentHandler > m_handler;
+ };
+}
+#endif // INCLUDED_SAX_TOOLS_DOCUMENTHANDLERADAPTER_HXX
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */