Пример #1
0
  public static SearchResult tagSearch(Mapx map) {
    SearchParameters sps = new SearchParameters();
    String site = map.getString("site");
    String order = map.getString("order");
    String keyword = map.getString("keyword");
    String query = map.getString("query");
    if (StringUtil.isEmpty(keyword)) {
      keyword = query;
    }
    String page = map.getString("page");
    String size = map.getString("size");

    if (StringUtil.isNotEmpty(keyword)) {
      sps.addLikeField("Tag", keyword, false);
    }

    if ("time".equalsIgnoreCase(order)) {
      sps.setSortField("PublishDate", 3, true);
    }
    if (StringUtil.isNotEmpty(page)) {
      sps.setPageIndex(Integer.parseInt(page) - 1);
    }
    if (StringUtil.isNotEmpty(size)) {
      sps.setPageSize(Integer.parseInt(size));
    }
    String id = SearchAPI.getIndexIDBySiteID(site);
    sps.setIndexID(Long.parseLong(id));
    return ArticleIndexer.search(sps);
  }
Пример #2
0
  public static SearchResult search(Mapx map) {
    SearchParameters sps = new SearchParameters();
    String site = map.getString("site");
    String id = map.getString("id");
    String catalog = map.getString("catalog");
    if (StringUtil.isEmpty(catalog)) {
      catalog = map.getString("Catalog");
    }
    String order = map.getString("order");
    String time = map.getString("time");
    String keyword = map.getString("keyword");
    String query = map.getString("query");
    if (StringUtil.isEmpty(keyword)) {
      keyword = query;
    }
    String page = map.getString("page");
    String size = map.getString("size");

    if (StringUtil.isEmpty(id)) {
      id = SearchAPI.getIndexIDBySiteID(site);
    }

    if (StringUtil.isNotEmpty(keyword)) {
      sps.addFulltextField("Title", keyword, false);
      sps.addFulltextField("Content", keyword, false);
      sps.addFulltextField("_Keyword", keyword, true);
    }

    if ("time".equalsIgnoreCase(order)) {
      sps.setSortField("PublishDate", 3, true);
    }

    if (StringUtil.isNotEmpty(time)) {
      Date today = new Date();
      String StartDate = DateUtil.toString(DateUtil.addDay(today, -36500));
      if (time.equals("week")) StartDate = DateUtil.toString(DateUtil.addDay(today, -7));
      else if (time.equals("month")) StartDate = DateUtil.toString(DateUtil.addDay(today, -30));
      else if (time.equals("quarter")) {
        StartDate = DateUtil.toString(DateUtil.addDay(today, -90));
      }
      String EndDate = "2999-01-01";
      sps.setDateRange("PublishDate", StartDate, EndDate);
    }
    if (StringUtil.isNotEmpty(catalog)) {
      sps.addLeftLikeField("CatalogInnerCode", catalog);
    }
    if (StringUtil.isNotEmpty(page)) {
      sps.setPageIndex(Integer.parseInt(page) - 1);
    }
    if (StringUtil.isNotEmpty(size)) {
      sps.setPageSize(Integer.parseInt(size));
    }
    if (StringUtil.isEmpty(id)) {
      SearchResult sr = new SearchResult();
      sr.Data = new DataTable();
      return sr;
    }
    sps.setIndexID(Long.parseLong(id));
    return ArticleIndexer.search(sps);
  }
Пример #3
0
 public void deal(Visit v) {
   if ("Unload".equals(v.Event)) {
     return;
   }
   if (!this.siteMap.containsKey(new Long(v.SiteID))) {
     VisitCount.getInstance().initLRUMap(v.SiteID, "Source", "Keyword", 1000, null);
     VisitCount.getInstance().initLRUMap(v.SiteID, "Source", "Referer", 1000, null);
     this.siteMap.put(new Long(v.SiteID), "");
   }
   VisitCount.getInstance().add(v.SiteID, "Source", "Host", v.Host);
   if (v.UVFlag)
     if ((StringUtil.isEmpty(v.Referer)) && (v.URL.indexOf("Result.jsp") < 0)) {
       VisitCount.getInstance().add(v.SiteID, "Source", "Direct", "0");
     } else {
       String[] se = getSearchEngine(v);
       if (se == null) {
         String domain = StatUtil.getDomain(v.Referer);
         if (!domain.equalsIgnoreCase(v.Host))
           VisitCount.getInstance().add(v.SiteID, "Source", "Referer", domain);
         else VisitCount.getInstance().add(v.SiteID, "Source", "Direct", "0");
       } else {
         VisitCount.getInstance().add(v.SiteID, "Source", "SearchEngine", se[0]);
         VisitCount.getInstance().add(v.SiteID, "Source", "Keyword", se[1]);
       }
     }
 }
