summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2012-11-16 15:08:40 +0100
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2013-01-27 20:45:04 +0100
commite820c249a4280fb38cf0ef7664006707382a687e (patch)
treea872ec0996b6531076872cb42496c16da7bf4130 /sc
parent55fc2b96bb808381fff62b3d34f0e25c13de84a4 (diff)
implement conditional date format import/export for ODF
Change-Id: I11d5583c994d84fe1163c6158c0794ea1d879f2e
Diffstat (limited to 'sc')
-rw-r--r--sc/source/filter/xml/xmlcondformat.cxx75
-rw-r--r--sc/source/filter/xml/xmlcondformat.hxx14
-rw-r--r--sc/source/filter/xml/xmlexprt.cxx43
-rw-r--r--sc/source/filter/xml/xmlimprt.cxx20
-rw-r--r--sc/source/filter/xml/xmlimprt.hxx11
5 files changed, 162 insertions, 1 deletions
diff --git a/sc/source/filter/xml/xmlcondformat.cxx b/sc/source/filter/xml/xmlcondformat.cxx
index 571426c08eb0..64e9d2ac8363 100644
--- a/sc/source/filter/xml/xmlcondformat.cxx
+++ b/sc/source/filter/xml/xmlcondformat.cxx
@@ -131,6 +131,9 @@ SvXMLImportContext* ScXMLConditionalFormatContext::CreateChildContext( sal_uInt1
case XML_TOK_CONDFORMAT_ICONSET:
pContext = new ScXMLIconSetFormatContext( GetScImport(), nPrefix, rLocalName, xAttrList, mpFormat );
break;
+ case XML_TOK_CONDFORMAT_DATE:
+ pContext = new ScXMLDateContext( GetScImport(), nPrefix, rLocalName, xAttrList, mpFormat );
+ break;
default:
break;
}
@@ -703,4 +706,76 @@ ScXMLFormattingEntryContext::ScXMLFormattingEntryContext( ScXMLImport& rImport,
setColorEntryType(sType, pColorScaleEntry, sVal, GetScImport());
}
+namespace {
+
+condformat::ScCondFormatDateType getDateFromString(const rtl::OUString& rString)
+{
+ if(rString == "today")
+ return condformat::TODAY;
+ else if(rString == "yesterday")
+ return condformat::YESTERDAY;
+ else if(rString == "tomorrow")
+ return condformat::TOMORROW;
+ else if(rString == "last-7-days")
+ return condformat::LAST7DAYS;
+ else if(rString == "this-week")
+ return condformat::THISWEEK;
+ else if(rString == "last-week")
+ return condformat::LASTWEEK;
+ else if(rString == "next-week")
+ return condformat::NEXTWEEK;
+ else if(rString == "this-month")
+ return condformat::THISMONTH;
+ else if(rString == "last-month")
+ return condformat::LASTMONTH;
+ else if(rString == "next-month")
+ return condformat::NEXTMONTH;
+ else if(rString == "this-year")
+ return condformat::THISYEAR;
+ else if(rString == "last-year")
+ return condformat::LASTYEAR;
+ else if(rString == "next-year")
+ return condformat::NEXTYEAR;
+
+ SAL_WARN("sc", "unknown date type: " << rString);
+ return condformat::TODAY;
+}
+
+}
+
+ScXMLDateContext::ScXMLDateContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
+ const ::rtl::OUString& rLName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
+ ScConditionalFormat* pFormat ):
+ SvXMLImportContext( rImport, nPrfx, rLName )
+{
+ rtl::OUString sDateType, sStyle;
+ sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
+ const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetCondDateAttrMap();
+ for( sal_Int16 i=0; i < nAttrCount; ++i )
+ {
+ const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
+ rtl::OUString aLocalName;
+ sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
+ sAttrName, &aLocalName ));
+ const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
+
+ switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
+ {
+ case XML_TOK_COND_DATE_VALUE:
+ sDateType = sValue;
+ break;
+ case XML_TOK_COND_DATE_STYLE:
+ sStyle = sValue;
+ default:
+ break;
+ }
+ }
+
+ ScCondDateFormatEntry* pFormatEntry = new ScCondDateFormatEntry(GetScImport().GetDocument());
+ pFormatEntry->SetStyleName(sStyle);
+ pFormatEntry->SetDateType(getDateFromString(sDateType));
+ pFormat->AddEntry(pFormatEntry);
+
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/xml/xmlcondformat.hxx b/sc/source/filter/xml/xmlcondformat.hxx
index 0ace1eb03ae9..1b64cd5cf896 100644
--- a/sc/source/filter/xml/xmlcondformat.hxx
+++ b/sc/source/filter/xml/xmlcondformat.hxx
@@ -194,4 +194,18 @@ public:
virtual ~ScXMLCondContext() {}
};
+class ScXMLDateContext : public SvXMLImportContext
+{
+ const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
+ ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
+public:
+ ScXMLDateContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
+ const ::rtl::OUString& rLName,
+ const ::com::sun::star::uno::Reference<
+ ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
+ ScConditionalFormat* pFormat);
+
+ virtual ~ScXMLDateContext() {}
+};
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx
index a0b53b86ccb2..5782dbc4ebac 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -3820,6 +3820,41 @@ rtl::OUString getIconSetName(ScIconSetType eType)
return rtl::OUString::createFromAscii(pName);
}
+rtl::OUString getDateStringForType(condformat::ScCondFormatDateType eType)
+{
+ switch(eType)
+ {
+ case condformat::TODAY:
+ return rtl::OUString("today");
+ case condformat::YESTERDAY:
+ return rtl::OUString("yesterday");
+ case condformat::TOMORROW:
+ return rtl::OUString("tomorrow");
+ case condformat::LAST7DAYS:
+ return rtl::OUString("last-7-days");
+ case condformat::THISWEEK:
+ return rtl::OUString("this-week");
+ case condformat::LASTWEEK:
+ return rtl::OUString("last-week");
+ case condformat::NEXTWEEK:
+ return rtl::OUString("next-week");
+ case condformat::THISMONTH:
+ return rtl::OUString("this-month");
+ case condformat::LASTMONTH:
+ return rtl::OUString("last-month");
+ case condformat::NEXTMONTH:
+ return rtl::OUString("next-month");
+ case condformat::THISYEAR:
+ return rtl::OUString("this-year");
+ case condformat::LASTYEAR:
+ return rtl::OUString("last-year");
+ case condformat::NEXTYEAR:
+ return rtl::OUString("next-year");
+ }
+
+ return rtl::OUString();
+}
+
}
void ScXMLExport::ExportConditionalFormat(SCTAB nTab)
@@ -4076,6 +4111,14 @@ void ScXMLExport::ExportConditionalFormat(SCTAB nTab)
SvXMLElementExport aElementColorScaleEntry(*this, XML_NAMESPACE_CALC_EXT, XML_FORMATTING_ENTRY, true, true);
}
}
+ else if(pFormatEntry->GetType() == condformat::DATE)
+ {
+ const ScCondDateFormatEntry& mrDateFormat = static_cast<const ScCondDateFormatEntry&>(*pFormatEntry);
+ rtl::OUString aDateType = getDateStringForType(mrDateFormat.GetDateType());
+ AddAttribute( XML_NAMESPACE_CALC_EXT, XML_STYLE, mrDateFormat.GetStyleName());
+ AddAttribute( XML_NAMESPACE_CALC_EXT, XML_DATE, aDateType);
+ SvXMLElementExport aElementDateFormat(*this, XML_NAMESPACE_CALC_EXT, XML_DATE_IS, true, true);
+ }
}
}
}
diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx
index 717d0ee79ae3..dd9d155e3ae4 100644
--- a/sc/source/filter/xml/xmlimprt.cxx
+++ b/sc/source/filter/xml/xmlimprt.cxx
@@ -611,6 +611,7 @@ const SvXMLTokenMap& ScXMLImport::GetCondFormatTokenMap()
{ XML_NAMESPACE_CALC_EXT, XML_DATA_BAR, XML_TOK_CONDFORMAT_DATABAR },
{ XML_NAMESPACE_CALC_EXT, XML_CONDITION, XML_TOK_CONDFORMAT_CONDITION },
{ XML_NAMESPACE_CALC_EXT, XML_ICON_SET, XML_TOK_CONDFORMAT_ICONSET },
+ { XML_NAMESPACE_CALC_EXT, XML_DATE_IS, XML_TOK_CONDFORMAT_DATE },
XML_TOKEN_MAP_END
};
@@ -636,6 +637,23 @@ const SvXMLTokenMap& ScXMLImport::GetCondFormatAttrMap()
return *pCondFormatAttrMap;
}
+const SvXMLTokenMap& ScXMLImport::GetCondDateAttrMap()
+{
+ if( !pCondDateAttrMap )
+ {
+ static SvXMLTokenMapEntry aCondDateAttrTokenMap[] =
+ {
+ { XML_NAMESPACE_CALC_EXT, XML_DATE, XML_TOK_COND_DATE_VALUE },
+ { XML_NAMESPACE_CALC_EXT, XML_STYLE, XML_TOK_COND_DATE_STYLE },
+ XML_TOKEN_MAP_END
+ };
+
+ pCondDateAttrMap = new SvXMLTokenMap( aCondDateAttrTokenMap );
+ }
+
+ return *pCondDateAttrMap;
+}
+
const SvXMLTokenMap& ScXMLImport::GetConditionAttrMap()
{
if( !pConditionAttrMap )
@@ -1879,6 +1897,7 @@ ScXMLImport::ScXMLImport(
pCondFormatsTokenMap( 0 ),
pCondFormatTokenMap( 0 ),
pCondFormatAttrMap( 0 ),
+ pCondDateAttrMap( 0 ),
pConditionAttrMap( 0 ),
pColorScaleTokenMap( 0 ),
pColorScaleEntryAttrTokenMap( 0 ),
@@ -2017,6 +2036,7 @@ ScXMLImport::~ScXMLImport() throw()
delete pCondFormatsTokenMap;
delete pCondFormatTokenMap;
delete pCondFormatAttrMap;
+ delete pCondDateAttrMap;
delete pConditionAttrMap;
delete pColorScaleTokenMap;
delete pColorScaleEntryAttrTokenMap;
diff --git a/sc/source/filter/xml/xmlimprt.hxx b/sc/source/filter/xml/xmlimprt.hxx
index ee5708f9aed4..532d83a31e2f 100644
--- a/sc/source/filter/xml/xmlimprt.hxx
+++ b/sc/source/filter/xml/xmlimprt.hxx
@@ -154,7 +154,8 @@ enum ScXMLCondFormatTokens
XML_TOK_CONDFORMAT_COLORSCALE,
XML_TOK_CONDFORMAT_DATABAR,
XML_TOK_CONDFORMAT_CONDITION,
- XML_TOK_CONDFORMAT_ICONSET
+ XML_TOK_CONDFORMAT_ICONSET,
+ XML_TOK_CONDFORMAT_DATE
};
enum ScXMLCondFormatAttrTokens
@@ -162,6 +163,12 @@ enum ScXMLCondFormatAttrTokens
XML_TOK_CONDFORMAT_TARGET_RANGE
};
+enum ScXMLCondDateAttrTokens
+{
+ XML_TOK_COND_DATE_VALUE,
+ XML_TOK_COND_DATE_STYLE
+};
+
enum ScXMLConditionAttrTokens
{
XML_TOK_CONDITION_VALUE,
@@ -775,6 +782,7 @@ class ScXMLImport: public SvXMLImport, boost::noncopyable
SvXMLTokenMap *pCondFormatsTokenMap;
SvXMLTokenMap *pCondFormatTokenMap;
SvXMLTokenMap *pCondFormatAttrMap;
+ SvXMLTokenMap *pCondDateAttrMap;
SvXMLTokenMap *pConditionAttrMap;
SvXMLTokenMap *pColorScaleTokenMap;
SvXMLTokenMap *pColorScaleEntryAttrTokenMap;
@@ -939,6 +947,7 @@ public:
const SvXMLTokenMap& GetCondFormatsTokenMap();
const SvXMLTokenMap& GetCondFormatTokenMap();
const SvXMLTokenMap& GetCondFormatAttrMap();
+ const SvXMLTokenMap& GetCondDateAttrMap();
const SvXMLTokenMap& GetConditionAttrMap();
const SvXMLTokenMap& GetColorScaleTokenMap();
const SvXMLTokenMap& GetColorScaleEntryAttrMap();