16 #include <QStringList>
19 class KDSoapValue::Private :
public QSharedData
27 Private(
const QString &n,
const QVariant &v,
const QString &typeNameSpace,
const QString &typeName)
30 , m_typeNamespace(typeNameSpace)
31 , m_typeName(typeName)
38 QString m_nameNamespace;
40 QString m_typeNamespace;
45 QXmlStreamNamespaceDeclarations m_environmentNamespaceDeclarations;
46 QXmlStreamNamespaceDeclarations m_localNamespaceDeclarations;
60 : d(new Private(n, v, typeNameSpace, typeName))
65 : d(new Private(n, QVariant(), typeNameSpace, typeName))
67 d->m_childValues = children;
81 return d->m_name.isEmpty() &&
isNil();
86 return d->m_value.isNull() && d->m_childValues.isEmpty() && d->m_childValues.attributes().isEmpty();
91 d->m_nillable = nillable;
116 return d->m_qualified;
121 d->m_qualified = qualified;
131 d->m_localNamespaceDeclarations.append(namespaceDeclaration);
136 return d->m_localNamespaceDeclarations;
146 return d->m_environmentNamespaceDeclarations;
167 switch (value.userType()) {
170 case QVariant::String:
171 return value.toString();
174 return value.toUrl().toString();
175 case QVariant::ByteArray: {
176 const QByteArray data = value.toByteArray();
178 if (type == QLatin1String(
"hexBinary")) {
179 const QByteArray hb = data.toHex();
180 return QString::fromLatin1(hb.constData(), hb.size());
184 const QByteArray b64 = value.toByteArray().toBase64();
185 return QString::fromLatin1(b64.constData(), b64.size());
189 case QVariant::LongLong:
192 return QString::number(value.toLongLong());
193 case QVariant::ULongLong:
194 return QString::number(value.toULongLong());
196 case QMetaType::Float:
197 case QVariant::Double:
198 return value.toString();
199 case QVariant::Time: {
200 const QTime time = value.toTime();
203 return time.toString(QLatin1String(
"hh:mm:ss.zzz"));
205 return time.toString(Qt::ISODate);
209 return value.toDate().toString(Qt::ISODate);
210 case QVariant::DateTime:
212 case QVariant::Invalid:
213 qDebug() <<
"ERROR: Got invalid QVariant in a KDSoapValue";
217 return value.value<
KDDateTime>().toDateString();
220 if (value.userType() == qMetaTypeId<float>()) {
221 return QString::number(value.value<
float>());
224 qDebug() << QString::fromLatin1(
"QVariants of type %1 are not supported in "
225 "KDSoap, see the documentation")
226 .arg(QLatin1String(value.typeName()));
227 return value.toString();
234 switch (value.userType()) {
237 case QVariant::String:
240 return QLatin1String(
"xsd:string");
241 case QVariant::ByteArray:
242 return QLatin1String(
"xsd:base64Binary");
245 case QVariant::LongLong:
248 return QLatin1String(
"xsd:int");
249 case QVariant::ULongLong:
250 return QLatin1String(
"xsd:unsignedInt");
252 return QLatin1String(
"xsd:boolean");
253 case QMetaType::Float:
254 return QLatin1String(
"xsd:float");
255 case QVariant::Double:
256 return QLatin1String(
"xsd:double");
258 return QLatin1String(
"xsd:time");
260 return QLatin1String(
"xsd:date");
261 case QVariant::DateTime:
262 return QLatin1String(
"xsd:dateTime");
264 if (value.userType() == qMetaTypeId<float>()) {
265 return QLatin1String(
"xsd:float");
268 return QLatin1String(
"xsd:dateTime");
273 qDebug() << QString::fromLatin1(
"variantToXmlType: QVariants of type %1 are not supported in "
274 "KDSoap, see the documentation")
275 .arg(QLatin1String(value.typeName()));
281 const QString &messageNamespace,
bool forceQualified)
const
283 Q_ASSERT(!
name().isEmpty());
284 if (!d->m_nameNamespace.isEmpty() && d->m_nameNamespace != messageNamespace) {
285 forceQualified =
true;
288 if (d->m_qualified || forceQualified) {
289 const QString ns = d->m_nameNamespace.isEmpty() ? messageNamespace : d->m_nameNamespace;
294 writer.writeStartElement(ns,
name());
296 writer.writeStartElement(
name());
298 writeElementContents(namespacePrefixes, writer, use, messageNamespace);
299 writer.writeEndElement();
303 const QString &messageNamespace)
const
307 for (
const QXmlStreamNamespaceDeclaration &decl : qAsConst(d->m_localNamespaceDeclarations)) {
308 writer.writeNamespace(decl.namespaceUri().toString(), decl.prefix().toString());
311 if (
isNil() && d->m_nillable) {
318 if (!this->
type().isEmpty()) {
321 if (type.isEmpty() && !
value.isNull()) {
324 if (!
type.isEmpty()) {
329 const bool isArray = !list.
arrayType().isEmpty();
336 writeChildren(namespacePrefixes, writer, use, messageNamespace,
false);
338 if (!
value.isNull()) {
340 if (!txt.isEmpty()) {
341 writer.writeCharacters(txt);
347 const QString &messageNamespace,
bool forceQualified)
const
354 const QString attributeNamespace = attr.namespaceUri();
355 if (attr.isQualified() || forceQualified) {
356 writer.writeAttribute(attributeNamespace, attr.name(),
variantToTextValue(attr.value(), attr.typeNs(), attr.type()));
358 writer.writeAttribute(attr.name(),
variantToTextValue(attr.value(), attr.typeNs(), attr.type()));
362 while (it.hasNext()) {
364 element.writeElement(namespacePrefixes, writer, use, messageNamespace, forceQualified);
372 dbg.space() << value.
name() << value.
value();
376 while (it.hasNext()) {
380 dbg <<
"</children>";
383 dbg <<
"<attributes>";
385 while (it.hasNext()) {
389 dbg <<
"</attributes>";
396 d->m_typeNamespace = nameSpace;
397 d->m_typeName =
type;
402 return d->m_typeNamespace;
407 return d->m_typeName;
413 #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
414 const QStringList list =
value().toString().split(QLatin1Char(
' '), Qt::SkipEmptyParts);
416 const QStringList list =
value().toString().split(QLatin1Char(
' '), QString::SkipEmptyParts);
418 valueList.reserve(list.count());
419 for (
const QString &part : qAsConst(list)) {
421 value.setValue(part);
430 if (val.name() == name) {
439 m_arrayType = qMakePair(nameSpace, type);
444 return m_arrayType.first;
449 return m_arrayType.second;
454 append(
KDSoapValue(argumentName, argumentValue, typeNameSpace, typeName));
459 return d->m_nameNamespace;
464 d->m_nameNamespace = ns;
470 QXmlStreamWriter writer(&data);
471 writer.writeStartDocument();
476 writeElement(namespacePrefixes, writer, use, messageNamespace,
false);
477 writer.writeEndDocument();
static QString variantToTextValue(const QVariant &value, const QString &typeNs, const QString &type)
static QString variantToXMLType(const QVariant &value)
QDebug operator<<(QDebug dbg, const KDSoapValue &value)
uint qHash(const KDSoapValue &value)
QListIterator< KDSoapValue > KDSoapValueListIterator
QString toDateString() const
static QString soapEncoding()
static QString xmlSchema1999()
static QString xmlSchemaInstance2001()
static QString xmlSchema2001()
void writeStandardNamespaces(QXmlStreamWriter &writer, KDSoap::SoapVersion version=KDSoap::SOAP1_1, bool messageAddressingEnabled=false, KDSoapMessageAddressingProperties::KDSoapAddressingNamespace messageAddressingNamespace=KDSoapMessageAddressingProperties::Addressing200508)
QString resolve(const QString &ns, const QString &localName) const
QList< KDSoapValue > & attributes()
QString arrayTypeNs() const
KDSoapValue child(const QString &name) const
QString arrayType() const
void addArgument(const QString &argumentName, const QVariant &argumentValue, const QString &typeNameSpace=QString(), const QString &typeName=QString())
void setArrayType(const QString &nameSpace, const QString &type)
KDSoapValueList & childValues() const
@ EncodedUse
each message part references an abstract type using the xsi:type attribute
QXmlStreamNamespaceDeclarations environmentNamespaceDeclarations() const
void addNamespaceDeclaration(const QXmlStreamNamespaceDeclaration &namespaceDeclaration)
QXmlStreamNamespaceDeclarations namespaceDeclarations() const
void setNamespaceUri(const QString &ns)
void setName(const QString &name)
QString namespaceUri() const
void setNillable(bool nillable)
void setType(const QString &nameSpace, const QString &type)
void setNamespaceDeclarations(const QXmlStreamNamespaceDeclarations &namespaceDeclarations)
bool operator==(const KDSoapValue &other) const
void setValue(const QVariant &value)
void setEnvironmentNamespaceDeclarations(const QXmlStreamNamespaceDeclarations &environmentNamespaceDeclarations)
QByteArray toXml(Use use=LiteralUse, const QString &messageNamespace=QString()) const
KDSoapValueList split() const
bool operator!=(const KDSoapValue &other) const
void setQualified(bool qualified)