Пример #4
0
  public void init(FilterConfig config) throws ServletException {
    this.config = config;

    String value = null;
    try {
      value = config.getInitParameter("debug");
      this.debug = Integer.parseInt(value);
    } catch (Throwable localThrowable) {
    }

    try {
      value = config.getInitParameter("expires");
      if (StringUtil.isEmpty(value)) {
        value = "0";
      }
      this.expires = Long.valueOf(value);
    } catch (NumberFormatException e) {
      this.expires = null;
      config
          .getServletContext()
          .log("Invalid format for expires initParam; expected integer (seconds)");
    } catch (Throwable localThrowable1) {
    }
    if (this.debug > 0)
      config
          .getServletContext()
          .log("SSIFilter.init() SSI invoker started with 'debug'=" + this.debug);
  }
Пример #5
0
  public static void dg1DataBind(DataGridAction dga) {
    String searchUserName = dga.getParam("searchUserName");

    QueryBuilder qb = new QueryBuilder("select * from ZSOrder where IsValid = 'Y' and status='10'");
    QueryBuilder totalQB =
        new QueryBuilder("select * from ZSOrder where IsValid = 'Y' and status='10'");
    if (StringUtil.isNotEmpty(searchUserName)) {
      qb.append(" and UserName like ? ", "%" + searchUserName + "%");
      totalQB.append(" and UserName like ? ", "%" + searchUserName + "%");
    }
    dga.setTotal(totalQB);

    qb.append(" order by id desc");
    DataTable dt = qb.executePagedDataTable(dga.getPageSize(), dga.getPageIndex());
    dt.decodeColumn("IsValid", HtmlUtil.codeToMapx("Order.IsValid"));
    dt.decodeColumn("HasInvoice", HtmlUtil.codeToMapx("Order.HasInvoice"));
    dt.decodeColumn("Status", HtmlUtil.codeToMapx("Order.Status"));
    DataTable dc =
        new QueryBuilder("select Name,Code from zddistrict Order by Code").executeDataTable();
    Mapx map = dc.toMapx("Code", "Name");
    dt.decodeColumn("Province", map);
    dt.decodeColumn("City", map);
    dt.decodeColumn("District", map);
    dga.bindData(dt);
  }
Пример #6
0
  public void setRelaTableMaxNo(SiteTableRela.TableRela tr, DataRow dr, boolean newIDFlag) {
    for (int i = 0; i < this.NoRelas.length; ++i) {
      SiteTableRela.NoType nr = this.NoRelas[i];
      if (nr.TableCode.equalsIgnoreCase(tr.TableCode)) {
        String id = dr.getString(nr.FieldName);
        if (newIDFlag) {
          id = String.valueOf(NoUtil.getMaxID(nr.NoType));
        }
        addIDMapping(nr.TableCode + "." + nr.FieldName, dr.getString(nr.FieldName), id);
        dr.set(nr.FieldName, id);
      }
    }
    for (int i = 0; i < this.TableRelas.length; ++i)
      if (this.TableRelas[i].TableCode.equals(tr.TableCode)) {
        String type = this.TableRelas[i].RelaTable;
        if ((((type.equals("ZCArticle"))
                || (type.equals("ZCAttachment"))
                || (type.equals("ZCImage"))
                || (type.equals("ZCAudio"))
                || (type.equals("ZCVideo"))))
            && (this.TableRelas[i].RelaField.equals("ID"))) {
          type = "Document";
        }

        String id =
            getIDMapping(
                type + "." + this.TableRelas[i].RelaField,
                dr.getString(this.TableRelas[i].KeyField));
        if (StringUtil.isNotEmpty(id)) dr.set(this.TableRelas[i].KeyField, id);
      }
  }
Пример #7
0
  public static Mapx initDetailDialog(Mapx params) {
    String id = params.getString("ID");
    String Type = params.getString("Type");
    if (StringUtil.isEmpty(id)) {
      return null;
    }
    DataTable dt = new QueryBuilder("select * from ZCMessage where ID=?", id).executeDataTable();
    if ((dt != null) && (dt.getRowCount() > 0)) {
      params.putAll(dt.getDataRow(0).toMapx());
      if ("history".equals(Type)) {
        params.put("UserType", "收");
        params.put("FromUser", "");
      } else {
        params.put("UserType", "发");
        params.put("ToUser", "");

        int readFlag = Integer.parseInt(dt.getDataRow(0).getString("ReadFlag"));
        if (readFlag == 0) {
          new QueryBuilder("update ZCMessage set ReadFlag = 1 where ID=?", id).executeNoQuery();
          QueryBuilder qb =
              new QueryBuilder(
                  "select count(1) from ZCMessage where ReadFlag=0 and ToUser=?",
                  User.getUserName());
          CacheManager.set("Message", "Count", User.getUserName(), qb.executeInt());
        }
      }
    }
    return params;
  }
