Exemple #1
0
  public static void main(String[] args) throws Exception {
    SimpleDateFormat df = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.ENGLISH);
    // String fm=/*"Sun "+*/"Apr 15 16:11:21 JST 2012";
    // fmt="MMM dd HH:mm:ss z yyyy";
    // System.out.println(df.format( new Date()));

    Common.parseArgs(args);
    SFile sFile = getNewestBackupFile(Common.workspace.getBackupDir(Common.dbid));

    // SFile sFile = new SFile(args[0]);
    System.out.println("sFile=" + sFile);
    // String src=sFile.text();
    SFile newFile = sFile.parent().rel("dot_" + sFile.name());
    Map m = (Map) JSON.decode(sFile.inputStream());
    List docs = (List) m.get("DocumentRecord");
    Map<String, String> ids = new HashMap<String, String>();
    Map<Long, Date> lu2Date = new HashMap<Long, Date>();
    List logs = (List) m.get("LogRecord");
    if (logs != null) {
      for (Object l : logs) {
        Map log = (Map) l;
        long id = Long.parseLong(log.get("id") + "");
        Date d = df.parse(log.get("date") + "");
        // d.to
        lu2Date.put(id, d);
        // System.out.println(id+"-"+d);
      }
    }
    // System.exit(1);
    int ser = 0;
    for (Object s : docs) {
      Map doc = (Map) s;
      String id = doc.get("id") + "";
      String newId = id.replace("@", ".");
      ids.put(id, newId);
      if (Common.dbid.equals(SDB.dbIdPart(newId))) {
        int se = SDB.serialPart(newId);
        if (se > ser) ser = se;
      }
      // System.out.println(newId);
      doc.put("id", newId);

      String scope = doc.get("scope") + "";
      if (scope.compareTo("null") != 0) {
        doc.put("scope", scope.replaceAll("@", "."));
      }
      String con = doc.get("constructor") + "";
      if (con.compareTo("null") != 0) {
        doc.put("constructor", con.replaceAll("@", "."));
      }

      convertDate(lu2Date, doc, "lastUpdate");
      convertDate(lu2Date, doc, "lastAccessed");
      String content = doc.get("content") + "";
      //                   byId\("[^"]+@[^"]+"\)
      //                  (byId\("[^"]+)@([^"]+"\))
      //                  (byId\\(\"[^\"]+)@([^\"]+\"\\))
      content = content.replaceAll(idPat, "$1.$2");
      doc.put("content", content);

      doc.put("version", MD5.crypt(content));

      String sum = doc.get("summary") + "";
      int i = 0;
      Matcher ma = around.matcher(content);
      while (true) {
        if (ma.find(i)) {
          String group = ma.group();
          if (group.matches(".*@[a-z\\.]+\\.(com|jp).*")
              || group.contains("アドレス")
              || group.contains("ac.jp/soytext2/exec/")) {

          } else {
            System.out.println(id + ":" + sum + ": " + group);
          }
          i = ma.end();
        } else break;
      }
    }
    for (Object s : docs) {
      Map doc = (Map) s;
      String sum = doc.get("summary") + "";
      if (ids.get(sum) != null) {
        doc.put("summary", ids.get(sum));
      }
    }
    m.remove("IndexRecord");
    m.remove("LogRecord");
    m.put("IdSerialRecord", new Object[] {Maps.create("serial", ser).p("id", 0)});
    /*int idc=ids.size();
    int c=0;
    for (String oldId:ids.keySet()) {
    	String newId=ids.get(oldId);
    	oldId=oldId.replaceAll("\\.", "\\\\$0");
    	newId=newId.replaceAll("\\.", "\\\\$0");
    	System.out.println("["+c+"/"+idc+"]"+"s/"+oldId+"/"+newId+"/g");
    	src=src.replaceAll(oldId, newId);
    }*/
    JSON j = new JSON();
    j.setPrettyPrint(true);
    j.format(m, newFile.outputStream());
    // newFile.text(j.format(m));
    /*for (String s:newFile.lines()) {
    	if (s.indexOf('@')>=0) {
    		System.out.println(s);
    	}
    }*/
  }
Exemple #2
0
 /*private Scriptable newObject() {
 	return (Scriptable)objFactory.construct(org.mozilla.javascript.Context.getCurrentContext(), null, new Object[0]);
 }
 private Scriptable newArray() {
 	return (Scriptable)aryFactory.construct(org.mozilla.javascript.Context.getCurrentContext(), null, new Object[0]);
 }*/
 public String format(Object s) {
   return json.format(s);
 }