Exemple #1
0
  private static String convertPage(
      @NotNull PageProperties props, @NotNull File file, @NotNull String htmlBody)
      throws IOException {
    String path = file.getPath();
    File templateFile = new File(websiteDir, "template.html");
    String template = CharsetDetectorHelper.toString(templateFile);

    Pair[] pairs =
        new Pair[] {
          props.title, props.author, props.keywords, props.description,
          props.overview, props.download, props.screenshots, props.more
        };

    for (Pair pair : pairs) {
      String key = "${" + pair.key + "}";
      template = UtilGlobal.replace(path, template, key, pair.value);
    }

    String year = String.valueOf(Calendar.getInstance().get(Calendar.YEAR));
    template = UtilGlobal.replace(path, template, "${year}", year);

    String html = UtilGlobal.replace(path, template, "${contents}", htmlBody);

    // Insert awards table on main page
    if (file.getName().equals("index.markdown")) {
      File awardsFile = new File(websiteDir, "awards.html");
      String awardsTable = CharsetDetectorHelper.toString(awardsFile);
      html = UtilGlobal.replace(path, html, "${awards_table}", awardsTable);
    }

    // Insert version number; must be done after inserting the markdown
    String versionKey = "${version}";
    if (html.contains(versionKey)) html = UtilGlobal.replace(path, html, versionKey, version);

    return html;
  }
Exemple #2
0
  public static void main(String[] args) throws Exception {
    for (File srcDir : Util.listFiles(websiteDir)) {
      if (!srcDir.isDirectory()) continue;
      if (srcDir.getName().equals("all")) continue;

      File dstDir = new File("dist/website/" + srcDir.getName());
      dstDir.mkdirs();
      Util.deleteContents(dstDir);

      PegDownProcessor processor = new PegDownProcessor(Extensions.TABLES);
      File propsFile = new File(srcDir, "/page.properties");
      PageProperties props = new PageProperties(propsFile);
      convertDir(processor, props, srcDir, dstDir);
    }

    // Deploy files in the website/all directory
    for (File file : Util.listFiles(new File(websiteDir + "/all"))) {
      File dstFile = new File("dist/website/all", file.getName());
      Files.createParentDirs(dstFile);
      Files.copy(file, dstFile);
    }

    // Deploy PAD file
    File padFileSrc = new File(websiteDir, "docfetcher-pad-template.xml");
    File padFileDst = new File("dist/website", "docfetcher-pad.xml");
    String padContents = CharsetDetectorHelper.toString(padFileSrc);
    padContents = UtilGlobal.replace(padFileSrc.getPath(), padContents, "${version}", version);
    Files.write(padContents, padFileDst, Charsets.UTF_8);
    Util.println("File written: " + padFileDst.getPath());

    // Deploy English Resource.properties; this is currently used for
    // GUI translation via transifex.com
    Properties prop = new Properties();
    for (Msg msg : Msg.values()) prop.put(msg.name(), msg.get());
    File propFile = new File("dist/website", "Resource.properties");
    FileWriter w = new FileWriter(propFile);
    prop.store(w, "");
    Closeables.closeQuietly(w);
    Util.println("File written: " + propFile.getPath());

    // Deploy index.php file
    File indexPhpFile = new File("dist/website/index.php");
    Files.copy(new File(websiteDir, "index.php"), indexPhpFile);
    Util.println("File written: " + indexPhpFile.getPath());

    // Deploy help file for GUI translators
    File propHelpSrc = new File(websiteDir, "prop-help-template.html");
    File propHelpDst = new File("dist/website", "properties-help.html");
    StringBuilder sb = new StringBuilder();
    for (Msg msg : Msg.values()) {
      sb.append("<tr align=\"left\">");
      sb.append("<td>");
      sb.append(escapeHtml(propHelpSrc.getPath(), msg.get()));
      sb.append("</td>");
      sb.append(Util.LS);
      sb.append("<td>");
      sb.append(msg.getComment());
      sb.append("</td>");
      sb.append("</tr>");
      sb.append(Util.LS);
    }
    String propHelpContents = CharsetDetectorHelper.toString(propHelpSrc);
    propHelpContents =
        UtilGlobal.replace(propHelpSrc.getPath(), propHelpContents, "${contents}", sb.toString());
    Files.write(propHelpContents, propHelpDst, Charsets.UTF_8);
    Util.println("File written: " + propHelpDst.getPath());
  }
Exemple #3
0
 @NotNull
 private static String escapeHtml(@NotNull String srcPath, @NotNull String input) {
   return UtilGlobal.replaceSilently(
       input, "&", "&amp;", "\"", "&quot;", "<", "&lt;", ">", "&gt;", "\n", "<br/>", "\t",
       "&emsp;");
 }