Пример #8
0
 public void execute() {
   ZDUserSchema user = new ZDUserSchema();
   user.setUserName("demo");
   user.fill();
   user.setPassword(StringUtil.md5Hex("demo"));
   user.setStatus("1");
   user.update();
 }
Пример #9
0
  public void setSiteIDTableMaxNo(String tableName, DataRow dr, boolean newIDFlag) {
    try {
      if (dr.getDataColumn("SiteID") != null)
        dr.set("SiteID", getIDMapping("ZCSite", String.valueOf(this.siteID)));
    } catch (Throwable t) {
      t.printStackTrace();
      LogUtil.warn(tableName);
    }
    for (int i = 0; i < this.NoRelas.length; ++i) {
      SiteTableRela.NoType nr = this.NoRelas[i];
      if (nr.TableCode.equalsIgnoreCase(tableName)) {
        String id = dr.getString(nr.FieldName);
        if (newIDFlag) {
          if ((nr.TableCode.equals("ZCCatalog")) && (nr.FieldName.equals("InnerCode")))
            if (id.length() == 6) {
              id = CatalogUtil.createCatalogInnerCode(null);
            } else {
              String parent = id.substring(0, id.length() - 6);
              parent = getIDMapping(nr.TableCode + "." + nr.FieldName, parent);
              id = CatalogUtil.createCatalogInnerCode(parent);
            }
          else {
            id = String.valueOf(NoUtil.getMaxID(nr.NoType));
          }
        }
        String type = nr.TableCode;
        if ((((type.equals("ZCArticle"))
                || (type.equals("ZCAttachment"))
                || (type.equals("ZCImage"))
                || (type.equals("ZCAudio"))
                || (type.equals("ZCVideo"))))
            && (nr.NoType.equals("DocID"))) {
          type = "Document";
        }

        addIDMapping(type + "." + nr.FieldName, dr.getString(nr.FieldName), id);
        dr.set(nr.FieldName, id);
      }
    }
    for (int i = 0; i < this.TableRelas.length; ++i)
      if (this.TableRelas[i].TableCode.equals(tableName)) {
        String type = this.TableRelas[i].RelaTable;
        if ((((type.equals("ZCArticle"))
                || (type.equals("ZCAttachment"))
                || (type.equals("ZCImage"))
                || (type.equals("ZCAudio"))
                || (type.equals("ZCVideo"))))
            && (this.TableRelas[i].RelaField.equals("ID"))) {
          type = "Document";
        }

        String id =
            getIDMapping(
                type + "." + this.TableRelas[i].RelaField,
                dr.getString(this.TableRelas[i].KeyField));
        if (StringUtil.isNotEmpty(id)) dr.set(this.TableRelas[i].KeyField, id);
      }
  }
Пример #10
0
 public void reply() {
   String toUser = $V("ToUser");
   if (!StringUtil.checkID(toUser)) {
     this.Response.setLogInfo(0, "传入参数错误!");
     return;
   }
   if (MessageCache.addMessage($V("Subject"), $V("Content"), toUser))
     this.Response.setLogInfo(1, "添加回复成功!");
   else this.Response.setLogInfo(0, "添加回复失败!");
 }
Пример #11
0
  public void add() {
    String toUser = $V("ToUser");
    if (!StringUtil.checkID(toUser)) {
      this.Response.setLogInfo(0, "传入参数错误!");
      return;
    }
    String[] userList = toUser.split(",");

    String toRole = $V("ToRole");
    if (!StringUtil.checkID(toRole)) {
      this.Response.setLogInfo(0, "传入参数错误!");
      return;
    }
    String[] roleList = toRole.split(",");

    if (roleList.length > 0) {
      String roleStr = "";
      for (int j = 0; j < roleList.length; ++j) {
        if (StringUtil.isNotEmpty(roleList[j])) {
          if (j == 0) roleStr = roleStr + "'" + roleList[j] + "'";
          else {
            roleStr = roleStr + ",'" + roleList[j] + "'";
          }
        }
      }
      if (StringUtil.isNotEmpty(roleStr)) {
        DataTable dt =
            new QueryBuilder("select UserName from zduserRole where rolecode in (" + roleStr + ")")
                .executeDataTable();
        for (int k = 0; k < dt.getRowCount(); ++k) {
          String userName = dt.getString(k, "UserName");
          if ((!User.getUserName().equals(userName))
              && (!ArrayUtils.contains(userList, userName))) {
            userList = (String[]) ArrayUtils.add(userList, userName);
          }
        }
      }
    }

    if (MessageCache.addMessage($V("Subject"), $V("Content"), userList, User.getUserName()))
      this.Response.setLogInfo(1, "新建成功!");
    else this.Response.setLogInfo(0, "新建失败!");
  }
