diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2021-08-02 22:27:28 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-09-02 11:21:31 +0200 |
commit | 43d30b5031396d8842b0a70cad7d095ee4be1fdd (patch) | |
tree | 3646521374e0e8f190693e72a38606dcb578cc1e /sw | |
parent | a9b2ebe1ea5576ab1ef6e58b3da20162a056d217 (diff) |
indexing: use XML as input that is identical to indexing XML
Change-Id: I2242b4bd77220b55e67c2e0f0fe54f008759d282
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120194
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
(cherry picked from commit 7da5537f6a43c1b82afc5e0c8d18b8d847293fda)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121113
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/uibase/uno/unotxdoc.cxx | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index 6f4a24402ca5..3f029d1b53e6 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -124,7 +124,6 @@ #include <swruler.hxx> #include <docufld.hxx> - #include <EnhancedPDFExportHelper.hxx> #include <numrule.hxx> @@ -164,6 +163,8 @@ #include <SearchResultLocator.hxx> #include <boost/property_tree/json_parser.hpp> +#include <tools/XmlWalker.hxx> + #define TWIPS_PER_PIXEL 15 using namespace ::com::sun::star; @@ -3413,23 +3414,45 @@ SwXTextDocument::getSearchResultRectangles(const char* pPayload) { std::vector<basegfx::B2DRange> aRectangles; - boost::property_tree::ptree aTree; - std::stringstream aStream(pPayload); - boost::property_tree::read_json(aStream, aTree); + const OString aPayloadString(pPayload); - sw::search::SearchIndexData aData; + SvMemoryStream aStream(const_cast<char *>(aPayloadString.getStr()), aPayloadString.getLength(), StreamMode::READ); + tools::XmlWalker aWalker; + if (!aWalker.open(&aStream)) + return aRectangles; - int nType = aTree.get<int>("type"); + if (aWalker.name() == "indexing") + { + SwDoc* pDoc = m_pDocShell->GetDoc(); - aData.nNodeIndex = sal_uInt32(aTree.get<int>("node_index")); - aData.eType = sw::search::NodeType(nType); + sw::search::SearchIndexData aData; - SwDoc* pDoc = m_pDocShell->GetDoc(); + aWalker.children(); + while (aWalker.isValid()) + { + if (aWalker.name() == "paragraph") + { + OString sType = aWalker.attribute("type"); + OString sIndex = aWalker.attribute("index"); + + if (!sType.isEmpty() && !sIndex.isEmpty()) + { + aData.nNodeIndex = sIndex.toInt32(); + aData.eType = sw::search::NodeType(sType.toInt32()); - sw::search::SearchResultLocator aLocator(pDoc); - sw::search::LocationResult aResult = aLocator.find(aData); - if (aResult.mbFound) - aRectangles = aResult.maRectangles; + sw::search::SearchResultLocator aLocator(pDoc); + sw::search::LocationResult aResult = aLocator.find(aData); + if (aResult.mbFound) + { + for (auto const & rRect : aResult.maRectangles) + aRectangles.push_back(rRect); + } + } + } + aWalker.next(); + } + aWalker.parent(); + } return aRectangles; } |