JSONMarkUp.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #include "jstring.hpp"
  2. #include "SchemaCommon.hpp"
  3. #include "BuildSet.hpp"
  4. #include "JSONMarkUp.hpp"
  5. #include "ConfigSchemaHelper.hpp"
  6. using namespace CONFIGURATOR;
  7. void CJSONMarkUpHelper::markUpString(::StringBuffer &str)
  8. {
  9. //str.replaceString("\"","\\\"");
  10. //str.replace("[","\\[");
  11. //str.replace("]","/]");
  12. }
  13. void CJSONMarkUpHelper::createUIContent(::StringBuffer &strJSON, unsigned int &offset, const char *pUIType, const char* pLabel, const char* pKey, \
  14. const char *pToolTip, const char *pDefaultValue, const char *pValues, const char *pValue)
  15. {
  16. assert(pUIType);
  17. offset+= STANDARD_OFFSET_1;
  18. strJSON.appendf(" %s \"%s\"", JSON_LABEL, pLabel);
  19. strJSON.appendf(", %s \"%s\"", JSON_TYPE, pUIType);
  20. StringBuffer strKey(pKey);
  21. strKey.replace('/','_'); // for frontend
  22. if (strKey[0] == '[') //check for array
  23. strJSON.appendf(", %s %s", JSON_KEY, strKey.str());
  24. else
  25. strJSON.appendf(", %s \"%s\"", JSON_KEY, strKey.str());
  26. StringBuffer strToolTip;
  27. if (pToolTip)
  28. {
  29. strToolTip.set(pToolTip);
  30. strToolTip.replaceString("\"","\'");
  31. }
  32. strJSON.appendf(", %s \"%s\"", JSON_TOOLTIP, strToolTip.str());
  33. strJSON.appendf(", %s \"%s\"", JSON_DEFAULT_VALUE, pDefaultValue);
  34. if (strcmp(pUIType, JSON_TYPE_TABLE) != 0 && strcmp(pUIType, JSON_TYPE_TAB) != 0)
  35. strJSON.appendf(", %s %s", JSON_VALUE, pValue);
  36. if (strcmp(pUIType, JSON_TYPE_DROP_DOWN) == 0 && pValues && *pValues)
  37. strJSON.appendf(", %s [ \"%s\" ]", JSON_VALUES, pValues);
  38. else if (strcmp(pUIType, JSON_TYPE_TABLE) == 0 && pValues && *pValues)
  39. strJSON.appendf(", %s [ \"%s\" ]", JSON_COLUMN_NAMES_VALUE, pValues);
  40. }
  41. /*void CJSONMarkUpHelper::createUIContent(::StringBuffer &strJSON, unsigned int &offset, ::StringBuffer strUIType, ::StringBuffer strLabel, ::StringBuffer strKey, ::StringBuffer strToolTip, ::StringBuffer strDefaultValue,\
  42. ::StringBuffer strValues, ::StringBuffer strValue)
  43. {
  44. assert(strUIType.length() > 0);
  45. CJSONMarkUpHelper::markUpString(strUIType);
  46. CJSONMarkUpHelper::markUpString(strLabel);
  47. CJSONMarkUpHelper::markUpString(strToolTip);
  48. CJSONMarkUpHelper::markUpString(strDefaultValue);
  49. CJSONMarkUpHelper::markUpString(strValues);
  50. CJSONMarkUpHelper::markUpString(strValue);
  51. offset+= STANDARD_OFFSET_1;
  52. strJSON.appendf(" %s \"%s\"", JSON_LABEL, strLabel.str());
  53. strJSON.appendf(", %s \"%s\"", JSON_TYPE, strUIType.str());
  54. strKey.replace('/','_'); // for frontend
  55. strJSON.appendf(", %s \"%s\"", JSON_KEY, strKey.str());
  56. strJSON.appendf(", %s \"%s\"", JSON_TOOLTIP, strToolTip.str());
  57. strJSON.appendf(", %s \"%s\"", JSON_DEFAULT_VALUE, strDefaultValue.str());
  58. if (strcmp(strUIType.str(), JSON_TYPE_TABLE) != 0 && strcmp(strUIType.str(), JSON_TYPE_TAB) != 0)
  59. strJSON.appendf(", %s %s", JSON_VALUE, strValue.str());
  60. if (strcmp(strUIType.str(), JSON_TYPE_DROP_DOWN) == 0 && strValues.length() > 0)
  61. strJSON.appendf(", %s [ \"%s\" ]", JSON_VALUES, strValues.str());
  62. else if (strcmp(strUIType.str(), JSON_TYPE_TABLE) == 0 && strValues.length() > 0)
  63. strJSON.appendf(", %s [ \"%s\" ]", JSON_COLUMN_NAMES_VALUE, strValues.str());
  64. }*/
  65. void CJSONMarkUpHelper::getNavigatorJSON(::StringBuffer &strJSON)
  66. {
  67. int nComponents = CBuildSetManager::getInstance()->getBuildSetComponentCount();
  68. if (nComponents == 0)
  69. return;
  70. strJSON.append(JSON_NAVIGATOR_BEGIN);
  71. strJSON.append(JSON_NAVIGATOR_TEXT).append("\"").append(CConfigSchemaHelper::getInstance()->getEnvFilePath()).append("\",").append("\n");
  72. strJSON.append(JSON_NAVIGATOR_KEY).append("\"#").append(CConfigSchemaHelper::getInstance()->getEnvFilePath()).append("\",").append("\n");
  73. for (int i = 0; i < nComponents; i++)
  74. {
  75. if (i == 0)
  76. {
  77. strJSON.append("\n");
  78. strJSON.append(JSON_NAVIGATOR_NODES);
  79. strJSON.append(JSON_NAVIGATOR_NODE_BEGIN);
  80. }
  81. StringBuffer strComponentTypeName(CBuildSetManager::getInstance()->getBuildSetComponentTypeName(i));
  82. StringBuffer strComponentProcessName(CBuildSetManager::getInstance()->getBuildSetProcessName(i));
  83. strJSON.append(JSON_NAVIGATOR_TEXT).append("\"").append(strComponentTypeName.str()).append("\",").append("\n");
  84. strJSON.append(JSON_NAVIGATOR_KEY).append("\"#").append(CBuildSetManager::getInstance()->getBuildSetComponentFileName(i)).append("\"");
  85. int nInstanceCount = CConfigSchemaHelper::getInstance()->getInstancesOfComponentType(strComponentTypeName.str());
  86. if (CConfigSchemaHelper::getInstance()->getEnvFilePath() != NULL && strlen(CConfigSchemaHelper::getInstance()->getEnvFilePath()) > 0)
  87. {
  88. for (int ii = 0; ii < nInstanceCount; ii++)
  89. {
  90. if (ii == 0)
  91. {
  92. strJSON.append(",\n");
  93. strJSON.append(JSON_NAVIGATOR_NODES);
  94. strJSON.append(JSON_NAVIGATOR_NODE_BEGIN);
  95. }
  96. strJSON.append(JSON_NAVIGATOR_TEXT).append("\"").append(CConfigSchemaHelper::getInstance()->getInstanceNameOfComponentType(strComponentProcessName.str(),ii)).append("\",").append("\n");
  97. strJSON.append(JSON_NAVIGATOR_KEY).append("\"#").append(strComponentProcessName.str()).append("[").append(ii+1).append("]").append("\"\n");
  98. if (ii+1 < nInstanceCount)
  99. {
  100. strJSON.append("},\n{");
  101. }
  102. else
  103. {
  104. strJSON.append("\n");
  105. strJSON.append(JSON_NAVIGATOR_NODE_END);
  106. }
  107. }
  108. if (i+1 < nComponents)
  109. {
  110. strJSON.append("},\n{");
  111. }
  112. else
  113. {
  114. strJSON.append("\n");
  115. strJSON.append(JSON_NAVIGATOR_NODE_END);
  116. }
  117. }
  118. else if (i+1 < nComponents)
  119. {
  120. strJSON.append(",");
  121. }
  122. else
  123. {
  124. strJSON.append("\n");
  125. strJSON.append(JSON_NAVIGATOR_NODE_END);
  126. }
  127. }
  128. strJSON.append(JSON_NAVIGATOR_END);
  129. }