Пример #12
0
 public static Mapx initReplyDialog(Mapx params) {
   String id = params.getString("ID");
   if (StringUtil.isEmpty(id)) {
     return null;
   }
   DataTable dt = new QueryBuilder("select * from ZCMessage where ID=?", id).executeDataTable();
   if ((dt != null) && (dt.getRowCount() > 0)) {
     return dt.getDataRow(0).toMapx();
   }
   return null;
 }
Пример #13
0
 public String getIDMapping(String type, String oldID) {
   Object obj = this.idMap.get(type);
   if (StringUtil.isEmpty(oldID)) {
     return null;
   }
   if (obj == null) {
     LogUtil.info("站点导入时未找到ID映射关系:Type=" + type + ",OldID=" + oldID);
     return null;
   }
   Mapx map = (Mapx) obj;
   return map.getString(oldID);
 }
Пример #14
0
  public static void bindRoleList(DataGridAction dga) {
    String searchRoleName = dga.getParam("SearchRoleName");
    QueryBuilder qb = new QueryBuilder("select * from ZDRole");
    qb.append(" where BranchInnerCode like ?", User.getBranchInnerCode() + "%");
    if (StringUtil.isNotEmpty(searchRoleName)) {
      qb.append(" and (RoleCode like ?", "%" + searchRoleName.trim() + "%");

      qb.append(" or RoleName like ?)", "%" + searchRoleName.trim() + "%");
    }
    qb.append(" order by AddTime desc");
    dga.bindData(qb);
  }
Пример #15
0
 public static boolean evalCondition(Treex.TreeNode parent, TemplateContext context) {
   LogicClause clause = (LogicClause) parent.getData();
   if ((clause != null) && (StringUtil.isNotEmpty(clause.getClauseString()))) {
     return clause.execute(context);
   }
   Treex.TreeNodeList list = parent.getChildren();
   boolean v = true;
   for (int i = 0; i < list.size(); ++i) {
     clause = (LogicClause) list.get(i).getData();
     boolean isOr = clause.isOr;
     if ((clause == null) || (StringUtil.isEmpty(clause.getClauseString()))) {
       if ((isOr) && (v)) {
         continue;
       }
       if ((!isOr) && (!v)) {
         continue;
       }
       v = (v) || (evalCondition(list.get(i), context));
     }
   }
   return v;
 }
Пример #16
0
 public void getNewMessage() {
   if (!Config.isInstalled) {
     redirect(Config.getContextPath() + "Install.jsp");
     return;
   }
   this.Response.put("Count", MessageCache.getNoReadCount());
   String message = MessageCache.getFirstPopMessage();
   if (StringUtil.isEmpty(message)) {
     this.Response.put("PopFlag", "0");
   } else {
     this.Response.put("Message", message);
     this.Response.put("PopFlag", "1");
   }
 }
Пример #17
0
  public static void bindUserList(DataGridAction dga) {
    String searchUserName = dga.getParam("SearchUserName");
    QueryBuilder qb = new QueryBuilder("select * from ZDUser");
    qb.append(" where BranchInnerCode like ?", User.getBranchInnerCode() + "%");
    qb.append(" and UserName <> ?", User.getUserName());
    if (StringUtil.isNotEmpty(searchUserName)) {
      qb.append(" and (UserName like ?", "%" + searchUserName.trim() + "%");

      qb.append(" or realname like ?)", "%" + searchUserName.trim() + "%");
    }
    qb.append(" order by AddTime desc");
    dga.setTotal(qb);
    DataTable dt = qb.executePagedDataTable(dga.getPageSize(), dga.getPageIndex());
    dt.decodeColumn("Status", UserList.STATUS_MAP);
    dga.bindData(dt);
  }
