/* **************************************************************************** * * ContextElement::render - */ std::string ContextElement::render(ConnectionInfo* ciP, RequestType requestType, const std::string& indent, bool comma, bool omitAttributeValues) { std::string out = ""; std::string xmlTag = "contextElement"; std::string jsonTag = "contextElement"; bool attributeDomainNameRendered = attributeDomainName.get() != ""; bool contextAttributeVectorRendered = contextAttributeVector.size() != 0; bool domainMetadataVectorRendered = domainMetadataVector.size() != 0; bool commaAfterDomainMetadataVector = false; // Last element bool commaAfterContextAttributeVector = domainMetadataVectorRendered; bool commaAfterAttributeDomainName = domainMetadataVectorRendered || contextAttributeVectorRendered; bool commaAfterEntityId = commaAfterAttributeDomainName || attributeDomainNameRendered; if (requestType == UpdateContext) { out += startTag(indent, xmlTag, jsonTag, ciP->outFormat, false, false); } else { out += startTag(indent, xmlTag, jsonTag, ciP->outFormat, false, true); } out += entityId.render(ciP->outFormat, indent + " ", commaAfterEntityId, false); out += attributeDomainName.render(ciP->outFormat, indent + " ", commaAfterAttributeDomainName); out += contextAttributeVector.render(ciP, requestType, indent + " ", commaAfterContextAttributeVector, omitAttributeValues); out += domainMetadataVector.render(ciP->outFormat, indent + " ", commaAfterDomainMetadataVector); out += endTag(indent, xmlTag, ciP->outFormat, comma, false); return out; }
/* **************************************************************************** * * startTag - */ TEST(commonTag, startTag) { std::string tag = "TAG"; std::string out; out = startTag(tag, false); EXPECT_EQ("\"TAG\":{", out); out = startTag(tag, true); EXPECT_EQ("\"TAG\":[", out); out = startTag(); EXPECT_EQ("{", out); }
static bool isValueStr(const STString &str) { bool ret = false; if( str.empty() ) { return ret; } STString valueTag = getFirstTagName(str); if ("bool" != valueTag && "int" != valueTag && "string" != valueTag) { return ret; } STString startTag("<" + valueTag + ">"); STString endTag("</" + valueTag + ">"); int beginPos = str.find(startTag); int endPos = str.find_last_of(endTag); if (findError(beginPos) || findError(endPos) ) { return ret; } else { ret = true; } return ret; }
/* **************************************************************************** * * QueryContextResponse::render - */ std::string QueryContextResponse::render(RequestType requestType, Format format, std::string indent) { std::string out = ""; std::string tag = "queryContextResponse"; out += startTag(indent, tag, format, false); if ((errorCode.code == SccNone) || (errorCode.code == SccOk)) { if (contextElementResponseVector.size() == 0) { errorCode.fill(SccContextElementNotFound); out += errorCode.render(format, indent + " "); } else { out += contextElementResponseVector.render(QueryContext, format, indent + " "); } } else out += errorCode.render(format, indent + " "); out += endTag(indent, tag, format); return out; }
/* **************************************************************************** * * ContextElement::render - */ std::string ContextElement::render(RequestType requestType, Format format, const std::string& indent, bool comma) { std::string out = ""; std::string xmlTag = "contextElement"; std::string jsonTag = "contextElement"; bool attributeDomainNameRendered = attributeDomainName.get() != ""; bool contextAttributeVectorRendered = contextAttributeVector.size() != 0; bool domainMetadataVectorRendered = domainMetadataVector.size() != 0; bool commaAfterDomainMetadataVector = false; // Last element bool commaAfterContextAttributeVector = domainMetadataVectorRendered; bool commaAfterAttributeDomainName = domainMetadataVectorRendered || contextAttributeVectorRendered; bool commaAfterEntityId = domainMetadataVectorRendered || contextAttributeVectorRendered || attributeDomainNameRendered; out += startTag(indent, xmlTag, jsonTag, format, false, true); out += entityId.render(format, indent + " ", commaAfterEntityId, false); out += attributeDomainName.render(format, indent + " ", commaAfterAttributeDomainName); out += contextAttributeVector.render(requestType, format, indent + " ", commaAfterContextAttributeVector); out += domainMetadataVector.render(format, indent + " ", commaAfterDomainMetadataVector); out += endTag(indent, xmlTag, format, comma, false); return out; }
/* **************************************************************************** * * SubscribeContextRequest::render - */ std::string SubscribeContextRequest::render(RequestType requestType, Format format, const std::string& indent) { std::string out = ""; std::string tag = "subscribeContextRequest"; std::string indent2 = indent + " "; bool attributeListRendered = attributeList.size() != 0; bool referenceRendered = true; // Mandatory bool durationRendered = duration.get() != ""; bool restrictionRendered = restrictions != 0; bool notifyConditionVectorRendered = notifyConditionVector.size() != 0; bool throttlingRendered = throttling.get() != ""; bool commaAfterThrottling = false; // Last element; bool commaAfterNotifyConditionVector = throttlingRendered; bool commaAfterRestriction = notifyConditionVectorRendered || throttlingRendered; bool commaAfterDuration = restrictionRendered || notifyConditionVectorRendered || throttlingRendered; bool commaAfterReference = durationRendered || restrictionRendered ||notifyConditionVectorRendered || throttlingRendered; bool commaAfterAttributeList = referenceRendered || durationRendered || restrictionRendered ||notifyConditionVectorRendered || throttlingRendered; bool commaAfterEntityIdVector = attributeListRendered || referenceRendered || durationRendered || restrictionRendered ||notifyConditionVectorRendered || throttlingRendered; out += startTag(indent, tag, format, false); out += entityIdVector.render(format, indent2, commaAfterEntityIdVector); out += attributeList.render(format, indent2, commaAfterAttributeList); out += reference.render(format, indent2, commaAfterReference); out += duration.render(format, indent2, commaAfterDuration); out += restriction.render(format, indent2, restrictions, commaAfterRestriction); out += notifyConditionVector.render(format, indent2, commaAfterNotifyConditionVector); out += throttling.render(format, indent2, commaAfterThrottling); out += endTag(indent, tag, format); return out; }
/* **************************************************************************** * * ContextElementVector::render - */ std::string ContextElementVector::render ( ConnectionInfo* ciP, RequestType requestType, const std::string& indent, bool comma ) { std::string out = ""; std::string xmlTag = "contextElementList"; std::string jsonTag = "contextElements"; if (vec.size() == 0) { return ""; } out += startTag(indent, xmlTag, jsonTag, ciP->outFormat, true, true); for (unsigned int ix = 0; ix < vec.size(); ++ix) { out += vec[ix]->render(ciP, requestType, indent + " ", ix != vec.size() - 1); } out += endTag(indent, xmlTag, ciP->outFormat, comma, true); return out; }
/* **************************************************************************** * * StatusCode::render - */ std::string StatusCode::render(Format format, const std::string& indent, bool comma, bool showTag) { std::string out = ""; if (strstr(details.c_str(), "\"") != NULL) { int len = details.length() * 2; char* s2 = (char*) calloc(1, len + 1); strReplace(s2, len, details.c_str(), "\"", "\\\""); details = s2; free(s2); } if (code == SccNone) { fill(SccReceiverInternalError, ""); details += " - ZERO code set to 500"; } out += startTag(indent, tag, format, showTag); out += valueTag(indent + " ", "code", code, format, true); out += valueTag(indent + " ", "reasonPhrase", reasonPhrase, format, details != ""); if (details != "") { out += valueTag(indent + " ", "details", details, format, false); } out += endTag(indent, tag, format, comma); return out; }
/* **************************************************************************** * * EntityTypeVector::render - */ std::string EntityTypeVector::render ( ConnectionInfo* ciP, const std::string& indent, bool comma ) { std::string out = ""; std::string xmlTag = "typeEntities"; std::string jsonTag = "types"; if (vec.size() > 0) { out += startTag(indent, xmlTag, jsonTag, ciP->outFormat, true, true); for (unsigned int ix = 0; ix < vec.size(); ++ix) { out += vec[ix]->render(ciP, indent + " ", ix != vec.size() - 1); } out += endTag(indent, xmlTag, ciP->outFormat, comma, true); } return out; }
/* **************************************************************************** * * UpdateContextSubscriptionRequest::render - */ std::string UpdateContextSubscriptionRequest::render(RequestType requestType, Format format, std::string indent) { std::string out = ""; std::string tag = "updateContextSubscriptionRequest"; bool restrictionRendered = restrictions != 0; bool subscriptionIdRendered = true; // Mandatory bool notifyConditionVectorRendered = notifyConditionVector.size() != 0; bool throttlingRendered = throttling.get() != ""; bool commaAfterThrottling = false; // Last element bool commaAfterNotifyConditionVector = throttlingRendered; bool commaAfterSubscriptionId = notifyConditionVectorRendered || throttlingRendered; bool commaAfterRestriction = subscriptionIdRendered || notifyConditionVectorRendered || throttlingRendered; bool commaAfterDuration = restrictionRendered || subscriptionIdRendered || notifyConditionVectorRendered || throttlingRendered; out += startTag(indent, tag, format, false); out += duration.render(format, indent + " ", commaAfterDuration); out += restriction.render(format, indent + " ", restrictions, commaAfterRestriction); out += subscriptionId.render(UpdateContextSubscription, format, indent + " ", commaAfterSubscriptionId); out += notifyConditionVector.render(format, indent + " ", commaAfterNotifyConditionVector); out += throttling.render(format, indent + " ", commaAfterThrottling); out += endTag(indent, tag, format); return out; }
/* **************************************************************************** * * TypeEntityVector::render - */ std::string TypeEntityVector::render ( ConnectionInfo* ciP, const std::string& indent, bool comma ) { std::string out = ""; std::string xmlTag = "typeEntities"; std::string jsonTag = "types"; if (vec.size() > 0) { if ((ciP->uriParam["attributesFormat"] == "object") && (ciP->outFormat == JSON)) { return renderAsJsonObject(ciP, indent, comma); } out += startTag(indent, xmlTag, jsonTag, ciP->outFormat, true, true); for (unsigned int ix = 0; ix < vec.size(); ++ix) { out += vec[ix]->render(ciP, indent + " ", ix != vec.size() - 1); } out += endTag(indent, xmlTag, ciP->outFormat, comma, true); } return out; }
/* **************************************************************************** * * OrionError::render - */ std::string OrionError::render(Format format, const std::string& _indent) { std::string out = ""; std::string tag = "orionError"; std::string initialIndent = _indent; std::string indent = _indent; // // OrionError is NEVER part of any other payload, so the JSON start/end braces must be added here // if (format == JSON) { out = initialIndent + "{\n"; indent += " "; } out += startTag(indent, tag, format); out += valueTag(indent + " ", "code", code, format, true); out += valueTag(indent + " ", "reasonPhrase", reasonPhrase, format, details != ""); if (details != "") out += valueTag(indent + " ", "details", details, format); out += endTag(indent, tag, format); if (format == JSON) out += initialIndent + "}\n"; return out; }
/* **************************************************************************** * * DiscoverContextAvailabilityResponse::toJsonV1 - */ std::string DiscoverContextAvailabilityResponse::toJsonV1(void) { std::string out = ""; // // JSON commas: // Exactly ONE of responseVector|errorCode is included in the discovery response so, // no JSON commas necessary // out += startTag(); if (responseVector.size() > 0) { bool commaNeeded = (errorCode.code != SccNone); out += responseVector.toJsonV1(commaNeeded); } if (errorCode.code != SccNone) { out += errorCode.toJsonV1(false); } /* Safety check: neither errorCode nor CER vector was filled by mongoBackend */ if (errorCode.code == SccNone && responseVector.size() == 0) { errorCode.fill(SccReceiverInternalError, "Both the error-code structure and the response vector were empty"); out += errorCode.toJsonV1(false); } out += endTag(); return out; }
/* **************************************************************************** * * AppendContextElementResponse::render - */ std::string AppendContextElementResponse::render(ConnectionInfo* ciP, RequestType requestType, std::string indent) { std::string tag = "appendContextElementResponse"; std::string out = ""; out += startTag(indent, tag, ciP->outFormat, false); if ((errorCode.code != SccNone) && (errorCode.code != SccOk)) { out += errorCode.render(ciP->outFormat, indent + " "); } else { if (entity.id != "") { out += entity.render(ciP->outFormat, indent + " ", true); } out += contextResponseVector.render(ciP, requestType, indent + " "); } out += endTag(indent, tag, ciP->outFormat); return out; }
/* **************************************************************************** * * UpdateContextResponse::render - */ std::string UpdateContextResponse::render(ConnectionInfo* ciP, RequestType requestType, const std::string& indent) { std::string out = ""; std::string tag = "updateContextResponse"; out += startTag(indent, tag, ciP->outFormat, false); if ((errorCode.code != SccNone) && (errorCode.code != SccOk)) { out += errorCode.render(ciP->outFormat, indent + " "); } else { if (contextElementResponseVector.size() == 0) { errorCode.fill(SccContextElementNotFound, errorCode.details); out += errorCode.render(ciP->outFormat, indent + " "); } else out += contextElementResponseVector.render(ciP, RtUpdateContextResponse, indent + " ", false); } out += endTag(indent, tag, ciP->outFormat); return out; }
/* **************************************************************************** * * render - */ std::string UpdateContextElementRequest::render(RequestType requestType, Format format, std::string indent) { std::string tag = "updateContextElementRequest"; std::string out = ""; out += startTag(indent, tag, format, false); out += attributeDomainName.render(format, indent + " ", true); out += contextAttributeVector.render(requestType, format, indent + " "); out += endTag(indent, tag, format); return out; }
/* **************************************************************************** * * NotifyContextAvailabilityResponse::render - */ std::string NotifyContextAvailabilityResponse::render(RequestType requestType, Format format, std::string indent) { std::string out = ""; std::string tag = "notifyContextAvailabilityResponse"; responseCode.tagSet("responseCode"); out += startTag(indent, tag, format, false); out += responseCode.render(format, indent + " "); out += endTag(indent, tag, format); return out; }
/* **************************************************************************** * * ContextElementResponse::render - */ std::string ContextElementResponse::render(RequestType requestType, Format format, std::string indent, bool comma) { std::string xmlTag = "contextElementResponse"; std::string jsonTag = "contextElement"; std::string out = ""; out += startTag(indent, xmlTag, jsonTag, format, false, false); out += contextElement.render(requestType, format, indent + " ", true); out += statusCode.render(format, indent + " ", false); out += endTag(indent, xmlTag, format, comma, false); return out; }
bool TupXmlParserBase::startElement(const QString& , const QString& , const QString& qname, const QXmlAttributes& atts) { if (k->ignore) return true; if (k->root.isEmpty()) k->root = qname; bool r = startTag(qname, atts); k->currentTag = qname; return r; }
/* **************************************************************************** * * render - */ std::string UpdateContextAttributeRequest::render(Format format, std::string indent) { std::string tag = "updateContextAttributeRequest"; std::string out = ""; std::string indent2 = indent + " "; out += startTag(indent, tag, format, false); out += valueTag(indent2, "type", type, format, true); out += valueTag(indent2, "contextValue", contextValue, format, true); out += metadataVector.render(format, indent2); out += endTag(indent, tag, format); return out; }
/* **************************************************************************** * * EntityTypeAttributesResponse::render - */ std::string EntityTypeAttributesResponse::render(ConnectionInfo* ciP, const std::string& indent) { std::string out = ""; std::string tag = "entityTypeAttributesResponse"; out += startTag(indent, tag, ciP->outFormat, false); out += entityType.render(ciP, indent + " ", true, true); out += statusCode.render(ciP->outFormat, indent + " "); out += endTag(indent, tag, ciP->outFormat); return out; }
/* **************************************************************************** * * Scope::render - */ std::string Scope::render(Format format, std::string indent, bool notLastInVector) { std::string out = ""; std::string tag = "operationScope"; const char* tTag = (format == XML)? "scopeType" : "type"; const char* vTag = (format == XML)? "scopeValue" : "value"; out += startTag(indent, tag, tag, format, false, false); out += valueTag(indent + " ", tTag, type, format, true); out += valueTag(indent + " ", vTag, value, format); out += endTag(indent, tag, format, notLastInVector); return out; }
/* **************************************************************************** * * UpdateContextRequest::render - */ std::string UpdateContextRequest::render(RequestType requestType, Format format, const std::string& indent) { std::string out = ""; std::string tag = "updateContextRequest"; // JSON commas: // Both fields are MANDATORY, so, comma after "contextElementVector" // out += startTag(indent, tag, format, false); out += contextElementVector.render(UpdateContext, format, indent + " ", true); out += updateActionType.render(format, indent + " ", false); out += endTag(indent, tag, format, false); return out; }
/* **************************************************************************** * * EntityTypesResponse::renderAsJsonObject - */ std::string EntityTypesResponse::renderAsJsonObject(ConnectionInfo* ciP, const std::string& indent) { std::string out = ""; out += startTag(indent, "", ciP->outFormat, false); if (typeEntityVector.size() > 0) out += typeEntityVector.render(ciP, indent + " ", true); out += statusCode.render(ciP->outFormat, indent + " "); out += endTag(indent, "", ciP->outFormat); return out; }
/* **************************************************************************** * * SubscribeResponse::render - */ std::string SubscribeResponse::render(Format format, std::string indent, bool comma) { std::string out = ""; std::string tag = "subscribeResponse"; bool durationRendered = !duration.isEmpty(); bool throttlingRendered = !throttling.isEmpty(); out += startTag(indent, tag, format); out += subscriptionId.render(RtSubscribeResponse, format, indent + " ", durationRendered || throttlingRendered); out += duration.render(format, indent + " ", throttlingRendered); out += throttling.render(format, indent + " ", false); out += endTag(indent, tag, format, comma); return out; }
/* **************************************************************************** * * Restriction::render - */ std::string Restriction::render(Format format, std::string indent, int restrictions, bool comma) { std::string tag = "restriction"; std::string out = ""; bool scopeVectorRendered = scopeVector.size() != 0; if (restrictions == 0) return ""; out += startTag(indent, tag, format); out += attributeExpression.render(format, indent + " ", scopeVectorRendered); out += scopeVector.render(format, indent + " ", false); out += endTag(indent, tag, format, comma); return out; }
/* **************************************************************************** * * MetadataVector::render - */ std::string MetadataVector::render(Format format, std::string indent, bool comma) { std::string out = ""; std::string jsonTag = "metadatas"; if (vec.size() == 0) return ""; out += startTag(indent, tag, jsonTag, format, true); for (unsigned int ix = 0; ix < vec.size(); ++ix) out += vec[ix]->render(format, indent + " ", ix != vec.size() - 1); out += endTag(indent, tag, format, comma, true); return out; }
/* **************************************************************************** * * RegisterProviderRequest::toJsonV1 - */ std::string RegisterProviderRequest::toJsonV1(void) { std::string out = ""; bool providingApplicationRendered = providingApplication.get() != ""; bool registrationIdRendered = registrationId.get() != ""; bool commaAfterProvidingApplication = registrationIdRendered; bool commaAfterDuration = commaAfterProvidingApplication || providingApplicationRendered; out += startTag(); out += duration.toJsonV1(commaAfterDuration); out += providingApplication.toJsonV1(commaAfterProvidingApplication); out += registrationId.toJsonV1(RegisterContext, false); out += endTag(false); return out; }
/* **************************************************************************** * * ContextRegistrationAttributeVector::render - */ std::string ContextRegistrationAttributeVector::render(Format format, const std::string& indent, bool comma) { std::string xmlTag = "contextRegistrationAttributeList"; std::string jsonTag = "attributes"; std::string out = ""; if (vec.size() == 0) return ""; out += startTag(indent, xmlTag, jsonTag, format, true, true); for (unsigned int ix = 0; ix < vec.size(); ++ix) out += vec[ix]->render(format, indent + " ", ix != vec.size() - 1); out += endTag(indent, xmlTag, format, comma, true); return out; }
/* **************************************************************************** * * SubscribeContextResponse::render - */ std::string SubscribeContextResponse::render(RequestType requestType, Format format, std::string indent) { std::string out = ""; std::string tag = "subscribeContextResponse"; out += startTag(indent, tag, format, false); if (subscribeError.errorCode.code == SccNone) out += subscribeResponse.render(format, indent + " ", false); else out += subscribeError.render(SubscribeContext, format, indent + " ", false); out += endTag(indent, tag, format, false); return out; }