Пример #1
0
  @Override
  public void handle(StringBuilder line, TemplateReader tpl, Environment env, Appendable out)
      throws IOException {
    // get the class name
    String klass = getArgs(line);

    // read in the class
    ClassReader rdr = new ClassReader();
    while (true) {
      line = tpl.next();

      if (line == null || (isCodeLine(line) && getCmd(line).equals("endclass"))) break;

      rdr.add(line.toString());
    }

    // format and print objects!
    Environment oenv;
    int i = 0;
    for (TemplateObject o : env.getObjectsFor(klass)) {
      rdr.rewind();
      oenv = env.getEnvironmentFor(o);
      oenv.setValue("FIRST", (i == 0) ? "1" : null);
      oenv.setValue("NOTFIRST", (i != 0) ? "1" : null);
      oenv.setValue("INDEX", String.valueOf(i++));
      Template.doTemplateLoop(rdr, oenv, out);
    }
  }