Пример #18
0
 public void setReadFlag() {
   String ids = $V("IDs");
   if (!StringUtil.checkID(ids)) {
     this.Response.setLogInfo(0, "传入ID时发生错误");
     return;
   }
   ZCMessageSet set =
       new ZCMessageSchema().query(new QueryBuilder("where ReadFlag=0 and id in (" + ids + ")"));
   QueryBuilder qb = new QueryBuilder("update ZCMessage set ReadFlag=1 where id in (" + ids + ")");
   qb.executeNoQuery();
   this.Response.setLogInfo(1, "标记成功");
   MessageCache.removeIDs(set);
   qb =
       new QueryBuilder(
           "select count(1) from ZCMessage where ReadFlag=0 and ToUser=?", User.getUserName());
   CacheManager.set("Message", "Count", User.getUserName(), qb.executeInt());
 }
Пример #19
0
 private void dealCustomTable(DataTable dt, QueryBuilder qb) throws Exception {
   try {
     qb.clearBatches();
     qb.getParams().clear();
     for (int i = 0; i < dt.getRowCount(); ++i) {
       for (int j = 0; j < dt.getColCount() - 1; ++j) {
         String v = dt.getString(i, j);
         if (StringUtil.isEmpty(v)) {
           v = null;
         }
         qb.add(v);
       }
       qb.addBatch();
     }
     this.da.executeNoQuery(qb);
   } catch (Throwable t) {
     t.printStackTrace();
   }
 }
Пример #20
0
 public void getTables() {
   if (StringUtil.isEmpty($V("DatabaseID"))) {
     this.Response.setError("未传入DatabaseID");
     return;
   }
   long id = Long.parseLong($V("DatabaseID"));
   Connection conn = null;
   try {
     conn = getConnection(id);
     DatabaseMetaData dbm = conn.getMetaData();
     String currentCatalog = conn.getCatalog();
     ResultSet rs = dbm.getTables(currentCatalog, null, null, null);
     ArrayList al = new ArrayList();
     while (rs.next()) {
       if (rs.getObject(2) != null) al.add(rs.getObject(2) + "." + rs.getObject(3));
       else {
         al.add(rs.getObject(3));
       }
     }
     String[] arr = new String[al.size()];
     for (int i = 0; i < arr.length; ++i) {
       arr[i] = al.get(i).toString();
     }
     this.Response.put("Tables", arr);
     this.Response.setMessage("获取表信息成功");
     return;
   } catch (Exception e) {
     e.printStackTrace();
     this.Response.setError("连接到数据库时发生错误:" + e.getMessage());
     return;
   } finally {
     if (conn != null)
       try {
         conn.close();
       } catch (SQLException e) {
         e.printStackTrace();
       }
   }
 }
Пример #21
0
  public void del() {
    String ids = $V("IDs");
    if (!StringUtil.checkID(ids)) {
      this.Response.setLogInfo(0, "传入ID时发生错误");
      return;
    }
    Transaction trans = new Transaction();

    ZCMessageSchema message = new ZCMessageSchema();
    ZCMessageSet set = message.query(new QueryBuilder("where id in (" + ids + ")"));
    trans.add(set, 5);

    if (trans.commit()) {
      MessageCache.removeIDs(set);
      QueryBuilder qb =
          new QueryBuilder(
              "select count(1) from ZCMessage where ReadFlag=0 and ToUser=?", User.getUserName());
      CacheManager.set("Message", "Count", User.getUserName(), qb.executeInt());
      this.Response.setLogInfo(1, "删除成功");
    } else {
      this.Response.setLogInfo(0, "删除失败");
    }
  }
Пример #22
0
 public void save() {
   ZCDatabaseSchema db = new ZCDatabaseSchema();
   if (StringUtil.isEmpty($V("ID"))) {
     db.setValue(this.Request);
     db.setID(NoUtil.getMaxID("DatabaseID"));
     db.setAddTime(new Date());
     db.setAddUser(User.getUserName());
     db.setSiteID(Application.getCurrentSiteID());
     if (db.insert()) this.Response.setMessage("添加数据库连接成功");
     else this.Response.setError("发生错误,添加数据库连接失败");
   } else {
     db.setID(Long.parseLong($V("ID")));
     db.fill();
     db.setValue(this.Request);
     db.setModifyTime(new Date());
     db.setModifyUser(User.getUserName());
     if (db.update()) this.Response.setMessage("修改数据库连接成功");
     else {
       this.Response.setError("发生错误,修改数据库连接失败");
     }
   }
   removeConnPool(db.getID());
   addConnPool(db);
 }
