コード例 #1
0
  @Override
  public String getLabelFromMessage(String message, WebRenderer renderer) {
    Map<String, String> propertyMap = new HashMap<String, String>();

    PropertyStringParser propertyParser = new PropertyStringParser(message);

    // Build the map with resolved properties
    Set<String> parsedProperties = propertyParser.parseProperties();

    for (String propertyName : parsedProperties) {
      NabuccoProperty resolvedProperty = this.resolver.resolveProperty(propertyName);

      if (resolvedProperty == null) {
        propertyMap.put(propertyName, DEFAULT_LABEL);
        continue;
      }

      Object propertyInstance = resolvedProperty.getInstance();

      if (propertyInstance instanceof Basetype) {
        String value = renderer.render((NType) propertyInstance, resolvedProperty);
        propertyMap.put(propertyName, value);
      } else if (propertyInstance instanceof Enumeration) {
        String value = renderer.render((NType) propertyInstance, resolvedProperty);
        propertyMap.put(propertyName, value);
      } else if (propertyInstance instanceof Code) {
        String value = renderer.render((NType) propertyInstance, resolvedProperty);
        propertyMap.put(propertyName, value);
      } else {
        propertyMap.put(propertyName, DEFAULT_LABEL);
      }
    }

    String retVal = MessageFormatter.format(message, propertyMap);

    return retVal;
  }
コード例 #2
0
  @Override
  public String getLabel(String propertyPath, WebRenderer renderer) {
    NabuccoProperty property = this.resolver.resolveProperty(propertyPath);

    if (property == null) {
      return DEFAULT_LABEL;
    }

    Object instance = property.getInstance();

    if (!(instance instanceof NType)) {
      return DEFAULT_LABEL;
    }

    return renderer.render((NType) instance, property);
  }