/* **************************************************************************** * * EntityId::render - * * FIXME P1: startTag() is not enough for the XML case of entityId - XML attributes ... * Perhaps add a vector of attributes to startTag() ? */ std::string EntityId::render ( Format format, const std::string& indent, bool comma, bool isInVector, const std::string& assocTag ) { std::string out = ""; char* isPatternEscaped = htmlEscape(isPattern.c_str()); char* typeEscaped = htmlEscape(type.c_str()); char* idEscaped = htmlEscape(id.c_str()); if (format == XML) { out += indent + "<" + tag + " type=\"" + typeEscaped + "\" isPattern=\"" + isPatternEscaped + "\">\n"; out += indent + " " + "<id>" + idEscaped + "</id>" + "\n"; out += indent + "</" + tag + ">\n"; } else { bool isAssoc = !assocTag.empty(); std::string indent2 = indent; if (isInVector) { indent2 += " "; } out += (isInVector? indent + (isAssoc? "\"" + assocTag + "\" : ": "") + "{\n": ""); out += indent2 + "\"type\" : \"" + typeEscaped + "\"," + "\n"; out += indent2 + "\"isPattern\" : \"" + isPatternEscaped + "\"," + "\n"; out += indent2 + "\"id\" : \"" + idEscaped + "\""; if ((comma == true) && (isInVector == false)) { out += ",\n"; } else { out += "\n"; out += (isInVector? indent + "}" : ""); out += (comma == true)? ",\n" : (isInVector? "\n" : ""); } } free(typeEscaped); free(idEscaped); free(isPatternEscaped); return out; }
/* **************************************************************************** * * OrionError::toJson - */ std::string OrionError::toJson(void) { char* reasonPhraseEscaped = htmlEscape(reasonPhrase.c_str()); char* detailsEscaped = htmlEscape(details.c_str()); JsonObjectHelper jh; jh.addString("error", reasonPhraseEscaped); jh.addString("description", detailsEscaped); free(reasonPhraseEscaped); free(detailsEscaped); return jh.str(); }
/* **************************************************************************** * * EntityId::toJson - */ std::string EntityId::toJson(void) const { std::string out; char* typeEscaped = htmlEscape(type.c_str()); char* idEscaped = htmlEscape(id.c_str()); out += JSON_VALUE("id", idEscaped); out += ","; out += JSON_VALUE("type", typeEscaped); delete typeEscaped; delete idEscaped; return out; }
char *getArtistCommentBody(int idNumber) { artistCommentNode_t *a; a = getArtistComment(idNumber); if (a != NULL) { return htmlEscape(a->comment, FALSE); } return NULL; }
/* Function: getArtistName * Params: int idNumber * Returns: char*. * * This function retrieves the name of an artist with the specified id. * It returns NULL if the artistdoes not exist in the database. */ char *getArtistName(int idNumber) { artistNode_t *a; a = getArtist(idNumber); if (a != NULL) { return htmlEscape(a->name, TRUE); } return NULL; }
/* Function: getAlbumTitle * Params: int idNumber * Returns: char*. * * This function retrieves the title of an album with the specified id. * It returns NULL if the album does not exist in the database. */ char *getAlbumTitle(int idNumber) { albumNode_t *a; a = getAlbum(idNumber); if (a != NULL) { return htmlEscape(a->title, TRUE); } return NULL; }
char *getUserEmail(int idNumber) { userNode_t *a; a = getUser(idNumber); if (a != NULL) { return htmlEscape(a->emailAddress, TRUE); } return NULL; }
char *getUserName(int idNumber) { userNode_t *a; a = getUser(idNumber); if (a != NULL) { return htmlEscape(a->userName, TRUE); } return NULL; }
/* **************************************************************************** * * EntityId::render - * */ std::string EntityId::render ( const std::string& indent, bool comma, bool isInVector ) { std::string out = ""; char* isPatternEscaped = htmlEscape(isPattern.c_str()); char* typeEscaped = htmlEscape(type.c_str()); char* idEscaped = htmlEscape(id.c_str()); std::string indent2 = indent; if (isInVector) { indent2 += " "; } out += (isInVector? indent + "{\n" : ""); out += indent2 + "\"type\" : \"" + typeEscaped + "\"," + "\n"; out += indent2 + "\"isPattern\" : \"" + isPatternEscaped + "\"," + "\n"; out += indent2 + "\"id\" : \"" + idEscaped + "\""; if ((comma == true) && (isInVector == false)) { out += ",\n"; } else { out += "\n"; out += (isInVector? indent + "}" : ""); out += (comma == true)? ",\n" : (isInVector? "\n" : ""); } free(typeEscaped); free(idEscaped); free(isPatternEscaped); return out; }
/* **************************************************************************** * * valueTag - * * NOTE * The value of the tag is not HTML-escaped if the value is an Association. <* In the case of Associations, the specific values must be HTML-escaped instead. */ std::string valueTag ( const std::string& indent, const std::string& tagName, const std::string& unescapedValue, Format format, bool showComma, bool isAssociation, bool isVectorElement ) { char* value; if (isAssociation == false) { value = htmlEscape(unescapedValue.c_str()); } else { // unnecessary malloc, but this way I can always free => easier to read value = strdup(unescapedValue.c_str()); } if (value == NULL) { return "ERROR: no memory"; } if (format == XML) { std::string out = indent + "<" + tagName + ">" + value + "</" + tagName + ">" + "\n"; free(value); return out; } if (showComma == true) { if (isAssociation == true) { std::string out = indent + "\"" + tagName + "\" : " + value + ",\n"; free(value); return out; } else if (isVectorElement == true) { std::string out = indent + "\"" + value + "\",\n"; free(value); return out; } else { std::string out = indent + "\"" + tagName + "\" : \"" + value + "\",\n"; free(value); return out; } } else { if (isAssociation == true) { std::string out = indent + "\"" + tagName + "\" : " + value + "\n"; free(value); return out; } else if (isVectorElement == true) { std::string out = indent + "\"" + value + "\"\n"; free(value); return out; } else { std::string out = indent + "\"" + tagName + "\" : \"" + value + "\"\n"; free(value); return out; } } }
// Format a tooltip fow with aligned colon. static void formatToolTipRow(QTextStream &str, const QString &category, const QString &value) { str << "<tr><td>" << category << "</td><td> : </td><td>" << htmlEscape(value) << "</td></tr>"; }