2010-10-27 13:11:31 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-12 17:21:24 +00:00
|
|
|
/*
|
|
|
|
* 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 .
|
|
|
|
*/
|
2007-04-11 12:36:53 +00:00
|
|
|
|
2013-10-23 19:09:35 +02:00
|
|
|
#ifndef INCLUDED_XMLOFF_XMLUCONV_HXX
|
|
|
|
#define INCLUDED_XMLOFF_XMLUCONV_HXX
|
2007-04-11 12:36:53 +00:00
|
|
|
|
2013-11-09 15:30:56 -06:00
|
|
|
#include <sal/config.h>
|
|
|
|
#include <xmloff/dllapi.h>
|
|
|
|
#include <sal/types.h>
|
2007-04-11 12:36:53 +00:00
|
|
|
|
2011-10-11 14:19:10 +02:00
|
|
|
#include <memory>
|
2007-04-11 12:36:53 +00:00
|
|
|
#include <limits.h>
|
2011-10-11 18:58:57 +02:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
#include <rtl/ustring.hxx>
|
|
|
|
#include <rtl/ustrbuf.hxx>
|
2007-04-11 12:36:53 +00:00
|
|
|
#include <xmloff/xmlement.hxx>
|
|
|
|
#include <xmloff/xmltoken.hxx>
|
|
|
|
#include <com/sun/star/util/Date.hpp>
|
|
|
|
#include <com/sun/star/frame/XModel.hpp>
|
|
|
|
#include <com/sun/star/beans/XPropertySet.hpp>
|
|
|
|
#include <com/sun/star/drawing/Position3D.hpp>
|
|
|
|
|
2013-01-16 17:12:47 +02:00
|
|
|
#include <com/sun/star/uno/XComponentContext.hpp>
|
2014-07-30 14:15:39 +02:00
|
|
|
#include <tools/fldunit.hxx>
|
2014-07-31 10:19:33 +02:00
|
|
|
#include <tools/mapunit.hxx>
|
2007-04-11 12:36:53 +00:00
|
|
|
|
2014-02-25 19:06:16 +01:00
|
|
|
|
2007-04-11 12:36:53 +00:00
|
|
|
// predeclarations
|
|
|
|
|
2014-09-28 15:49:26 +02:00
|
|
|
namespace tools { class Time; }
|
2007-04-11 12:36:53 +00:00
|
|
|
|
|
|
|
namespace com { namespace sun { namespace star {
|
|
|
|
namespace util { struct DateTime; }
|
|
|
|
namespace text { class XNumberingTypeInfo; }
|
|
|
|
}}}
|
|
|
|
|
|
|
|
namespace basegfx
|
|
|
|
{
|
|
|
|
class B3DVector;
|
|
|
|
} // end of namespace basegfx
|
|
|
|
|
|
|
|
class XMLOFF_DLLPUBLIC SvXMLTokenEnumerator
|
|
|
|
{
|
|
|
|
private:
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString& maTokenString;
|
2007-04-11 12:36:53 +00:00
|
|
|
sal_Int32 mnNextTokenPos;
|
2013-05-15 10:42:04 +03:00
|
|
|
sal_Unicode mcSeparator;
|
2007-04-11 12:36:53 +00:00
|
|
|
|
|
|
|
public:
|
2013-05-15 10:42:04 +03:00
|
|
|
SvXMLTokenEnumerator( const OUString& rString, sal_Unicode cSeparator = sal_Unicode(' ') );
|
2007-04-11 12:36:53 +00:00
|
|
|
|
2014-03-31 11:47:05 +02:00
|
|
|
bool getNextToken( OUString& rToken );
|
2007-04-11 12:36:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** the SvXMLTypeConverter converts values of various types from
|
2014-11-12 12:25:13 +01:00
|
|
|
their internal representation to the textual form used in xml
|
2007-04-11 12:36:53 +00:00
|
|
|
and back.
|
|
|
|
Most of the methods are static but the SvXMLTypeConverter can
|
|
|
|
also store default units for both numerical and textual measures.
|
2011-10-11 14:19:08 +02:00
|
|
|
|
|
|
|
@attention:
|
|
|
|
a lot of the methods here have been moved to <sax/tools/converter.hxx>!
|
2007-04-11 12:36:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
class XMLOFF_DLLPUBLIC SvXMLUnitConverter
|
|
|
|
{
|
|
|
|
private:
|
2015-02-17 13:43:17 +00:00
|
|
|
SvXMLUnitConverter(const SvXMLUnitConverter&) SAL_DELETED_FUNCTION;
|
|
|
|
SvXMLUnitConverter& operator=(const SvXMLUnitConverter&) SAL_DELETED_FUNCTION;
|
|
|
|
|
2011-10-11 14:19:10 +02:00
|
|
|
struct Impl;
|
2014-09-30 08:13:36 +02:00
|
|
|
::std::unique_ptr<Impl> m_pImpl;
|
2007-04-11 12:36:53 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
/** constructs a SvXMLUnitConverter. The core measure unit is the
|
|
|
|
default unit for numerical measures, the XML measure unit is
|
|
|
|
the default unit for textual measures */
|
|
|
|
SvXMLUnitConverter(
|
2011-10-11 14:19:09 +02:00
|
|
|
const ::com::sun::star::uno::Reference<
|
2013-01-16 17:12:47 +02:00
|
|
|
::com::sun::star::uno::XComponentContext >& xContext,
|
2014-07-31 10:19:33 +02:00
|
|
|
sal_Int16 eCoreMeasureUnit /*css::util::MeasureUnit*/,
|
|
|
|
sal_Int16 eXMLMeasureUnit /*css::util::MeasureUnit*/);
|
2007-04-11 12:36:53 +00:00
|
|
|
|
|
|
|
virtual ~SvXMLUnitConverter();
|
|
|
|
|
2014-07-30 14:15:39 +02:00
|
|
|
static sal_Int16 GetMeasureUnit(FieldUnit const nFieldUnit);
|
2007-04-11 12:36:53 +00:00
|
|
|
|
|
|
|
/** sets the default unit for numerical measures */
|
2014-07-31 10:19:33 +02:00
|
|
|
void SetCoreMeasureUnit( sal_Int16 const eCoreMeasureUnit /*css::util::MeasureUnit*/);
|
2007-04-11 12:36:53 +00:00
|
|
|
|
|
|
|
/** sets the default unit for textual measures */
|
2014-07-31 10:19:33 +02:00
|
|
|
void SetXMLMeasureUnit( sal_Int16 const eXMLMeasureUnit /*css::util::MeasureUnit*/);
|
2007-04-11 12:36:53 +00:00
|
|
|
|
|
|
|
/** gets the default unit for textual measures */
|
2011-10-11 14:19:09 +02:00
|
|
|
sal_Int16 GetXMLMeasureUnit() const;
|
2007-04-11 12:36:53 +00:00
|
|
|
|
|
|
|
/** gets XNumberingTypeInfo */
|
|
|
|
const ::com::sun::star::uno::Reference<
|
2011-10-11 14:19:10 +02:00
|
|
|
::com::sun::star::text::XNumberingTypeInfo >& getNumTypeInfo() const;
|
2007-04-11 12:36:53 +00:00
|
|
|
|
2011-10-11 14:19:09 +02:00
|
|
|
/** convert string to measure with meCoreMeasureUnit,
|
|
|
|
using optional min and max values*/
|
|
|
|
bool convertMeasureToCore( sal_Int32& rValue,
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString& rString,
|
2007-04-11 12:36:53 +00:00
|
|
|
sal_Int32 nMin = SAL_MIN_INT32,
|
|
|
|
sal_Int32 nMax = SAL_MAX_INT32) const;
|
|
|
|
|
2011-10-11 14:19:09 +02:00
|
|
|
/** convert measure to string: from meCoreMeasureUnit to meXMLMeasureUnit */
|
2013-04-07 12:06:47 +02:00
|
|
|
void convertMeasureToXML( OUStringBuffer& rBuffer,
|
2007-04-11 12:36:53 +00:00
|
|
|
sal_Int32 nMeasure ) const;
|
|
|
|
|
|
|
|
/** convert string to enum using given enum map, if the enum is
|
|
|
|
not found in the map, this method will return false */
|
2014-03-31 11:47:05 +02:00
|
|
|
static bool convertEnum( sal_uInt16& rEnum,
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString& rValue,
|
2007-04-11 12:36:53 +00:00
|
|
|
const SvXMLEnumMapEntry *pMap );
|
|
|
|
|
|
|
|
/** convert string to enum using given token map, if the enum is
|
|
|
|
not found in the map, this method will return false */
|
2014-03-31 11:47:05 +02:00
|
|
|
static bool convertEnum( sal_uInt16& rEnum,
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString& rValue,
|
2007-04-11 12:36:53 +00:00
|
|
|
const SvXMLEnumStringMapEntry *pMap );
|
|
|
|
|
|
|
|
/** convert enum to string using given enum map with an optional
|
|
|
|
default token. If the enum is not found in the map,
|
|
|
|
this method will either use the given default or return
|
|
|
|
false if not default is set */
|
2014-03-31 11:47:05 +02:00
|
|
|
static bool convertEnum( OUStringBuffer& rBuffer,
|
2007-04-11 12:36:53 +00:00
|
|
|
unsigned int nValue,
|
|
|
|
const SvXMLEnumMapEntry *pMap,
|
|
|
|
enum ::xmloff::token::XMLTokenEnum eDefault =
|
|
|
|
::xmloff::token::XML_TOKEN_INVALID );
|
|
|
|
|
|
|
|
/** convert double number to string (using ::rtl::math) and DO
|
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
|
|
|
convert to export MapUnit using meCoreMeasureUnit/meXMLMeasureUnit */
|
2013-04-07 12:06:47 +02:00
|
|
|
void convertDouble(OUStringBuffer& rBuffer,
|
2014-03-31 11:47:05 +02:00
|
|
|
double fNumber, bool bWriteUnits) const;
|
2007-04-11 12:36:53 +00:00
|
|
|
|
|
|
|
/** convert string to double number (using ::rtl::math) and DO convert. */
|
2014-03-31 11:47:05 +02:00
|
|
|
bool convertDouble(double& rValue, const OUString& rString, bool bLookForUnits) const;
|
2007-04-11 12:36:53 +00:00
|
|
|
|
|
|
|
/** get the Null Date of the XModel and set it to the UnitConverter */
|
2014-03-31 11:47:05 +02:00
|
|
|
bool setNullDate (
|
2007-04-11 12:36:53 +00:00
|
|
|
const com::sun::star::uno::Reference <com::sun::star::frame::XModel>& xModel);
|
|
|
|
|
|
|
|
/** convert double to ISO Date Time String */
|
2013-04-07 12:06:47 +02:00
|
|
|
void convertDateTime( OUStringBuffer& rBuffer,
|
2007-04-11 12:36:53 +00:00
|
|
|
const double& fDateTime,
|
2011-10-11 14:19:10 +02:00
|
|
|
bool const bAddTimeIf0AM = false);
|
2007-04-11 12:36:53 +00:00
|
|
|
|
|
|
|
/** convert ISO Date Time String to double */
|
2011-10-11 14:19:10 +02:00
|
|
|
bool convertDateTime(double& fDateTime,
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString& rString);
|
2007-04-11 12:36:53 +00:00
|
|
|
|
2011-10-11 14:19:08 +02:00
|
|
|
/// these 2 functions use tools Date, so they're not yet moved to sax
|
|
|
|
|
2007-04-11 12:36:53 +00:00
|
|
|
/** convert double to ISO Date Time String */
|
2013-04-07 12:06:47 +02:00
|
|
|
static void convertDateTime( OUStringBuffer& rBuffer,
|
2007-04-11 12:36:53 +00:00
|
|
|
const double& fDateTime,
|
|
|
|
const com::sun::star::util::Date& aNullDate,
|
2014-03-31 11:47:05 +02:00
|
|
|
bool bAddTimeIf0AM = false);
|
2007-04-11 12:36:53 +00:00
|
|
|
/** convert ISO Date Time String to double */
|
2014-03-31 11:47:05 +02:00
|
|
|
static bool convertDateTime( double& fDateTime,
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString& rString,
|
2007-04-11 12:36:53 +00:00
|
|
|
const com::sun::star::util::Date& aNullDate);
|
|
|
|
|
|
|
|
|
|
|
|
/** convert string to ::basegfx::B3DVector */
|
2014-03-31 11:47:05 +02:00
|
|
|
static bool convertB3DVector( ::basegfx::B3DVector& rVector,
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString& rValue );
|
2007-04-11 12:36:53 +00:00
|
|
|
|
|
|
|
/** convert B3DVector to string */
|
2013-04-07 12:06:47 +02:00
|
|
|
static void convertB3DVector( OUStringBuffer &rBuffer,
|
2007-04-11 12:36:53 +00:00
|
|
|
const ::basegfx::B3DVector& rVector );
|
|
|
|
|
|
|
|
/** convert string to Position3D */
|
2014-03-31 11:47:05 +02:00
|
|
|
bool convertPosition3D( com::sun::star::drawing::Position3D& rPosition,
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString& rValue );
|
2007-04-11 12:36:53 +00:00
|
|
|
|
|
|
|
/** convert Position3D to string */
|
2013-04-07 12:06:47 +02:00
|
|
|
void convertPosition3D( OUStringBuffer &rBuffer,
|
2007-04-11 12:36:53 +00:00
|
|
|
const com::sun::star::drawing::Position3D& rVector );
|
|
|
|
|
|
|
|
|
|
|
|
/** convert num-forat and num-letter-sync values to NumberingType */
|
2014-03-31 11:47:05 +02:00
|
|
|
bool convertNumFormat( sal_Int16& rType,
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString& rNumFormat,
|
|
|
|
const OUString& rNumLetterSync,
|
2014-03-31 11:47:05 +02:00
|
|
|
bool bNumberNone = false ) const;
|
2007-04-11 12:36:53 +00:00
|
|
|
|
|
|
|
/** convert NumberingType to num-forat and num-letter-sync values */
|
2013-04-07 12:06:47 +02:00
|
|
|
void convertNumFormat( OUStringBuffer& rBuffer,
|
2007-04-11 12:36:53 +00:00
|
|
|
sal_Int16 nType ) const;
|
2015-04-02 14:07:31 +02:00
|
|
|
static void convertNumLetterSync( OUStringBuffer& rBuffer,
|
|
|
|
sal_Int16 nType );
|
2007-04-11 12:36:53 +00:00
|
|
|
|
|
|
|
static void convertPropertySet(com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& rProps,
|
|
|
|
const com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet>& aProperties);
|
|
|
|
static void convertPropertySet(com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet>& rProperties,
|
|
|
|
const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& aProps);
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString encodeStyleName( const OUString& rName,
|
2014-03-31 11:47:05 +02:00
|
|
|
bool *pEncoded=0 ) const;
|
2011-12-22 17:27:32 +01:00
|
|
|
/** convert string (hex) to number (sal_uInt32) */
|
2014-03-31 11:47:05 +02:00
|
|
|
static bool convertHex( sal_uInt32& nVal,
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString& rValue );
|
2011-12-22 17:27:32 +01:00
|
|
|
|
|
|
|
/** convert number (sal_uInt32) to string (hex) */
|
2013-04-07 12:06:47 +02:00
|
|
|
static void convertHex( OUStringBuffer& rBuffer,
|
2011-12-22 17:27:32 +01:00
|
|
|
sal_uInt32 nVal );
|
2007-04-11 12:36:53 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-10-23 19:09:35 +02:00
|
|
|
#endif // INCLUDED_XMLOFF_XMLUCONV_HXX
|
2010-10-27 13:11:31 +01:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|