SAP NetWeaver '04

com.sap.netweaver.bc.rf.common
Class UriCodec

[contained in: com.sap.netweaver.bc.rf.par - bc.rf.common_api.jar]
java.lang.Object
  |
  +--com.sap.netweaver.bc.rf.common.UriCodec

public class UriCodec
extends java.lang.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
 java.lang.String decode(java.lang.String quoted)
          Converts an encoded URI into a Java String.
static java.lang.String Decode(java.lang.String quotedURI)
          Decode the given URI.
static java.util.Properties DecodeQuery(java.lang.String query)
          Decode the given http query string.
 java.lang.String encode(java.lang.String unquoted)
          Converts a URI in plain Java String to a format suitable for transmitting in Http requests.
static java.lang.String Encode(java.lang.String unquotedURI)
          Encode the given URI.
 java.lang.String encodePath(java.lang.String unquoted)
          Converts a URI in plain Java String to a format suitable for transmitting in Http requests.
static java.lang.String EncodePath(java.lang.String path)
          Encode the given http path string.
static java.lang.String EncodeQuery(java.util.Properties params)
          Encode the given http query string.
static java.lang.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 java.lang.String RemoveParameter(java.lang.String query, java.lang.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 java.lang.String Encode(java.lang.String unquotedURI)
Encode the given URI. Escapes reserved URI characters.
Parameters:
unquotedURI - non-encoded URI
Returns:
encoded URI

Decode

public static java.lang.String Decode(java.lang.String quotedURI)
Decode the given URI. De-escapes reserved URI characters.
Parameters:
quotedURI - encoded URI
Returns:
decoded URI

EncodeQuery

public static java.lang.String EncodeQuery(java.util.Properties params)
Encode the given http query string. Escapes reserved URI characters.
Parameters:
params - parameter to encode
Returns:
encoded query string

EncodePath

public static java.lang.String EncodePath(java.lang.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 java.util.Properties DecodeQuery(java.lang.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 java.lang.String RemoveParameter(java.lang.String query,
                                               java.lang.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 java.lang.String decode(java.lang.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 java.lang.String encode(java.lang.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 java.lang.String encodePath(java.lang.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 java.lang.String getURIEncoding(byte b)
Get string with URI escapes for given byte.
Parameters:
b - byte to escape
Returns:
string with uri encoding of byte

SAP NetWeaver '04

Copyright © 2004 by SAP AG. All Rights Reserved.
SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary.

These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.