Пример #23
0
  public static SearchResult advanceSearch(Mapx map) {
    SearchParameters sps = new SearchParameters();

    String site = map.getString("site");
    String id = map.getString("id");
    String startDate = map.getString("startdate");
    String endDate = map.getString("enddate");
    String catalog = map.getString("catalog");
    String author = map.getString("author");
    String title = map.getString("title");
    String content = map.getString("content");
    String keyword = map.getString("keyword");
    String query = map.getString("query");
    if (StringUtil.isEmpty(keyword)) {
      keyword = query;
    }
    String orderField = map.getString("orderfield");
    String descFlag = map.getString("descflag");
    String page = map.getString("page");
    String size = map.getString("size");

    if (StringUtil.isEmpty(id)) {
      id = SearchAPI.getIndexIDBySiteID(site);
    }

    if ((StringUtil.isNotEmpty(startDate)) && (StringUtil.isEmpty(endDate))) {
      endDate = "2099-01-01";
    }
    if ((StringUtil.isNotEmpty(endDate)) && (StringUtil.isEmpty(startDate))) {
      startDate = "1900-01-01";
    }
    if (StringUtil.isNotEmpty(startDate)) {
      sps.setDateRange("PublishDate", startDate, endDate);
    }
    if (StringUtil.isNotEmpty(catalog)) {
      sps.addLeftLikeField("CatalogInnerCode", catalog, true);
    }
    if (StringUtil.isNotEmpty(title)) {
      sps.addFulltextField("Title", title);
    }
    if (StringUtil.isNotEmpty(content)) {
      sps.addFulltextField("Content", content);
    }
    if (StringUtil.isNotEmpty(keyword)) {
      sps.addFulltextField("Title", keyword, false);
      sps.addFulltextField("Content", keyword, false);
      sps.addFulltextField("_Keyword", keyword, true);
    }
    if (StringUtil.isNotEmpty(orderField)) {
      boolean isDesc = "true".equals(descFlag);
      sps.setSortField(orderField, 3, isDesc);
    }
    if (StringUtil.isNotEmpty(author)) {
      sps.addEqualField("Author", author);
    }
    if (StringUtil.isNotEmpty(page)) {
      sps.setPageIndex(Integer.parseInt(page) - 1);
    }
    if (StringUtil.isNotEmpty(size)) {
      sps.setPageSize(Integer.parseInt(size));
    }
    if (StringUtil.isEmpty(id)) {
      SearchResult sr = new SearchResult();
      sr.Data = new DataTable();
      return sr;
    }

    sps.setIndexID(Long.parseLong(id));
    return ArticleIndexer.search(sps);
  }
