use of com.cubrid.cubridmanager.ui.host.model.CubridCMConfProperty in project cubrid-manager by CUBRID.
the class UnifyHostConfigUtil method parseCubridCMConfConfigToDocumnetString.
/**
* parse a CubridConfConfig model to a document string
* @param config CubridBrokerConfig
* @return String
*/
public String parseCubridCMConfConfigToDocumnetString(CubridCMConfConfig config) {
StringBuilder contents = new StringBuilder();
for (CubridCMConfProperty cubridCMConfProperty : config.getPropertyList()) {
String annotation = cubridCMConfProperty.getCubridCMConfPropAnnotation();
if (annotation != null) {
contents.append(annotation);
}
contents.append(cubridCMConfProperty.getCubridCMConfPropKey()).append("=").append(cubridCMConfProperty.getCubridCMConfPropValue()).append(StringUtil.NEWLINE);
}
return contents.toString();
}
use of com.cubrid.cubridmanager.ui.host.model.CubridCMConfProperty in project cubrid-manager by CUBRID.
the class UnifyHostConfigUtil method parseStringLineToCubridCMConfConfig.
/**
* parseStringLineToCubridCMConfConfig
* @param content
* @return
* @throws Exception
*/
public CubridCMConfConfig parseStringLineToCubridCMConfConfig(String content) {
CubridCMConfConfig config = new CubridCMConfConfig();
String annotationRegex = "#((\\s*).+)|.+";
Pattern annotationPattern = Pattern.compile(annotationRegex);
String propertyRegex = ".+=.+";
Pattern propertyPattern = Pattern.compile(propertyRegex);
StringBuilder annotationBuilder = new StringBuilder();
String[] contentArray = content.split(StringUtil.NEWLINE);
for (String lineString : contentArray) {
Matcher propertyMatcher = propertyPattern.matcher(lineString);
Matcher annotationMatcher = annotationPattern.matcher(lineString);
if (propertyMatcher.find()) {
//find key and value
if (lineString.startsWith("#")) {
if (annotationBuilder == null) {
annotationBuilder = new StringBuilder();
}
annotationBuilder.append(lineString).append(StringUtil.NEWLINE);
continue;
}
String[] keyValueString = lineString.split("=");
if (keyValueString.length == 2) {
String key = keyValueString[0].trim();
String value = keyValueString[1].trim();
//new property then set parameter
CubridCMConfProperty property = new CubridCMConfProperty();
property.setCubridCMConfPropKey(key);
property.setCubridCMConfPropValue(value);
if (annotationBuilder != null) {
property.setCubridCMConfPropAnnotation((annotationBuilder.toString()));
}
config.addCubridCMConfProperty(property);
annotationBuilder = null;
}
} else if (annotationMatcher.find() || lineString.equals("")) {
//find annotation
if (annotationBuilder == null) {
annotationBuilder = new StringBuilder();
}
annotationBuilder.append(lineString).append(StringUtil.NEWLINE);
}
}
return config;
}
use of com.cubrid.cubridmanager.ui.host.model.CubridCMConfProperty in project cubrid-manager by CUBRID.
the class UnifyHostConfigUtil method parseCubridCMConfConfigToCommonTableValue.
/**
* parse cubrid cm conf data to table value
* @param Map<String, CubridConfConfig> cubridConfConfigDataMap
*/
public List<Map<String, String>> parseCubridCMConfConfigToCommonTableValue(Map<String, CubridCMConfConfig> cubridCMConfConfigDataMap) {
List<Map<String, String>> result = new ArrayList<Map<String, String>>();
//mark property in the list
List<String> propList = new ArrayList<String>();
Map<String, String> dataMap = null;
Map<String, String> serverMap = new HashMap<String, String>();
//first row as server name
result.add(serverMap);
serverMap.put("0", UnifyHostConfigEditor.SERVERNAMECOLUMNTITLE);
int index = 1;
for (String serverName : cubridCMConfConfigDataMap.keySet()) {
//server name
serverMap.put("" + (index++), serverName);
}
for (Entry<String, CubridCMConfConfig> entry : cubridCMConfConfigDataMap.entrySet()) {
String serverName = entry.getKey();
CubridCMConfConfig cubridCMConfConfig = entry.getValue();
for (CubridCMConfProperty cubridCMConfProperty : cubridCMConfConfig.getPropertyList()) {
String properKey = cubridCMConfProperty.getCubridCMConfPropKey();
if (!propList.contains(properKey)) {
//a new property
propList.add(properKey);
dataMap = new HashMap<String, String>();
result.add(dataMap);
if (cubridCMConfProperty.getCubridCMConfPropValue() != null) {
dataMap.put("0", cubridCMConfProperty.getCubridCMConfPropKey());
}
String indexString = getMapKeyByValue(serverMap, serverName);
if (indexString != null) {
dataMap.put(indexString, cubridCMConfProperty.getCubridCMConfPropValue());
if (cubridCMConfProperty.getCubridCMConfPropAnnotation() != null) {
dataMap.put(indexString + UnifyHostConfigEditor.ANNOTATION, cubridCMConfProperty.getCubridCMConfPropAnnotation());
}
}
} else {
Map<String, String> oneRowData = getRowData(result, properKey);
String indexString = getMapKeyByValue(serverMap, serverName);
String value = cubridCMConfProperty.getCubridCMConfPropValue();
String annotation = cubridCMConfProperty.getCubridCMConfPropAnnotation();
if (oneRowData != null && indexString != null && value != null) {
oneRowData.put(indexString, value);
if (annotation != null) {
oneRowData.put(indexString + UnifyHostConfigEditor.ANNOTATION, annotation);
}
}
}
}
}
return result;
}
use of com.cubrid.cubridmanager.ui.host.model.CubridCMConfProperty in project cubrid-manager by CUBRID.
the class UnifyHostConfigUtil method parseCommonTableValueToCubridCMConfConfig.
/**
* parse common table value to cubrid config model list
* @param dataList
* @return
*/
public LinkedHashMap<String, CubridCMConfConfig> parseCommonTableValueToCubridCMConfConfig(List<Map<String, String>> dataList, int tableColumnCount) {
LinkedHashMap<String, CubridCMConfConfig> cubridCMConfConfigMap = new LinkedHashMap<String, CubridCMConfConfig>();
Map<String, String> serverNameMap = null;
for (int i = 0; i < dataList.size(); i++) {
if (i == 0) {
//first data is server name
serverNameMap = dataList.get(i);
for (int j = 1; j < serverNameMap.size(); j++) {
String serverName = serverNameMap.get(j + "");
if (serverName == null || "".equals(serverName)) {
continue;
}
if (cubridCMConfConfigMap.get(serverName) == null) {
CubridCMConfConfig config = new CubridCMConfConfig();
cubridCMConfConfigMap.put(serverName, config);
}
}
} else {
Map<String, String> valueMap = dataList.get(i);
String propName = "";
String propValue = "";
for (int j = 0; j < tableColumnCount; j++) {
String value = valueMap.get(Integer.toString(j));
if (j == 0) {
propName = value;
continue;
}
propValue = value;
if (propValue != null && !"".equals(propValue)) {
String serverName = serverNameMap.get(j + "");
CubridCMConfConfig cubridCMConfConfig = cubridCMConfConfigMap.get(serverName);
CubridCMConfProperty cubridCMConfProperty = new CubridCMConfProperty();
cubridCMConfConfig.addCubridCMConfProperty(cubridCMConfProperty);
cubridCMConfProperty.setCubridCMConfPropKey(propName);
cubridCMConfProperty.setCubridCMConfPropValue(propValue);
String annotation = valueMap.get(Integer.toString(j) + UnifyHostConfigEditor.ANNOTATION);
cubridCMConfProperty.setCubridCMConfPropAnnotation(annotation);
}
}
}
}
return cubridCMConfConfigMap;
}
Aggregations