public void addConfiguredHtmlFragment(HtmlFragment fragment) {
   final String name = fragment.getName();
   if (name == null) {
     throw new BuildException("Nested HTML-fragments must have a name");
   }
   if (null == fragment.getFromFile()) {
     throw new BuildException("Nested HTML-fragments must have a from file");
   }
   fragments.put(name, fragment);
 }
  private void transform(String fromFile, String toFile) {
    if (fromFile == null) {
      throw new BuildException("fromfile must be set");
    }
    if (toFile == null) {
      throw new BuildException("tofile must be set");
    }

    try {
      final Project proj = getProject();
      File tmp = new File(outdir, toFile).getParentFile();

      if (!tmp.exists()) {
        if (tmp.exists() || !tmp.mkdirs()) {
          throw new IOException("Could not create " + tmp);
        }
      }

      tmp = new File(toFile);
      String pathToRoot = ".";

      while ((tmp = tmp.getParentFile()) != null) {
        pathToRoot = pathToRoot + "/..";
      }

      // Compute the relative path from directory holding the toFile
      // to the javadoc direcotry.
      String pathToOutDir = "";
      tmp = new File(outdir, toFile).getParentFile();
      while ((tmp = tmp.getParentFile()) != null && tmp.equals(outdir)) {
        pathToOutDir = pathToOutDir + "../";
      }
      final String pathToJavadocDir = pathToOutDir + javadocRelPath;

      String content = FileUtil.loadFile(template.toString());
      content = Util.replace(content, "$(LINKS)", links());
      content = Util.replace(content, "$(MAIN)", FileUtil.loadFile(fromFile));
      for (final Object element : fragments.keySet()) {
        final String key = (String) element;
        final HtmlFragment frag = fragments.get(key);
        final String linkText = frag.getLinkText();
        if (null != linkText && 0 < linkText.length()) {
          final String fragLink = "<a href=\"#" + key + "\">" + linkText + "</a>";
          content = Util.replace(content, "$(" + key + "_LINK)", fragLink);
        }
        String fragCont = FileUtil.loadFile(frag.getFromFile().getPath());
        if (null != fragCont && 0 < fragCont.length()) {
          fragCont = "<a name=\"" + key + "\"></a>\n" + fragCont;
        }
        content = Util.replace(content, "$(" + key + ")", fragCont);
      }
      content = Util.replace(content, "$(TITLE)", title);
      content = Util.replace(content, "$(DESC)", description);
      content = Util.replace(content, "$(TSTAMP)", TIMESTAMP);
      content = Util.replace(content, "$(YEAR)", YEAR);
      content = Util.replace(content, "$(USER)", System.getProperty("user.name"));
      content = Util.replace(content, "$(VERSION)", proj.getProperty("version"));
      content = Util.replace(content, "$(VERSION_PREV)", proj.getProperty("version.previous"));
      content = Util.replace(content, "$(KF_VERSION)", proj.getProperty("kf_version"));
      content = Util.replace(content, "$(BASE_VERSION)", proj.getProperty("base_version"));
      content = Util.replace(content, "$(BASE_URL)", proj.getProperty("base.url"));
      content = Util.replace(content, "$(DISTNAME)", proj.getProperty("distname"));
      content = Util.replace(content, "$(DISTRIB_NAME)", proj.getProperty("distrib.name"));
      content = Util.replace(content, "$(RELEASE_NAME)", proj.getProperty("release.name"));
      content = Util.replace(content, "$(RELEASE_DATE)", proj.getProperty("release.date"));
      content = Util.replace(content, "$(MESSAGE)", proj.getProperty("release"));
      content = Util.replace(content, "$(BUNDLE_LIST)", bundleList);
      content = Util.replace(content, "$(ROOT)", pathToRoot);
      content = Util.replace(content, "$(JAVADOC)", proj.getProperty("JAVADOC"));
      content =
          Util.replace(content, "$(CLASS_NAVIGATION)", proj.getProperty("css_navigation_enabled"));
      content = Util.replace(content, "$(SVN_REPO_URL)", proj.getProperty("svn.repo.url"));
      content = Util.replace(content, "$(SVN_TAG)", proj.getProperty("svn.tag"));
      content = Util.replace(content, "$(JAVADOCPATH)", pathToJavadocDir);
      content = Util.replace(content, "$(JAVADOCLINK)", pathToJavadocDir + "/index.html?");

      // Used for bundle_doc generation
      if (do_manpage) {
        content = Util.replace(content, "$(BUNDLE_NAME)", this.projectName);
        content =
            Util.replace(content, "$(BUNDLE_VERSION)", proj.getProperty("bmfa.Bundle-Version"));

        final BundleArchives bas = getBundleArchives();

        // Create links to jardoc for bundles built from this project
        content = Util.replace(content, "$(BUNDLE_JARDOCS)", basToString(bas));

        content =
            Util.replace(content, "$(BUNDLE_EXPORT_PACKAGE)", getExportPkgs(bas, pathToJavadocDir));

        // Replce H1-H3 headers to man page style, if manpage style
        content = Util.replace(content, "<h1", "<h1 class=\"man\"");
        content = Util.replace(content, "<H1", "<h1 class=\"man\"");
        content = Util.replace(content, "<h2", "<h2 class=\"man\"");
        content = Util.replace(content, "<H2", "<h2 class=\"man\"");
        content = Util.replace(content, "<h3", "<h3 class=\"man\"");
        content = Util.replace(content, "<H3", "<h3 class=\"man\"");
      }

      final String s = proj.getProperty("navigation_pages");
      final String navEnabled = proj.getProperty("css_navigation_enabled");
      final String navDisabled = proj.getProperty("css_navigation_disabled");
      // System.out.println("Navigation pages: " + s);
      if (s != null) {
        final String[] navPages = Util.splitwords(s);
        for (final String navPage : navPages) {
          // System.out.println("Checking: " + navPages[i]);
          if (disable != null && disable.equals(navPage)) {
            content = Util.replace(content, "$(CLASS_NAVIGATION_" + navPage + ")", navDisabled);
          } else {
            content = Util.replace(content, "$(CLASS_NAVIGATION_" + navPage + ")", navEnabled);
          }
        }
      }

      FileUtil.writeStringToFile(new File(outdir, toFile), content);
      log("Created: " + new File(outdir, toFile));
    } catch (final IOException e) {
      e.printStackTrace();
      throw new BuildException(e);
    } catch (final Exception e) {
      e.printStackTrace();
      throw new BuildException(e);
    }
  }