diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-11-29 16:18:16 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-11-30 08:13:28 +0100 |
commit | 5e8f6dcb8ce00d2d5e35b3cf5654187b3068276c (patch) | |
tree | 0d81eed04980c244163f064db63269f30dc077d3 /sw/qa/uibase | |
parent | 1d9221ebc86f2696a65c12287ea19eea44d680cf (diff) |
sw lok, .uno:SetDocumentProperties: expose value of custom document properties
LOK API clients currently have no knowledge about document properties.
Clients like Zotero that want to store custom properties on documents
need a way to read and write such properties. This commit focuses on the
reading side.
Add a getter for .uno:SetDocumentProperties that allows filtering for a
certain prefix, this way the returned value can contain only the
relevant information.
Rework doc_getCommandValues() and SwXTextDocument::getCommandValues() a
bit, so adding new getters require less duplication.
Change-Id: I0c52cd2efcc8b1ea7307763c8252dd1e8ffdea2d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143468
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw/qa/uibase')
-rw-r--r-- | sw/qa/uibase/uno/uno.cxx | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/sw/qa/uibase/uno/uno.cxx b/sw/qa/uibase/uno/uno.cxx index 02d95df370c4..8e6b06453d86 100644 --- a/sw/qa/uibase/uno/uno.cxx +++ b/sw/qa/uibase/uno/uno.cxx @@ -15,6 +15,7 @@ #include <com/sun/star/text/XTextViewTextRangeSupplier.hpp> #include <com/sun/star/util/XCloseable.hpp> #include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/beans/PropertyAttribute.hpp> #include <vcl/scheduler.hxx> #include <tools/json_writer.hxx> @@ -195,12 +196,46 @@ CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testGetTextFormFields) std::stringstream aStream(pJSON.get()); boost::property_tree::ptree aTree; boost::property_tree::read_json(aStream, aTree); - // Without the needed PixelToLogic() call in place, this test would have failed with: + // Without the accompanying fix in place, this test would have failed with: // - No such node (fields) // i.e. the returned JSON was just empty. CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), aTree.get_child("fields").count("")); } +CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testGetDocumentProperties) +{ + // Given a document with 3 custom properties: 2 zotero ones and an other one: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + SwDocShell* pDocShell = pDoc->GetDocShell(); + uno::Reference<document::XDocumentPropertiesSupplier> xDPS(pDocShell->GetModel(), + uno::UNO_QUERY); + uno::Reference<document::XDocumentProperties> xDP = xDPS->getDocumentProperties(); + uno::Reference<beans::XPropertyContainer> xUDP = xDP->getUserDefinedProperties(); + xUDP->addProperty("ZOTERO_PREF_1", beans::PropertyAttribute::REMOVABLE, + uno::Any(OUString("foo"))); + xUDP->addProperty("ZOTERO_PREF_2", beans::PropertyAttribute::REMOVABLE, + uno::Any(OUString("bar"))); + xUDP->addProperty("OTHER", beans::PropertyAttribute::REMOVABLE, uno::Any(OUString("baz"))); + + // When getting the zotero properties: + tools::JsonWriter aJsonWriter; + std::string_view aCommand(".uno:SetDocumentProperties?namePrefix=ZOTERO_PREF_"); + auto pXTextDocument = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + pXTextDocument->getCommandValues(aJsonWriter, aCommand); + + // Then make sure we find the 2 properties and ignore the other one: + std::unique_ptr<char[], o3tl::free_delete> pJSON(aJsonWriter.extractData()); + std::stringstream aStream(pJSON.get()); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + // Without the accompanying fix in place, this test would have failed with: + // - No such node (userDefinedProperties) + // i.e. the returned JSON was just empty. + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), + aTree.get_child("userDefinedProperties").count("")); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |