summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2021-06-18 20:21:20 +0900
committerTomaž Vajngerl <quikee@gmail.com>2021-06-19 11:14:31 +0200
commitb3a62ab0a43510cf43c88aa4d6e145e46db7e7e5 (patch)
treec552864a9463e01729253036163cac52e7f699b6
parentc23408aeafc1f2ce3f7dde685d0b519d8e2daff7 (diff)
indexing: indexing tables for the IndexingExport
Adds handling of tables to the IndexingExport and also handling of the end node (as table node is also a start node), so we know which paragraphs belong to a table. Change-Id: I624ce12a3e810797a37ae2efe5baa552828f75dc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117450 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r--sw/qa/extras/indexing/IndexingExportTest.cxx64
-rw-r--r--sw/qa/extras/indexing/data/IndexingExport_Tables.odtbin0 -> 10748 bytes
-rw-r--r--sw/source/filter/indexing/IndexingExport.cxx34
3 files changed, 98 insertions, 0 deletions
diff --git a/sw/qa/extras/indexing/IndexingExportTest.cxx b/sw/qa/extras/indexing/IndexingExportTest.cxx
index 350e75c3d49f..fbc2c9d0ece2 100644
--- a/sw/qa/extras/indexing/IndexingExportTest.cxx
+++ b/sw/qa/extras/indexing/IndexingExportTest.cxx
@@ -30,12 +30,14 @@ public:
void testIndexingExport_Images();
void testIndexingExport_OLE();
void testIndexingExport_Shapes();
+ void testIndexingExport_Tables();
CPPUNIT_TEST_SUITE(IndexingExportTest);
CPPUNIT_TEST(testIndexingExport_Paragraphs);
CPPUNIT_TEST(testIndexingExport_Images);
CPPUNIT_TEST(testIndexingExport_OLE);
CPPUNIT_TEST(testIndexingExport_Shapes);
+ CPPUNIT_TEST(testIndexingExport_Tables);
CPPUNIT_TEST_SUITE_END();
};
@@ -150,6 +152,68 @@ void IndexingExportTest::testIndexingExport_Shapes()
assertXPathContent(pXmlDoc, "/indexing/shape[3]/paragraph[3]", "Para3");
}
+void IndexingExportTest::testIndexingExport_Tables()
+{
+ SwDoc* pDoc = createDoc("IndexingExport_Tables.odt");
+ CPPUNIT_ASSERT(pDoc);
+
+ SvMemoryStream aMemoryStream;
+ sw::IndexingExport aIndexingExport(aMemoryStream, pDoc);
+ aIndexingExport.runExport();
+ aMemoryStream.Seek(0);
+
+ xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream);
+ CPPUNIT_ASSERT(pXmlDoc);
+
+ assertXPath(pXmlDoc, "/indexing");
+
+ assertXPath(pXmlDoc, "/indexing/table[1]", "name", "Table1");
+ assertXPathContent(pXmlDoc, "/indexing/table[1]/paragraph[1]", "A");
+ assertXPathContent(pXmlDoc, "/indexing/table[1]/paragraph[2]", "B");
+ assertXPathContent(pXmlDoc, "/indexing/table[1]/paragraph[3]", "1");
+ assertXPathContent(pXmlDoc, "/indexing/table[1]/paragraph[4]", "2");
+
+ assertXPath(pXmlDoc, "/indexing/table[2]", "name", "Table2");
+ assertXPathContent(pXmlDoc, "/indexing/table[2]/paragraph[1]", "A");
+ assertXPathContent(pXmlDoc, "/indexing/table[2]/paragraph[2]", "B");
+ assertXPathContent(pXmlDoc, "/indexing/table[2]/paragraph[3]", "C");
+ assertXPathContent(pXmlDoc, "/indexing/table[2]/paragraph[4]", "1");
+ assertXPathContent(pXmlDoc, "/indexing/table[2]/paragraph[5]", "10");
+ assertXPathContent(pXmlDoc, "/indexing/table[2]/paragraph[6]", "100");
+ assertXPathContent(pXmlDoc, "/indexing/table[2]/paragraph[7]", "2");
+ assertXPathContent(pXmlDoc, "/indexing/table[2]/paragraph[8]", "20");
+ assertXPathContent(pXmlDoc, "/indexing/table[2]/paragraph[9]", "200");
+ assertXPathContent(pXmlDoc, "/indexing/table[2]/paragraph[10]", "3");
+ assertXPathContent(pXmlDoc, "/indexing/table[2]/paragraph[11]", "30");
+ assertXPathContent(pXmlDoc, "/indexing/table[2]/paragraph[12]", "300");
+ assertXPathContent(pXmlDoc, "/indexing/table[2]/paragraph[13]", "4");
+ assertXPathContent(pXmlDoc, "/indexing/table[2]/paragraph[14]", "40");
+ assertXPathContent(pXmlDoc, "/indexing/table[2]/paragraph[15]", "400");
+
+ assertXPath(pXmlDoc, "/indexing/table[3]", "name", "WeirdTable");
+ assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[1]", "A1");
+ assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[2]", "B1");
+ assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[3]", "C1");
+ assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[4]", "D1");
+ assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[5]", "A2B2");
+ assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[6]", "C2D2");
+ assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[7]", "A3B3C3D3");
+ assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[8]", "A4-1");
+ assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[9]", "A4-2");
+ assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[10]", "B4-1");
+ assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[11]", "C4-1");
+ assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[12]", "D4-1");
+ assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[13]", "D4-2");
+ assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[14]", "");
+ assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[15]", "");
+ assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[16]", "B4-2");
+ assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[17]", "C4-2");
+ assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[18]", "");
+ assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[19]", "");
+ assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[20]", "A5B5C5");
+ assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[21]", "D5");
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(IndexingExportTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/qa/extras/indexing/data/IndexingExport_Tables.odt b/sw/qa/extras/indexing/data/IndexingExport_Tables.odt
new file mode 100644
index 000000000000..a15acc7de309
--- /dev/null
+++ b/sw/qa/extras/indexing/data/IndexingExport_Tables.odt
Binary files differ
diff --git a/sw/source/filter/indexing/IndexingExport.cxx b/sw/source/filter/indexing/IndexingExport.cxx
index 3ec39c1d338c..83bac26fc51d 100644
--- a/sw/source/filter/indexing/IndexingExport.cxx
+++ b/sw/source/filter/indexing/IndexingExport.cxx
@@ -18,6 +18,8 @@
#include <svx/svdotext.hxx>
#include <editeng/outlobj.hxx>
#include <editeng/editobj.hxx>
+#include <swtable.hxx>
+#include <deque>
namespace sw
{
@@ -28,6 +30,8 @@ class IndexingNodeHandler : public ModelTraverseHandler
private:
tools::XmlWriter& m_rXmlWriter;
+ std::deque<SwNode*> maNodeStack;
+
public:
IndexingNodeHandler(tools::XmlWriter& rXmlWriter)
: m_rXmlWriter(rXmlWriter)
@@ -48,6 +52,15 @@ public:
{
handleTextNode(pNode->GetTextNode());
}
+ else if (pNode->IsTableNode())
+ {
+ handleTableNode(pNode->GetTableNode());
+ }
+
+ if (pNode->IsEndNode())
+ {
+ handleEndNode(pNode->GetEndNode());
+ }
}
void handleOLENode(SwOLENode* pOleNode)
@@ -105,6 +118,27 @@ public:
m_rXmlWriter.endElement();
}
+
+ void handleTableNode(SwTableNode* pTableNode)
+ {
+ const SwTableFormat* pFormat = pTableNode->GetTable().GetFrameFormat();
+ OUString sName = pFormat->GetName();
+
+ m_rXmlWriter.startElement("table");
+ m_rXmlWriter.attribute("index", pTableNode->GetIndex());
+ m_rXmlWriter.attribute("name", sName);
+
+ maNodeStack.push_back(pTableNode);
+ }
+
+ void handleEndNode(SwEndNode* pEndNode)
+ {
+ if (!maNodeStack.empty() && pEndNode->StartOfSectionNode() == maNodeStack.back())
+ {
+ maNodeStack.pop_back();
+ m_rXmlWriter.endElement();
+ }
+ }
};
} // end anonymous namespace