comphelper: support property values arrays in JsonToPropertyValues()
Needed for an uncoming .uno:TextFormFields uno command where one of the parameters has the []com.sun.star.beans.PropertyValues type at an UNO level, and we can't provide JSON at the moment that would express that. Change-Id: I288a540b2fcac0e5a4a82bca235199c559ba2d0c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143302 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
This commit is contained in:
@@ -14,9 +14,12 @@
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
#include <comphelper/propertyvalue.hxx>
|
||||
#include <comphelper/propertysequence.hxx>
|
||||
#include <cppu/unotype.hxx>
|
||||
#include <o3tl/any.hxx>
|
||||
|
||||
using namespace com::sun::star;
|
||||
|
||||
namespace
|
||||
{
|
||||
class MakePropertyValueTest : public CppUnit::TestFixture
|
||||
@@ -25,6 +28,7 @@ class MakePropertyValueTest : public CppUnit::TestFixture
|
||||
CPPUNIT_TEST(testLvalue);
|
||||
CPPUNIT_TEST(testRvalue);
|
||||
CPPUNIT_TEST(testBitField);
|
||||
CPPUNIT_TEST(testJson);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void testLvalue()
|
||||
@@ -52,6 +56,73 @@ class MakePropertyValueTest : public CppUnit::TestFixture
|
||||
CPPUNIT_ASSERT_EQUAL(cppu::UnoType<bool>::get(), v.Value.getValueType());
|
||||
CPPUNIT_ASSERT_EQUAL(false, *o3tl::doAccess<bool>(v.Value));
|
||||
}
|
||||
|
||||
void testJson()
|
||||
{
|
||||
std::vector<beans::PropertyValue> aRet = comphelper::JsonToPropertyValues(R"json(
|
||||
{
|
||||
"FieldType": {
|
||||
"type": "string",
|
||||
"value": "vnd.oasis.opendocument.field.UNHANDLED"
|
||||
},
|
||||
"FieldCommandPrefix": {
|
||||
"type": "string",
|
||||
"value": "ADDIN ZOTERO_ITEM"
|
||||
},
|
||||
"Fields": {
|
||||
"type": "[][]com.sun.star.beans.PropertyValue",
|
||||
"value": [
|
||||
{
|
||||
"FieldType": {
|
||||
"type": "string",
|
||||
"value": "vnd.oasis.opendocument.field.UNHANDLED"
|
||||
},
|
||||
"FieldCommand": {
|
||||
"type": "string",
|
||||
"value": "ADDIN ZOTERO_ITEM new command 1"
|
||||
},
|
||||
"Fields": {
|
||||
"type": "string",
|
||||
"value": "new result 1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"FieldType": {
|
||||
"type": "string",
|
||||
"value": "vnd.oasis.opendocument.field.UNHANDLED"
|
||||
},
|
||||
"FieldCommandPrefix": {
|
||||
"type": "string",
|
||||
"value": "ADDIN ZOTERO_ITEM new command 2"
|
||||
},
|
||||
"Fields": {
|
||||
"type": "string",
|
||||
"value": "new result 2"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
)json");
|
||||
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), aRet.size());
|
||||
beans::PropertyValue aFirst = aRet[0];
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("FieldType"), aFirst.Name);
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("vnd.oasis.opendocument.field.UNHANDLED"),
|
||||
aFirst.Value.get<OUString>());
|
||||
beans::PropertyValue aSecond = aRet[1];
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("FieldCommandPrefix"), aSecond.Name);
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("ADDIN ZOTERO_ITEM"), aSecond.Value.get<OUString>());
|
||||
beans::PropertyValue aThird = aRet[2];
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("Fields"), aThird.Name);
|
||||
uno::Sequence<uno::Sequence<beans::PropertyValue>> aSeqs;
|
||||
aThird.Value >>= aSeqs;
|
||||
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), aSeqs.getLength());
|
||||
uno::Sequence<beans::PropertyValue> aFirstSeq = aSeqs[0];
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("FieldType"), aFirstSeq[0].Name);
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("FieldCommand"), aFirstSeq[1].Name);
|
||||
CPPUNIT_ASSERT_EQUAL(OUString("ADDIN ZOTERO_ITEM new command 1"),
|
||||
aFirstSeq[1].Value.get<OUString>());
|
||||
}
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(MakePropertyValueTest);
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <comphelper/propertysequence.hxx>
|
||||
#include <sal/log.hxx>
|
||||
#include <o3tl/string_view.hxx>
|
||||
#include <comphelper/sequence.hxx>
|
||||
|
||||
using namespace com::sun::star;
|
||||
|
||||
@@ -366,6 +367,19 @@ std::vector<css::beans::PropertyValue> JsonToPropertyValues(const OString& rJson
|
||||
aValue.Value <<= aSeq;
|
||||
}
|
||||
}
|
||||
else if (rType == "[][]com.sun.star.beans.PropertyValue")
|
||||
{
|
||||
aNodeValue = rPair.second.get_child("value", aNodeNull);
|
||||
std::vector<uno::Sequence<beans::PropertyValue>> aSeqs;
|
||||
for (const auto& rItem : aNodeValue)
|
||||
{
|
||||
std::stringstream s;
|
||||
boost::property_tree::write_json(s, rItem.second);
|
||||
std::vector<beans::PropertyValue> aPropertyValues = JsonToPropertyValues(s.str().c_str());
|
||||
aSeqs.push_back(comphelper::containerToSequence(aPropertyValues));
|
||||
}
|
||||
aValue.Value <<= comphelper::containerToSequence(aSeqs);
|
||||
}
|
||||
else
|
||||
SAL_WARN("comphelper", "JsonToPropertyValues: unhandled type '" << rType << "'");
|
||||
aArguments.push_back(aValue);
|
||||
|
||||
Reference in New Issue
Block a user