Search in sources :

Example 6 with CubridBrokerProperty

use of com.cubrid.common.ui.spi.model.CubridBrokerProperty in project cubrid-manager by CUBRID.

the class BrokerConfPersistUtil method parseStringLineToBrokerConfig.

/**
	 * parseStringLineToCubridBrokerConfig
	 *
	 * @param content
	 * @return
	 * @throws Exception
	 */
public BrokerConfig parseStringLineToBrokerConfig(String content) {
    BrokerConfig config = new BrokerConfig();
    String cubridBrokerConfRegex = "\\[.*";
    Pattern cubridBrokerConfPattern = Pattern.compile(cubridBrokerConfRegex);
    String annotationRegex = "#(\\s*).+";
    Pattern annotationPattern = Pattern.compile(annotationRegex);
    String propertyRegex = ".+=.+";
    Pattern propertyPattern = Pattern.compile(propertyRegex);
    CubridBrokerProperty brokerConfProp = null;
    StringBuilder annotationBuilder = new StringBuilder();
    String[] contentArray = content.split(StringUtil.NEWLINE);
    for (String lineString : contentArray) {
        Matcher cubridBrokerConfMatcher = cubridBrokerConfPattern.matcher(lineString);
        Matcher annotationMatcher = annotationPattern.matcher(lineString);
        Matcher propertyMatcher = propertyPattern.matcher(lineString);
        if (cubridBrokerConfMatcher.find()) {
            //find broker like [broker] [%query_editor]
            brokerConfProp = new CubridBrokerProperty();
            brokerConfProp.setCubridBrokerPropKey(lineString);
            brokerConfProp.setCubridBroker(true);
            if (annotationBuilder != null) {
                brokerConfProp.setCubridBrokerPropAnnotation(annotationBuilder.toString());
            }
            config.addCubridBrokerProperty(brokerConfProp);
            annotationBuilder = null;
        } else if (annotationMatcher.find() || lineString.equals("")) {
            //find annotation
            if (annotationBuilder == null) {
                annotationBuilder = new StringBuilder();
            }
            annotationBuilder.append(lineString).append(StringUtil.NEWLINE);
        } else if (propertyMatcher.find()) {
            //find key and value
            if (brokerConfProp == null) {
                //if there is no broker,ignore the property
                continue;
            }
            String[] keyValueString = lineString.split("=");
            if (keyValueString.length == 2) {
                String key = keyValueString[0].trim();
                String value = keyValueString[1].trim();
                //new property then set parameter
                CubridBrokerProperty property = new CubridBrokerProperty();
                property.setCubridBrokerPropKey(key);
                property.setCubridBrokerPropValue(value);
                if (annotationBuilder != null) {
                    property.setCubridBrokerPropAnnotation(annotationBuilder.toString());
                }
                brokerConfProp.addCubridBrokerProperty(property);
                annotationBuilder = null;
            }
        } else {
            // opthers see it to bottom annotation
            if (annotationBuilder != null) {
                annotationBuilder.append(lineString).append(StringUtil.NEWLINE);
            }
        }
    }
    if (annotationBuilder != null) {
        config.setConfAnnotation(annotationBuilder.toString());
    }
    return config;
}
Also used : Pattern(java.util.regex.Pattern) BrokerConfig(com.cubrid.common.ui.spi.model.BrokerConfig) Matcher(java.util.regex.Matcher) CubridBrokerProperty(com.cubrid.common.ui.spi.model.CubridBrokerProperty)

Example 7 with CubridBrokerProperty

use of com.cubrid.common.ui.spi.model.CubridBrokerProperty in project cubrid-manager by CUBRID.

the class BrokerConfPersistUtil method parseBrokerConfigToCommonTableValue.

/**
	 * parse CubridBrokerConfig model to common table value
	 *
	 * @param config
	 * @return
	 */
public List<Map<String, String>> parseBrokerConfigToCommonTableValue(BrokerConfig config) {
    List<Map<String, String>> result = new ArrayList<Map<String, String>>();
    //mark property in the list
    List<String> propList = new ArrayList<String>();
    //first row as title
    Map<String, String> titleMap = new HashMap<String, String>();
    result.add(titleMap);
    Map<String, String> dataMap = null;
    titleMap.put("0", BROKERNAMECOLUMNTITLE);
    int index = 1;
    for (CubridBrokerProperty cubridBroker : config.getPropertyList()) {
        titleMap.put(Integer.toString(index), cubridBroker.getCubridBrokerPropKey());
        if (cubridBroker.getCubridBrokerPropAnnotation() != null) {
            //set annotation
            titleMap.put(Integer.toString(index) + ANNOTATION, cubridBroker.getCubridBrokerPropAnnotation());
        }
        index++;
    }
    for (CubridBrokerProperty cubridBroker : config.getPropertyList()) {
        String brokerName = cubridBroker.getCubridBrokerPropKey();
        for (CubridBrokerProperty prop : cubridBroker.getPropertyList()) {
            String properKey = prop.getCubridBrokerPropKey();
            if (!propList.contains(properKey)) {
                //a new property
                propList.add(properKey);
                dataMap = new HashMap<String, String>();
                result.add(dataMap);
                dataMap.put("0", prop.getCubridBrokerPropKey());
                if (prop.getCubridBrokerPropValue() != null) {
                    dataMap.put("0", prop.getCubridBrokerPropKey());
                }
                String indexString = getMapKeyByValue(titleMap, brokerName);
                if (indexString != null) {
                    dataMap.put(indexString, prop.getCubridBrokerPropValue());
                    if (prop.getCubridBrokerPropAnnotation() != null) {
                        dataMap.put(indexString + ANNOTATION, prop.getCubridBrokerPropAnnotation());
                    }
                }
            } else {
                Map<String, String> oneRowData = getRowData(result, properKey);
                String indexString = getMapKeyByValue(titleMap, brokerName);
                String value = prop.getCubridBrokerPropValue();
                String annotation = prop.getCubridBrokerPropAnnotation();
                if (oneRowData != null && indexString != null && value != null) {
                    oneRowData.put(indexString, value);
                    if (annotation != null) {
                        oneRowData.put(indexString + ANNOTATION, annotation);
                    }
                }
            }
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CubridBrokerProperty(com.cubrid.common.ui.spi.model.CubridBrokerProperty) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

CubridBrokerProperty (com.cubrid.common.ui.spi.model.CubridBrokerProperty)7 BrokerConfig (com.cubrid.common.ui.spi.model.BrokerConfig)5 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Point (org.eclipse.swt.graphics.Point)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 TableItem (org.eclipse.swt.widgets.TableItem)1