public String buildInterfaceTable(String rule, String[] serviceList) throws FilterParseException {
    StringBuffer buffer = new StringBuffer();
    Filter filter = new Filter();
    Map interfaces = filter.getIPServiceMap(rule);

    Iterator i = interfaces.keySet().iterator();
    while (i.hasNext()) {
      String key = (String) i.next();
      buffer.append("<tr><td valign=\"top\">").append(key).append("</td>");
      buffer.append("<td>");

      if (serviceList != null && serviceList.length != 0) {
        Map services = (Map) interfaces.get(key);
        Iterator j = services.keySet().iterator();
        while (j.hasNext()) {
          String svc = (String) j.next();
          for (int idx = 0; idx < serviceList.length; idx++) {
            if (svc.equals(serviceList[idx])) {
              buffer.append(svc).append("<br>");
            }
          }
        }
      } else {
        buffer.append("All services");
      }
      buffer.append("</td>");

      buffer.append("</tr>");
    }

    return buffer.toString();
  }
Ejemplo n.º 2
0
 @Override
 public String getParameter(String name) {
   if (!requestParse.isParsed()) requestParse.parseParmeter();
   String[] values = parameterMap.get(name);
   if (values == null) return null;
   return parameterMap.get(name)[0];
 }
	// post方式发送email
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		File file = doAttachment(request);
		EmailAttachment attachment = new EmailAttachment();
		attachment.setPath(file.getPath());
		attachment.setDisposition(EmailAttachment.ATTACHMENT);
		attachment.setName(file.getName());
		MultiPartEmail email = new MultiPartEmail();
		email.setCharset("UTF-8");
		email.setHostName("smtp.sina.com");
		email.setAuthentication("T-GWAP", "dangdang");
		try {
			email.addTo(parameters.get("to"));
			email.setFrom(parameters.get("from"));
			email.setSubject(parameters.get("subject"));
			email.setMsg(parameters.get("body"));
			email.attach(attachment);
			email.send();
			request.setAttribute("sendmail.message", "邮件发送成功!");
		} catch (EmailException e) {
			Logger logger = Logger.getLogger(SendAttachmentMailServlet.class);
			logger.error("邮件发送不成功", e);
			request.setAttribute("sendmail.message", "邮件发送不成功!");
		}
		request.getRequestDispatcher("/sendResult.jsp").forward(request,
				response);
	}
Ejemplo n.º 4
0
  private String calculateViewId(FacesContext context) {
    Map map = context.getExternalContext().getRequestMap();

    String viewId = (String) map.get(RequestDispatcher.INCLUDE_PATH_INFO);

    if (viewId == null) viewId = context.getExternalContext().getRequestPathInfo();

    if (viewId == null) viewId = (String) map.get(RequestDispatcher.INCLUDE_SERVLET_PATH);

    if (viewId == null) viewId = context.getExternalContext().getRequestServletPath();

    return viewId;
  }
Ejemplo n.º 5
0
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    String pathInfo = req.getPathInfo();

    HttpSession session = req.getSession();
    if (session == null) {
      resp.setStatus(401);
      return;
    }
    String username = (String) session.getAttribute("username");
    if (username == null) {
      resp.setStatus(401);
      return;
    }

    Map userMap = loadUserSettingsMap(username);
    if (userMap == null) {
      resp.setStatus(401);
      return;
    }
    if (pathInfo.equals("/")) {
      resp.setContentType("application/json; charset=UTF-8");
      resp.getWriter().write(JSONUtil.write(userMap));
      return;
    }

    String key = pathInfo.substring(1);
    String value = (String) userMap.get(key);

    Map jsonObject = new HashMap();
    jsonObject.put(key, value);
    resp.setContentType("application/json; charset=UTF-8");
    resp.getWriter().write(JSONUtil.write(jsonObject));
  }
 public Enumeration<String> getHeaders(String s) {
   String[] values = headerMap.get(s);
   if (values == null) {
     return null;
   }
   return Collections.enumeration(Arrays.asList(values));
 }
 public String getHeader(String s) {
   String[] values = headerMap.get(s);
   if (values == null || values.length == 0) {
     return null;
   }
   return values[0];
 }
Ejemplo n.º 8
0
  public static boolean isZero(List list, String col) {
    if (list == null) {
      return false;
    }
    boolean b = false;
    int i, num = 0;
    String v = null;
    Map m = null;
    double dv = 0;

    num = list.size();
    for (i = 0; i < num; i++) {
      m = (Map) list.get(i);
      v = (String) m.get(col);
      // if(f.empty(v)){return true;}
      if (f.empty(v)) {
        continue;
      }
      // System.out.println(v);
      v = f.v(v);
      dv = f.getDouble(v, 0);
      // if(dv==0){return true;}
      if (dv > 0) {
        return false;
      }
      b = true;
    }

    return b;
  }
