Esempio n. 1
0
package cn.jcenterhome.web.action.admin;
  @Override
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) {
    if (!Common.checkPerm(request, response, "managenetwork")) {
      return cpMessage(request, mapping, "cp_no_authority_management_operation");
    }

    try {
      if (submitCheck(request, "networksubmit")) {
        Map<String, Object> network = (Map<String, Object>) getParameters(request, "network");
        if (network != null) {
          Pattern pattern = Pattern.compile("[^a-z]", Pattern.CASE_INSENSITIVE);
          Pattern separatorPattern = Pattern.compile(",");
          String[] arr = null;
          Map<Integer, Integer> narr = null;
          int tempV = 0;
          for (Entry<String, Object> entry : network.entrySet()) {
            String type = entry.getKey();
            Map<String, Object> values = (Map<String, Object>) entry.getValue();
            for (Entry<String, Object> subEntry : values.entrySet()) {
              String key = subEntry.getKey();
              String value = "";
              value = ((String) subEntry.getValue()).trim();
              if (value.indexOf(",") >= 0) {
                narr = new HashMap<Integer, Integer>();
                arr = separatorPattern.split(value);
                for (String v : arr) {
                  v = v.trim();
                  tempV = Common.intval(v);
                  if (tempV != 0) narr.put(tempV, tempV);
                }
                value = Common.implode(narr, ",");
              } else if (pattern.matcher(value).matches()) {
                value = String.valueOf(Common.intval(value));
              }
              values.put(key, value);
            }
            network.put(type, values);
          }
          Common.setData("network", network, false);
          cacheService.network_cache();
        }
        return cpMessage(request, mapping, "do_success", "admincp.jsp?ac=network");
      }
    } catch (Exception e1) {
      return showMessage(request, response, e1.getMessage());
    }
    Map<String, Map<String, Object>> globalNetWork =
        Common.getCacheDate(request, response, "/data/cache/cache_network.jsp", "globalNetWork");
    Map<String, String> orders = new HashMap<String, String>();
    String[] types = new String[] {"blog", "pic", "thread", "poll", "event", "share"};
    for (String type : types) {
      Map<String, Object> netWork = globalNetWork.get(type);
      if (netWork != null) {
        orders.put("order_" + type + "_" + netWork.get("order"), " selected");
        orders.put("sc_" + type + "_" + netWork.get("sc"), " selected");
      }
    }
    request.setAttribute("orders", orders);
    return mapping.findForward("network");
  }
Esempio n. 3
0
  public synchronized boolean cronNextRun(HttpServletRequest request, Map<String, Object> crons) {

    if (Common.empty(crons)) return false;

    Map<String, Object> sConfig = (Map<String, Object>) request.getAttribute("sConfig");
    Map<String, Object> sGlobal = (Map<String, Object>) request.getAttribute("sGlobal");

    String minute = (String) crons.get("minute");
    Map<String, Object> setarr = new HashMap<String, Object>();
    if (minute.equals("")) {
      setarr.put("available", 0);
    } else {
      short hour = Short.parseShort(String.valueOf(crons.get("hour")));
      short day = Short.parseShort(String.valueOf(crons.get("day")));
      byte weekDay = Byte.parseByte(String.valueOf(crons.get("weekday")));
      Calendar calendar = Common.getCalendar(String.valueOf(sConfig.get("timeoffset")));
      calendar.set(Calendar.SECOND, 0);
      Date date = calendar.getTime();
      String[] minuteArray = minute.split("\t");
      int minuteLengh = minuteArray.length;
      int[] minuteIntArray = new int[minuteLengh];
      for (int i = 0; i < minuteLengh; i++) {
        minuteIntArray[i] = Integer.parseInt(minuteArray[i]);
      }
      Arrays.sort(minuteIntArray);
      int nowMinute = calendar.get(Calendar.MINUTE);
      int minMinute = 0;
      int maxMinute = 0;
      int nextRunM = 0;
      if (minuteLengh > 0) {
        minMinute = minuteIntArray[0];
        maxMinute = minuteIntArray[minuteLengh - 1];
      }
      if (nowMinute >= maxMinute) {
        nextRunM = minMinute;
        if (hour == -1) {
          calendar.add(Calendar.HOUR_OF_DAY, 1);
        }
      } else {
        for (int tempMinute : minuteIntArray) {
          if (tempMinute > nowMinute) {
            nextRunM = tempMinute;
            break;
          }
        }
      }
      calendar.set(Calendar.MINUTE, nextRunM);
      if (hour > -1) {
        calendar.set(Calendar.HOUR_OF_DAY, hour);
        if (!calendar.getTime().after(date) && weekDay == -1 && day == -1) {
          calendar.add(Calendar.DAY_OF_YEAR, 1);
        }
      }
      if (weekDay > -1) {
        calendar.set(Calendar.DAY_OF_WEEK, weekDay + 1);
        if (!calendar.getTime().after(date)) {
          calendar.add(Calendar.WEEK_OF_MONTH, 1);
        }
      } else {
        if (day > -1) {
          calendar.set(Calendar.DAY_OF_MONTH, day);
          if (!calendar.getTime().after(date)) {
            calendar.add(Calendar.MONTH, 1);
          }
        }
      }
      int nextrun = (int) (calendar.getTimeInMillis() / 1000);
      int timestamp = (Integer) sGlobal.get("timestamp");

      setarr.put("lastrun", timestamp);
      setarr.put("nextrun", nextrun);
      if (nextrun <= timestamp) {
        setarr.put("available", 0);
      }
    }
    DataBaseService dataBaseService = (DataBaseService) BeanFactory.getBean("dataBaseService");
    Map<String, Object> whereSQLArr = new HashMap<String, Object>();
    whereSQLArr.put("cronid", crons.get("cronid"));
    dataBaseService.updateTable("cron", setarr, whereSQLArr);
    return true;
  }