diff options
-rw-r--r-- | sfx2/qa/complex/DocumentMetaData.java | 34 | ||||
-rw-r--r-- | sfx2/source/doc/SfxDocumentMetaData.cxx | 90 |
2 files changed, 69 insertions, 55 deletions
diff --git a/sfx2/qa/complex/DocumentMetaData.java b/sfx2/qa/complex/DocumentMetaData.java index 86c4f1fb9dc1..54b0f7afd3be 100644 --- a/sfx2/qa/complex/DocumentMetaData.java +++ b/sfx2/qa/complex/DocumentMetaData.java @@ -41,9 +41,10 @@ import com.sun.star.lang.XSingleServiceFactory; import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.lang.Locale; import com.sun.star.lang.EventObject; -import com.sun.star.util.Time; import com.sun.star.util.Date; import com.sun.star.util.DateTime; +import com.sun.star.util.Time; +import com.sun.star.util.Duration; import com.sun.star.util.XModifyListener; import com.sun.star.util.XModifyBroadcaster; import com.sun.star.beans.XPropertyContainer; @@ -352,6 +353,7 @@ public class DocumentMetaData extends ComplexTestCase // differently some day... boolean b = true; double d = 3.1415; + // note that Time is only supported for backward compatibilty! Time t = new Time(); t.Hours = 1; t.Minutes = 16; @@ -360,10 +362,20 @@ public class DocumentMetaData extends ComplexTestCase date.Month = 2; date.Day = 3; dt.Year = 2065; + Duration dur = new Duration(); + dur.Negative = true; + dur.Years = 1001; + dur.Months = 999; + dur.Days = 888; + dur.Hours = 777; + dur.Minutes = 666; + dur.Seconds = 555; + dur.HundredthSeconds = 444; udpc.addProperty("Frobnicate", PropertyAttribute.REMOVEABLE, new Boolean(b)); - udpc.addProperty("FrobDuration", PropertyAttribute.REMOVEABLE, t); + udpc.addProperty("FrobDuration", PropertyAttribute.REMOVEABLE, dur); + udpc.addProperty("FrobDuration2", PropertyAttribute.REMOVEABLE, t); udpc.addProperty("FrobEndDate", PropertyAttribute.REMOVEABLE, date); udpc.addProperty("FrobStartTime", PropertyAttribute.REMOVEABLE, dt); udpc.addProperty("Pi", PropertyAttribute.REMOVEABLE, new Double(d)); @@ -389,8 +401,10 @@ public class DocumentMetaData extends ComplexTestCase assure ("UserDefined bool", new Boolean(b).equals( udps.getPropertyValue("Frobnicate"))); - assure ("UserDefined time", eqTime(t, (Time) + assure ("UserDefined duration", eqDuration(dur, (Duration) udps.getPropertyValue("FrobDuration"))); + assure ("UserDefined time", eqTime(t, (Time) + udps.getPropertyValue("FrobDuration2"))); assure ("UserDefined date", eqDate(date, (Date) udps.getPropertyValue("FrobEndDate"))); assure ("UserDefined datetime", eqDateTime(dt, (DateTime) @@ -431,8 +445,10 @@ public class DocumentMetaData extends ComplexTestCase assure ("UserDefined bool", new Boolean(b).equals( udps.getPropertyValue("Frobnicate"))); - assure ("UserDefined time", eqTime(t, (Time) + assure ("UserDefined duration", eqDuration(dur, (Duration) udps.getPropertyValue("FrobDuration"))); + assure ("UserDefined time", eqTime(t, (Time) + udps.getPropertyValue("FrobDuration2"))); assure ("UserDefined date", eqDate(date, (Date) udps.getPropertyValue("FrobEndDate"))); assure ("UserDefined datetime", eqDateTime(dt, (DateTime) @@ -485,8 +501,6 @@ public class DocumentMetaData extends ComplexTestCase } boolean eqDate(Date a, Date b) { -log.println("a: " + a.Year +" "+ a.Month +" "+ a.Day); -log.println("b: " + b.Year +" "+ b.Month +" "+ b.Day); return a.Year == b.Year && a.Month == b.Month && a.Day == b.Day; } @@ -496,6 +510,14 @@ log.println("b: " + b.Year +" "+ b.Month +" "+ b.Day); && a.HundredthSeconds == b.HundredthSeconds; } + boolean eqDuration(Duration a, Duration b) { + return a.Years == b.Years && a.Months == b.Months && a.Days == b.Days + && a.Hours == b.Hours && a.Minutes == b.Minutes + && a.Seconds == b.Seconds + && a.HundredthSeconds == b.HundredthSeconds + && a.Negative == b.Negative; + } + java.util.Collection fromArray(Object[] os) { java.util.Collection ret = new java.util.HashSet(); for (int i = 0; i < os.length; ++i) { diff --git a/sfx2/source/doc/SfxDocumentMetaData.cxx b/sfx2/source/doc/SfxDocumentMetaData.cxx index 50bbb9241f8e..c2bbaea36cef 100644 --- a/sfx2/source/doc/SfxDocumentMetaData.cxx +++ b/sfx2/source/doc/SfxDocumentMetaData.cxx @@ -66,6 +66,7 @@ #include "com/sun/star/xml/xpath/XXPathAPI.hpp" #include "com/sun/star/util/Date.hpp" #include "com/sun/star/util/Time.hpp" +#include "com/sun/star/util/Duration.hpp" #include "SfxDocumentMetaData.hxx" #include "rtl/ustrbuf.hxx" @@ -510,13 +511,6 @@ textToDateOrDateTime(css::util::Date & io_rd, css::util::DateTime & io_rdt, { if (::sax::Converter::convertDateOrDateTime( io_rd, io_rdt, o_rIsDateTime, i_text)) { - if (o_rIsDateTime) { - // NB: there may be rounding errors; handle these here - if (io_rdt.HundredthSeconds > 0) { - io_rdt.Seconds++; - io_rdt.HundredthSeconds = 0; - } - } return true; } else { DBG_WARNING1("SfxDocumentMetaData: invalid date: %s", @@ -530,11 +524,6 @@ bool SAL_CALL textToDateTime(css::util::DateTime & io_rdt, ::rtl::OUString i_text) throw () { if (::sax::Converter::convertDateTime(io_rdt, i_text)) { - // NB: there may be rounding errors; handle these here - if (io_rdt.HundredthSeconds > 0) { - io_rdt.Seconds++; - io_rdt.HundredthSeconds = 0; - } return true; } else { DBG_WARNING1("SfxDocumentMetaData: invalid date: %s", @@ -581,60 +570,48 @@ dateTimeToText(css::util::DateTime const& i_rdt) throw () } // convert string to duration -bool SAL_CALL -textToDuration(css::util::Time& io_rut, ::rtl::OUString i_text) throw () +bool +textToDuration(css::util::Duration& io_rDur, ::rtl::OUString const& i_rText) +throw () { - css::util::DateTime dt; - if (::sax::Converter::convertTime(dt, i_text)) { - // NB: there may be rounding errors; handle these here - if (dt.HundredthSeconds > 0) { - dt.Seconds++; - dt.HundredthSeconds = 0; - } - io_rut.Hours = dt.Hours; - io_rut.Minutes = dt.Minutes; - io_rut.Seconds = dt.Seconds; - io_rut.HundredthSeconds = dt.HundredthSeconds; + if (::sax::Converter::convertDuration(io_rDur, i_rText)) { return true; } else { DBG_WARNING1("SfxDocumentMetaData: invalid duration: %s", - OUStringToOString(i_text, RTL_TEXTENCODING_UTF8).getStr()); + OUStringToOString(i_rText, RTL_TEXTENCODING_UTF8).getStr()); return false; } } -sal_Int32 SAL_CALL textToDuration(::rtl::OUString i_text) throw () +sal_Int32 textToDuration(::rtl::OUString const& i_rText) throw () { - css::util::Time t; - if (textToDuration(t, i_text)) { - return t.Hours * 3600 + t.Minutes * 60 + t.Seconds; + css::util::Duration d; + if (textToDuration(d, i_rText)) { + return (d.Days * (24*3600)) + + (d.Hours * 3600) + (d.Minutes * 60) + d.Seconds; } else { return 0; // default } } // convert duration to string -::rtl::OUString SAL_CALL durationToText(css::util::Time const& i_rut) throw () +::rtl::OUString durationToText(css::util::Duration const& i_rDur) throw () { - css::util::DateTime dt; - dt.Hours = i_rut.Hours; - dt.Minutes = i_rut.Minutes; - dt.Seconds = i_rut.Seconds; - dt.HundredthSeconds = i_rut.HundredthSeconds; ::rtl::OUStringBuffer buf; - ::sax::Converter::convertTime(buf, dt); + ::sax::Converter::convertDuration(buf, i_rDur); return buf.makeStringAndClear(); } // convert duration to string ::rtl::OUString SAL_CALL durationToText(sal_Int32 i_value) throw () { - css::util::Time ut; - ut.Hours = static_cast<sal_Int16>(i_value / 3600); - ut.Minutes = static_cast<sal_Int16>((i_value % 3600) / 60); - ut.Seconds = static_cast<sal_Int16>(i_value % 60); - ut.HundredthSeconds = 0; - return durationToText(ut); + css::util::Duration ud; + ud.Days = static_cast<sal_Int16>(i_value / (24 * 3600)); + ud.Hours = static_cast<sal_Int16>((i_value % (24 * 3600)) / 3600); + ud.Minutes = static_cast<sal_Int16>((i_value % 3600) / 60); + ud.Seconds = static_cast<sal_Int16>(i_value % 60); + ud.HundredthSeconds = 0; + return durationToText(ud); } // extract base URL (necessary for converting relative links) @@ -965,9 +942,22 @@ propsToStrings(css::uno::Reference<css::beans::XPropertySet> const & i_xPropSet) as.push_back(std::make_pair(vt, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("date")))); } else if (type == ::cppu::UnoType<css::util::Time>::get()) { + // #i97029#: replaced by Duration + // Time is supported for backward compatibility with OOo 3.x, x<=2 css::util::Time ut; any >>= ut; - values.push_back(durationToText(ut)); + css::util::Duration ud; + ud.Hours = ut.Hours; + ud.Minutes = ut.Minutes; + ud.Seconds = ut.Seconds; + ud.HundredthSeconds = ut.HundredthSeconds; + values.push_back(durationToText(ud)); + as.push_back(std::make_pair(vt, + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("time")))); + } else if (type == ::cppu::UnoType<css::util::Duration>::get()) { + css::util::Duration ud; + any >>= ud; + values.push_back(durationToText(ud)); as.push_back(std::make_pair(vt, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("time")))); } else if (::cppu::UnoType<double>::get().isAssignableFrom(type)) { @@ -1298,9 +1288,9 @@ void SAL_CALL SfxDocumentMetaData::init( continue; } } else if (type.equalsAscii("time")) { - css::util::Time ut; - if (textToDuration(ut, text)) { - any <<= ut; + css::util::Duration ud; + if (textToDuration(ud, text)) { + any <<= ud; } else { DBG_WARNING1("SfxDocumentMetaData: invalid time: %s", OUStringToOString(text, RTL_TEXTENCODING_UTF8).getStr()); @@ -2284,17 +2274,19 @@ void SfxDocumentMetaData::createUserDefined() { if ( !m_xUserDefined.is() ) { - css::uno::Sequence<css::uno::Type> types(10); + css::uno::Sequence<css::uno::Type> types(11); types[0] = ::cppu::UnoType<bool>::get(); types[1] = ::cppu::UnoType< ::rtl::OUString>::get(); types[2] = ::cppu::UnoType<css::util::DateTime>::get(); types[3] = ::cppu::UnoType<css::util::Date>::get(); - types[4] = ::cppu::UnoType<css::util::Time>::get(); + types[4] = ::cppu::UnoType<css::util::Duration>::get(); types[5] = ::cppu::UnoType<float>::get(); types[6] = ::cppu::UnoType<double>::get(); types[7] = ::cppu::UnoType<sal_Int16>::get(); types[8] = ::cppu::UnoType<sal_Int32>::get(); types[9] = ::cppu::UnoType<sal_Int64>::get(); + // Time is supported for backward compatibility with OOo 3.x, x<=2 + types[10] = ::cppu::UnoType<css::util::Time>::get(); css::uno::Sequence<css::uno::Any> args(2); args[0] <<= css::beans::NamedValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AllowedTypes")), |