[Libreoffice-commits] core.git: sc/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Aug 6 20:05:31 UTC 2018


 sc/source/filter/xml/xmltransformationi.cxx |  169 ++++++++++++++++++++++++++++
 sc/source/filter/xml/xmltransformationi.hxx |   33 +++++
 2 files changed, 202 insertions(+)

New commits:
commit d1fa83231c8afd2b2c14f89f869ba14ba2f3e628
Author:     Vikas Mahato <vikasmahato0 at gmail.com>
AuthorDate: Sat Jul 28 23:31:11 2018 +0530
Commit:     Markus Mohrhard <markus.mohrhard at googlemail.com>
CommitDate: Mon Aug 6 22:05:08 2018 +0200

    Import ODF with data transformations - follow-up
    
    Change-Id: If8bef32ff4a08edef3bb86f366a7b47d8ac1e397
    Reviewed-on: https://gerrit.libreoffice.org/58258
    Tested-by: Jenkins
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>

diff --git a/sc/source/filter/xml/xmltransformationi.cxx b/sc/source/filter/xml/xmltransformationi.cxx
index 857895149bf5..f48fa02ecdc0 100644
--- a/sc/source/filter/xml/xmltransformationi.cxx
+++ b/sc/source/filter/xml/xmltransformationi.cxx
@@ -75,6 +75,11 @@ uno::Reference<xml::sax::XFastContextHandler>
             pContext = new ScXMLColumnNumberContext(GetScImport(), pAttribList);
         }
         break;
+        case XML_ELEMENT(CALC_EXT, XML_COLUMN_REPLACENULL_TRANSFORMATION):
+        {
+            pContext = new ScXMLColumnRemoveNullContext(GetScImport(), pAttribList);
+        }
+        break;
     }
 
     if (!pContext)
@@ -511,4 +516,168 @@ uno::Reference<xml::sax::XFastContextHandler>
     return new SvXMLImportContext(GetImport());
 }
 