Ejemplo n.º 9
0
  protected Properties convertProperties(Map<String, Object> m) {
    Properties res = null;

    {
      if (m != null) {
        res = new Properties();

        Set<String> keys = m.keySet();
        for (String key : keys) {
          String value = null;

          // Set 'value':
          {
            Object o = m.get(key);
            if (o != null) {
              value = o.toString();
            }
          }

          res.setProperty(key, value);
        }
      }
    }

    return res;
  }
Ejemplo n.º 10
0
  public String getTokenValue(HttpServletRequest request, String uri) {
    String tokenValue = null;
    HttpSession session = request.getSession(false);

    if (session != null) {
      if (isTokenPerPageEnabled()) {
        @SuppressWarnings("unchecked")
        Map<String, String> pageTokens =
            (Map<String, String>) session.getAttribute(CsrfGuard.PAGE_TOKENS_KEY);

        if (pageTokens != null) {
          if (isTokenPerPagePrecreate()) {
            createPageToken(pageTokens, uri);
          }
          tokenValue = pageTokens.get(uri);
        }
      }

      if (tokenValue == null) {
        tokenValue = (String) session.getAttribute(getSessionKey());
      }
    }

    return tokenValue;
  }
Ejemplo n.º 11
0
 /**
  * Returns a File object for the specified file saved on the server's filesystem, or null if the
  * file was not included in the upload.
  *
  * @param name the html page's file parameter name.
  * @return a File object for the named file.
  */
 public File getFile(String name) {
   try {
     UploadedFile file = (UploadedFile) files.get(name);
     return file.getFile(); // may be null
   } catch (Exception e) {
     return null;
   }
 }
Ejemplo n.º 12
0
 /**
  * Returns the filesystem name of the specified file, or null if the file was not included in the
  * upload. A filesystem name is the name specified by the user. It is also the name under which
  * the file is actually saved.
  *
  * @param name the html page's file parameter name.
  * @return the filesystem name of the file.
  */
 public String getFilesystemName(String name) {
   try {
     UploadedFile file = files.get(name);
     return file.getFilesystemName(); // may be null
   } catch (Exception e) {
     return null;
   }
 }
 public String getParameter(String name) {
   String[] values = parameterMap.get(name);
   if (values == null || values.length == 0) {
     return null;
   } else {
     return values[0];
   }
 }
 public FileItem getFileItem(String name) {
   FileItem[] values = fileItemMap.get(name);
   if (values == null) {
     return null;
   } else {
     return values[0];
   }
 }
Ejemplo n.º 15
0
 /**
  * Returns the original filesystem name of the specified file (before any renaming policy was
  * applied), or null if the file was not included in the upload. A filesystem name is the name
  * specified by the user.
  *
  * @param name the html page's file parameter name.
  * @return the original file name of the file.
  */
 public String getOriginalFileName(String name) {
   try {
     UploadedFile file = (UploadedFile) files.get(name);
     return file.getOriginalFileName(); // may be null
   } catch (Exception e) {
     return null;
   }
 }
Ejemplo n.º 16
0
 public String getProcessStatus(String sessionId) {
   String status = (String) statusMap.get(sessionId);
   // log.info("M statusMap="+statusMap+" "+statusMap.hashCode());
   log.info("status=" + status + " sessionId=" + sessionId);
   if (status == null) {
     return "0%";
   } else {
     return status + "%";
   }
 }
Ejemplo n.º 17
0
  public static int getZeroNum(List stationList, Map data, String col) {
    int num = 0;
    int i, stationNum = 0;
    String station_id = null;
    List list = null;
    String ep_type = null;
    Map m = null;
    stationNum = stationList.size();
    for (i = 0; i < stationNum; i++) {
      m = (Map) stationList.get(i);
      station_id = (String) m.get("station_id");
      ep_type = (String) m.get("ep_type");
      list = (List) data.get(station_id);
      if (isZero(list, col)) {
        num++;
      }
    }

    return num;
  }
Ejemplo n.º 18
0
  public static List getOfflineList2(List stationList, Map data) {
    List list = new ArrayList();

    int i, stationNum = 0;
    String station_id = null;
    List tmp = null;
    Map m = null;
    stationNum = stationList.size();
    for (i = 0; i < stationNum; i++) {
      m = (Map) stationList.get(i);
      station_id = (String) m.get("station_id");

      tmp = (List) data.get(station_id);
      if (tmp != null) {
        list.add(m);
      }
    }

    return list;
  }
