Example #1
0
  private void toConf(StringBuilder buf, ConfigEntryType[] category) {
    for (int i = 0; i < category.length; i++) {

      ConfigEntry entry = table.get(category[i]);

      if (entry != null && !entry.getType().isSynthetic()) {
        String text = entry.toConf();
        if (text != null && text.length() > 0) {
          buf.append(entry.toConf());
        }
      }
    }
  }
Example #2
0
  private void loadContents(BufferedReader in) throws IOException {
    StringBuilder buf = new StringBuilder();
    while (true) {
      // Empty out the buffer
      buf.setLength(0);

      String line = advance(in);
      if (line == null) {
        break;
      }

      // skip blank lines
      if (line.length() == 0) {
        continue;
      }

      Matcher matcher = KEY_VALUE_PATTERN.matcher(line);
      if (!matcher.matches()) {
        log.warn("Expected to see '=' in " + internal + ": " + line);
        continue;
      }

      String key = matcher.group(1).trim();
      String value = matcher.group(2).trim();
      // Only CIPHER_KEYS that are empty are not ignored
      if (value.length() == 0 && !ConfigEntryType.CIPHER_KEY.getName().equals(key)) {
        log.warn("Ignoring empty entry in " + internal + ": " + line);
        continue;
      }

      // Create a configEntry so that the name is normalized.
      ConfigEntry configEntry = new ConfigEntry(internal, key);

      ConfigEntryType type = configEntry.getType();

      ConfigEntry e = table.get(type);

      if (e == null) {
        if (type == null) {
          log.warn("Extra entry in " + internal + " of " + configEntry.getName());
          extra.put(key, configEntry);
        } else if (type.isSynthetic()) {
          log.warn("Ignoring unexpected entry in " + internal + " of " + configEntry.getName());
        } else {
          table.put(type, configEntry);
        }
      } else {
        configEntry = e;
      }

      buf.append(value);
      getContinuation(configEntry, in, buf);

      // History is a special case it is of the form History_x.x
      // The config entry is History without the x.x.
      // We want to put x.x at the beginning of the string
      value = buf.toString();
      if (ConfigEntryType.HISTORY.equals(type)) {
        int pos = key.indexOf('_');
        value = key.substring(pos + 1) + ' ' + value;
      }

      configEntry.addValue(value);
    }
  }