예제 #1
0
  private void setProperty(String name, String value) {
    Object expr = value;

    if (value != null) {
      expr = CompositeExpression.parse(value);
    }

    if (expr == null) {
      getValues().remove(name);
      getKeys().remove(name);
    } else {
      getValues().put(name, expr);
      getValues().put(StringUtil.getValidIdentifier(name), expr);
      getKeys().add(name);
    }
  }
예제 #2
0
  /**
   * 对所有properties的key排序并分组。
   *
   * @param level 分组的级别
   * @return 分组列表
   */
  private List[] getSortedKeys(Map props, int level) {
    List keys = new ArrayList(props.keySet());

    Collections.sort(keys);

    List groups = new ArrayList();
    List group = null;
    String prefix = null;

    for (Iterator i = keys.iterator(); i.hasNext(); ) {
      String key = (String) i.next();
      String[] parts = StringUtil.split(key, ".");
      StringBuffer buffer = new StringBuffer();

      for (int j = 0; j < parts.length - 1 && j < level; j++) {
        if (buffer.length() > 0) {
          buffer.append('.');
        }

        buffer.append(parts[j]);
      }

      String keyPrefix = buffer.toString();

      if (!keyPrefix.equals(prefix)) {
        if (group != null) {
          groups.add(group);
        }

        prefix = keyPrefix;
        group = new ArrayList();
      }

      group.add(key);
    }

    if (group != null && group.size() > 0) {
      groups.add(group);
    }

    return (List[]) groups.toArray(new List[groups.size()]);
  }
예제 #3
0
  /**
   * 将&#92;uxxxx转换成unicode字符,将特殊符号转换成其原来的格式。
   *
   * @param str 要转换的字符串
   * @return 转换后的字符串
   */
  private String loadConvert(String str, String url, int lineNumber) {
    char ch;
    int len = str.length();
    StringBuffer buffer = new StringBuffer(len);

    if (StringUtil.isEmpty(url)) {
      url = "<unknown source>";
    }

    for (int x = 0; x < len; ) {
      ch = str.charAt(x++);

      if (ch == '\\') {
        ch = str.charAt(x++);

        if (ch == 'u') {
          // Read the xxxx
          int value = 0;

          for (int i = 0; i < 4; i++) {
            ch = str.charAt(x++);

            switch (ch) {
              case '0':
              case '1':
              case '2':
              case '3':
              case '4':
              case '5':
              case '6':
              case '7':
              case '8':
              case '9':
                value = (value << 4) + ch - '0';
                break;

              case 'a':
              case 'b':
              case 'c':
              case 'd':
              case 'e':
              case 'f':
                value = (value << 4) + 10 + ch - 'a';
                break;

              case 'A':
              case 'B':
              case 'C':
              case 'D':
              case 'E':
              case 'F':
                value = (value << 4) + 10 + ch - 'A';
                break;

              default:
                throw new IllegalArgumentException(
                    "Malformed \\uxxxx encoding at " + url + ", line " + lineNumber);
            }
          }

          buffer.append((char) value);
        } else {
          if (ch == '\\') {
            ch = '\\';
          } else if (ch == 't') {
            ch = '\t';
          } else if (ch == 'r') {
            ch = '\r';
          } else if (ch == 'n') {
            ch = '\n';
          } else if (ch == 'f') {
            ch = '\f';
          } else {
            throw new IllegalArgumentException(
                "Invalid \\" + ch + " at " + url + ", line " + lineNumber);
          }

          buffer.append(ch);
        }
      } else {
        buffer.append(ch);
      }
    }

    return buffer.toString();
  }