summaryrefslogtreecommitdiff
path: root/sfx2/source/doc/SfxDocumentMetaData.cxx
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2013-07-11 17:27:06 +0200
committerMichael Stahl <mstahl@redhat.com>2013-07-15 15:23:25 +0200
commit20cbf5bd3042ed547408f324e020a3d6405705f7 (patch)
tree5aa9ef1f1b960bd4f5b1013e3db582916fc76c28 /sfx2/source/doc/SfxDocumentMetaData.cxx
parent604aae1fd240254fe851d93dc35b5408bd13296c (diff)
i#108348: support DateTimeWithTimezone in user defined Document Properties
- fix interface of sax::Converter to allow passing time zones (rename the parsing methods while at it to reduce pointless overloading) - SfxDocumentMetaData supports DateWithTimezone and DateTimeWithTimezone in user-defined properties - add some ugly hacks to SfxCustomPropertiesPage to preserve existing time zones (which are not displayed in UI currently) Change-Id: Ice94112b9d79c285f80b5beda15f0ace91db97f3
Diffstat (limited to 'sfx2/source/doc/SfxDocumentMetaData.cxx')
-rw-r--r--sfx2/source/doc/SfxDocumentMetaData.cxx75
1 files changed, 52 insertions, 23 deletions
diff --git a/sfx2/source/doc/SfxDocumentMetaData.cxx b/sfx2/source/doc/SfxDocumentMetaData.cxx
index 520db84f3e12..f1fe1233b4a0 100644
--- a/sfx2/source/doc/SfxDocumentMetaData.cxx
+++ b/sfx2/source/doc/SfxDocumentMetaData.cxx
@@ -54,6 +54,8 @@
#include "com/sun/star/xml/xpath/XPathAPI.hpp"
#include "com/sun/star/util/Date.hpp"
#include "com/sun/star/util/Time.hpp"
+#include "com/sun/star/util/DateWithTimezone.hpp"
+#include "com/sun/star/util/DateTimeWithTimezone.hpp"
#include "com/sun/star/util/Duration.hpp"
#include "SfxDocumentMetaData.hxx"
@@ -530,10 +532,11 @@ OUString SAL_CALL getNameSpace(const char* i_qname) throw ()
bool SAL_CALL
textToDateOrDateTime(css::util::Date & io_rd, css::util::DateTime & io_rdt,
- bool & o_rIsDateTime, OUString i_text) throw ()
+ bool & o_rIsDateTime, boost::optional<sal_Int16> & o_rTimeZone,
+ OUString i_text) throw ()
{
- if (::sax::Converter::convertDateOrDateTime(
- io_rd, io_rdt, o_rIsDateTime, i_text)) {
+ if (::sax::Converter::parseDateOrDateTime(
+ &io_rd, io_rdt, o_rIsDateTime, &o_rTimeZone, i_text)) {
return true;
} else {
DBG_WARNING1("SfxDocumentMetaData: invalid date: %s",
@@ -546,7 +549,7 @@ textToDateOrDateTime(css::util::Date & io_rd, css::util::DateTime & io_rdt,
bool SAL_CALL
textToDateTime(css::util::DateTime & io_rdt, OUString i_text) throw ()
{
- if (::sax::Converter::convertDateTime(io_rdt, i_text)) {
+ if (::sax::Converter::parseDateTime(io_rdt, 0, i_text)) {
return true;
} else {
DBG_WARNING1("SfxDocumentMetaData: invalid date: %s",
@@ -567,11 +570,12 @@ textToDateTimeDefault(OUString i_text) throw ()
// convert date to string
OUString SAL_CALL
-dateToText(css::util::Date const& i_rd) throw ()
+dateToText(css::util::Date const& i_rd,
+ sal_Int16 const*const pTimeZone = 0) throw ()
{
if (isValidDate(i_rd)) {
OUStringBuffer buf;
- ::sax::Converter::convertDate(buf, i_rd);
+ ::sax::Converter::convertDate(buf, i_rd, pTimeZone);
return buf.makeStringAndClear();
} else {
return OUString();
@@ -581,11 +585,12 @@ dateToText(css::util::Date const& i_rd) throw ()
// convert date/time to string
OUString SAL_CALL
-dateTimeToText(css::util::DateTime const& i_rdt) throw ()
+dateTimeToText(css::util::DateTime const& i_rdt,
+ sal_Int16 const*const pTimeZone = 0) throw ()
{
if (isValidDateTime(i_rdt)) {
OUStringBuffer buf;
- ::sax::Converter::convertDateTime(buf, i_rdt, true);
+ ::sax::Converter::convertDateTime(buf, i_rdt, pTimeZone, true);
return buf.makeStringAndClear();
} else {
return OUString();
@@ -960,6 +965,18 @@ propsToStrings(css::uno::Reference<css::beans::XPropertySet> const & i_xPropSet)
values.push_back(dateToText(d));
as.push_back(std::make_pair(vt,
OUString("date")));
+ } else if (type == ::cppu::UnoType<css::util::DateTimeWithTimezone>::get()) {
+ css::util::DateTimeWithTimezone dttz;
+ any >>= dttz;
+ values.push_back(dateTimeToText(dttz.DateTimeInTZ, &dttz.Timezone));
+ as.push_back(std::make_pair(vt,
+ OUString("date")));
+ } else if (type == ::cppu::UnoType<css::util::DateWithTimezone>::get()) {
+ css::util::DateWithTimezone dtz;
+ any >>= dtz;
+ values.push_back(dateToText(dtz.DateInTZ, &dtz.Timezone));
+ as.push_back(std::make_pair(vt,
+ OUString("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
@@ -1293,11 +1310,21 @@ void SAL_CALL SfxDocumentMetaData::init(
bool isDateTime;
css::util::Date d;
css::util::DateTime dt;
- if (textToDateOrDateTime(d, dt, isDateTime, text)) {
+ boost::optional<sal_Int16> nTimeZone;
+ if (textToDateOrDateTime(d, dt, isDateTime, nTimeZone, text)) {
if (isDateTime) {
- any <<= dt;
+ if (nTimeZone.is_initialized()) {
+ any <<= css::util::DateTimeWithTimezone(dt,
+ nTimeZone.get());
+ } else {
+ any <<= dt;
+ }
} else {
- any <<= d;
+ if (nTimeZone.is_initialized()) {
+ any <<= css::util::DateWithTimezone(d, nTimeZone.get());
+ } else {
+ any <<= d;
+ }
}
} else {
DBG_WARNING1("SfxDocumentMetaData: invalid date: %s",
@@ -2261,19 +2288,21 @@ void SfxDocumentMetaData::createUserDefined()
// values of allowed types
if ( !m_xUserDefined.is() )
{
- css::uno::Sequence<css::uno::Type> types(11);
- types[0] = ::cppu::UnoType<bool>::get();
- types[1] = ::cppu::UnoType< OUString>::get();
- types[2] = ::cppu::UnoType<css::util::DateTime>::get();
- types[3] = ::cppu::UnoType<css::util::Date>::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();
+ css::uno::Sequence<css::uno::Type> types(13);
+ types[ 0] = ::cppu::UnoType<bool>::get();
+ types[ 1] = ::cppu::UnoType< OUString>::get();
+ types[ 2] = ::cppu::UnoType<css::util::DateTime>::get();
+ types[ 3] = ::cppu::UnoType<css::util::Date>::get();
+ types[ 4] = ::cppu::UnoType<css::util::DateTimeWithTimezone>::get();
+ types[ 5] = ::cppu::UnoType<css::util::DateWithTimezone>::get();
+ types[ 6] = ::cppu::UnoType<css::util::Duration>::get();
+ types[ 7] = ::cppu::UnoType<float>::get();
+ types[ 8] = ::cppu::UnoType<double>::get();
+ types[ 9] = ::cppu::UnoType<sal_Int16>::get();
+ types[10] = ::cppu::UnoType<sal_Int32>::get();
+ types[11] = ::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();
+ types[12] = ::cppu::UnoType<css::util::Time>::get();
// #i94175#: ODF allows empty user-defined property names!
m_xUserDefined.set(
css::beans::PropertyBag::createWithTypes( m_xContext, types, sal_True/*AllowEmptyPropertyName*/, sal_False/*AutomaticAddition*/ ),