summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2021-08-02 22:27:28 +0900
committerTomaž Vajngerl <quikee@gmail.com>2021-08-10 08:32:57 +0200
commit7da5537f6a43c1b82afc5e0c8d18b8d847293fda (patch)
treec0f50cd596465a83faac448de6e28f9fb6d1e88b
parentfa5202f746b25ea444d120d746a0dc35b8f8cca5 (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>
-rw-r--r--desktop/qa/desktop_lib/test_desktop_lib.cxx7
-rw-r--r--sw/source/uibase/uno/unotxdoc.cxx49
2 files changed, 40 insertions, 16 deletions
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index f23f9709416e..dc8b4caf1de4 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -3117,13 +3117,16 @@ void DesktopLOKTest::testRenderSearchResult()
Scheduler::ProcessEventsToIdle();
unsigned char* pBuffer = nullptr;
- OString aJSON = "{ \"type\" : 1, \"node_index\" : 19 }";
+ OString aPayload =
+ "<indexing>"
+ "<paragraph type=\"1\" index=\"19\">ABC</paragraph>"
+ "</indexing>";
int nWidth = 0;
int nHeight = 0;
size_t nByteSize = 0;
- bool bResult = pDocument->m_pDocumentClass->renderSearchResult(pDocument, aJSON.getStr(), &pBuffer, &nWidth, &nHeight, &nByteSize);
+ bool bResult = pDocument->m_pDocumentClass->renderSearchResult(pDocument, aPayload.getStr(), &pBuffer, &nWidth, &nHeight, &nByteSize);
CPPUNIT_ASSERT(bResult);
CPPUNIT_ASSERT(pBuffer);
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index 2940c52b8256..51dfac84254c 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -122,7 +122,6 @@
#include <swruler.hxx>
#include <docufld.hxx>
-
#include <EnhancedPDFExportHelper.hxx>
#include <numrule.hxx>
@@ -164,7 +163,7 @@
#include <IDocumentOutlineNodes.hxx>
#include <SearchResultLocator.hxx>
-#include <boost/property_tree/json_parser.hpp>
+#include <tools/XmlWalker.hxx>
#define TWIPS_PER_PIXEL 15
@@ -3397,23 +3396,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;
}