Ejemplo n.º 19
0
  public static int getOfflineNum(List stationList, Map data) {
    int num = 0;
    int stationNum = 0;
    int i = 0;
    Map m = null;
    String station_id = null;
    List list = null;

    stationNum = stationList.size();

    for (i = 0; i < stationNum; i++) {
      m = (Map) stationList.get(i);
      station_id = (String) m.get("station_id");
      list = (List) data.get(station_id);
      if (list == null) {
        num++;
      }
    }

    return num;
  }
Ejemplo n.º 20
0
  /**
   * Retrieves UUID value from parameters map.
   *
   * @param key Key.
   * @param params Parameters map.
   * @return UUID value from parameters map or {@code null} if null or not exists.
   * @throws GridException If parsing failed.
   */
  @Nullable
  private static UUID uuidValue(String key, Map<String, Object> params) throws GridException {
    assert key != null;

    String val = (String) params.get(key);

    try {
      return val == null ? null : UUID.fromString(val);
    } catch (NumberFormatException ignore) {
      throw new GridException("Failed to parse parameter of UUID type [" + key + "=" + val + "]");
    }
  }
Ejemplo n.º 21
0
  public Session getSessionFromId(String id) throws IOException {
    Session res = null;

    {
      synchronized (lookupSessionById) {
        AbstractSession session = lookupSessionById.get(id);
        expandSession(session);
        res = session;
      }
    }

    return res;
  }
Ejemplo n.º 22
0
 /**
  * 获取所得到的k个最近邻元组的多数类
  *
  * @param pq 存储k个最近近邻元组的优先级队列
  * @return 多数类的名称
  */
 private String getMostClass(PriorityQueue<KNNNode> pq) {
   Map<Double, Integer> classCount = new HashMap<Double, Integer>();
   for (int i = 0; i < pq.size(); i++) {
     KNNNode node = pq.remove();
     double c = node.getC();
     if (classCount.containsKey(c)) {
       classCount.put(c, classCount.get(c) + 1);
     } else {
       classCount.put(c, 1);
     }
   }
   int maxIndex = -1;
   int maxCount = 0;
   Object[] classes = classCount.keySet().toArray();
   for (int i = 0; i < classes.length; i++) {
     if (classCount.get(classes[i]) > maxCount) {
       maxIndex = i;
       maxCount = classCount.get(classes[i]);
     }
   }
   return classes[maxIndex].toString();
 }
Ejemplo n.º 23
0
  /**
   * Retrieves long value from parameters map.
   *
   * @param key Key.
   * @param params Parameters map.
   * @param dfltVal Default value.
   * @return Long value from parameters map or {@code dfltVal} if null or not exists.
   * @throws GridException If parsing failed.
   */
  @Nullable
  private static Long longValue(String key, Map<String, Object> params, Long dfltVal)
      throws GridException {
    assert key != null;

    String val = (String) params.get(key);

    try {
      return val == null ? dfltVal : Long.valueOf(val);
    } catch (NumberFormatException ignore) {
      throw new GridException("Failed to parse parameter of Long type [" + key + "=" + val + "]");
    }
  }
Ejemplo n.º 24
0
  public StringBuilder listToCSV(List list) {
    StringBuilder csv = new StringBuilder();
    csv.append(
        "Work Product,,Name,State,Owner,Plan Estimate,Task Estimate,Task Remaining,Time Spent\n");

    for (int i = 0; i < list.size(); i++) {
      Map map = (Map) list.get(i);
      String type = (String) map.get("type");
      String formattedId = (String) map.get("formattedId");
      String name = (String) map.get("name");
      String taskStatus = (String) map.get("taskStatus");
      String owner = (String) map.get("owner");
      String planEstimate = (String) map.get("planEstimate");
      String taskEstimateTotal = (String) map.get("taskEstimateTotal");
      String taskRemainingTotal = (String) map.get("taskRemainingTotal");
      String taskTimeSpentTotal = (String) map.get("taskTimeSpentTotal");

      if ("task".equals(type)) {
        csv.append("," + formattedId + ",");
      } else if ("userstory".equals(type)) {
        csv.append(formattedId + ",,");
      } else if ("iteration".equals(type)) {
        csv.append(",,");
      }

      if (planEstimate == null) {
        planEstimate = "";
      }

      if (taskEstimateTotal == null) {
        taskEstimateTotal = "";
      }

      if (taskRemainingTotal == null) {
        taskRemainingTotal = "";
      }

      csv.append("\"" + name + "\",");
      csv.append(taskStatus + ",");
      csv.append(owner + ",");
      csv.append(planEstimate + ",");
      csv.append(taskEstimateTotal + ",");
      csv.append(taskRemainingTotal + ",");
      csv.append(taskTimeSpentTotal + "\n");
    }

    return csv;
  }
