Exemplo n.º 1
0
 public void writeTo(OutputStream output, Charset charset) throws IOException {
   // Build
   final HTMLFragment start;
   final HTMLFragment end;
   StringBuilder b = new StringBuilder().append('<').append(name);
   if (attributes != null) {
     for (Entry<String, String> att : attributes.entrySet()) {
       b.append(' ').append(att.getKey()).append("=\"").append(att.getValue()).append('"');
     }
   }
   if (xhtml && !hasContent() && !ALWAYS_CLOSING_TAG.contains(name.toLowerCase())) {
     start = HTMLFragments.of(b.append(" />\n").toString());
     end = null;
   } else {
     start = HTMLFragments.of(b.append(">\n").toString());
     if (!keepOpen) {
       end = HTMLFragments.of("\n</" + name + ">\n");
     } else {
       end = HTMLFragments.of("\n");
     }
   }
   // Write
   start.writeTo(output, charset);
   super.writeTo(output, charset);
   if (end != null) {
     end.writeTo(output, charset);
   }
 }
Exemplo n.º 2
0
  public static void main(String[] args) {
    if (args.length != 1) {
      usage();
      System.exit(0);
    }

    if (args[0].equals("plain")) {
      TextBuilder textBuilder = new TextBuilder();
      Director director = new Director(textBuilder);
      director.construct();
      String result = textBuilder.getResult();
      System.out.println(result);
    } else if (args[0].equals("html")) {
      HTMLBuilder htmlBuilder = new HTMLBuilder();
      Director director = new Director(htmlBuilder);
      director.construct();
      String result = htmlBuilder.getResult();
      System.out.println(result);
    } else {
      usage();
      System.exit(0);
    }
  }