EN · DE · RU · FR · ES

#2835: URLHelper.java

projectforge-wicket/src/main/java/org/projectforge/web/URLHelper.java Type: Java · Role: Component · Source: projectforge-wicket/src/main/java/org/projectforge/web/URLHelper.java 76 lines · 37 code · 34 comments · 5 blank
Source code file at projectforge-wicket/src/main/java/org/projectforge/web/URLHelper.java containing Java code for the Component layer.

Code Structure

Package: org.projectforge.web

Classes: URLHelper

Methods (2): encode, removeJSessionId

Imports: 2 packages

Source Code (abridged)

package org.projectforge.web;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class URLHelper
{
  private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(URLHelper.class);

  /**
   * Uses UTF-8
   * @param str
   * @see URLEncoder#encode(String, String)
   */
  public static String encode(final String str)
  {
    if (str == null) {
      return "";
    }
    try {
      return URLEncoder.encode(str, "UTF-8");
    } catch (final UnsupportedEncodingException ex) {
      log.info("Can't URL-encode '" + str + "': " + ex.getMessage());
      return "";
    }
  }

  /**
   * Removes the jsessionid parameter from the given url if exists.
   * @param url
   * @return
   */
  public static String removeJSessionId(final String url)
  {
    if (url == null) {
      return null;
    }
    final int pos = url.indexOf(";jsessionid=");
    if (pos < 0) {
      return url;
    }
    final int questionMark = url.indexOf('?');
    if (questionMark < 0) {
      // No parameters, so url ends with jsession id.
      return url.substring(0, pos);
    }
    if (questionMark < pos) {
      // What the hell?
      return url;
    }
    return url.substring(0, pos) + url.substring(questionMark);
  }
}

Git History

868d6abb7 2025 -> 2026
63081666f Source file headers: 2024-> 2025.
b6092df09 Copyright 2023 -> 2024
ab45d51fa Copyright 2001-2022 -> 2001-2023.
5f7ef41b8 Copyright 2021 -> 2022