コード例 #1
0
ファイル: Crawler.java プロジェクト: dalinhuang/xdarkness
 if (!publishDateFlag) {
   String[] lastURLs = this.config.getUrlLevels()[(this.config.getUrlLevels().length - 1)].split("\\\n", -1);
   if (lastURLs.length != 1) {
     return;
   }
   RegexParser rpUrl = new RegexParser(lastURLs[0]);
   boolean numberFlag = true;
   for (int i = 0; i < set.size(); ++i) {
     String url = set.get(i).getReferURL();
     rpUrl.setText(url);
     if (rpUrl.match()) {
       String v = rpUrl.getMapx().getString("SortID");
       set.get(i).setProp2(v);
       if (!NumberUtil.isLong(v)) {
         numberFlag = false;
       }
     }
   }
   set.sort("Prop2", "asc", numberFlag);
   for (int i = set.size() - 1; i >= 0; --i) {
     set.get(i).setOrderFlag(OrderUtil.getDefaultOrder());
     set.get(i).setProp2(null);
   }
   set.update();
 }
コード例 #2
0
  public void processSubmit() {
    ZCCustomTableSchema table = new ZCCustomTableSchema();
    table.setID($V("_TableID"));
    if (!table.fill()) {
      LogUtil.warn("没有ID为" + table.getCode() + "的表!");
      return;
    }
    if ((!"Y".equals(table.getAllowModify())) && (!User.isManager())) {
      LogUtil.warn("ID为" + table.getID() + "的表不允许前台修改!");
      return;
    }

    DataAccess da = null;
    String code = table.getCode();
    if (table.getType().equals("Link")) {
      da = new DataAccess(OuterDatabase.getConnection(table.getDatabaseID()));
      code = table.getOldCode();
    } else {
      da = new DataAccess();
    }
    try {
      da.setAutoCommit(false);
      ZCCustomTableColumnSet set =
          new ZCCustomTableColumnSchema().query(new QueryBuilder("where TableID=?", table.getID()));
      StringBuffer sb = new StringBuffer("insert into " + code + "(");
      for (int j = 0; j < set.size(); ++j) {
        if (j != 0) {
          sb.append(",");
        }
        sb.append(set.get(j).getCode());
      }
      sb.append(") values (");
      for (int j = 0; j < set.size(); ++j) {
        if (j != 0) {
          sb.append(",");
        }
        sb.append("?");
      }
      sb.append(")");
      QueryBuilder qb = new QueryBuilder(sb.toString());
      StringBuffer messageSB = new StringBuffer();
      for (int j = 0; j < set.size(); ++j) {
        ZCCustomTableColumnSchema column = set.get(j);
        String v = $V("_Form_" + set.get(j).getCode());
        if (StringUtil.isEmpty(v)) {
          v = null;
          if ("Y".equals(set.get(j).getIsAutoID())) {
            v = String.valueOf(OrderUtil.getDefaultOrder());
          }
        }
        if (((("Y".equals(column.getIsMandatory())) || ("Y".equals(column.getIsPrimaryKey()))))
            && (StringUtil.isEmpty(v))) {
          messageSB.append(column.getName() + "不能为空!\n");
        }

        int dataType = Integer.parseInt(column.getDataType());
        if (v != null) {
          if ((column.getMaxLength() != 0) && (v.length() < column.getMaxLength()))
            messageSB.append(column.getName() + "数据过长,最大允许" + column.getMaxLength() + "个字符!\n");
          try {
            if (dataType == 0) {
              v = DateUtil.toDateTimeString(DateUtil.parseDateTime(v));
              if (v == null) {
                throw new SQLException("日期时间错误");
              }
            }
            if ((dataType == 8) || (dataType == 9)) {
              v = String.valueOf(new Double(Double.parseDouble(v)).intValue());
            }
            if (dataType == 7) {
              v = String.valueOf(new Double(Double.parseDouble(v)).longValue());
            }
            if (dataType == 5) {
              v = String.valueOf(new Double(Double.parseDouble(v)).floatValue());
            }
            if ((dataType == 4) || (dataType == 6) || (dataType == 3))
              v = String.valueOf(Double.parseDouble(v));
          } catch (Exception e) {
            messageSB.append(column.getName() + "数据不正确!\n");
          }
        }
        qb.add(v);
      }
      if (messageSB.length() != 0) {
        this.Response.setError(messageSB.toString());
      } else {
        da.executeNoQuery(qb);
        da.commit();
        this.Response.setMessage("提交成功!");
      }
    } catch (Exception e) {
      e.printStackTrace();
      try {
        da.rollback();
      } catch (SQLException e1) {
        e1.printStackTrace();
      }
      this.Response.setMessage("提交失败:" + e.getMessage());
    } finally {
      try {
        da.setAutoCommit(true);
        da.close();
      } catch (SQLException e) {
        e.printStackTrace();
      }
    }
  }
