com.sap.netweaver.bc.rf.common

Class UriCodec

java.lang.Object
  extended bycom.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


Copyright 2006 SAP AG. All rights reserved. No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice. Microsoft, Windows, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation. Oracle is a registered trademark of Oracle Corporation. UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group. Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc. HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C, World Wide Web Consortium, Massachusetts Institute of Technology. Java is a registered trademark of Sun Microsystems, Inc. JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape. MaxDB is a trademark of MySQL AB, Sweden. 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.