Пример #24
0
   public void writeArticle()
   {
     prepareList();
     if (this.config.getType() == 1) {
       QueryBuilder imageQB = new QueryBuilder("select id from zccatalog where type=4 and siteid=?", 
         CatalogUtil.getSiteID(this.config.getCatalogID()));
       String imageCatalogID = imageQB.executeString();
       if (StringUtil.isEmpty(CatalogUtil.getSiteID(this.config.getCatalogID()))) {
         LogUtil.getLogger().warn("文档采集的目的栏目不存在:ID=" + this.config.getCatalogID());
         return;
       }
       String sitePath = SiteUtil.getAbsolutePath(CatalogUtil.getSiteID(this.config.getCatalogID()));
       String imagePath = "upload/Image/" + CatalogUtil.getAlias(imageCatalogID) + "/";
 
       RegexParser rp = this.config.getTemplate("Ref1");
       RegexParser[] filters = this.config.getFilterBlocks();
       this.list.moveFirst();
       WebDocument doc = null;
       int cSuccess = 0;
       int cFailure = 0;
       int cLost = 0;
 
       boolean publishDateFlag = false;
       ZCArticleSet set = new ZCArticleSet();
       while ((doc = this.list.next()) != null) {
         if (this.task.checkStop()) {
           return;
         }
         if (doc.getLevel() != this.config.getUrlLevels().length - 1) {
           continue;
         }
         int percent = (100 - this.task.getPercent()) * (cSuccess + cFailure + cLost) / this.list.size();
         this.task.setPercent(this.task.getPercent() + percent);
         if ((doc.isTextContent()) && (doc.getContent() != null)) {
           String text = doc.getContentText();
           rp.setText(text);
           if (rp.match()) {
             Mapx map = rp.getMapx();
             Object[] ks = map.keyArray();
             Object[] vs = map.valueArray();
             for (int i = 0; i < map.size(); ++i) {
               String key = ks[i].toString();
               String value = vs[i].toString();
               if (!key.equalsIgnoreCase("Content")) {
                 value = this.tagPattern.matcher(value).replaceAll("");
               }
               value = StringUtil.htmlDecode(value);
               value = value.trim();
               map.put(key, value);
             }
             String title = map.getString("Title");
             String content = map.getString("Content");
             String author = map.getString("Author");
             String source = map.getString("Source");
             String strDate = map.getString("PublishDate");
             Date publishDate = doc.getLastmodifiedDate();
             if ((StringUtil.isNotEmpty(strDate)) && (StringUtil.isNotEmpty(this.config.getPublishDateFormat())))
             {
               try {
                 strDate = DateUtil.convertChineseNumber(strDate);
                 publishDate = DateUtil.parse(strDate, this.config.getPublishDateFormat());
               } catch (Exception e) {
                 this.task.addError("日期" + strDate + "不符合指定格式" + doc.getUrl());
               }
               publishDateFlag = true;
             }
             if (publishDate.getTime() > System.currentTimeMillis()) {
               publishDate = new Date();
             }
             ArticleAPI api = new ArticleAPI();
             try {
               ZCArticleSchema article = new ZCArticleSchema();
               if (StringUtil.isNotEmpty(title)) {
                 article.setTitle(title);
               } else {
                 ++cLost;
                 break label1209:
               }
               if (StringUtil.isNotEmpty(content)) {
                 content = content.trim();
                 while (rp.match()) {
                   String html = rp.getMapx().getString("Content");
                   content = content + html;
                 }
                 if (this.config.isCleanLinkFlag()) {
                   content = this.framePattern.matcher(content).replaceAll("");
                   content = this.stylePattern.matcher(content).replaceAll("");
                   content = this.scriptPattern.matcher(content).replaceAll("");
                   content = this.linkPattern.matcher(content).replaceAll("$1");
                 }
                 if (filters != null) {
                   for (int k = 0; k < filters.length; ++k) {
                     content = filters[k].replace(content, "");
                   }
                 }
 
                 String str = dealImage(content, doc.getUrl(), sitePath, imagePath, imageCatalogID);
                 article.setContent(str);
               } else {
                 ++cLost;
                 break label1209:
               }
               if (StringUtil.isNotEmpty(author)) {
                 article.setAuthor(author);
               }
               if (StringUtil.isNotEmpty(source)) {
                 article.setReferName(source);
               }
               article.setReferURL(doc.getUrl());
               article.setPublishDate(publishDate);
               article.setCatalogID(this.config.getCatalogID());
               article.setBranchInnerCode("0001");
               article.setProp2("FromWeb");
 
               if (ExtendManager.hasAction("FromWeb.BeforeSave")) {
                 ExtendManager.executeAll("FromWeb.BeforeSave", new Object[] { article });
               }
 
               Date date = (Date)new QueryBuilder(
                 "select PublishDate from ZCArticle where ReferURL=? and CatalogID=?", doc.getUrl(), 
                 this.config.getCatalogID()).executeOneValue();
               if (date != null) {
                 if (date.getTime() < doc.getLastDownloadTime()) {
                   QueryBuilder qb = new QueryBuilder(
                     "update ZCArticle set Title=?,Content=? where CatalogID=? and ReferURL=?");
                   qb.add(article.getTitle());
                   qb.add(article.getContent());
                   qb.add(this.config.getCatalogID());
                   qb.add(doc.getUrl());
                   qb.executeNoQuery();
                 }
                 ++cSuccess;
               } else {
                 api.setSchema(article);
                 set.add(article);
                 if (api.insert() > 0L)
                   ++cSuccess;
                 else
                   ++cFailure;
               }
             }
             catch (Exception e) {
               ++cFailure;
               e.printStackTrace();
             }
           } else {
             LogUtil.getLogger().info("未能匹配" + doc.getUrl());
             this.task.addError("未能匹配" + doc.getUrl());
             ++cLost;
           }
           label1209: this.task.setCurrentInfo("正在转换文档, <font class='green'>" + cSuccess + "</font> 个成功, <font class='red'>" + 
             cFailure + "</font> 个失败, <font class='green'>" + cLost + "</font> 个未匹配");
         }
       }
Пример #25
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();
      }
    }
  }
Пример #26
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();
      }
    }
  }
