summaryrefslogtreecommitdiff
path: root/sw/source
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2021-06-11 12:23:45 +0900
committerTomaž Vajngerl <quikee@gmail.com>2021-06-19 11:12:44 +0200
commit686c35a3c37674d08c1f8585a621143c959b3f29 (patch)
treed5add6b678d48c825d2a0a2cc3985b75cb8aae6d /sw/source
parente6cb7f9ab25bca32dc85aef8ff127e070cd109b6 (diff)
indexing: indexing paragraph text with the ModelTraverser
This adds the basic paragraph text export for indexing, which uses the new ModelTraverser, which is inspired by AccessibilityCheck (and in the future it will be changed to use the ModelTraverser too, when it matures). ModelTraverser implements traversing through the model and executes a handler for a element of a model (which can be various things). IndexingExport class implements indexing export that uses the ModelTraverser to write into the indexing xml document, that uses the tools::XmlWriter. Change-Id: I7a6a5de332534270fe894a881131e5eb5ea9d881 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117356 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sw/source')
-rw-r--r--sw/source/core/inc/ModelTraverser.hxx49
-rw-r--r--sw/source/core/model/ModelTraverser.cxx39
-rw-r--r--sw/source/filter/inc/IndexingExport.hxx32
-rw-r--r--sw/source/filter/indexing/IndexingExport.cxx71
4 files changed, 191 insertions, 0 deletions
diff --git a/sw/source/core/inc/ModelTraverser.hxx b/sw/source/core/inc/ModelTraverser.hxx
new file mode 100644
index 000000000000..ab38032773df
--- /dev/null
+++ b/sw/source/core/inc/ModelTraverser.hxx
@@ -0,0 +1,49 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#pragma once
+
+#include <doc.hxx>
+
+class SwNode;
+
+namespace sw
+{
+class SW_DLLPUBLIC ModelTraverseHandler
+{
+public:
+ virtual ~ModelTraverseHandler() {}
+
+ virtual void handleNode(SwNode* pNode) = 0;
+};
+
+class SW_DLLPUBLIC ModelTraverser
+{
+private:
+ std::vector<std::shared_ptr<ModelTraverseHandler>> mpNodeHandler;
+ SwDoc* m_pDoc;
+
+public:
+ ModelTraverser(SwDoc* pDoc)
+ : m_pDoc(pDoc)
+ {
+ }
+
+ void traverse();
+
+ void addNodeHandler(std::shared_ptr<ModelTraverseHandler> pHandler)
+ {
+ mpNodeHandler.push_back(pHandler);
+ }
+};
+
+} // end sw namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/model/ModelTraverser.cxx b/sw/source/core/model/ModelTraverser.cxx
new file mode 100644
index 000000000000..f46e173eca9f
--- /dev/null
+++ b/sw/source/core/model/ModelTraverser.cxx
@@ -0,0 +1,39 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#include <ModelTraverser.hxx>
+#include <node.hxx>
+#include <ndarr.hxx>
+
+namespace sw
+{
+void ModelTraverser::traverse()
+{
+ if (m_pDoc == nullptr)
+ return;
+
+ auto const& pNodes = m_pDoc->GetNodes();
+ SwNode* pNode = nullptr;
+ for (sal_uLong n = 0; n < pNodes.Count(); ++n)
+ {
+ pNode = pNodes[n];
+ if (pNode)
+ {
+ for (auto& pNodeHandler : mpNodeHandler)
+ {
+ pNodeHandler->handleNode(pNode);
+ }
+ }
+ }
+}
+
+} // end sw namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/inc/IndexingExport.hxx b/sw/source/filter/inc/IndexingExport.hxx
new file mode 100644
index 000000000000..782ddf7f5f0f
--- /dev/null
+++ b/sw/source/filter/inc/IndexingExport.hxx
@@ -0,0 +1,32 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#pragma once
+
+#include <ModelTraverser.hxx>
+#include <tools/XmlWriter.hxx>
+
+namespace sw
+{
+class SW_DLLPUBLIC IndexingExport
+{
+private:
+ ModelTraverser m_aModelTraverser;
+ tools::XmlWriter m_aXmlWriter;
+
+public:
+ IndexingExport(SvStream& rStream, SwDoc* pDoc);
+
+ bool runExport();
+};
+
+} // end sw namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/indexing/IndexingExport.cxx b/sw/source/filter/indexing/IndexingExport.cxx
new file mode 100644
index 000000000000..8df7d56f7ff6
--- /dev/null
+++ b/sw/source/filter/indexing/IndexingExport.cxx
@@ -0,0 +1,71 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#include <IndexingExport.hxx>
+
+#include <ndtxt.hxx>
+
+namespace sw
+{
+namespace
+{
+class IndexingNodeHandler : public ModelTraverseHandler
+{
+private:
+ tools::XmlWriter& m_rXmlWriter;
+
+public:
+ IndexingNodeHandler(tools::XmlWriter& rXmlWriter)
+ : m_rXmlWriter(rXmlWriter)
+ {
+ }
+
+ void handleNode(SwNode* pNode) override
+ {
+ if (!pNode->IsTextNode())
+ return;
+
+ SwTextNode* pTextNode = pNode->GetTextNode();
+ const OUString& rString
+ = pTextNode->GetText().replaceAll(OUStringChar(CH_TXTATR_BREAKWORD), "");
+ m_rXmlWriter.startElement("paragraph");
+ m_rXmlWriter.attribute("index", pTextNode->GetIndex());
+ m_rXmlWriter.content(rString);
+ m_rXmlWriter.endElement();
+ }
+};
+
+} // end anonymous namespace
+
+IndexingExport::IndexingExport(SvStream& rStream, SwDoc* pDoc)
+ : m_aModelTraverser(pDoc)
+ , m_aXmlWriter(&rStream)
+{
+}
+
+bool IndexingExport::runExport()
+{
+ bool bResult = m_aXmlWriter.startDocument(2);
+ if (!bResult)
+ return false;
+
+ m_aXmlWriter.startElement("indexing");
+ m_aModelTraverser.addNodeHandler(std::make_shared<IndexingNodeHandler>(m_aXmlWriter));
+ m_aModelTraverser.traverse();
+ m_aXmlWriter.endElement();
+
+ m_aXmlWriter.endDocument();
+
+ return true;
+}
+
+} // end sw namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */