JSONMarkUp.cpp 6.0 KB

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