***  This class provides Binary Compatibility only, not Source Compatibility  ***

com.sas.services.webdav
Class Utils

com.sas.services.webdav.Utils

public class Utils

A convenience class to bring together a number of utilties.

Since:
1.0

Constructor Summary
Utils()
           
 
Method Summary
static java.lang.String addSegment(java.lang.String path, java.lang.String segment)
          Append a segment to a path.
static java.lang.String bytesToHex(byte[] chars)
          Convert a byte array to a hex representation that is easy to visualise.
static java.lang.String byteStreamToHex(java.io.InputStream byteStream)
          Convert a stream of bytes to hex.
static java.lang.String CDATA(java.lang.String text)
          Encapsulate the text in a CDATA section in case there is any markup in text.
static PropertyMap convertPropertyArray(org.apache.webdav.lib.Property[] props)
          A utility method to convert an array of WebDAV Property objects to a property map.
static java.lang.String getRelativePath(java.lang.String urlString)
          Get the relative path for a given url.
static java.lang.String intToHex(int number, int width)
          Convert an int to printable hex format (eg 33 = x'21') padding if necessary.
static boolean isCollection(java.util.Map properties)
          A utility method to check through a set of properties and determine if it is a collection or not.
static boolean isSameUrl(java.lang.String url1, java.lang.String url2)
          Compare two url strings.
static void print(java.lang.String a)
           
static java.lang.String stringToHex(java.lang.String chars)
          Convert a set of characters to hex.
static java.lang.String stripLeadingSlashes(java.lang.String buffer)
          Strip off leading forward slash characters
static java.lang.String URIDecode(java.lang.String uriString)
          Decodes a URI and produces a Java string user version of the URI.
static java.lang.String URIDecode(java.lang.String uriString, boolean forcePort)
          Decodes a URI and produces a Java string user version of the URI.
static java.lang.String XMLESCAPE(java.lang.String text)
          Escape the characters '<', '&', '>' and '"', which shouldn't appear in literal form except as markup (unless they are in a CDATA section).
 

Constructor Detail

Utils

public Utils()
Method Detail

bytesToHex

public static java.lang.String bytesToHex(byte[] chars)
Convert a byte array to a hex representation that is easy to visualise.

Parameters:
chars - The byte array to convert to hex display
Returns:
String A string with the multiline hex display output.

byteStreamToHex

public static java.lang.String byteStreamToHex(java.io.InputStream byteStream)
Convert a stream of bytes to hex.

Parameters:
byteStream - A stream containing the bytes to convert
Returns:
String Hex representation of chars

stringToHex

public static java.lang.String stringToHex(java.lang.String chars)
Convert a set of characters to hex.

Parameters:
chars - A string containing the characters to convert
Returns:
String Hex representation of chars

intToHex

public static java.lang.String intToHex(int number,
                                        int width)
Convert an int to printable hex format (eg 33 = x'21') padding if necessary.

Parameters:
number - The number to be converted
width - The width of the resulting string
Returns:
String A string of width "width" containing the hex representation of the number "number"

isSameUrl

public static boolean isSameUrl(java.lang.String url1,
                                java.lang.String url2)
Compare two url strings. A trailing slash is not significant and so this method checks to see whether the two urls are equal with trailing slashes.

Parameters:
url1 - The first url string
url2 - The second url string
Returns:
boolean true if the urls represent the same resource, false otherwise

isCollection

public static boolean isCollection(java.util.Map properties)
A utility method to check through a set of properties and determine if it is a collection or not. When using depth=1 or depth=infinity, it is possible to get this information without having to bind to the resource itself. Use the value for the "{DAV:}resourcetype" property to determine whether this is a collection or not.

Parameters:
properties - The property map for this resource.
Returns:
boolean True if properties describe a collection, false otherwise.

convertPropertyArray

public static PropertyMap convertPropertyArray(org.apache.webdav.lib.Property[] props)
A utility method to convert an array of WebDAV Property objects to a property map.

Parameters:
props - An array of Property objects
Returns:
PropertyMap (maps property names to values). The property names in this case use the format "{namespace}propertyname".

getRelativePath

public static java.lang.String getRelativePath(java.lang.String urlString)
Get the relative path for a given url. This is the last segment of the name after the last forward slash, unless there is a forward slash at the end of the url. In this case it is the name inbetween the two slashes.

Parameters:
urlString - A string representing a url
Returns:
String The relative path, or last segment in the url

addSegment

public static java.lang.String addSegment(java.lang.String path,
                                          java.lang.String segment)
Append a segment to a path. Concatenate the segment to the path with a slash inbetween. This routine takes into account all the nasties, including blanks before or after the slashes, empty segment or path, muliple slashes, and missing slashes.

Parameters:
path - The path (or url)
segment - The segment to be added to the path
Returns:
String The correctly created new path

CDATA

public static java.lang.String CDATA(java.lang.String text)
Encapsulate the text in a CDATA section in case there is any markup in text. If text already a CDATA section then just return it.

Parameters:
text - The text to be encapsulated
Returns:
The CDATA section encapsulating the text

XMLESCAPE

public static java.lang.String XMLESCAPE(java.lang.String text)
Escape the characters '<', '&', '>' and '"', which shouldn't appear in literal form except as markup (unless they are in a CDATA section).

Parameters:
text - The text to be escaped
Returns:
The escaped text

stripLeadingSlashes

public static java.lang.String stripLeadingSlashes(java.lang.String buffer)
Strip off leading forward slash characters

Parameters:
buffer - Initial string from which to remove leading slashes
Returns:
String The input string with leading slashes removed

print

public static void print(java.lang.String a)

URIDecode

public static java.lang.String URIDecode(java.lang.String uriString)
Decodes a URI and produces a Java string user version of the URI. This includes the original unicode chars that would have produced this URI.

Parameters:
uriString - The actual URI (absolute or relative)
Returns:
String User Java string that will produce this URI

URIDecode

public static java.lang.String URIDecode(java.lang.String uriString,
                                         boolean forcePort)
Decodes a URI and produces a Java string user version of the URI. This includes the original unicode chars that would have produced this URI.

Parameters:
uriString - The actual URI (absolute or relative)
Returns:
String User Java string that will produce this URI

***  This class provides Binary Compatibility only, not Source Compatibility  ***




Copyright © 2009 SAS Institute Inc. All Rights Reserved.