コード例 #3
0
  public static void processSubmit(HttpServletRequest request, HttpServletResponse response) {
    ZCCustomTableSchema table = new ZCCustomTableSchema();
    table.setID(request.getParameter("_TableID"));
    if (!table.fill()) {
      LogUtil.warn("没有ID为" + table.getCode() + "的表!");
      return;
    }
    if ((!"Y".equals(table.getAllowModify())) && (!User.isManager())) {
      LogUtil.warn("ID为" + table.getID() + "的表不允许前台修改!");
      return;
    }

    DataAccess da = null;
    String code = table.getCode();
    if (table.getType().equals("Link")) {
      da = new DataAccess(OuterDatabase.getConnection(table.getDatabaseID()));
      code = table.getOldCode();
    } else {
      da = new DataAccess();
    }
    try {
      da.setAutoCommit(false);
      ZCCustomTableColumnSet set =
          new ZCCustomTableColumnSchema().query(new QueryBuilder("where TableID=?", table.getID()));
      StringBuffer insertSB = new StringBuffer("insert into " + code + "(");
      QueryBuilder deleteQB = new QueryBuilder("delete from  " + code + " where 1=1 ");
      for (int j = 0; j < set.size(); ++j) {
        if (j != 0) {
          insertSB.append(",");
        }
        insertSB.append(set.get(j).getCode());
      }
      insertSB.append(") values (");
      for (int j = 0; j < set.size(); ++j) {
        if (j != 0) {
          insertSB.append(",");
        }
        insertSB.append("?");
        if ("Y".equals(set.get(j).getIsPrimaryKey())) {
          String v = request.getParameter("_Form_" + set.get(j).getCode() + "_Old");
          deleteQB.append(" and " + set.get(j).getCode() + "=?", v);
        }
      }
      insertSB.append(")");
      QueryBuilder qb = new QueryBuilder(insertSB.toString());
      StringBuffer messageSB = new StringBuffer();
      for (int j = 0; j < set.size(); ++j) {
        ZCCustomTableColumnSchema column = set.get(j);
        String v = request.getParameter("_Form_" + set.get(j).getCode());
        if (StringUtil.isEmpty(v)) {
          v = null;
          if ("Y".equals(set.get(j).getIsAutoID())) {
            v = String.valueOf(OrderUtil.getDefaultOrder());
          }
        }
        if (((("Y".equals(column.getIsMandatory())) || ("Y".equals(column.getIsPrimaryKey()))))
            && (StringUtil.isEmpty(v))) {
          messageSB.append(column.getName() + "不能为空!\\n");
        }

        int dataType = Integer.parseInt(column.getDataType());
        if (v != null) {
          if ((column.getMaxLength() != 0) && (v.length() < column.getMaxLength()))
            messageSB.append(column.getName() + "数据过长,最大允许" + column.getMaxLength() + "个字符!\\n");
          try {
            if (dataType == 0) {
              v = DateUtil.toDateTimeString(DateUtil.parseDateTime(v));
              if (v == null) {
                throw new SQLException("日期时间错误");
              }
            }
            if ((dataType == 8) || (dataType == 9)) {
              v = String.valueOf(new Double(Double.parseDouble(v)).intValue());
            }
            if (dataType == 7) {
              v = String.valueOf(new Double(Double.parseDouble(v)).longValue());
            }
            if (dataType == 5) {
              v = String.valueOf(new Double(Double.parseDouble(v)).floatValue());
            }
            if ((dataType == 4) || (dataType == 6) || (dataType == 3))
              v = String.valueOf(Double.parseDouble(v));
          } catch (Exception e) {
            messageSB.append(column.getName() + "数据不正确!\\n");
          }
        }
        qb.add(v);
      }
      if (messageSB.length() != 0) {
        insertSB = new StringBuffer();
        insertSB.append("<script>");
        insertSB.append("alert(\"" + messageSB + "\");");
        insertSB.append("history.go(-1);");
        insertSB.append("</script>");
        response.getWriter().print(insertSB);
      } else {
        da.executeNoQuery(deleteQB);
        da.executeNoQuery(qb);
        da.commit();
        insertSB = new StringBuffer();
        insertSB.append("<script>");
        insertSB.append("alert(\"提交成功!\");");
        insertSB.append("window.location=\"" + request.getHeader("referer") + "\";");
        insertSB.append("</script>");
        response.getWriter().print(insertSB);
      }
    } catch (Exception e) {
      e.printStackTrace();
      try {
        da.rollback();
      } catch (SQLException e1) {
        e1.printStackTrace();
      }
      StringBuffer sb = new StringBuffer();
      sb.append("<script>");
      sb.append("alert(\"提交失败!\");");
      sb.append("history.go(-1);");
      sb.append("</script>");
      try {
        response.getWriter().print(sb);
      } catch (IOException e1) {
        e1.printStackTrace();
      }
    } finally {
      try {
        da.setAutoCommit(true);
        da.close();
      } catch (SQLException e) {
        e.printStackTrace();
      }
    }
  }