java.lang.Object
org.alfresco.officeservices.testclient.util.URLEncoder

public class URLEncoder extends Object
This class is similar to the well known java.net.URLEncoder, but it does provide a way to define the set of characters that should NOT be encoded.
This class has been adopted from org.apache.catalina.util.URLEncoder from Tomcat 6.0.35 under the Apache license.
Since:
2.8
Author:
Stefan Kopf, xaldon Technologies GmbH.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected BitSet
    set of safe characters that are not encoded
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a new URLEncoder and add the characters a-z, A-Z and 0-9 to the set of safe characters
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Add the given character to the set of safe characters
    encode(String path)
    Encode the given String by replacing all non safe characters by the sequence starting with the percent character followed by the two digit hex representation of that character.
    The given path is represented as UTF-8.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • safeCharacters

      protected BitSet safeCharacters
      set of safe characters that are not encoded
  • Constructor Details

    • URLEncoder

      public URLEncoder()
      Create a new URLEncoder and add the characters a-z, A-Z and 0-9 to the set of safe characters
  • Method Details

    • addSafeCharacter

      public void addSafeCharacter(char c)
      Add the given character to the set of safe characters
      Parameters:
      c - the character to be added to the set of safe characters
    • encode

      public String encode(String path)
      Encode the given String by replacing all non safe characters by the sequence starting with the percent character followed by the two digit hex representation of that character.
      The given path is represented as UTF-8.
      Parameters:
      path - the path to be encoded
      Returns:
      the encoded path