/* ****************************************************************************
*
* endTag - 
*/
TEST(commonTag, endTag)
{
   std::string      tag    = "TAG";
   std::string      indent = "  ";
   std::string      xml    = "  </TAG>\n";
   std::string      json   = "  }\n";
   std::string      out;

   out = endTag(indent, tag, XML);
   EXPECT_EQ(xml, out);

   out = endTag(indent, tag, JSON);
   EXPECT_EQ(json, out);
}
/* ****************************************************************************
*
* 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;
}
    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;
    }
/* ****************************************************************************
*
* 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;
}
/* ****************************************************************************
*
* 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;
}
/* ****************************************************************************
*
* 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;
}
/* ****************************************************************************
*
* 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;
}
/* ****************************************************************************
*
* 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;
}
示例#10
0
/* ****************************************************************************
*
* 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;
}
/* ****************************************************************************
*
* render -
*/
std::string UpdateContextElementResponse::render
(
  ConnectionInfo*     ciP,
  RequestType         requestType,
  const std::string&  indent
)
{
  std::string tag = "updateContextElementResponse";
  std::string out = "";

  out += startTag1(indent, tag, false);

  if ((errorCode.code != SccNone) && (errorCode.code != SccOk))
  {
    out += errorCode.render(indent + "  ");
  }
  else
  {
    out += contextAttributeResponseVector.render(ciP, requestType, indent + "  ");
  }

  out += endTag(indent);

  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;
}
示例#13
0
/* ****************************************************************************
*
* 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;
}
示例#14
0
/* ****************************************************************************
*
* versionTreat - 
*/
std::string versionTreat
(
  ConnectionInfo*            ciP,
  int                        components,
  std::vector<std::string>&  compV,
  ParseData*                 parseDataP
)
{
  std::string out     = "";
  std::string tag     = "orion";
  std::string indent  = "";

#ifdef UNIT_TEST
  std::string uptime = "0 d, 0 h, 0 m, 0 s";
#else
  std::string uptime = parsedUptime(getTimer()->getCurrentTime() - startTime);
#endif

  out += startTag1(indent, tag, true, true);
  out += valueTag1(indent + "  ", "version",       versionString,   true);
  out += valueTag1(indent + "  ", "uptime",        uptime,          true);
  out += valueTag1(indent + "  ", "git_hash",      GIT_HASH,        true);
  out += valueTag1(indent + "  ", "compile_time",  COMPILE_TIME,    true);
  out += valueTag1(indent + "  ", "compiled_by",   COMPILED_BY,     true);
  out += valueTag1(indent + "  ", "compiled_in",   COMPILED_IN,     false);
  out += endTag(indent, false, false, true, true);

  ciP->httpStatusCode = SccOk;
  return out;
}
示例#15
0
/* ****************************************************************************
*
* ContextElement::render - 
*/
std::string ContextElement::render(ConnectionInfo* ciP, RequestType requestType, 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               = commaAfterAttributeDomainName || attributeDomainNameRendered;

  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);
  out += domainMetadataVector.render(ciP->outFormat, indent + "  ", commaAfterDomainMetadataVector);

  out += endTag(indent, xmlTag, ciP->outFormat, comma, false);

  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;
}
示例#17
0
/* ****************************************************************************
*
* EntityType::render -
*
* This method is used by:
*   o EntityTypeVector
*   o EntityTypeResponse
*
* 'typeNameBefore' is set to TRUE when called from EntityTypeResponse
*/
std::string EntityType::render
(
  ConnectionInfo*     ciP,
  const std::string&  indent,
  bool                comma,
  bool                typeNameBefore
)
{
  std::string  out = "";
  std::string  key = "type";

  if ((typeNameBefore == true) && (ciP->outMimeType == JSON))
  {
    out += valueTag1(indent  + "  ", "name", type, true);
    out += contextAttributeVector.render(ciP, EntityTypes, indent + "  ", true, true, true);
  }
  else
  {
    out += startTag2(indent, key, false, false);

    if (ciP->uriParam[URI_PARAM_COLLAPSE] == "true" || contextAttributeVector.size() == 0)
    {     
      out += valueTag1(indent  + "  ", "name", type, false);
    }
    else
    {
      out += valueTag1(indent  + "  ", "name", type, true);
      out += contextAttributeVector.render(ciP, EntityTypes, indent + "  ", false, true, true);
    }

    out += endTag(indent, comma, false);
  }

  return out;
}
/* ****************************************************************************
*
* endTag -
*/
TEST(commonTag, endTag)
{
   std::string      json   = "}";
   std::string      out;

   out = endTag();
   EXPECT_EQ(json, out);
}
/*!
  Creates a start-tag of \a name with the given HTML attributes \a attributes.
*/
QString TViewHelper::tag(const QString &name, const THtmlAttribute &attributes)
{
    QString string = "<";
    string += name;
    string += attributes.toString();
    string += QLatin1Char('>');
    endTags << endTag(name);
    return string;
}
示例#20
0
// Before destroying check whether all the open tags are closed
XmlStream::~XmlStream()
{
	if (stateTagName == state) {
		s << "/>";
		state = stateNone;
	}
	while (tags.size())
		endTag(tags.top());
}
示例#21
0
void pfPrcHelper::startTag(const char* name) {
    if (inTag)
        endTag();
    char buf[256];
    snprintf(buf, 256, "<%s", name);
    writeTabbed(buf);
    openTags.push(name);
    inTag = true;
}
示例#22
0
/* ****************************************************************************
*
* endTag - 
*/
TEST(commonTag, endTag)
{
   std::string      indent = "  ";
   std::string      json   = "  }\n";
   std::string      out;

   out = endTag(indent);
   EXPECT_EQ(json, 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;
}
/* ****************************************************************************
*
* 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;
}
/* ****************************************************************************
*
* NotifyContextAvailabilityResponse::render -
*/
std::string NotifyContextAvailabilityResponse::render(RequestType requestType, const std::string& indent)
{
  std::string out = "";
  std::string tag = "notifyContextAvailabilityResponse";

  responseCode.keyNameSet("responseCode");

  out += startTag1(indent, tag, false);
  out += responseCode.render(indent + "  ");
  out += endTag(indent);

  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;
}
/* ****************************************************************************
*
* 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;
}
示例#28
0
/* ****************************************************************************
*
* 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;
}
/* ****************************************************************************
*
* 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;
}
/* ****************************************************************************
*
* 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;
}