Ejemplo n.º 25
0
  public static int getOnlineNumNation(List stationList, Map data) {
    int num = 0;
    int stationNum = 0;
    int i = 0;
    Map m = null;
    String station_id = null;
    List list = null;
    String ep_type = null;

    stationNum = stationList.size();

    for (i = 0; i < stationNum; i++) {
      m = (Map) stationList.get(i);
      station_id = (String) m.get("station_id");
      ep_type = (String) m.get("ep_type");
      list = (List) data.get(station_id);
      if (list != null && f.eq(ep_type, "1")) {
        num++;
      }
    }

    return num;
  }
Ejemplo n.º 26
0
  public static List getZeroList(List stationList, Map data, String col) {
    int num = 0;
    int i, stationNum = 0;
    String station_id = null;
    List list = null;
    String ep_type = null;
    Map m = null;
    List list2 = new ArrayList();
    stationNum = stationList.size();
    for (i = 0; i < stationNum; i++) {
      m = (Map) stationList.get(i);
      station_id = (String) m.get("station_id");
      // ep_type = (String)m.get("ep_type");

      list = (List) data.get(station_id);
      // if(isZero(list,col)&&f.eq(ep_type,"1")){num++;}
      if (isZero(list, col)) {
        list2.add(m);
      }
    }

    return list2;
  }
Ejemplo n.º 27
0
  public static List getZeroListNation(List stationList, Map data, String col) {
    List list = new ArrayList();

    int i, stationNum = 0;
    String station_id = null;
    List tmp = null;
    Map m = null;

    String ep_type = null;
    stationNum = stationList.size();
    for (i = 0; i < stationNum; i++) {
      m = (Map) stationList.get(i);
      station_id = (String) m.get("station_id");
      ep_type = (String) m.get("ep_type");

      tmp = (List) data.get(station_id);
      if (isZero(tmp, col) && f.eq(ep_type, "1")) {
        list.add(m);
      }
    }

    return list;
  }
Ejemplo n.º 28
0
  /**
   * Gets values referenced by sequential keys, e.g. {@code key1...keyN}.
   *
   * @param keyPrefix Key prefix, e.g. {@code key} for {@code key1...keyN}.
   * @param params Parameters map.
   * @return Values.
   */
  @Nullable
  protected List<Object> values(String keyPrefix, Map<String, Object> params) {
    assert keyPrefix != null;

    List<Object> vals = new LinkedList<>();

    for (int i = 1; ; i++) {
      String key = keyPrefix + i;

      if (params.containsKey(key)) vals.add(params.get(key));
      else break;
    }

    return vals;
  }
Ejemplo n.º 29
0
  protected void expandSessionPrincipal(AbstractSession session) throws IOException {
    if (session != null) {
      String id = session.getId();
      HttpSession httpSession = lookupHttpSessionById.get(id);

      // Set 'userPrincipal' upon session:
      {
        if (httpSession != null) {
          Principal userPrincipal = PrincipalSessionDecorator.getPrincipal(httpSession);
          if (userPrincipal != null) {
            session.setUserPrincipal(userPrincipal);
          }
        }
      }
    }
  }
Ejemplo n.º 30
0
  public StringBuilder listToCSVForUserView(List list) {
    StringBuilder csv = new StringBuilder();

    csv.append(
        "Project,Iteration,Work Product,Name,State,Owner,Task Estimate,Task Remaining,Time Spent\n");

    for (int i = 0; i < list.size(); i++) {
      Map map = (Map) list.get(i);
      String projectName = (String) map.get("projectName");
      String iterationName = (String) map.get("iterationName");
      String formattedId = (String) map.get("taskFormattedId");
      String taskName = (String) map.get("taskName");
      String taskState = (String) map.get("taskState");
      String owner = (String) map.get("owner");
      String taskEstimate = (String) map.get("taskEstimate");
      String taskRemaining = (String) map.get("taskRemaining");
      String taskTimeSpent = (String) map.get("hours");

      if (taskEstimate == null) {
        taskEstimate = "";
      }

      if (taskRemaining == null) {
        taskRemaining = "";
      }

      csv.append("" + projectName + ",");
      csv.append("\"" + iterationName + "\",");
      csv.append(formattedId + ",");
      csv.append(taskName + ",");
      csv.append(taskState + ",");
      csv.append(owner + ",");
      csv.append(taskEstimate + ",");
      csv.append(taskRemaining + ",");
      csv.append(taskTimeSpent + "\n");
    }

    return csv;
  }