Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
core
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
LibreOffice
core
Commits
1664de4d
Kaydet (Commit)
1664de4d
authored
Haz 18, 2018
tarafından
Henry Castro
Kaydeden (comit)
Jan Holesovsky
Haz 19, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
lokit: add jsonToUnoAny
Change-Id: I79c2fe22fe7f3a8daa121ecaa529b6bca3216bf3
üst
b1d003af
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
78 additions
and
3 deletions
+78
-3
init.cxx
desktop/source/lib/init.cxx
+78
-3
No files found.
desktop/source/lib/init.cxx
Dosyayı görüntüle @
1664de4d
...
...
@@ -48,6 +48,9 @@
#include <com/sun/star/lang/Locale.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/reflection/theCoreReflection.hpp>
#include <com/sun/star/reflection/XIdlClass.hpp>
#include <com/sun/star/reflection/XIdlReflection.hpp>
#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
#include <com/sun/star/ucb/XContentProvider.hpp>
#include <com/sun/star/ucb/XUniversalContentBroker.hpp>
...
...
@@ -248,19 +251,79 @@ static OUString getAbsoluteURL(const char* pURL)
return
OUString
();
}
static
uno
::
Any
jsonToUnoAny
(
const
boost
::
property_tree
::
ptree
&
aTree
)
{
uno
::
Any
aAny
;
uno
::
Any
aValue
;
sal_Int32
nFields
;
uno
::
TypeClass
aTypeClass
;
uno
::
Reference
<
reflection
::
XIdlField
>
aField
;
boost
::
property_tree
::
ptree
aNodeNull
,
aNodeValue
,
aNodeField
;
const
std
::
string
&
rType
=
aTree
.
get
<
std
::
string
>
(
"type"
,
""
);
const
std
::
string
&
rValue
=
aTree
.
get
<
std
::
string
>
(
"value"
,
""
);
uno
::
Sequence
<
uno
::
Reference
<
reflection
::
XIdlField
>
>
aFields
;
uno
::
Reference
<
reflection
::
XIdlClass
>
xIdlClass
=
css
::
reflection
::
theCoreReflection
::
get
(
comphelper
::
getProcessComponentContext
())
->
forName
(
OUString
::
fromUtf8
(
rType
.
c_str
()));
if
(
xIdlClass
.
is
())
{
aTypeClass
=
xIdlClass
->
getTypeClass
();
xIdlClass
->
createObject
(
aAny
);
aFields
=
xIdlClass
->
getFields
();
nFields
=
aFields
.
getLength
();
aNodeValue
=
aTree
.
get_child
(
"value"
,
aNodeNull
);
if
(
nFields
>
0
&&
aNodeValue
!=
aNodeNull
)
{
for
(
sal_Int32
itField
=
0
;
itField
<
nFields
;
++
itField
)
{
aField
=
aFields
[
itField
];
aNodeField
=
aNodeValue
.
get_child
(
aField
->
getName
().
toUtf8
().
getStr
(),
aNodeNull
);
if
(
aNodeField
!=
aNodeNull
)
{
aValue
=
jsonToUnoAny
(
aNodeField
);
aField
->
set
(
aAny
,
aValue
);
}
}
}
else
if
(
!
rValue
.
empty
())
{
if
(
aTypeClass
==
uno
::
TypeClass_VOID
)
aAny
.
clear
();
else
if
(
aTypeClass
==
uno
::
TypeClass_BYTE
)
aAny
<<=
static_cast
<
sal_Int8
>
(
OString
(
rValue
.
c_str
()).
toInt32
());
else
if
(
aTypeClass
==
uno
::
TypeClass_BOOLEAN
)
aAny
<<=
OString
(
rValue
.
c_str
()).
toBoolean
();
else
if
(
aTypeClass
==
uno
::
TypeClass_SHORT
)
aAny
<<=
static_cast
<
sal_Int16
>
(
OString
(
rValue
.
c_str
()).
toInt32
());
else
if
(
aTypeClass
==
uno
::
TypeClass_UNSIGNED_SHORT
)
aAny
<<=
static_cast
<
sal_uInt16
>
(
OString
(
rValue
.
c_str
()).
toUInt32
());
else
if
(
aTypeClass
==
uno
::
TypeClass_LONG
)
aAny
<<=
OString
(
rValue
.
c_str
()).
toInt32
();
else
if
(
aTypeClass
==
uno
::
TypeClass_UNSIGNED_LONG
)
aAny
<<=
static_cast
<
sal_uInt32
>
(
OString
(
rValue
.
c_str
()).
toInt32
());
else
if
(
aTypeClass
==
uno
::
TypeClass_FLOAT
)
aAny
<<=
OString
(
rValue
.
c_str
()).
toFloat
();
else
if
(
aTypeClass
==
uno
::
TypeClass_DOUBLE
)
aAny
<<=
OString
(
rValue
.
c_str
()).
toDouble
();
else
if
(
aTypeClass
==
uno
::
TypeClass_STRING
)
aAny
<<=
OUString
::
fromUtf8
(
rValue
.
c_str
());
}
}
return
aAny
;
}
static
std
::
vector
<
beans
::
PropertyValue
>
jsonToPropertyValuesVector
(
const
char
*
pJSON
)
{
std
::
vector
<
beans
::
PropertyValue
>
aArguments
;
if
(
pJSON
&&
pJSON
[
0
]
!=
'\0'
)
{
boost
::
property_tree
::
ptree
aTree
;
boost
::
property_tree
::
ptree
aTree
,
aNodeNull
,
aNodeValue
;
std
::
stringstream
aStream
(
pJSON
);
boost
::
property_tree
::
read_json
(
aStream
,
aTree
);
for
(
const
auto
&
rPair
:
aTree
)
{
const
std
::
string
&
rType
=
rPair
.
second
.
get
<
std
::
string
>
(
"type"
);
const
std
::
string
&
rValue
=
rPair
.
second
.
get
<
std
::
string
>
(
"value"
);
const
std
::
string
&
rType
=
rPair
.
second
.
get
<
std
::
string
>
(
"type"
,
""
);
const
std
::
string
&
rValue
=
rPair
.
second
.
get
<
std
::
string
>
(
"value"
,
""
);
beans
::
PropertyValue
aValue
;
aValue
.
Name
=
OUString
::
fromUtf8
(
rPair
.
first
.
c_str
());
...
...
@@ -274,6 +337,18 @@ static std::vector<beans::PropertyValue> jsonToPropertyValuesVector(const char*
aValue
.
Value
<<=
OString
(
rValue
.
c_str
()).
toInt32
();
else
if
(
rType
==
"unsigned short"
)
aValue
.
Value
<<=
static_cast
<
sal_uInt16
>
(
OString
(
rValue
.
c_str
()).
toUInt32
());
else
if
(
rType
==
"[]any"
)
{
aNodeValue
=
rPair
.
second
.
get_child
(
"value"
,
aNodeNull
);
if
(
aNodeValue
!=
aNodeNull
&&
aNodeValue
.
size
()
>
0
)
{
sal_Int32
itSeq
=
0
;
uno
::
Sequence
<
uno
::
Any
>
aSeq
(
aNodeValue
.
size
());
for
(
const
auto
&
rSeqPair
:
aNodeValue
)
aSeq
[
itSeq
++
]
=
jsonToUnoAny
(
rSeqPair
.
second
);
aValue
.
Value
<<=
aSeq
;
}
}
else
SAL_WARN
(
"desktop.lib"
,
"jsonToPropertyValuesVector: unhandled type '"
<<
rType
<<
"'"
);
aArguments
.
push_back
(
aValue
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment