예제 #1
0
  /**
   * @param configuration
   * @throws FileNotFoundException
   */
  public void generate(final Configuration configuration) {

    IOUtil ioUtil = new IOUtil();

    for (ConfigOutput configOutput : configuration.getOutputs()) {

      Writer writer = null;
      try {
        writer = this.generate(configOutput, configuration);
      } catch (Exception e) {
        e.printStackTrace();
        continue;
      }

      // TODO tratar o getFilenamePattern quando é "pattern"
      File outputFile =
          new File(configuration.getOutputBaseDir() + configOutput.getFilenamePattern());
      // grava no file system
      try {
        ioUtil.writeTo(outputFile, new StringReader(writer.toString()), "UTF-8");
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
예제 #2
0
  public Writer generate(ConfigOutput configOutput, final Configuration configuration)
      throws Exception {
    StringWriter writer = new StringWriter();

    final File templateFile =
        new File(configuration.getTemplateBaseDir() + configOutput.getTemplate());
    if (!templateFile.exists()) {
      System.err.println("Erro: template " + templateFile.getAbsolutePath() + " não existe.");
      throw new FileNotFoundException();
    }

    VelocityContext context = new VelocityContext();

    bindContext(context, configOutput.getInputs());

    // escapeUtil
    context.put("escape", new EscapeUtil());

    velocityEngine.evaluate(context, writer, "Gerando template", new FileReader(templateFile));

    return writer;
  }