Esempio n. 1
0
  private String redirectToView() {
    StringBuilder redirectUrl = new StringBuilder("BulkEditUserGroups!default.jspa?");

    Iterator<Group> groups = getSelectedGroupsUserHasPermToSee().iterator();
    while (groups.hasNext()) {
      Group group = groups.next();
      redirectUrl.append("selectedGroupsStr=").append(JiraUrlCodec.encode(group.getName()));
      if (groups.hasNext()) redirectUrl.append("&");
    }

    return getRedirect(redirectUrl.toString());
  }
  public static Cookie createConglomerateCookie(
      final String cookieName, final Map<String, String> map, final HttpServletRequest request) {
    StringBuilder cookieValue = new StringBuilder();
    String sep = "";
    for (Map.Entry<String, String> keyValuePair : map.entrySet()) {
      if (StringUtils.isNotBlank(keyValuePair.getValue())) {
        String s =
            JiraUrlCodec.encode(keyValuePair.getKey() + "=" + keyValuePair.getValue(), "UTF-8");
        cookieValue.append(sep).append(s);
        sep = "|";
      }
    }

    Cookie cookie = createCookie(cookieName, (cookieValue.toString()), request);
    cookie.setMaxAge(Integer.MAX_VALUE);
    return cookie;
  }
  /**
   * Parse the key/value pairs out of a conglomerate cookie.
   *
   * <p>The returned map will not contain empty values (zero length strings: they are discarded).
   *
   * @param cookieName the name of the cookie
   * @param currentRequest current request
   * @return the non-null map of key/value pairs
   */
  public static Map<String, String> parseConglomerateCookie(
      String cookieName, HttpServletRequest currentRequest) {
    Map<String, String> result = new LinkedHashMap<String, String>();

    final String cookieValue = CookieUtils.getCookieValue(cookieName, currentRequest);
    if (StringUtils.isNotBlank(cookieValue)) {
      final String[] values = cookieValue.split("[|]");
      for (String rawKeyValuePair : values) {
        if (StringUtils.isNotBlank(rawKeyValuePair)) {
          String keyValuePair = JiraUrlCodec.decode(rawKeyValuePair, "UTF-8");
          if (StringUtils.isNotBlank(keyValuePair)) {
            Matcher m = CONGLOMERATE_KEYPAIR_PATTERN.matcher(keyValuePair);
            if (m.matches()) {
              final String key = m.group(1);
              final String value = m.group(2);
              result.put(key, value);
            }
          }
        }
      }
    }

    return result;
  }