summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2021-06-18 21:36:29 +0900
committerTomaž Vajngerl <quikee@gmail.com>2021-06-19 11:15:30 +0200
commit2ce10eedfb1de8beef8ddfa457f1e19545846f86 (patch)
tree82eac0f63f1a0b556d86fbf697c2ff48d9e1de7d
parent705fe1c44b41cd11518069e0627d0f48a65a7dfc (diff)
indexing: indexing sections for the IndexingExport
Adds handling of sections to the IndexingExport. SectionNode also derives from StartNode, so we handle it similar as the tables. Change-Id: I5eb8d599bdf680144b161aa93295ea3d360eb5c0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117452 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r--sw/qa/extras/indexing/IndexingExportTest.cxx31
-rw-r--r--sw/qa/extras/indexing/data/IndexingExport_Sections.odtbin0 -> 10245 bytes
-rw-r--r--sw/source/filter/indexing/IndexingExport.cxx16
3 files changed, 45 insertions, 2 deletions
diff --git a/sw/qa/extras/indexing/IndexingExportTest.cxx b/sw/qa/extras/indexing/IndexingExportTest.cxx
index fbc2c9d0ece2..f714b50f042a 100644
--- a/sw/qa/extras/indexing/IndexingExportTest.cxx
+++ b/sw/qa/extras/indexing/IndexingExportTest.cxx
@@ -31,6 +31,7 @@ public:
void testIndexingExport_OLE();
void testIndexingExport_Shapes();
void testIndexingExport_Tables();
+ void testIndexingExport_Sections();
CPPUNIT_TEST_SUITE(IndexingExportTest);
CPPUNIT_TEST(testIndexingExport_Paragraphs);
@@ -38,6 +39,7 @@ public:
CPPUNIT_TEST(testIndexingExport_OLE);
CPPUNIT_TEST(testIndexingExport_Shapes);
CPPUNIT_TEST(testIndexingExport_Tables);
+ CPPUNIT_TEST(testIndexingExport_Sections);
CPPUNIT_TEST_SUITE_END();
};
@@ -214,6 +216,35 @@ void IndexingExportTest::testIndexingExport_Tables()
assertXPathContent(pXmlDoc, "/indexing/table[3]/paragraph[21]", "D5");
}
+void IndexingExportTest::testIndexingExport_Sections()
+{
+ SwDoc* pDoc = createDoc("IndexingExport_Sections.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/section[1]", "name", "Section1");
+ assertXPathContent(pXmlDoc, "/indexing/section[1]/paragraph[1]",
+ "This is a paragraph in a Section1");
+ assertXPathContent(pXmlDoc, "/indexing/section[1]/paragraph[2]", "Section1 - Paragraph 2");
+ assertXPathContent(pXmlDoc, "/indexing/section[1]/paragraph[3]", "Section1 - Paragraph 3");
+
+ assertXPath(pXmlDoc, "/indexing/section[2]", "name", "Section2");
+ assertXPathContent(pXmlDoc, "/indexing/section[2]/paragraph[1]", "Section2 - Paragraph 1");
+ assertXPathContent(pXmlDoc, "/indexing/section[2]/paragraph[2]", "Section2 - Paragraph 2");
+
+ assertXPathContent(pXmlDoc, "/indexing/paragraph[1]", "This is a paragraph outside sections");
+ assertXPathContent(pXmlDoc, "/indexing/paragraph[2]", "This is a paragraph outside sections");
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(IndexingExportTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/qa/extras/indexing/data/IndexingExport_Sections.odt b/sw/qa/extras/indexing/data/IndexingExport_Sections.odt
new file mode 100644
index 000000000000..ef92c83efd25
--- /dev/null
+++ b/sw/qa/extras/indexing/data/IndexingExport_Sections.odt
Binary files differ
diff --git a/sw/source/filter/indexing/IndexingExport.cxx b/sw/source/filter/indexing/IndexingExport.cxx
index b02bef0c9fe2..17a1670bd73c 100644
--- a/sw/source/filter/indexing/IndexingExport.cxx
+++ b/sw/source/filter/indexing/IndexingExport.cxx
@@ -56,8 +56,11 @@ public:
{
handleTableNode(pNode->GetTableNode());
}
-
- if (pNode->IsEndNode())
+ else if (pNode->IsSectionNode())
+ {
+ handleSectionNode(pNode->GetSectionNode());
+ }
+ else if (pNode->IsEndNode())
{
handleEndNode(pNode->GetEndNode());
}
@@ -138,6 +141,15 @@ public:
maNodeStack.push_back(pTableNode);
}
+ void handleSectionNode(SwSectionNode* pSectionNode)
+ {
+ m_rXmlWriter.startElement("section");
+ m_rXmlWriter.attribute("index", pSectionNode->GetIndex());
+ m_rXmlWriter.attribute("name", pSectionNode->GetSection().GetSectionName());
+
+ maNodeStack.push_back(pSectionNode);
+ }
+
void handleEndNode(SwEndNode* pEndNode)
{
if (!maNodeStack.empty() && pEndNode->StartOfSectionNode() == maNodeStack.back())