com.sap.netweaver.bc.rf.common

Class UriCodec

java.lang.Object
  extended by com.sap.netweaver.bc.rf.common.UriCodec

public class UriCodec
extends Object

Utility class for decoding/encoding URIs in HTTP requests. Handles escaping of reserved as well as non-7bit characters.

Instances of this class are not threadsafe. The class methods are threadsafe, however.

Copyright (c) SAP AG 2001-2003


Constructor Summary
UriCodec()
          Creates a new URICoded Instance.
 
Method Summary
 String decode(String quoted)
          Converts an encoded URI into a Java String.
static String Decode(String quotedURI)
          Decode the given URI.
static Properties DecodeQuery(String query)
          Decode the given http query string.
 String encode(String unquoted)
          Converts a URI in plain Java String to a format suitable for transmitting in Http requests.
static String Encode(String unquotedURI)
          Encode the given URI.
 String encodePath(String unquoted)
          Converts a URI in plain Java String to a format suitable for transmitting in Http requests.
static String EncodePath(String path)
          Encode the given http path string.
static String EncodeQuery(Properties params)
          Encode the given http query string.
static String getURIEncoding(byte b)
          Get string with URI escapes for given byte.
static int getUTF8SequenceLength(byte b)
          Return the sequence length of a UTF-8 sequence starting with the given byte.
static boolean looksLikeUTF8(byte[] bytes)
          Determines if bytes are a valid UTF-8 sequence.
static String RemoveParameter(String query, String paramName)
          Remove a parameter from a query string if present.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UriCodec

public UriCodec()
Creates a new URICoded Instance. It is safe to use this instance in one, single thread.

Method Detail

Encode

public static String Encode(String unquotedURI)
Encode the given URI. Escapes reserved URI characters.

Parameters:
unquotedURI - non-encoded URI
Returns:
encoded URI

Decode

public static String Decode(String quotedURI)
Decode the given URI. De-escapes reserved URI characters.

Parameters:
quotedURI - encoded URI
Returns:
decoded URI

EncodeQuery

public static String EncodeQuery(Properties params)
Encode the given http query string. Escapes reserved URI characters.

Parameters:
params - parameter to encode
Returns:
encoded query string

EncodePath

public static String EncodePath(String path)
Encode the given http path string. Escapes reserved URI characters.

Parameters:
path - TBD: Description of the incoming method parameter
Returns:
encoded query string

DecodeQuery

public static Properties DecodeQuery(String query)
Decode the given http query string. De-escapes reserved query characters.

Parameters:
query - http uri encoded
Returns:
set of decoded parameters

RemoveParameter

public static String RemoveParameter(String query,
                                     String paramName)
Remove a parameter from a query string if present. Returns the string unchanged if parameter is not present.

Parameters:
query - to remove parameter from
paramName - name of parameter
Returns:
query string with parameter removed

decode

public String decode(String quoted)
Converts an encoded URI into a Java String. Escaped octets are treated as octets in UTF-8 encoding.

This method is not multithread-safe.

Parameters:
quoted - the quoted URI
Returns:
the URI without escape characters

encode

public String encode(String unquoted)
Converts a URI in plain Java String to a format suitable for transmitting in Http requests. First, it escapes the reserved characters in URIs. Second, all characters not representable as 7-bit US-ASCII are escaped as octets in their UTF-8 encoding. Regards the last question mark in the string as query separator.

This method is not multithread-safe.

Parameters:
unquoted - URI in unquoted form
Returns:
URI with escaped characters

encodePath

public String encodePath(String unquoted)
Converts a URI in plain Java String to a format suitable for transmitting in Http requests. First, it escapes the reserved characters in URIs. Second, all characters not representable as 7-bit US-ASCII are escaped as octets in their UTF-8 encoding. Does no special handling of question marks.

This method is not multithread-safe.

Parameters:
unquoted - URI in unquoted form
Returns:
URI with escaped characters

looksLikeUTF8

public static final boolean looksLikeUTF8(byte[] bytes)
Determines if bytes are a valid UTF-8 sequence.

Parameters:
bytes - TBD: Description of the incoming method parameter
Returns:
if bytes are a valid UTF-8 sequence

getUTF8SequenceLength

public static final int getUTF8SequenceLength(byte b)
Return the sequence length of a UTF-8 sequence starting with the given byte. Returns -1 if byte is no valid sequence start.

Parameters:
b - byte for sequence start
Returns:
length of UTF-8 sequence or -1

getURIEncoding

public static final String getURIEncoding(byte b)
Get string with URI escapes for given byte.

Parameters:
b - byte to escape
Returns:
string with uri encoding of byte
Access Rights

This class can be accessed from:


SC DC Public Part ACH
[sap.com] KMC-CM [sap.com] tc/km/frwk api EP-KM-CM
[sap.com] KMC-WPC [sap.com] tc/kmc/wpc/wpcfacade api EP-PIN-WPC-WCM


Copyright 2014 SAP AG Complete Copyright Notice