diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2021-08-25 20:16:57 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-09-02 13:14:18 +0200 |
commit | db004939f9ca667decc53f33a61f2020fa162ee4 (patch) | |
tree | 8a72780ea405dc2c7790ce52e531925411bb13c4 /sw/source | |
parent | cd989a7d1f4a4ec6c6c37039d5a855f3a043032b (diff) |
indexing: move xml parsing into SearchResultLocator
Let's keep unneeded complexity out of SwXTextDocument, so move
parsing into SearchResultLocator.
As a bonus we can now test parsing.
Change-Id: I944bfc43e6953523eee19b26b7f483aa401809aa
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121032
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
(cherry picked from commit 0b698aa6eb26d75ca4baf677a461aee095f69317)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121116
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/core/inc/SearchResultLocator.hxx | 2 | ||||
-rw-r--r-- | sw/source/core/model/ModelTraverser.cxx | 1 | ||||
-rw-r--r-- | sw/source/core/model/SearchResultLocator.cxx | 50 | ||||
-rw-r--r-- | sw/source/uibase/uno/unotxdoc.cxx | 56 |
4 files changed, 61 insertions, 48 deletions
diff --git a/sw/source/core/inc/SearchResultLocator.hxx b/sw/source/core/inc/SearchResultLocator.hxx index cd1b2e4bb5e5..7dac632ae58f 100644 --- a/sw/source/core/inc/SearchResultLocator.hxx +++ b/sw/source/core/inc/SearchResultLocator.hxx @@ -58,6 +58,8 @@ public: } LocationResult find(std::vector<SearchIndexData> const& rSearchIndexDataVector); + + LocationResult findForPayload(const char* pPayload); }; } // end sw namespace diff --git a/sw/source/core/model/ModelTraverser.cxx b/sw/source/core/model/ModelTraverser.cxx index 0a01f5cd97c5..bb959a95dec6 100644 --- a/sw/source/core/model/ModelTraverser.cxx +++ b/sw/source/core/model/ModelTraverser.cxx @@ -24,6 +24,7 @@ void ModelTraverser::traverse() auto const& pNodes = m_pDoc->GetNodes(); SwNode* pNode = nullptr; + for (sal_uLong n = 0; n < pNodes.Count(); ++n) { pNode = pNodes[n]; diff --git a/sw/source/core/model/SearchResultLocator.cxx b/sw/source/core/model/SearchResultLocator.cxx index e98db11befec..d08e7835f7ee 100644 --- a/sw/source/core/model/SearchResultLocator.cxx +++ b/sw/source/core/model/SearchResultLocator.cxx @@ -18,6 +18,9 @@ #include <IDocumentLayoutAccess.hxx> #include <tools/UnitConversion.hxx> +#include <tools/XmlWalker.hxx> +#include <tools/stream.hxx> + #include <svx/svdpage.hxx> #include <svx/svdobj.hxx> @@ -87,6 +90,53 @@ LocationResult SearchResultLocator::find(std::vector<SearchIndexData> const& rSe return aResult; } +LocationResult SearchResultLocator::findForPayload(const char* pPayload) +{ + LocationResult aResult; + + const OString aPayloadString(pPayload); + + SvMemoryStream aStream(const_cast<char*>(aPayloadString.getStr()), aPayloadString.getLength(), + StreamMode::READ); + tools::XmlWalker aWalker; + + if (!aWalker.open(&aStream)) + return aResult; + + if (aWalker.name() == "indexing") + { + std::vector<sw::search::SearchIndexData> aDataVector; + aWalker.children(); + while (aWalker.isValid()) + { + if (aWalker.name() == "paragraph") + { + OString sType = aWalker.attribute("type"); + OString sIndex = aWalker.attribute("index"); + + if (!sType.isEmpty() && !sIndex.isEmpty()) + { + sw::search::SearchIndexData aData; + aData.mnNodeIndex = sIndex.toInt32(); + aData.meType = sw::search::NodeType(sType.toInt32()); + + aDataVector.push_back(aData); + } + } + aWalker.next(); + } + aWalker.parent(); + + if (!aDataVector.empty()) + { + for (auto const& rSearchIndexData : aDataVector) + findOne(aResult, rSearchIndexData); + } + } + + return aResult; +} + } // end sw namespace /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index fa3019a2ebf3..eba39194a7e0 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -162,8 +162,6 @@ #include <tools/json_writer.hxx> #include <SearchResultLocator.hxx> -#include <boost/property_tree/json_parser.hpp> -#include <tools/XmlWalker.hxx> #define TWIPS_PER_PIXEL 15 @@ -3412,55 +3410,17 @@ void SwXTextDocument::executeFromFieldEvent(const StringMap& aArguments) std::vector<basegfx::B2DRange> SwXTextDocument::getSearchResultRectangles(const char* pPayload) { - std::vector<basegfx::B2DRange> aRectangles; - - const OString aPayloadString(pPayload); - - SvMemoryStream aStream(const_cast<char *>(aPayloadString.getStr()), aPayloadString.getLength(), StreamMode::READ); - tools::XmlWalker aWalker; - if (!aWalker.open(&aStream)) - return aRectangles; + SwDoc* pDoc = m_pDocShell->GetDoc(); + if (!pDoc) + return std::vector<basegfx::B2DRange>(); - if (aWalker.name() == "indexing") + sw::search::SearchResultLocator aLocator(pDoc); + sw::search::LocationResult aResult = aLocator.findForPayload(pPayload); + if (aResult.mbFound) { - SwDoc* pDoc = m_pDocShell->GetDoc(); - - std::vector<sw::search::SearchIndexData> aDataVector; - aWalker.children(); - while (aWalker.isValid()) - { - if (aWalker.name() == "paragraph") - { - OString sType = aWalker.attribute("type"); - OString sIndex = aWalker.attribute("index"); - - if (!sType.isEmpty() && !sIndex.isEmpty()) - { - sw::search::SearchIndexData aData; - aData.mnNodeIndex = sIndex.toInt32(); - aData.meType = sw::search::NodeType(sType.toInt32()); - - aDataVector.push_back(aData); - } - } - aWalker.next(); - } - aWalker.parent(); - - - if (!aDataVector.empty()) - { - sw::search::SearchResultLocator aLocator(pDoc); - sw::search::LocationResult aResult = aLocator.find(aDataVector); - if (aResult.mbFound) - { - for (auto const & rRect : aResult.maRectangles) - aRectangles.push_back(rRect); - } - } + return aResult.maRectangles; } - - return aRectangles; + return std::vector<basegfx::B2DRange>(); } int SwXTextDocument::getPart() |