private void generateFile(Template temp, Map<String, Object> root)
      throws TemplateException, IOException {

    StringWriter out = new StringWriter();
    temp.process(root, out);
    String tempOutput = out.toString();

    if (tempOutput.isEmpty()) {
      System.out.println(
          "No file generation because applying template '" + temp.getName() + "' is empty");
      return;
    }

    StringTokenizer st = new StringTokenizer(tempOutput);

    String fileName = st.nextToken();

    File outputFile = new File(outputFolder.toFile(), fileName);

    if (!outputFile.getParentFile().exists()) {
      outputFile.getParentFile().mkdirs();
    }

    String sourceCode = tempOutput.substring(fileName.length() + 1, tempOutput.length());

    boolean generateFile = !outputFile.exists();
    if (outputFile.exists() && overwrite) {
      generateFile = true;
      String oldContent = readFile(outputFile);

      if (oldContent.equals(sourceCode)) {
        generateFile = false;
      }
    }

    if (generateFile) {
      Writer writer = new FileWriter(outputFile);
      writer.write(sourceCode);
      writer.close();
    }

    if (verbose) {
      System.out.println("File: " + fileName);
      System.out.println();
      System.out.println(sourceCode);
      System.out.println("---------------------------------------");
    }

    if (listGeneratedFiles) {
      System.out.print("Processed file:\t" + fileName);
      if (!generateFile) {
        System.out.println("\t(not generated)");
      } else {
        System.out.println();
      }
    }
  }