Пример #1
0
  private void map(String key, ResultSet rs, boolean railroads) throws Exception {
    ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
    while (rs.next()) {
      HashMap<String, String> map = new HashMap<String, String>();
      ResultSetMetaData meta = rs.getMetaData();
      for (int i = 0; i < meta.getColumnCount(); i++) {
        String k = StringUtils.toLowerEnglish(meta.getColumnLabel(i + 1));
        String value = rs.getString(i + 1);
        value = value.trim();
        map.put(k, PageParser.escapeHtml(value));
      }
      String topic = rs.getString("TOPIC");
      String syntax = rs.getString("SYNTAX").trim();
      if (railroads) {
        String railroad = bnf.getRailroadHtml(syntax);
        map.put("railroad", railroad);
      }
      syntax = bnf.getSyntaxHtml(syntax);
      map.put("syntax", syntax);

      // remove newlines in the regular text
      String text = map.get("text");
      if (text != null) {
        // text is enclosed in <p> .. </p> so this works.
        text = StringUtils.replaceAll(text, "<br /><br />", "</p><p>");
        text = StringUtils.replaceAll(text, "<br />", " ");
        map.put("text", text);
      }

      String link = topic.toLowerCase();
      link = StringUtils.replaceAll(link, " ", "_");
      // link = StringUtils.replaceAll(link, "_", "");
      link = StringUtils.replaceAll(link, "@", "_");
      map.put("link", StringUtils.urlEncode(link));
      list.add(map);
    }
    session.put(key, list);
    int div = 3;
    int part = (list.size() + div - 1) / div;
    for (int i = 0, start = 0; i < div; i++, start += part) {
      List<HashMap<String, String>> listThird =
          list.subList(start, Math.min(start + part, list.size()));
      session.put(key + "-" + i, listThird);
    }
    rs.close();
  }
Пример #2
0
 private void copy(File source, File target, boolean replaceFragments, boolean web)
     throws IOException {
   if (source.isDirectory()) {
     target.mkdirs();
     for (File f : source.listFiles()) {
       copy(f, new File(target, f.getName()), replaceFragments, web);
     }
   } else {
     String name = source.getName();
     if (name.endsWith("onePage.html") || name.startsWith("fragments")) {
       return;
     }
     if (web) {
       if (name.endsWith("main.html") || name.endsWith("main_ja.html")) {
         return;
       }
     } else {
       if (name.endsWith("mainWeb.html") || name.endsWith("mainWeb_ja.html")) {
         return;
       }
     }
     FileInputStream in = new FileInputStream(source);
     byte[] bytes = IOUtils.readBytesAndClose(in, 0);
     if (name.endsWith(".html")) {
       String page = new String(bytes, "UTF-8");
       if (web) {
         page = StringUtils.replaceAll(page, ANALYTICS_TAG, ANALYTICS_SCRIPT);
       }
       if (replaceFragments) {
         page = replaceFragments(name, page);
         page = StringUtils.replaceAll(page, "<a href=\"frame", "<a href=\"main");
         page = StringUtils.replaceAll(page, "html/frame.html", "html/main.html");
       }
       if (web) {
         page = StringUtils.replaceAll(page, TRANSLATE_START, "");
         page = StringUtils.replaceAll(page, TRANSLATE_END, "");
         page = StringUtils.replaceAll(page, "<pre>", "<pre class=\"notranslate\">");
         page = StringUtils.replaceAll(page, "<code>", "<code class=\"notranslate\">");
       }
       bytes = page.getBytes("UTF-8");
     }
     FileOutputStream out = new FileOutputStream(target);
     out.write(bytes);
     out.close();
     if (web) {
       if (name.endsWith("mainWeb.html")) {
         target.renameTo(new File(target.getParentFile(), "main.html"));
       } else if (name.endsWith("mainWeb_ja.html")) {
         target.renameTo(new File(target.getParentFile(), "main_ja.html"));
       }
     }
   }
 }
Пример #3
0
 /**
  * Convert HTML text to plain text.
  *
  * @param html the html text
  * @return the plain text
  */
 private static String convertHtml2Text(String html) {
   String s = html;
   s = StringUtils.replaceAll(s, "<b>", "");
   s = StringUtils.replaceAll(s, "</b>", "");
   s = StringUtils.replaceAll(s, "<ul>", "");
   s = StringUtils.replaceAll(s, "</ul>", "");
   s = StringUtils.replaceAll(s, "<li>", "- ");
   s = StringUtils.replaceAll(s, "</li>", "");
   s = StringUtils.replaceAll(s, "<a href=\"", "( ");
   s = StringUtils.replaceAll(s, "\">", " ) ");
   s = StringUtils.replaceAll(s, "</a>", "");
   s = StringUtils.replaceAll(s, "<br />", "");
   s = StringUtils.replaceAll(s, "<br/>", "");
   s = StringUtils.replaceAll(s, "<br>", "");
   if (s.indexOf('<') >= 0 || s.indexOf('>') >= 0) {
     throw new RuntimeException("Unsupported HTML Tag: < or > in " + s);
   }
   return s;
 }
 private static String escapeMetaDataPattern(String pattern) {
   if (pattern == null || pattern.length() == 0) {
     return pattern;
   }
   return StringUtils.replaceAll(pattern, "\\", "\\\\");
 }