Пример #27
0
  public boolean importSite(String poolName) {
    User.UserData user = new User.UserData();
    user.setUserName("admin");
    user.setBranchInnerCode("86");
    user.setLogin(true);
    user.setManager(true);
    User.setCurrent(user);

    this.isNewSite =
        (("0".equals(this.map.getString("ID"))) || (StringUtil.isEmpty(this.map.getString("ID"))));
    this.NoRelas = SiteTableRela.getNoRelaArray();
    this.TableRelas = SiteTableRela.getRelas();
    this.da = new DataAccess();
    FileInputStream fin = null;
    try {
      fin = new FileInputStream(this.file);
      this.da.setAutoCommit(false);
      this.ExportCharset = ((fin.read() == 1) ? "GBK" : "UTF-8");
      byte[] bs = new byte[8];
      fin.read(bs);
      this.siteID = NumberUtil.toLong(bs);
      boolean flag = true;
      int i = 0;
      while (true) {
        bs = new byte[4];
        if (!bufferRead(bs, fin)) {
          break;
        }
        int len = NumberUtil.toInt(bs);
        bs = new byte[len];
        if (!bufferRead(bs, fin)) {
          flag = false;
          break;
        }
        Object obj = FileUtil.unserialize(bs);

        bs = new byte[4];
        if (!bufferRead(bs, fin)) {
          flag = false;
          break;
        }
        len = NumberUtil.toInt(bs);
        bs = new byte[len];
        if (!bufferRead(bs, fin)) {
          flag = false;
          break;
        }
        bs = ZipUtil.unzip(bs);
        this.task.setPercent(i * 100 / 200);
        dealOneEntry(bs, obj);
        ++i;
      }
      if (flag) {
        this.da.commit();
      } else {
        LogUtil.error("读取站点导出文件时发生错误!");
        this.da.rollback();
      }
      this.da.setAutoCommit(true);
      Site.updatePrivAndFile(this.map.getString("Alias"));
      return flag;
    } catch (Exception e1) {
      e1.printStackTrace();
      try {
        this.da.rollback();
      } catch (SQLException e) {
        e.printStackTrace();
      }
      return false;
    } finally {
      try {
        this.da.setAutoCommit(true);
      } catch (Exception e) {
        e.printStackTrace();
      }
      try {
        this.da.close();
      } catch (Exception e) {
        e.printStackTrace();
      }
      try {
        fin.close();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
Пример #28
0
  public static String[] getSearchEngine(Visit v) {
    String url = v.URL;
    if (StringUtil.isEmpty(url)) {
      return null;
    }

    if (url.indexOf("Result.jsp") > 0) {
      String keyword = SearchAPI.getParameter(url, "query");
      return new String[] {"站内搜索", keyword};
    }
    url = v.Referer;
    String domain = StatUtil.getDomain(url);
    Mapx map = ServletUtil.getMapFromQueryString(url);
    String name = null;
    String keyword = null;
    if (domain.indexOf("baidu.") > 0) {
      keyword = StringUtil.urlDecode(map.getString("wd"), "GBK");
      name = "百度";
    } else if (domain.indexOf("google.") > 0) {
      String charset = map.getString("ie");
      if (StringUtil.isEmpty(charset)) {
        charset = "UTF-8";
      }
      keyword = StringUtil.urlDecode(map.getString("q"), charset);
      name = "谷歌";
    } else if (domain.indexOf("yahoo.") > 0) {
      String charset = map.getString("ei");
      if (StringUtil.isEmpty(charset)) {
        charset = "UTF-8";
      }
      keyword = StringUtil.urlDecode(map.getString("p"), charset);
      name = "雅虎";
    } else if (domain.indexOf("msn.") > 0) {
      keyword = StringUtil.urlDecode(map.getString("q"), "UTF-8");
      name = "MSN";
    } else if (domain.indexOf("soso.") > 0) {
      keyword = StringUtil.urlDecode(map.getString("w"), "GBK");
      name = "搜搜";
    } else if (domain.indexOf("sogou.") > 0) {
      keyword = StringUtil.urlDecode(map.getString("query"), "GBK");
      name = "搜狗";
    } else if (domain.indexOf("zhongsou.") > 0) {
      keyword = StringUtil.urlDecode(map.getString("word"), "GBK");
      name = "中搜";
    } else if (domain.indexOf("youdao.") > 0) {
      String charset = map.getString("ue");
      if (StringUtil.isEmpty(charset)) {
        charset = "UTF-8";
      }
      keyword = StringUtil.urlDecode(map.getString("q"), charset);
      name = "有道";
    } else if (domain.indexOf("live.") > 0) {
      keyword = StringUtil.urlDecode(map.getString("q"), "UTF-8");
      name = "Live.com";
    }
    if (StringUtil.isNotEmpty(keyword)) {
      return new String[] {name, keyword};
    }
    return null;
  }