+ScXMLColumnRemoveNullContext::ScXMLColumnRemoveNullContext(
+    ScXMLImport& rImport, const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList)
+    : ScXMLImportContext(rImport)
+{
+    if (rAttrList.is())
+    {
+        for (auto& aIter : *rAttrList)
+        {
+            switch (aIter.getToken())
+            {
+                case XML_ELEMENT(CALC_EXT, XML_REPLACE_STRING):
+                {
+                    maReplaceString = aIter.toString();
+                }
+                break;
+            }
+        }
+    }
+}
+
+ScXMLColumnRemoveNullContext::~ScXMLColumnRemoveNullContext()
+{
+    ScDocument* pDoc = GetScImport().GetDocument();
+    auto& rDataSources = pDoc->GetExternalDataMapper().getDataSources();
+    if (!rDataSources.empty())
+    {
+        rDataSources[rDataSources.size() - 1].AddDataTransformation(
+            std::make_shared<sc::ReplaceNullTransformation>(maColumns, maReplaceString));
+    }
+}
+
+uno::Reference<xml::sax::XFastContextHandler>
+    SAL_CALL ScXMLColumnRemoveNullContext::createFastChildContext(
+        sal_Int32 nElement, const uno::Reference<xml::sax::XFastAttributeList>& xAttrList)
+{
+    sax_fastparser::FastAttributeList* pAttribList
+        = sax_fastparser::FastAttributeList::castToFastAttributeList(xAttrList);
+    const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList = pAttribList;
+    switch (nElement)
+    {
+        case XML_ELEMENT(CALC_EXT, XML_COLUMN):
+        {
+            if (rAttrList.is())
+            {
+                for (auto& aIter : *rAttrList)
+                {
+                    switch (aIter.getToken())
+                    {
+                        case XML_ELEMENT(CALC_EXT, XML_COLUMN):
+                        {
+                            maColumns.insert(aIter.toInt32());
+                        }
+                        break;
+                    }
+                }
+            }
+        }
+        break;
+    }
+    return new SvXMLImportContext(GetImport());
+}
+
+ScXMLDateTimeContext::ScXMLDateTimeContext(
+    ScXMLImport& rImport, const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList)
+    : ScXMLImportContext(rImport)
+{
+    if (rAttrList.is())
+    {
+        for (auto& aIter : *rAttrList)
+        {
+            switch (aIter.getToken())
+            {
+                case XML_ELEMENT(CALC_EXT, XML_TYPE):
+                {
+                    aType = aIter.toString();
+                }
+                break;
+            }
+        }
+    }
+
+    if (!aType.isEmpty())
+    {
+        if (aType == "date-string")
+            maType = sc::DATETIME_TRANSFORMATION_TYPE::DATE_STRING;
+        else if (aType == "year")
+            maType = sc::DATETIME_TRANSFORMATION_TYPE::YEAR;
+        else if (aType == "start-of-year")
+            maType = sc::DATETIME_TRANSFORMATION_TYPE::START_OF_YEAR;
+        else if (aType == "end-of-year")
+            maType = sc::DATETIME_TRANSFORMATION_TYPE::END_OF_YEAR;
+        else if (aType == "month")
+            maType = sc::DATETIME_TRANSFORMATION_TYPE::MONTH;
+        else if (aType == "month-name")
+            maType = sc::DATETIME_TRANSFORMATION_TYPE::MONTH_NAME;
+        else if (aType == "start-of-month")
+            maType = sc::DATETIME_TRANSFORMATION_TYPE::START_OF_MONTH;
+        else if (aType == "end-of-month")
+            maType = sc::DATETIME_TRANSFORMATION_TYPE::END_OF_MONTH;
+        else if (aType == "day")
+            maType = sc::DATETIME_TRANSFORMATION_TYPE::DAY;
+        else if (aType == "day-of-week")
+            maType = sc::DATETIME_TRANSFORMATION_TYPE::DAY_OF_WEEK;
+        else if (aType == "day-of-year")
+            maType = sc::DATETIME_TRANSFORMATION_TYPE::DAY_OF_YEAR;
+        else if (aType == "quarter")
+            maType = sc::DATETIME_TRANSFORMATION_TYPE::QUARTER;
+        else if (aType == "start-of-quarter")
+            maType = sc::DATETIME_TRANSFORMATION_TYPE::START_OF_QUARTER;
+        else if (aType == "end-of-quarter")
+            maType = sc::DATETIME_TRANSFORMATION_TYPE::END_OF_QUARTER;
+        else if (aType == "time")
+            maType = sc::DATETIME_TRANSFORMATION_TYPE::TIME;
+        else if (aType == "hour")
+            maType = sc::DATETIME_TRANSFORMATION_TYPE::HOUR;
+        else if (aType == "minute")
+            maType = sc::DATETIME_TRANSFORMATION_TYPE::MINUTE;
+        else if (aType == "seconds")
+            maType = sc::DATETIME_TRANSFORMATION_TYPE::SECOND;
+    }
+}
+
+ScXMLDateTimeContext::~ScXMLDateTimeContext()
+{
+    ScDocument* pDoc = GetScImport().GetDocument();
+    auto& rDataSources = pDoc->GetExternalDataMapper().getDataSources();
+    if (!rDataSources.empty())
+    {
+        rDataSources[rDataSources.size() - 1].AddDataTransformation(
+            std::make_shared<sc::DateTimeTransformation>(maColumns, maType));
+    }
+}
+
+uno::Reference<xml::sax::XFastContextHandler> SAL_CALL ScXMLDateTimeContext::createFastChildContext(
+    sal_Int32 nElement, const uno::Reference<xml::sax::XFastAttributeList>& xAttrList)
+{
+    sax_fastparser::FastAttributeList* pAttribList
+        = sax_fastparser::FastAttributeList::castToFastAttributeList(xAttrList);
+    const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList = pAttribList;
+
+    switch (nElement)
+    {
+        case XML_ELEMENT(CALC_EXT, XML_COLUMN):
+        {
+            if (rAttrList.is())
+            {
+                for (auto& aIter : *rAttrList)
+                {
+                    switch (aIter.getToken())
+                    {
+                        case XML_ELEMENT(CALC_EXT, XML_COLUMN):
+                        {
+                            maColumns.insert(aIter.toInt32());
+                        }
+                        break;
+                    }
+                }
+            }
+        }
+        break;
+    }
+    return new SvXMLImportContext(GetImport());
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/xml/xmltransformationi.hxx b/sc/source/filter/xml/xmltransformationi.hxx
index 42c8a66090f4..2fc712f158fe 100644
--- a/sc/source/filter/xml/xmltransformationi.hxx
+++ b/sc/source/filter/xml/xmltransformationi.hxx
@@ -135,6 +135,39 @@ public:
         sal_Int32 nElement,
         const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList) override;
 };
+
+class ScXMLColumnRemoveNullContext : public ScXMLImportContext
+{
+    std::set<SCCOL> maColumns;
+    OUString maReplaceString;
+
+public:
+    ScXMLColumnRemoveNullContext(
+        ScXMLImport& rImport, const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList);
+
+    virtual ~ScXMLColumnRemoveNullContext() override;
+
+    virtual css::uno::Reference<css::xml::sax::XFastContextHandler> SAL_CALL createFastChildContext(
+        sal_Int32 nElement,
+        const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList) override;
+};
+
+class ScXMLDateTimeContext : public ScXMLImportContext
+{
+    OUString aType;
+    sc::DATETIME_TRANSFORMATION_TYPE maType;
+    std::set<SCCOL> maColumns;
+
+public:
+    ScXMLDateTimeContext(ScXMLImport& rImport,
+                         const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList);
+
+    virtual ~ScXMLDateTimeContext() override;
+
+    virtual css::uno::Reference<css::xml::sax::XFastContextHandler> SAL_CALL createFastChildContext(
+        sal_Int32 nElement,
+        const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList) override;
+};
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list