diff options
author | Michael Stahl <mst@openoffice.org> | 2011-10-11 14:19:08 +0200 |
---|---|---|
committer | Michael Stahl <mst@openoffice.org> | 2011-10-11 17:57:00 +0200 |
commit | ae3e2f170045a1525f67e9f3e9b7e03d94f2b56b (patch) | |
tree | 8b7caefa4e6f3f7520653dc66f59bacecbeeda1a /xmloff | |
parent | #i108468#: clean up xmluconv code duplication, part 1: (diff) | |
download | core-ae3e2f170045a1525f67e9f3e9b7e03d94f2b56b.tar.gz core-ae3e2f170045a1525f67e9f3e9b7e03d94f2b56b.zip |
#i108468#: clean up xmluconv code duplication, DateTime edition:
remove duplicate methods from SvXMLUnitConverter:
convertTime (all variants), convertDateTime (DateTime variants),
convertTimeDuration.
move convertAny from SvXMLUnitConverter to sax::converter.
Diffstat (limited to 'xmloff')
24 files changed, 137 insertions, 887 deletions
diff --git a/xmloff/inc/xmloff/xmluconv.hxx b/xmloff/inc/xmloff/xmluconv.hxx index 1ca051b888bd..c605f7bdc354 100644 --- a/xmloff/inc/xmloff/xmluconv.hxx +++ b/xmloff/inc/xmloff/xmluconv.hxx @@ -85,6 +85,9 @@ public: and back. Most of the methods are static but the SvXMLTypeConverter can also store default units for both numerical and textual measures. + + @attention: + a lot of the methods here have been moved to <sax/tools/converter.hxx>! */ class XMLOFF_DLLPUBLIC SvXMLUnitConverter @@ -222,22 +225,6 @@ public: /** Set the Null Date of the UnitConverter */ void setNullDate ( const com::sun::star::util::Date& aTempNullDate ) { aNullDate = aTempNullDate; } - /** convert double to ISO Time String */ - static void convertTime( ::rtl::OUStringBuffer& rBuffer, - const double& fTime); - - /** convert util::DateTime to ISO Time String */ - static void convertTime( ::rtl::OUStringBuffer& rBuffer, - const ::com::sun::star::util::DateTime& rDateTime ); - - /** convert ISO Time String to double */ - static sal_Bool convertTime( double& fTime, - const ::rtl::OUString& rString); - - /** convert ISO Time String to util::DateTime */ - static sal_Bool convertTime( ::com::sun::star::util::DateTime& rDateTime, - const ::rtl::OUString& rString ); - /** convert double to ISO Date Time String */ void convertDateTime( ::rtl::OUStringBuffer& rBuffer, const double& fDateTime, @@ -247,6 +234,8 @@ public: sal_Bool convertDateTime( double& fDateTime, const ::rtl::OUString& rString) { return convertDateTime(fDateTime, rString, aNullDate); } + /// these 2 functions use tools Date, so they're not yet moved to sax + /** convert double to ISO Date Time String */ static void convertDateTime( ::rtl::OUStringBuffer& rBuffer, const double& fDateTime, @@ -257,32 +246,6 @@ public: const ::rtl::OUString& rString, const com::sun::star::util::Date& aNullDate); - /** converts the given time value into an ISO-conform duration string - - @param rTime - the time value to convert. This parameter is evaluated only down to the seconds - in particular, - "100th seconds" are ignored. - @param nSecondsFraction - Additional milleseconds to add to the time. Must be smaller than 1000. - This parameter is necessary since neither <type>Time</type> nor <type scope="com::sun::star::util">Time</type> - have a sufficient resolution to transport milliseconds. - @see http://www.w3.org/TR/xmlschema-2/#duration - */ - static ::rtl::OUString convertTimeDuration( const ::Time& rTime, sal_Int32 nSecondsFraction = 0 ); - - /** converts the given ISO-conform duration string into a time value - - @param rTime - the converted time value. Fractions of seconds of this object are not filled, even if present in - the string. See <arg>nSecondsFraction</arg> - - @param pSecondsFraction - recieves fractions of whole seconds, in milliseconds. May be <NULL/> - This parameter is necessary since neither <type>Time</type> nor <type scope="com::sun::star::util">Time</type> - have a sufficient resolution to transport milliseconds. - @see http://www.w3.org/TR/xmlschema-2/#duration - */ - static bool convertTimeDuration( const rtl::OUString& rString, ::Time& rTime, sal_Int32* pSecondsFraction = NULL ); /** convert string to ::basegfx::B3DVector */ static sal_Bool convertB3DVector( ::basegfx::B3DVector& rVector, @@ -300,15 +263,6 @@ public: void convertPosition3D( ::rtl::OUStringBuffer &rBuffer, const com::sun::star::drawing::Position3D& rVector ); - /** convert util::DateTime to ISO Date String */ - static void convertDateTime( ::rtl::OUStringBuffer& rBuffer, - const com::sun::star::util::DateTime& rDateTime, - sal_Bool bAddTimeIf0AM=sal_False ); - - /** convert ISO Date String to util::DateTime */ - static sal_Bool convertDateTime( com::sun::star::util::DateTime& rDateTime, - const ::rtl::OUString& rString ); - /** convert num-forat and num-letter-sync values to NumberingType */ sal_Bool convertNumFormat( sal_Int16& rType, @@ -330,15 +284,6 @@ public: ::rtl::OUString encodeStyleName( const ::rtl::OUString& rName, sal_Bool *pEncoded=0 ) const; - /** convert an Any to string (typesafe) */ - static sal_Bool convertAny( ::rtl::OUStringBuffer& sValue, - ::rtl::OUStringBuffer& sType , - const com::sun::star::uno::Any& aValue); - - /** convert a string to Any (typesafe) */ - static sal_Bool convertAny( com::sun::star::uno::Any& aValue, - const ::rtl::OUString& sType , - const ::rtl::OUString& sValue); }; inline void SvXMLUnitConverter::setCoreMeasureUnit( MapUnit eCoreMeasureUnit ) diff --git a/xmloff/source/chart/SchXMLCalculationSettingsContext.cxx b/xmloff/source/chart/SchXMLCalculationSettingsContext.cxx index 531388d943e6..9a3b40dd8ac3 100644 --- a/xmloff/source/chart/SchXMLCalculationSettingsContext.cxx +++ b/xmloff/source/chart/SchXMLCalculationSettingsContext.cxx @@ -31,11 +31,13 @@ #include <SchXMLCalculationSettingsContext.hxx> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/util/DateTime.hpp> + +#include <sax/tools/converter.hxx> + #include <xmloff/xmlimp.hxx> #include <xmloff/nmspmap.hxx> #include "xmloff/xmlnmspe.hxx" #include <xmloff/xmltoken.hxx> -#include <xmloff/xmluconv.hxx> using ::rtl::OUString; @@ -64,7 +66,7 @@ SchXMLCalculationSettingsContext::SchXMLCalculationSettingsContext( SvXMLImport& { util::DateTime aNullDate; const rtl::OUString sValue = xAttrList->getValueByIndex( i ); - GetImport().GetMM100UnitConverter().convertDateTime(aNullDate, sValue); + ::sax::Converter::convertDateTime(aNullDate, sValue); m_aNullDate <<= aNullDate; } } diff --git a/xmloff/source/chart/SchXMLExport.cxx b/xmloff/source/chart/SchXMLExport.cxx index 9bd03631a28e..089772832f08 100644 --- a/xmloff/source/chart/SchXMLExport.cxx +++ b/xmloff/source/chart/SchXMLExport.cxx @@ -1278,7 +1278,7 @@ void SchXMLExportHelper_Impl::parseDocument( Reference< chart::XChartDocument >& SvXMLElementExport aSet( mrExport, XML_NAMESPACE_TABLE, XML_CALCULATION_SETTINGS, sal_True, sal_True ); { ::rtl::OUStringBuffer sBuffer; - SvXMLUnitConverter::convertDateTime(sBuffer,aNullDate); + ::sax::Converter::convertDateTime(sBuffer, aNullDate); mrExport.AddAttribute( XML_NAMESPACE_TABLE,XML_DATE_VALUE,sBuffer.makeStringAndClear()); SvXMLElementExport aNull( mrExport, XML_NAMESPACE_TABLE, XML_NULL_DATE, sal_True, sal_True ); } diff --git a/xmloff/source/core/xmluconv.cxx b/xmloff/source/core/xmluconv.cxx index 8d32a055aa90..1963fc80875f 100644 --- a/xmloff/source/core/xmluconv.cxx +++ b/xmloff/source/core/xmluconv.cxx @@ -61,19 +61,6 @@ #include <sax/tools/converter.hxx> -//TODO just temporary => remove! -static sal_Bool convertNumber( sal_Int32& rValue, - const ::rtl::OUString& rString, - sal_Int32 nMin = SAL_MIN_INT32, - sal_Int32 nMax = SAL_MAX_INT32) -{ - return ::sax::Converter::convertNumber(rValue, rString, nMin, nMax); -} -static void convertNumber( ::rtl::OUStringBuffer& rBuffer, sal_Int32 nNumber ) -{ - return ::sax::Converter::convertNumber(rBuffer, nNumber); -} - using namespace com::sun::star; using namespace com::sun::star::uno; using namespace com::sun::star::lang; @@ -585,254 +572,6 @@ sal_Bool SvXMLUnitConverter::setNullDate(const com::sun::star::uno::Reference <c return sal_False; } -/** convert double to ISO Time String; negative durations allowed */ -void SvXMLUnitConverter::convertTime( OUStringBuffer& rBuffer, - const double& fTime) -{ - - double fValue = fTime; - - // take care of negative durations as specified in: - // XML Schema, W3C Working Draft 07 April 2000, section 3.2.6.1 - if (fValue < 0.0) - { - rBuffer.append(sal_Unicode('-')); - fValue = - fValue; - } - - rBuffer.appendAscii(RTL_CONSTASCII_STRINGPARAM( "PT" )); - fValue *= 24; - double fHoursValue = ::rtl::math::approxFloor (fValue); - fValue -= fHoursValue; - fValue *= 60; - double fMinsValue = ::rtl::math::approxFloor (fValue); - fValue -= fMinsValue; - fValue *= 60; - double fSecsValue = ::rtl::math::approxFloor (fValue); - fValue -= fSecsValue; - double f100SecsValue; - if (fValue > 0.00001) - f100SecsValue = ::rtl::math::round( fValue, XML_MAXDIGITSCOUNT_TIME - 5); - else - f100SecsValue = 0.0; - - if (f100SecsValue == 1.0) - { - f100SecsValue = 0.0; - fSecsValue += 1.0; - } - if (fSecsValue >= 60.0) - { - fSecsValue -= 60.0; - fMinsValue += 1.0; - } - if (fMinsValue >= 60.0) - { - fMinsValue -= 60.0; - fHoursValue += 1.0; - } - - if (fHoursValue < 10) - rBuffer.append( sal_Unicode('0')); - rBuffer.append( sal_Int32( fHoursValue)); - rBuffer.append( sal_Unicode('H')); - if (fMinsValue < 10) - rBuffer.append( sal_Unicode('0')); - rBuffer.append( sal_Int32( fMinsValue)); - rBuffer.append( sal_Unicode('M')); - if (fSecsValue < 10) - rBuffer.append( sal_Unicode('0')); - rBuffer.append( sal_Int32( fSecsValue)); - if (f100SecsValue > 0.0) - { - OUString a100th( ::rtl::math::doubleToUString( fValue, - rtl_math_StringFormat_F, XML_MAXDIGITSCOUNT_TIME - 5, '.', - sal_True)); - if ( a100th.getLength() > 2 ) - { - rBuffer.append( sal_Unicode('.')); - rBuffer.append( a100th.copy( 2 ) ); // strip 0. - } - } - rBuffer.append( sal_Unicode('S')); -} - -/** convert ISO Time String to double; negative durations allowed */ -static bool lcl_convertTime( const ::rtl::OUString& rString, sal_Int32& o_rDays, sal_Int32& o_rHours, sal_Int32& o_rMins, - sal_Int32& o_rSecs, sal_Bool& o_rIsNegativeTime, double& o_rFractionalSecs ) -{ - OUString aTrimmed = rString.trim().toAsciiUpperCase(); - const sal_Unicode* pStr = aTrimmed.getStr(); - - // negative time duration? - if ( sal_Unicode('-') == (*pStr) ) - { - o_rIsNegativeTime = sal_True; - pStr++; - } - - if ( *(pStr++) != sal_Unicode('P') ) // duration must start with "P" - return false; - - ::rtl::OUString sDoubleStr; - sal_Bool bSuccess = true; - sal_Bool bDone = sal_False; - sal_Bool bTimePart = sal_False; - sal_Bool bIsFraction = sal_False; - sal_Int32 nTemp = 0; - - while ( bSuccess && !bDone ) - { - sal_Unicode c = *(pStr++); - if ( !c ) // end - bDone = sal_True; - else if ( sal_Unicode('0') <= c && sal_Unicode('9') >= c ) - { - if ( nTemp >= SAL_MAX_INT32 / 10 ) - bSuccess = false; - else - { - if ( !bIsFraction ) - { - nTemp *= 10; - nTemp += (c - sal_Unicode('0')); - } - else - { - sDoubleStr += OUString::valueOf(c); - } - } - } - else if ( bTimePart ) - { - if ( c == sal_Unicode('H') ) - { - o_rHours = nTemp; - nTemp = 0; - } - else if ( c == sal_Unicode('M') ) - { - o_rMins = nTemp; - nTemp = 0; - } - else if ( (c == sal_Unicode(',')) || (c == sal_Unicode('.')) ) - { - o_rSecs = nTemp; - nTemp = 0; - bIsFraction = sal_True; - sDoubleStr = OUString(RTL_CONSTASCII_USTRINGPARAM("0.")); - } - else if ( c == sal_Unicode('S') ) - { - if ( !bIsFraction ) - { - o_rSecs = nTemp; - nTemp = 0; - sDoubleStr = OUString(RTL_CONSTASCII_USTRINGPARAM("0.0")); - } - } - else - bSuccess = false; // invalid character - } - else - { - if ( c == sal_Unicode('T') ) // "T" starts time part - bTimePart = sal_True; - else if ( c == sal_Unicode('D') ) - { - o_rDays = nTemp; - nTemp = 0; - } - else if ( c == sal_Unicode('Y') || c == sal_Unicode('M') ) - { - //! how many days is a year or month? - - OSL_FAIL("years or months in duration: not implemented"); - bSuccess = false; - } - else - bSuccess = false; // invalid character - } - } - - if ( bSuccess ) - o_rFractionalSecs = sDoubleStr.toDouble(); - return bSuccess; -} - -sal_Bool SvXMLUnitConverter::convertTime( double& fTime, - const ::rtl::OUString& rString) -{ - sal_Int32 nDays = 0; - sal_Int32 nHours = 0; - sal_Int32 nMins = 0; - sal_Int32 nSecs = 0; - sal_Bool bIsNegativeDuration = sal_False; - double fFractionalSecs = 0.0; - if ( lcl_convertTime( rString, nDays, nHours, nMins, nSecs, bIsNegativeDuration, fFractionalSecs ) ) - { - if ( nDays ) - nHours += nDays * 24; // add the days to the hours part - double fTempTime = 0.0; - double fHour = nHours; - double fMin = nMins; - double fSec = nSecs; - double fSec100 = 0.0; - fTempTime = fHour / 24; - fTempTime += fMin / (24 * 60); - fTempTime += fSec / (24 * 60 * 60); - fTempTime += fSec100 / (24 * 60 * 60 * 60); - fTempTime += fFractionalSecs / (24 * 60 * 60); - - // negative duration? - if ( bIsNegativeDuration ) - { - fTempTime = -fTempTime; - } - - fTime = fTempTime; - return sal_True; - } - return sal_False; -} - -/** convert util::DateTime to ISO Time String */ -void SvXMLUnitConverter::convertTime( OUStringBuffer& rBuffer, - const ::com::sun::star::util::DateTime& rDateTime ) -{ - double fHour = rDateTime.Hours; - double fMin = rDateTime.Minutes; - double fSec = rDateTime.Seconds; - double fSec100 = rDateTime.HundredthSeconds; - double fTempTime = fHour / 24; - fTempTime += fMin / (24 * 60); - fTempTime += fSec / (24 * 60 * 60); - fTempTime += fSec100 / (24 * 60 * 60 * 100); - convertTime( rBuffer, fTempTime ); -} - -/** convert ISO Time String to util::DateTime */ -sal_Bool SvXMLUnitConverter::convertTime( ::com::sun::star::util::DateTime& rDateTime, - const OUString& rString ) -{ - sal_Int32 nDays = 0, nHours = 0, nMins = 0, nSecs = 0; - sal_Bool bIsNegativeDuration = sal_False; - double fFractionalSecs = 0.0; - if ( lcl_convertTime( rString, nDays, nHours, nMins, nSecs, bIsNegativeDuration, fFractionalSecs ) ) - { - rDateTime.Year = 0; - rDateTime.Month = 0; - rDateTime.Day = 0; - rDateTime.Hours = static_cast < sal_uInt16 > ( nHours ); - rDateTime.Minutes = static_cast < sal_uInt16 > ( nMins ); - rDateTime.Seconds = static_cast < sal_uInt16 > ( nSecs ); - rDateTime.HundredthSeconds = static_cast < sal_uInt16 > ( fFractionalSecs * 100.0 ); - - return sal_True; - } - return sal_False; -} - /** convert double to ISO Date Time String */ void SvXMLUnitConverter::convertDateTime( OUStringBuffer& rBuffer, const double& fDateTime, @@ -939,7 +678,7 @@ sal_Bool SvXMLUnitConverter::convertDateTime( double& fDateTime, const OUString& rString, const com::sun::star::util::Date& aTempNullDate) { com::sun::star::util::DateTime aDateTime; - sal_Bool bSuccess = convertDateTime(aDateTime,rString); + sal_Bool bSuccess = ::sax::Converter::convertDateTime(aDateTime, rString); if (bSuccess) { @@ -961,148 +700,6 @@ sal_Bool SvXMLUnitConverter::convertDateTime( double& fDateTime, return bSuccess; } -/** convert util::DateTime to ISO Date String */ -void SvXMLUnitConverter::convertDateTime( - OUStringBuffer& rBuffer, - const com::sun::star::util::DateTime& rDateTime, - sal_Bool bAddTimeIf0AM ) -{ - String aString( String::CreateFromInt32( rDateTime.Year ) ); - aString += '-'; - if( rDateTime.Month < 10 ) - aString += '0'; - aString += String::CreateFromInt32( rDateTime.Month ); - aString += '-'; - if( rDateTime.Day < 10 ) - aString += '0'; - aString += String::CreateFromInt32( rDateTime.Day ); - - if( rDateTime.Seconds != 0 || - rDateTime.Minutes != 0 || - rDateTime.Hours != 0 || - bAddTimeIf0AM ) - { - aString += 'T'; - if( rDateTime.Hours < 10 ) - aString += '0'; - aString += String::CreateFromInt32( rDateTime.Hours ); - aString += ':'; - if( rDateTime.Minutes < 10 ) - aString += '0'; - aString += String::CreateFromInt32( rDateTime.Minutes ); - aString += ':'; - if( rDateTime.Seconds < 10 ) - aString += '0'; - aString += String::CreateFromInt32( rDateTime.Seconds ); - if ( rDateTime.HundredthSeconds > 0) - { - aString += '.'; - if (rDateTime.HundredthSeconds < 10) - aString += '0'; - aString += String::CreateFromInt32( rDateTime.HundredthSeconds ); - } - } - - rBuffer.append( aString ); -} - -/** convert ISO Date String to util::DateTime */ -sal_Bool SvXMLUnitConverter::convertDateTime( com::sun::star::util::DateTime& rDateTime, - const OUString& rString ) -{ - sal_Bool bSuccess = sal_True; - - OUString aDateStr, aTimeStr, sDoubleStr; - sal_Int32 nPos = rString.indexOf( (sal_Unicode) 'T' ); - sal_Int32 nPos2 = rString.indexOf( (sal_Unicode) ',' ); - if (nPos2 < 0) - nPos2 = rString.indexOf( (sal_Unicode) '.' ); - if ( nPos >= 0 ) - { - aDateStr = rString.copy( 0, nPos ); - if ( nPos2 >= 0 ) - { - aTimeStr = rString.copy( nPos + 1, nPos2 - nPos - 1 ); - sDoubleStr = OUString(RTL_CONSTASCII_USTRINGPARAM("0.")); - sDoubleStr += rString.copy( nPos2 + 1 ); - } - else - { - aTimeStr = rString.copy(nPos + 1); - sDoubleStr = OUString(RTL_CONSTASCII_USTRINGPARAM("0.0")); - } - } - else - aDateStr = rString; // no separator: only date part - - sal_Int32 nYear = 1899; - sal_Int32 nMonth = 12; - sal_Int32 nDay = 30; - sal_Int32 nHour = 0; - sal_Int32 nMin = 0; - sal_Int32 nSec = 0; - - const sal_Unicode* pStr = aDateStr.getStr(); - sal_Int32 nDateTokens = 1; - while ( *pStr ) - { - if ( *pStr == '-' ) - nDateTokens++; - pStr++; - } - if ( nDateTokens > 3 || aDateStr.getLength() == 0 ) - bSuccess = sal_False; - else - { - sal_Int32 n = 0; - if ( !convertNumber( nYear, aDateStr.getToken( 0, '-', n ), 0, 9999 ) ) - bSuccess = sal_False; - if ( nDateTokens >= 2 ) - if ( !convertNumber( nMonth, aDateStr.getToken( 0, '-', n ), 0, 12 ) ) - bSuccess = sal_False; - if ( nDateTokens >= 3 ) - if ( !convertNumber( nDay, aDateStr.getToken( 0, '-', n ), 0, 31 ) ) - bSuccess = sal_False; - } - - if ( aTimeStr.getLength() > 0 ) // time is optional - { - pStr = aTimeStr.getStr(); - sal_Int32 nTimeTokens = 1; - while ( *pStr ) - { - if ( *pStr == ':' ) - nTimeTokens++; - pStr++; - } - if ( nTimeTokens > 3 ) - bSuccess = sal_False; - else - { - sal_Int32 n = 0; - if ( !convertNumber( nHour, aTimeStr.getToken( 0, ':', n ), 0, 23 ) ) - bSuccess = sal_False; - if ( nTimeTokens >= 2 ) - if ( !convertNumber( nMin, aTimeStr.getToken( 0, ':', n ), 0, 59 ) ) - bSuccess = sal_False; - if ( nTimeTokens >= 3 ) - if ( !convertNumber( nSec, aTimeStr.getToken( 0, ':', n ), 0, 59 ) ) - bSuccess = sal_False; - } - } - - if (bSuccess) - { - rDateTime.Year = (sal_uInt16)nYear; - rDateTime.Month = (sal_uInt16)nMonth; - rDateTime.Day = (sal_uInt16)nDay; - rDateTime.Hours = (sal_uInt16)nHour; - rDateTime.Minutes = (sal_uInt16)nMin; - rDateTime.Seconds = (sal_uInt16)nSec; - rDateTime.HundredthSeconds = (sal_uInt16)(sDoubleStr.toDouble() * 100); - } - return bSuccess; -} SvXMLTokenEnumerator::SvXMLTokenEnumerator( const OUString& rString, sal_Unicode cSeperator /* = sal_Unicode(' ') */ ) : maTokenString( rString ), mnNextTokenPos(0), mcSeperator( cSeperator ) @@ -1525,329 +1122,4 @@ OUString SvXMLUnitConverter::encodeStyleName( return aBuffer.makeStringAndClear(); } -// static -OUString SvXMLUnitConverter::convertTimeDuration( const Time& rTime, sal_Int32 nSecondsFraction ) -{ - // return ISO time period string - OUStringBuffer sTmp; - sTmp.append( sal_Unicode('P') ); // "period" - - sal_uInt16 nHours = rTime.GetHour(); - sal_Bool bHasHours = ( nHours > 0 ); - if ( nHours >= 24 ) - { - // add days - - sal_uInt16 nDays = nHours / 24; - sTmp.append( (sal_Int32) nDays ); - sTmp.append( sal_Unicode('D') ); // "days" - - nHours -= nDays * 24; - } - sTmp.append( sal_Unicode('T') ); // "time" - - if ( bHasHours ) - { - sTmp.append( (sal_Int32) nHours ); - sTmp.append( sal_Unicode('H') ); // "hours" - } - sal_uInt16 nMinutes = rTime.GetMin(); - if ( bHasHours || nMinutes > 0 ) - { - sTmp.append( (sal_Int32) nMinutes ); - sTmp.append( sal_Unicode('M') ); // "minutes" - } - sal_uInt16 nSeconds = rTime.GetSec(); - sTmp.append( (sal_Int32) nSeconds ); - if ( nSecondsFraction ) - { - sTmp.append( sal_Unicode( '.' ) ); - OUStringBuffer aFractional; - convertNumber( aFractional, nSecondsFraction ); - sTmp.append( aFractional.getStr() ); - } - sTmp.append( sal_Unicode('S') ); // "seconds" - - return sTmp.makeStringAndClear(); -} - -// static -bool SvXMLUnitConverter::convertTimeDuration( const OUString& rString, Time& rTime, sal_Int32* pSecondsFraction ) -{ - OUString aTrimmed = rString.trim().toAsciiUpperCase(); - const sal_Unicode* pStr = aTrimmed.getStr(); - - if ( *(pStr++) != sal_Unicode('P') ) // duration must start with "P" - return false; - - bool bSuccess = true; - sal_Bool bDone = sal_False; - sal_Bool bTimePart = sal_False; - sal_Bool bFractional = sal_False; - sal_Int32 nDays = 0; - sal_Int32 nHours = 0; - sal_Int32 nMins = 0; - sal_Int32 nSecs = 0; - sal_Int32 nTemp = 0; - sal_Int32 nSecondsFraction = 0; - - while ( bSuccess && !bDone ) - { - sal_Unicode c = *(pStr++); - if ( !c ) // end - bDone = sal_True; - else if ( sal_Unicode('0') <= c && sal_Unicode('9') >= c ) - { - if ( bFractional ) - { - if ( nSecondsFraction >= SAL_MAX_INT32 / 10 ) - bSuccess = false; - else - { - nSecondsFraction *= 10; - nSecondsFraction += (c - sal_Unicode('0')); - } - } - else - { - if ( nTemp >= SAL_MAX_INT32 / 10 ) - bSuccess = false; - else - { - nTemp *= 10; - nTemp += (c - sal_Unicode('0')); - } - } - } - else if ( bTimePart ) - { - if ( c == sal_Unicode('H') ) - { - nHours = nTemp; - nTemp = 0; - } - else if ( c == sal_Unicode('M') ) - { - nMins = nTemp; - nTemp = 0; - } - else if ( c == sal_Unicode('S') ) - { - nSecs = nTemp; - nTemp = 0; - } - else if ( c == '.' ) - { - bFractional = sal_True; - } - else - bSuccess = false; // invalid characted - } - else - { - if ( c == sal_Unicode('T') ) // "T" starts time part - bTimePart = sal_True; - else if ( c == sal_Unicode('D') ) - { - nDays = nTemp; - nTemp = 0; - } - else if ( c == sal_Unicode('Y') || c == sal_Unicode('M') ) - { - //! how many days is a year or month? - - OSL_FAIL("years or months in duration: not implemented"); - bSuccess = false; - } - else - bSuccess = false; // invalid characted - } - } - - if ( bSuccess ) - { - if ( nDays ) - nHours += nDays * 24; // add the days to the hours part - rTime = Time( nHours, nMins, nSecs ); - if ( pSecondsFraction ) - *pSecondsFraction = nSecondsFraction % 1000; - } - return bSuccess; -} - -sal_Bool SvXMLUnitConverter::convertAny( OUStringBuffer& sValue, - OUStringBuffer& sType , - const com::sun::star::uno::Any& aValue) -{ - sal_Bool bConverted = sal_False; - - sValue.setLength(0); - sType.setLength (0); - - switch(aValue.getValueTypeClass()) - { - case com::sun::star::uno::TypeClass_BYTE : - case com::sun::star::uno::TypeClass_SHORT : - case com::sun::star::uno::TypeClass_UNSIGNED_SHORT : - case com::sun::star::uno::TypeClass_LONG : - case com::sun::star::uno::TypeClass_UNSIGNED_LONG : - { - sal_Int32 nTempValue = 0; - if (aValue >>= nTempValue) - { - sType.appendAscii("integer"); - bConverted = sal_True; - ::sax::Converter::convertNumber(sValue, nTempValue); - } - } - break; - - case com::sun::star::uno::TypeClass_BOOLEAN : - { - sal_Bool bTempValue = sal_False; - if (aValue >>= bTempValue) - { - sType.appendAscii("boolean"); - bConverted = sal_True; - ::sax::Converter::convertBool(sValue, bTempValue); - } - } - break; - - case com::sun::star::uno::TypeClass_FLOAT : - case com::sun::star::uno::TypeClass_DOUBLE : - { - double fTempValue = 0.0; - if (aValue >>= fTempValue) - { - sType.appendAscii("float"); - bConverted = sal_True; - ::sax::Converter::convertDouble(sValue, fTempValue); - } - } - break; - - case com::sun::star::uno::TypeClass_STRING : - { - OUString sTempValue; - if (aValue >>= sTempValue) - { - sType.appendAscii("string"); - bConverted = sal_True; - sValue.append(sTempValue); - } - } - break; - - case com::sun::star::uno::TypeClass_STRUCT : - { - com::sun::star::util::Date aDate ; - com::sun::star::util::Time aTime ; - com::sun::star::util::DateTime aDateTime; - - if (aValue >>= aDate) - { - sType.appendAscii("date"); - bConverted = sal_True; - com::sun::star::util::DateTime aTempValue; - aTempValue.Day = aDate.Day; - aTempValue.Month = aDate.Month; - aTempValue.Year = aDate.Year; - aTempValue.HundredthSeconds = 0; - aTempValue.Seconds = 0; - aTempValue.Minutes = 0; - aTempValue.Hours = 0; - SvXMLUnitConverter::convertDateTime(sValue, aTempValue); - } - else - if (aValue >>= aTime) - { - sType.appendAscii("time"); - bConverted = sal_True; - com::sun::star::util::DateTime aTempValue; - aTempValue.Day = 0; - aTempValue.Month = 0; - aTempValue.Year = 0; - aTempValue.HundredthSeconds = aTime.HundredthSeconds; - aTempValue.Seconds = aTime.Seconds; - aTempValue.Minutes = aTime.Minutes; - aTempValue.Hours = aTime.Hours; - SvXMLUnitConverter::convertTime(sValue, aTempValue); - } - else - if (aValue >>= aDateTime) - { - sType.appendAscii("date"); - bConverted = sal_True; - SvXMLUnitConverter::convertDateTime(sValue, aDateTime); - } - } - break; - default: - break; - } - - return bConverted; -} - -sal_Bool SvXMLUnitConverter::convertAny( com::sun::star::uno::Any& aValue, - const OUString& sType , - const OUString& sValue) -{ - sal_Bool bConverted = sal_False; - - if (sType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("boolean"))) - { - bool bTempValue = false; - ::sax::Converter::convertBool(bTempValue, sValue); - aValue <<= bTempValue; - bConverted = sal_True; - } - else - if (sType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("integer"))) - { - sal_Int32 nTempValue = 0; - ::sax::Converter::convertNumber(nTempValue, sValue); - aValue <<= nTempValue; - bConverted = sal_True; - } - else - if (sType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("float"))) - { - double fTempValue = 0.0; - ::sax::Converter::convertDouble(fTempValue, sValue); - aValue <<= fTempValue; - bConverted = sal_True; - } - else - if (sType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("string"))) - { - aValue <<= sValue; - bConverted = sal_True; - } - else - if (sType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("date"))) - { - com::sun::star::util::DateTime aTempValue; - SvXMLUnitConverter::convertDateTime(aTempValue, sValue); - aValue <<= aTempValue; - bConverted = sal_True; - } - else - if (sType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("time"))) - { - com::sun::star::util::DateTime aTempValue; - com::sun::star::util::Time aConvValue; - SvXMLUnitConverter::convertTime(aTempValue, sValue); - aConvValue.HundredthSeconds = aTempValue.HundredthSeconds; - aConvValue.Seconds = aTempValue.Seconds; - aConvValue.Minutes = aTempValue.Minutes; - aConvValue.Hours = aTempValue.Hours; - aValue <<= aConvValue; - bConverted = sal_True; - } - - return bConverted; -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/draw/animationexport.cxx b/xmloff/source/draw/animationexport.cxx index 57c1cd22f7d4..a5f2ed0e03ca 100644 --- a/xmloff/source/draw/animationexport.cxx +++ b/xmloff/source/draw/animationexport.cxx @@ -65,7 +65,6 @@ #include <sax/tools/converter.hxx> #include <tools/debug.hxx> -#include <tools/time.hxx> #include <xmloff/unointerfacetouniqueidentifiermapper.hxx> #include "sdxmlexp_impl.hxx" #include "sdpropls.hxx" @@ -1066,9 +1065,10 @@ void AnimationsExporterImpl::exportContainer( const Reference< XTimeContainer >& if( 0 == ( mrExport.getExportFlags() & EXPORT_SAVEBACKWARDCOMPATIBLE ) ) { // issue 146582 - sal_Int32 nSecondsFraction = static_cast<sal_Int32>(fTemp * 1000 ) % 1000; - ::Time aTime( static_cast<sal_Int32>( fTemp * 100 ) ); - mrExport.AddAttribute( XML_NAMESPACE_ANIMATION, XML_ITERATE_INTERVAL, SvXMLUnitConverter::convertTimeDuration( aTime, nSecondsFraction ) ); + ::rtl::OUStringBuffer buf; + ::sax::Converter::convertDuration(buf, fTemp / (24*60*60)); + mrExport.AddAttribute( XML_NAMESPACE_ANIMATION, + XML_ITERATE_INTERVAL, buf.makeStringAndClear()); } else { diff --git a/xmloff/source/draw/animationimport.cxx b/xmloff/source/draw/animationimport.cxx index 81a53fe8a280..32d455c233c9 100644 --- a/xmloff/source/draw/animationimport.cxx +++ b/xmloff/source/draw/animationimport.cxx @@ -30,7 +30,6 @@ #include "precompiled_xmloff.hxx" #include <tools/debug.hxx> -#include <tools/time.hxx> #include <xmloff/unointerfacetouniqueidentifiermapper.hxx> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XInitialization.hpp> @@ -60,6 +59,7 @@ #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/animations/EventTrigger.hpp> #include <com/sun/star/presentation/EffectCommands.hpp> +#include <com/sun/star/util/Duration.hpp> #include <comphelper/processfactory.hxx> #include <cppuhelper/implbase1.hxx> @@ -1179,11 +1179,12 @@ void AnimationNodeContext::init_node( const ::com::sun::star::uno::Reference< : double fInterval = 0.0; if( rValue.matchAsciiL(RTL_CONSTASCII_STRINGPARAM("P")) ) { - ::Time aTime; - sal_Int32 nSecondsFraction = 0; - if( SvXMLUnitConverter::convertTimeDuration( rValue, aTime, &nSecondsFraction ) ) + ::com::sun::star::util::Duration aDuration; + if (::sax::Converter::convertDuration(aDuration, rValue)) { - fInterval = ((((aTime.GetHour() * 60) + aTime.GetMin()) * 60) + aTime.GetSec()) + (nSecondsFraction / 1000.0); + fInterval = ((((aDuration.Hours * 60) + + aDuration.Minutes) * 60) + aDuration.Seconds) + + (aDuration.MilliSeconds / 1000.0); } } else diff --git a/xmloff/source/draw/propimp0.cxx b/xmloff/source/draw/propimp0.cxx index 34deab9fd332..10db980509b8 100644 --- a/xmloff/source/draw/propimp0.cxx +++ b/xmloff/source/draw/propimp0.cxx @@ -32,7 +32,7 @@ #include <rtl/ustrbuf.hxx> #include "propimp0.hxx" #include <com/sun/star/drawing/LineDash.hpp> -#include <com/sun/star/util/DateTime.hpp> +#include <com/sun/star/util/Duration.hpp> #include <com/sun/star/uno/Any.hxx> #include <sax/tools/converter.hxx> @@ -65,10 +65,11 @@ sal_Bool XMLDurationPropertyHdl::importXML( ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& ) const { - util::DateTime aTime; - SvXMLUnitConverter::convertTime( aTime, rStrImpValue ); + util::Duration aDuration; + ::sax::Converter::convertDuration(aDuration, rStrImpValue); - const sal_Int32 nSeconds = ( aTime.Hours * 60 + aTime.Minutes ) * 60 + aTime.Seconds; + const sal_Int32 nSeconds = ((aDuration.Days * 24 + aDuration.Hours) * 60 + + aDuration.Minutes) * 60 + aDuration.Seconds; rValue <<= nSeconds; return sal_True; @@ -83,10 +84,11 @@ sal_Bool XMLDurationPropertyHdl::exportXML( if(rValue >>= nVal) { - util::DateTime aTime( 0, (sal_uInt16)nVal, 0, 0, 0, 0, 0 ); + util::Duration aDuration; + aDuration.Seconds = static_cast<sal_uInt16>(nVal); OUStringBuffer aOut; - SvXMLUnitConverter::convertTime( aOut, aTime ); + ::sax::Converter::convertDuration(aOut, aDuration); rStrExpValue = aOut.makeStringAndClear(); return sal_True; } diff --git a/xmloff/source/draw/sdxmlexp.cxx b/xmloff/source/draw/sdxmlexp.cxx index 13eb605039fe..9b0dfae988c7 100644 --- a/xmloff/source/draw/sdxmlexp.cxx +++ b/xmloff/source/draw/sdxmlexp.cxx @@ -58,9 +58,11 @@ #include <com/sun/star/chart/XChartDocument.hpp> #include <com/sun/star/animations/XAnimationNodeSupplier.hpp> #include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/util/Duration.hpp> #include <rtl/ustrbuf.hxx> #include <tools/gen.hxx> #include <tools/debug.hxx> +#include <sax/tools/converter.hxx> #include <xmloff/xmlaustp.hxx> #include <xmloff/families.hxx> #include <xmloff/styleexp.hxx> @@ -2045,10 +2047,11 @@ void SdXMLExport::exportPresentationSettings() sal_Int32 nPause = 0; xPresProps->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Pause" ) ) ) >>= nPause; - util::DateTime aTime( 0, (sal_uInt16)nPause, 0, 0, 0, 0, 0 ); + util::Duration aDuration; + aDuration.Seconds = static_cast<sal_uInt16>(nPause); OUStringBuffer aOut; - SvXMLUnitConverter::convertTime( aOut, aTime ); + ::sax::Converter::convertDuration(aOut, aDuration); AddAttribute(XML_NAMESPACE_PRESENTATION, XML_PAUSE, aOut.makeStringAndClear() ); } @@ -2769,7 +2772,7 @@ void SdXMLExport::exportAnnotations( const Reference<XDrawPage>& xDrawPage ) { // date time DateTime aDate( xAnnotation->getDateTime() ); - GetMM100UnitConverter().convertDateTime(sStringBuffer, aDate, sal_True); + ::sax::Converter::convertDateTime(sStringBuffer, aDate, true); SvXMLElementExport aDateElem( *this, XML_NAMESPACE_DC, XML_DATE, sal_True, sal_False ); Characters(sStringBuffer.makeStringAndClear()); } diff --git a/xmloff/source/draw/ximppage.cxx b/xmloff/source/draw/ximppage.cxx index 5ba019fee9f2..874ef34d166a 100644 --- a/xmloff/source/draw/ximppage.cxx +++ b/xmloff/source/draw/ximppage.cxx @@ -34,6 +34,7 @@ #include <com/sun/star/text/XTextCursor.hpp> #include <com/sun/star/util/DateTime.hpp> #include <cppuhelper/implbase1.hxx> +#include <sax/tools/converter.hxx> #include "XMLNumberStylesImport.hxx" #include <xmloff/xmlstyle.hxx> #include <xmloff/xmltoken.hxx> @@ -204,8 +205,11 @@ void DrawAnnotationContext::EndElement() mxAnnotation->setAuthor( maAuthorBuffer.makeStringAndClear() ); DateTime aDateTime; - if(SvXMLUnitConverter::convertDateTime(aDateTime, maDateBuffer.makeStringAndClear())) + if (::sax::Converter::convertDateTime(aDateTime, + maDateBuffer.makeStringAndClear())) + { mxAnnotation->setDateTime(aDateTime); + } } } diff --git a/xmloff/source/draw/ximpshow.cxx b/xmloff/source/draw/ximpshow.cxx index 02717ace72d5..19d85f89fbab 100644 --- a/xmloff/source/draw/ximpshow.cxx +++ b/xmloff/source/draw/ximpshow.cxx @@ -30,7 +30,7 @@ #include "precompiled_xmloff.hxx" #include <tools/debug.hxx> -#include <com/sun/star/util/DateTime.hpp> +#include <com/sun/star/util/Duration.hpp> #include <com/sun/star/xml/sax/XAttributeList.hpp> #include <com/sun/star/lang/XSingleServiceFactory.hpp> #include <com/sun/star/container/XNameContainer.hpp> @@ -38,6 +38,7 @@ #include <com/sun/star/presentation/XPresentationSupplier.hpp> #include <com/sun/star/container/XIndexContainer.hpp> #include <com/sun/star/drawing/XDrawPagesSupplier.hpp> +#include <sax/tools/converter.hxx> #include <xmloff/xmltoken.hxx> #include <comphelper/extract.hxx> #include "xmloff/xmlnmspe.hxx" @@ -134,11 +135,12 @@ SdXMLShowsContext::SdXMLShowsContext( SdXMLImport& rImport, sal_uInt16 nPrfx, c } else if( IsXMLToken( aLocalName, XML_PAUSE ) ) { - DateTime aTime; - if( !SvXMLUnitConverter::convertTime( aTime, sValue ) ) + Duration aDuration; + if (!::sax::Converter::convertDuration(aDuration, sValue)) continue; - const sal_Int32 nMS = ( aTime.Hours * 60 + aTime.Minutes ) * 60 + aTime.Seconds; + const sal_Int32 nMS = (aDuration.Hours * 60 + + aDuration.Minutes) * 60 + aDuration.Seconds; aAny <<= nMS; mpImpl->mxPresProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Pause" ) ), aAny ); } diff --git a/xmloff/source/forms/elementexport.cxx b/xmloff/source/forms/elementexport.cxx index ca3b8c65390c..4fa6b5e54e9a 100644 --- a/xmloff/source/forms/elementexport.cxx +++ b/xmloff/source/forms/elementexport.cxx @@ -43,6 +43,7 @@ #include <com/sun/star/text/XText.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/io/XPersistObject.hpp> +#include <com/sun/star/util/Duration.hpp> #include <com/sun/star/form/FormComponentType.hpp> #include <com/sun/star/beans/PropertyAttribute.hpp> #include <com/sun/star/form/FormSubmitEncoding.hpp> @@ -89,6 +90,7 @@ namespace xmloff #endif using namespace ::xmloff::token; + using namespace ::com::sun::star; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::sdb; using namespace ::com::sun::star::awt; @@ -1152,10 +1154,17 @@ namespace xmloff m_xProps->getPropertyValue( PROPERTY_REPEAT_DELAY ) >>= nRepeatDelay; Time aTime; aTime.MakeTimeFromMS( nRepeatDelay ); - + util::Duration aDuration; + aDuration.Hours = aTime.GetHour(); + aDuration.Minutes = aTime.GetMin(); + aDuration.Seconds = aTime.GetSec(); + aDuration.MilliSeconds = nRepeatDelay % 1000; + + ::rtl::OUStringBuffer buf; + ::sax::Converter::convertDuration(buf, aDuration); AddAttribute(OAttributeMetaData::getSpecialAttributeNamespace( SCA_REPEAT_DELAY ) ,OAttributeMetaData::getSpecialAttributeName( SCA_REPEAT_DELAY ) - ,SvXMLUnitConverter::convertTimeDuration( aTime, nRepeatDelay % 1000 ) ); + ,buf.makeStringAndClear()); exportedProperty( PROPERTY_REPEAT_DELAY ); diff --git a/xmloff/source/forms/elementimport.cxx b/xmloff/source/forms/elementimport.cxx index 678fd2023a6e..3fde263f6022 100644 --- a/xmloff/source/forms/elementimport.cxx +++ b/xmloff/source/forms/elementimport.cxx @@ -32,7 +32,6 @@ #include "elementimport.hxx" #include "xmloff/xmlimp.hxx" #include "xmloff/nmspmap.hxx" -#include "xmloff/xmluconv.hxx" #include "strings.hxx" #include "callbacks.hxx" #include "attriblistmerge.hxx" @@ -48,6 +47,7 @@ /** === begin UNO includes === **/ #include <com/sun/star/text/XText.hpp> #include <com/sun/star/util/XCloneable.hpp> +#include <com/sun/star/util/Duration.hpp> #include <com/sun/star/form/FormComponentType.hpp> #include <com/sun/star/awt/ImagePosition.hpp> #include <com/sun/star/beans/XMultiPropertySet.hpp> @@ -58,7 +58,6 @@ #include <sax/tools/converter.hxx> #include <tools/urlobj.hxx> #include <tools/diagnose_ex.h> -#include <tools/time.hxx> #include <rtl/logfile.hxx> #include <rtl/strbuf.hxx> #include <comphelper/extract.hxx> @@ -816,13 +815,15 @@ namespace xmloff if ( _rLocalName.equalsAscii( pRepeatDelayAttributeName ) ) { - ::Time aTime; - sal_Int32 nFractions = 0; - if ( SvXMLUnitConverter::convertTimeDuration( _rValue, aTime, &nFractions ) ) + util::Duration aDuration; + if (::sax::Converter::convertDuration(aDuration, _rValue)) { PropertyValue aProp; aProp.Name = PROPERTY_REPEAT_DELAY; - aProp.Value <<= (sal_Int32)( ( ( aTime.GetMSFromTime() / 1000 ) * 1000 ) + nFractions ); + sal_Int32 const nMS = + ((aDuration.Hours * 60 + aDuration.Minutes) * 60 + + aDuration.Seconds) * 1000 + aDuration.MilliSeconds; + aProp.Value <<= nMS; implPushBackPropertyValue(aProp); } diff --git a/xmloff/source/forms/handler/vcl_date_handler.cxx b/xmloff/source/forms/handler/vcl_date_handler.cxx index a24609fc72d1..2762d825e3eb 100644 --- a/xmloff/source/forms/handler/vcl_date_handler.cxx +++ b/xmloff/source/forms/handler/vcl_date_handler.cxx @@ -28,7 +28,6 @@ #include "precompiled_xmloff.hxx" #include "vcl_date_handler.hxx" -#include "xmloff/xmluconv.hxx" #include <rtl/ustrbuf.hxx> @@ -76,7 +75,7 @@ namespace xmloff aDateTime.Year = aVCLDate.GetYear(); ::rtl::OUStringBuffer aBuffer; - SvXMLUnitConverter::convertDateTime( aBuffer, aDateTime, sal_False ); + ::sax::Converter::convertDateTime( aBuffer, aDateTime, false ); return aBuffer.makeStringAndClear(); } @@ -86,7 +85,7 @@ namespace xmloff sal_Int32 nVCLDate(0); DateTime aDateTime; - if ( SvXMLUnitConverter::convertDateTime( aDateTime, i_attributeValue ) ) + if (::sax::Converter::convertDateTime( aDateTime, i_attributeValue )) { ::Date aVCLDate( aDateTime.Day, aDateTime.Month, aDateTime.Year ); nVCLDate = aVCLDate.GetDate(); diff --git a/xmloff/source/forms/handler/vcl_time_handler.cxx b/xmloff/source/forms/handler/vcl_time_handler.cxx index 837c533cc2e7..211b10209b4d 100644 --- a/xmloff/source/forms/handler/vcl_time_handler.cxx +++ b/xmloff/source/forms/handler/vcl_time_handler.cxx @@ -28,11 +28,10 @@ #include "precompiled_xmloff.hxx" #include "vcl_time_handler.hxx" -#include "xmloff/xmluconv.hxx" #include <rtl/ustrbuf.hxx> -#include <com/sun/star/util/DateTime.hpp> +#include <com/sun/star/util/Duration.hpp> #include <sax/tools/converter.hxx> @@ -46,7 +45,7 @@ namespace xmloff using ::com::sun::star::uno::Any; using ::com::sun::star::uno::makeAny; - using ::com::sun::star::util::DateTime; + using ::com::sun::star::util::Duration; //================================================================================================================== //= VCLTimeHandler @@ -70,14 +69,14 @@ namespace xmloff OSL_VERIFY( i_propertyValue >>= nVCLTime ); ::Time aVCLTime( nVCLTime ); - DateTime aDateTime; // default-inited to 0 - aDateTime.Hours = aVCLTime.GetHour(); - aDateTime.Minutes = aVCLTime.GetMin(); - aDateTime.Seconds = aVCLTime.GetSec(); - aDateTime.HundredthSeconds = aVCLTime.Get100Sec(); + Duration aDuration; // default-inited to 0 + aDuration.Hours = aVCLTime.GetHour(); + aDuration.Minutes = aVCLTime.GetMin(); + aDuration.Seconds = aVCLTime.GetSec(); + aDuration.MilliSeconds = aVCLTime.Get100Sec() * 10; ::rtl::OUStringBuffer aBuffer; - SvXMLUnitConverter::convertTime( aBuffer, aDateTime ); + ::sax::Converter::convertDuration( aBuffer, aDuration ); return aBuffer.makeStringAndClear(); } @@ -86,10 +85,11 @@ namespace xmloff { sal_Int32 nVCLTime(0); - DateTime aDateTime; - if ( SvXMLUnitConverter::convertTime( aDateTime, i_attributeValue ) ) + Duration aDuration; + if (::sax::Converter::convertDuration( aDuration, i_attributeValue )) { - ::Time aVCLTime( aDateTime.Hours, aDateTime.Minutes, aDateTime.Seconds, aDateTime.HundredthSeconds ); + ::Time aVCLTime(aDuration.Hours, aDuration.Minutes, + aDuration.Seconds, aDuration.MilliSeconds / 10); nVCLTime = aVCLTime.GetTime(); } else diff --git a/xmloff/source/meta/xmlmetae.cxx b/xmloff/source/meta/xmlmetae.cxx index e50be583d072..1569ae90271b 100644 --- a/xmloff/source/meta/xmlmetae.cxx +++ b/xmloff/source/meta/xmlmetae.cxx @@ -38,15 +38,17 @@ #include <xmloff/xmlmetae.hxx> #include <xmloff/xmlexp.hxx> -#include <xmloff/xmluconv.hxx> #include <xmloff/nmspmap.hxx> #include "xmloff/xmlnmspe.hxx" #include <com/sun/star/beans/XPropertyAccess.hpp> #include <com/sun/star/beans/StringPair.hpp> +#include <com/sun/star/util/Duration.hpp> #include <com/sun/star/xml/dom/XDocument.hpp> #include <com/sun/star/xml/sax/XSAXSerializable.hpp> +#include <sax/tools/converter.hxx> + #include <comphelper/sequenceasvector.hxx> #include <unotools/docinfohelper.hxx> @@ -191,8 +193,10 @@ void SvXMLMetaExport::_MExport() SvXMLElementExport aElem( mrExport, XML_NAMESPACE_META, XML_EDITING_DURATION, sal_True, sal_False ); - mrExport.Characters( SvXMLUnitConverter::convertTimeDuration( - Time(secs/3600, (secs%3600)/60, secs%60)) ); + ::rtl::OUStringBuffer buf; + ::sax::Converter::convertDuration(buf, util::Duration( + false, 0, 0, 0, secs/3600, (secs%3600)/60, secs%60, 0)); + mrExport.Characters(buf.makeStringAndClear()); } // default target @@ -221,10 +225,11 @@ void SvXMLMetaExport::_MExport() mrExport.AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, mrExport.GetRelativeReference( sReloadURL ) ); + ::rtl::OUStringBuffer buf; + ::sax::Converter::convertDuration(buf, util::Duration(false, 0, 0, 0, + sReloadDelay/3600, (sReloadDelay%3600)/60, sReloadDelay%60, 0)); mrExport.AddAttribute( XML_NAMESPACE_META, XML_DELAY, - SvXMLUnitConverter::convertTimeDuration( - Time(sReloadDelay/3600, (sReloadDelay%3600)/60, - sReloadDelay%60 )) ); + buf.makeStringAndClear()); SvXMLElementExport aElem( mrExport, XML_NAMESPACE_META, XML_AUTO_RELOAD, sal_True, sal_False ); @@ -261,8 +266,8 @@ void SvXMLMetaExport::_MExport() for (sal_Int32 i = 0; i < props.getLength(); ++i) { ::rtl::OUStringBuffer sValueBuffer; ::rtl::OUStringBuffer sType; - if (!SvXMLUnitConverter::convertAny( - sValueBuffer, sType, props[i].Value)) { + if (!::sax::Converter::convertAny(sValueBuffer, sType, props[i].Value)) + { continue; } mrExport.AddAttribute( XML_NAMESPACE_META, XML_NAME, props[i].Name ); diff --git a/xmloff/source/style/durationhdl.cxx b/xmloff/source/style/durationhdl.cxx index d25dcb6f911d..22f27e965ebf 100644 --- a/xmloff/source/style/durationhdl.cxx +++ b/xmloff/source/style/durationhdl.cxx @@ -30,9 +30,9 @@ #include "precompiled_xmloff.hxx" #include "durationhdl.hxx" #include <com/sun/star/uno/Any.hxx> -#include <com/sun/star/util/DateTime.hpp> +#include <com/sun/star/util/Duration.hpp> #include <rtl/ustrbuf.hxx> -#include <xmloff/xmluconv.hxx> +#include <sax/tools/converter.hxx> using ::rtl::OUString; using ::rtl::OUStringBuffer; @@ -48,11 +48,12 @@ sal_Bool XMLDurationMS16PropHdl_Impl::importXML( Any& rValue, const SvXMLUnitConverter& ) const { - DateTime aTime; - if( !SvXMLUnitConverter::convertTime( aTime, rStrImpValue ) ) + Duration aDuration; + if (!::sax::Converter::convertDuration( aDuration, rStrImpValue )) return false; - const sal_Int16 nMS = ( ( aTime.Hours * 60 + aTime.Minutes ) * 60 + aTime.Seconds ) * 100 + aTime.HundredthSeconds; + const sal_Int16 nMS = ((aDuration.Hours * 60 + aDuration.Minutes) * 60 + + aDuration.Seconds) * 100 + (aDuration.MilliSeconds / 10); rValue <<= nMS; return sal_True; @@ -68,8 +69,8 @@ sal_Bool XMLDurationMS16PropHdl_Impl::exportXML( if(rValue >>= nMS) { OUStringBuffer aOut; - DateTime aTime( nMS, 0, 0, 0, 0, 0, 0 ); - SvXMLUnitConverter::convertTime( aOut, aTime ); + Duration aDuration(false, 0, 0, 0, 0, 0, 0, nMS * 10); + ::sax::Converter::convertDuration(aOut, aDuration); rStrExpValue = aOut.makeStringAndClear(); return sal_True; } diff --git a/xmloff/source/style/numehelp.cxx b/xmloff/source/style/numehelp.cxx index a708d21cf0f1..71361140cba3 100644 --- a/xmloff/source/style/numehelp.cxx +++ b/xmloff/source/style/numehelp.cxx @@ -40,6 +40,7 @@ #include <rtl/ustring.hxx> #include <svl/zforlist.hxx> #include <com/sun/star/util/NumberFormat.hpp> +#include <sax/tools/converter.hxx> #include <rtl/math.hxx> #include <tools/debug.hxx> #include <rtl/ustrbuf.hxx> @@ -187,7 +188,7 @@ void XMLNumberFormatAttributesExportHelper::WriteAttributes(SvXMLExport& rXMLExp if (bExportValue) { rtl::OUStringBuffer sBuffer; - rXMLExport.GetMM100UnitConverter().convertTime(sBuffer, rValue); + ::sax::Converter::convertDuration(sBuffer, rValue); rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_TIME_VALUE, sBuffer.makeStringAndClear()); } } @@ -470,7 +471,7 @@ void XMLNumberFormatAttributesExportHelper::WriteAttributes( if (bExportValue) { rtl::OUStringBuffer sBuffer; - pExport->GetMM100UnitConverter().convertTime(sBuffer, rValue); + ::sax::Converter::convertDuration(sBuffer, rValue); pExport->AddAttribute(sAttrTimeValue, sBuffer.makeStringAndClear()); } } diff --git a/xmloff/source/text/XMLChangedRegionImportContext.cxx b/xmloff/source/text/XMLChangedRegionImportContext.cxx index 64528971e731..757cd4424912 100644 --- a/xmloff/source/text/XMLChangedRegionImportContext.cxx +++ b/xmloff/source/text/XMLChangedRegionImportContext.cxx @@ -40,7 +40,6 @@ #include "xmloff/xmlnmspe.hxx" #include <xmloff/nmspmap.hxx> #include <xmloff/xmltoken.hxx> -#include <xmloff/xmluconv.hxx> using namespace ::xmloff::token; @@ -169,7 +168,7 @@ void XMLChangedRegionImportContext::SetChangeInfo( const OUString& rDate) { DateTime aDateTime; - if (SvXMLUnitConverter::convertDateTime(aDateTime, rDate)) + if (::sax::Converter::convertDateTime(aDateTime, rDate)) { GetImport().GetTextImport()->RedlineAdd( rType, sID, rAuthor, rComment, aDateTime, bMergeLastPara); diff --git a/xmloff/source/text/XMLRedlineExport.cxx b/xmloff/source/text/XMLRedlineExport.cxx index 209a51ffa015..c42890b7ea29 100644 --- a/xmloff/source/text/XMLRedlineExport.cxx +++ b/xmloff/source/text/XMLRedlineExport.cxx @@ -42,6 +42,9 @@ #include <com/sun/star/text/XTextContent.hpp> #include <com/sun/star/text/XTextSection.hpp> #include <com/sun/star/util/DateTime.hpp> + +#include <sax/tools/converter.hxx> + #include <xmloff/xmltoken.hxx> #include "xmloff/xmlnmspe.hxx" #include <xmloff/xmlexp.hxx> @@ -495,7 +498,7 @@ void XMLRedlineExport::ExportChangeInfo( aAny >>= aDateTime; { OUStringBuffer sBuf; - rExport.GetMM100UnitConverter().convertDateTime(sBuf, aDateTime); + ::sax::Converter::convertDateTime(sBuf, aDateTime); SvXMLElementExport aDateElem( rExport, XML_NAMESPACE_DC, XML_DATE, sal_True, sal_False ); @@ -536,7 +539,7 @@ void XMLRedlineExport::ExportChangeInfo( util::DateTime aDateTime; rVal.Value >>= aDateTime; OUStringBuffer sBuf; - rExport.GetMM100UnitConverter().convertDateTime(sBuf, aDateTime); + ::sax::Converter::convertDateTime(sBuf, aDateTime); rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_CHG_DATE_TIME, sBuf.makeStringAndClear()); } diff --git a/xmloff/source/text/txtflde.cxx b/xmloff/source/text/txtflde.cxx index 0e4f6b54cb3a..d34e6769683a 100644 --- a/xmloff/source/text/txtflde.cxx +++ b/xmloff/source/text/txtflde.cxx @@ -46,6 +46,8 @@ #include <xmloff/XMLEventExport.hxx> #include "XMLTextCharStyleNamesElementExport.hxx" #include <xmloff/nmspmap.hxx> +#include <sax/tools/converter.hxx> + #include <com/sun/star/util/DateTime.hpp> #include <com/sun/star/util/Date.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> @@ -1753,9 +1755,7 @@ void XMLTextFieldExport::ExportFieldHelper( DateTime aDate( GetDateTimeProperty(sPropertyDateTimeValue, rPropSet) ); { OUStringBuffer aBuffer; - GetExport().GetMM100UnitConverter().convertDateTime(aBuffer, - aDate, - sal_True); + ::sax::Converter::convertDateTime(aBuffer, aDate, true); SvXMLElementExport aDateElem( GetExport(), XML_NAMESPACE_DC, XML_DATE, sal_True, sal_False ); @@ -2619,7 +2619,7 @@ void XMLTextFieldExport::ProcessDateTime(enum XMLTokenEnum eName, // date/time durationM handle bOmitDurationIfZero if (!bOmitDurationIfZero || !::rtl::math::approxEqual(dValue, 0.0)) { - rExport.GetMM100UnitConverter().convertTime(aBuffer, dValue); + ::sax::Converter::convertDuration(aBuffer, dValue); } } else @@ -2652,7 +2652,7 @@ void XMLTextFieldExport::ProcessDateTime(enum XMLTokenEnum eName, } // date/time value - rExport.GetMM100UnitConverter().convertDateTime(aBuffer, aDateTime); + ::sax::Converter::convertDateTime(aBuffer, aDateTime); // output attribute ProcessString(eName, aBuffer.makeStringAndClear(), sal_True, nPrefix); diff --git a/xmloff/source/text/txtfldi.cxx b/xmloff/source/text/txtfldi.cxx index ca2cfe2245e6..28f6f33d7f39 100644 --- a/xmloff/source/text/txtfldi.cxx +++ b/xmloff/source/text/txtfldi.cxx @@ -1125,8 +1125,7 @@ void XMLTimeFieldImportContext::ProcessAttribute( bTimeOK = sal_True; } - if (GetImport().GetMM100UnitConverter(). - convertDateTime(aDateTimeValue, sAttrValue )) + if (::sax::Converter::convertDateTime(aDateTimeValue, sAttrValue)) { bTimeOK = sal_True; } @@ -1156,7 +1155,7 @@ void XMLTimeFieldImportContext::ProcessAttribute( { double fTmp; - if (SvXMLUnitConverter::convertTime(fTmp, sAttrValue)) + if (::sax::Converter::convertDuration(fTmp, sAttrValue)) { // convert to minutes nAdjust = (sal_Int32)::rtl::math::approxFloor(fTmp * 60 * 24); @@ -1267,8 +1266,7 @@ void XMLDateFieldImportContext::ProcessAttribute( bTimeOK = sal_True; } - if (GetImport().GetMM100UnitConverter(). - convertDateTime(aDateTimeValue, sAttrValue )) + if (::sax::Converter::convertDateTime(aDateTimeValue, sAttrValue)) { bTimeOK = sal_True; } @@ -3763,7 +3761,7 @@ void XMLAnnotationImportContext::PrepareField( xPropertySet->setPropertyValue(sPropertyAuthor, makeAny(sAuthor)); DateTime aDateTime; - if (SvXMLUnitConverter::convertDateTime(aDateTime, + if (::sax::Converter::convertDateTime(aDateTime, aDateBuffer.makeStringAndClear())) { /* diff --git a/xmloff/source/text/txtvfldi.cxx b/xmloff/source/text/txtvfldi.cxx index 34549cb1f151..1307aec65d0d 100644 --- a/xmloff/source/text/txtvfldi.cxx +++ b/xmloff/source/text/txtvfldi.cxx @@ -1353,7 +1353,8 @@ void XMLValueImportHelper::ProcessAttribute( case XML_TOK_TEXTFIELD_TIME_VALUE: { double fTmp; - sal_Bool bRet = SvXMLUnitConverter::convertTime(fTmp,sAttrValue); + bool const bRet = + ::sax::Converter::convertDuration(fTmp, sAttrValue); if (bRet) { bFloatValueOK = sal_True; fValue = fTmp; diff --git a/xmloff/source/xforms/SchemaRestrictionContext.cxx b/xmloff/source/xforms/SchemaRestrictionContext.cxx index 5b61c1354927..beff12b544e5 100644 --- a/xmloff/source/xforms/SchemaRestrictionContext.cxx +++ b/xmloff/source/xforms/SchemaRestrictionContext.cxx @@ -36,7 +36,6 @@ #include <xmloff/nmspmap.hxx> #include <xmloff/xmlnmspe.hxx> #include <xmloff/xmltkmap.hxx> -#include <xmloff/xmluconv.hxx> #include <xmloff/xmlimp.hxx> #include <sax/tools/converter.hxx> @@ -46,6 +45,7 @@ #include <com/sun/star/util/Date.hpp> #include <com/sun/star/util/Time.hpp> #include <com/sun/star/util/DateTime.hpp> +#include <com/sun/star/util/Duration.hpp> #include <com/sun/star/xforms/XDataTypeRepository.hpp> #include <com/sun/star/xsd/DataTypeClass.hpp> #include <com/sun/star/xsd/WhiteSpaceTreatment.hpp> @@ -61,6 +61,7 @@ using com::sun::star::uno::makeAny; using com::sun::star::uno::UNO_QUERY; using com::sun::star::util::Date; using com::sun::star::util::DateTime; +using com::sun::star::util::Duration; using com::sun::star::xml::sax::XAttributeList; using com::sun::star::beans::XPropertySet; using com::sun::star::beans::XPropertySetInfo; @@ -213,21 +214,21 @@ Any lcl_date( const OUString& rValue ) Any lcl_dateTime( const OUString& rValue ) { DateTime aDateTime; - bool bSuccess = SvXMLUnitConverter::convertDateTime( aDateTime, rValue ); + bool const bSuccess = ::sax::Converter::convertDateTime(aDateTime, rValue); return bSuccess ? makeAny( aDateTime ) : Any(); } Any lcl_time( const OUString& rValue ) { Any aAny; - DateTime aDateTime; - if( SvXMLUnitConverter::convertTime( aDateTime, rValue ) ) + Duration aDuration; + if (::sax::Converter::convertDuration( aDuration, rValue )) { com::sun::star::util::Time aTime; - aTime.Hours = aDateTime.Hours; - aTime.Minutes = aDateTime.Minutes; - aTime.Seconds = aDateTime.Seconds; - aTime.HundredthSeconds = aDateTime.HundredthSeconds; + aTime.Hours = aDuration.Hours; + aTime.Minutes = aDuration.Minutes; + aTime.Seconds = aDuration.Seconds; + aTime.HundredthSeconds = aDuration.MilliSeconds / 10; aAny <<= aTime; } return aAny; diff --git a/xmloff/source/xforms/xformsexport.cxx b/xmloff/source/xforms/xformsexport.cxx index 54561d70f522..865ce8af3bef 100644 --- a/xmloff/source/xforms/xformsexport.cxx +++ b/xmloff/source/xforms/xformsexport.cxx @@ -39,7 +39,6 @@ #include "xmloff/xmlnmspe.hxx" #include <xmloff/nmspmap.hxx> #include "DomExport.hxx" -#include <xmloff/xmluconv.hxx> #include <sax/tools/converter.hxx> @@ -69,6 +68,7 @@ #include <com/sun/star/util/Date.hpp> #include <com/sun/star/util/Time.hpp> #include <com/sun/star/util/DateTime.hpp> +#include <com/sun/star/util/Duration.hpp> using namespace com::sun::star; using namespace com::sun::star::uno; @@ -94,6 +94,7 @@ using com::sun::star::xforms::XDataTypeRepository; using com::sun::star::xforms::XFormsSupplier; using com::sun::star::util::Date; using com::sun::star::util::DateTime; +using com::sun::star::util::Duration; void exportXForms( SvXMLExport& rExport ) { @@ -698,17 +699,17 @@ void lcl_formatDate( OUStringBuffer& aBuffer, const Date& rDate ) void lcl_formatTime( OUStringBuffer& aBuffer, const com::sun::star::util::Time& rTime ) { - DateTime aDateTime; - aDateTime.Hours = rTime.Hours; - aDateTime.Minutes = rTime.Minutes; - aDateTime.Seconds = rTime.Seconds; - aDateTime.HundredthSeconds = rTime.HundredthSeconds; - SvXMLUnitConverter::convertTime( aBuffer, aDateTime ); + Duration aDuration; + aDuration.Hours = rTime.Hours; + aDuration.Minutes = rTime.Minutes; + aDuration.Seconds = rTime.Seconds; + aDuration.MilliSeconds = rTime.HundredthSeconds * 10; + ::sax::Converter::convertDuration( aBuffer, aDuration ); } void lcl_formatDateTime( OUStringBuffer& aBuffer, const DateTime& aDateTime ) { - SvXMLUnitConverter::convertDateTime( aBuffer, aDateTime ); + ::sax::Converter::convertDateTime( aBuffer, aDateTime ); } OUString lcl_whitespace( const Any& rAny ) |