Esempio n. 1
0
  public void write(BufferedWriter out, int indent) throws IOException {
    String pad0 = getIndent(indent);
    String pad1 = getIndent(indent + 1);
    String pad2 = getIndent(indent + 2);

    write(out, pad0, "####################");
    write(out, pad0, "# ", name);

    if (comment != null) {
      write(out, pad0, "#===================");
      Splitter splitter = Splitter.onPattern("\r?\n");

      for (String line : splitter.split(comment)) {
        write(out, pad0, "# ", line);
      }
    }

    write(out, pad0, "####################", NEW_LINE);

    if (!allowedProperties.matchesAllOf(name)) {
      name = '"' + name + '"';
    }

    write(out, pad0, name, " {");

    Property[] props = properties.values().toArray(new Property[properties.size()]);

    for (int x = 0; x < props.length; x++) {
      Property prop = props[x];

      if (prop.comment != null) {
        if (x != 0) {
          out.newLine();
        }

        Splitter splitter = Splitter.onPattern("\r?\n");
        for (String commentLine : splitter.split(prop.comment)) {
          write(out, pad1, "# ", commentLine);
        }
      }

      String propName = prop.getName();

      if (!allowedProperties.matchesAllOf(propName)) {
        propName = '"' + propName + '"';
      }

      if (prop.isList()) {
        char type = prop.getType().getID();

        write(out, pad1, String.valueOf(type), ":", propName, " <");

        for (String line : prop.getStringList()) {
          write(out, pad2, line);
        }

        write(out, pad1, " >");
      } else if (prop.getType() == null) {
        write(out, pad1, propName, "=", prop.getString());
      } else {
        char type = prop.getType().getID();
        write(out, pad1, String.valueOf(type), ":", propName, "=", prop.getString());
      }
    }

    for (ConfigCategory child : children) {
      child.write(out, indent + 1);
    }

    write(out, pad0, "}", NEW_LINE);
  }
Esempio n. 2
0
 private void write(BufferedWriter out, String... data) throws IOException {
   write(out, true, data);
 }