org.jboss.shotoku.tools
Class Tools

java.lang.Object
  extended by org.jboss.shotoku.tools.Tools

public class Tools
extends java.lang.Object

Utility, helper functions used internally.

Author:
Adam Warski (adamw@aster.pl)

Constructor Summary
Tools()
           
 
Method Summary
static java.lang.String addPaths(java.lang.String path1, java.lang.String path2)
          Concatenates two parts of a path into 1: returns a string path1/path2.
static void checkName(java.lang.String name)
           
static java.lang.String concatenatePaths(java.lang.String path1, java.lang.String path2)
          Concatenates two parts of a path into 1: returns a string path1/path2, only with the necessary slashes (so running normalizeSlashes(String) won't have any effect on the string).
static java.lang.String concatenateProperties(java.lang.String property1, java.lang.String property2)
          Concatenates two parts of a property name: returns a string property1.property2.
static java.io.File createTemporaryFile()
           
static java.lang.String decodeURL(java.lang.String s)
          Decodes the given string from aa URL-friendly format (calls URLDecoder.decodeURL).
static java.lang.String encodeURL(java.lang.String s)
          Encodes the given string to an URL-friendly format (calls URLEncoder.encodeURL).
static java.lang.String getAttributeValue(org.w3c.dom.Node root, java.lang.String attrName)
          From the given node, gets the value of the specified attribute.
static java.nio.ByteBuffer getFileBytes(java.io.File file)
           
static java.lang.String getFileString(java.io.File file)
           
static java.util.Map<java.lang.String,java.lang.String> getMapFromNodeAttributes(org.w3c.dom.Node root)
          Reads all attributes of the given node and returns them as a map.
static java.lang.String getNameBasedMimeType(java.io.File file)
           
static java.lang.String getNameBasedMimeType(java.lang.String name)
           
static org.w3c.dom.Node getNamedNode(org.w3c.dom.Node root, java.lang.String name)
           
static ShotokuService getService()
           
static boolean isEmpty(java.lang.String s)
          Checks if the given string is empty (null or "").
static boolean isOutsideLink(java.lang.String link)
          Checks if the link is an outside link.
static boolean isTrue(java.lang.String s)
          Checks if the given string represents a true value.
static java.lang.String normalizeSlashes(java.lang.String toNormalize, boolean startingSlash)
          From the given string, removes unnecessary / in the middle and ending.
static boolean objectsEqual(java.lang.Object obj1, java.lang.Object obj2)
          Checks if two objects are equal - either both null, or their equals method returns true.
static java.lang.String toString(java.lang.Object o)
          Converts the given object to a String in a null-safe way.
static java.lang.String toStringNotNull(java.lang.Object o)
          Converts the given object to a String in a null-safe way.
static void transfer(java.io.InputStream is, java.io.OutputStream os)
          Transferes all bytes from the given input stream to the given output stream.
static void transfer(java.io.InputStream is, java.io.PrintWriter w)
          Transferes all bytes from the given input stream to the given output stream.
static java.lang.String unmarshallText(org.w3c.dom.Node textNode)
          Reads text contained in a tag of the form text.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Tools

public Tools()
Method Detail

getService

public static ShotokuService getService()

unmarshallText

public static java.lang.String unmarshallText(org.w3c.dom.Node textNode)
Reads text contained in a tag of the form text.

Parameters:
textNode - Node to read text from.
Returns:
Text contained in the given node.

getNamedNode

public static org.w3c.dom.Node getNamedNode(org.w3c.dom.Node root,
                                            java.lang.String name)
Parameters:
root - Node which children should be searched.
name - Name of the node that is being searched.
Returns:
A child node of the given one with the given name if such exists, or null otherwise.

getAttributeValue

public static java.lang.String getAttributeValue(org.w3c.dom.Node root,
                                                 java.lang.String attrName)
From the given node, gets the value of the specified attribute.

Parameters:
root - Node to read the attribute from.
attrName - Name of the attribute to read.
Returns:
Value of the given attribute or null, if no such attribute is present.

getMapFromNodeAttributes

public static java.util.Map<java.lang.String,java.lang.String> getMapFromNodeAttributes(org.w3c.dom.Node root)
Reads all attributes of the given node and returns them as a map. Only signle-value attributes are supported.

Parameters:
root - Node from which to read the attributes.
Returns:
A map holding all attributes of the given node.

normalizeSlashes

public static java.lang.String normalizeSlashes(java.lang.String toNormalize,
                                                boolean startingSlash)
From the given string, removes unnecessary / in the middle and ending. If startingSlash = true, ensures that the returned string starts with a slash. For example: "///a//b//c/" is transformed to "/a/b/c" (here, startingSlash = true).

Parameters:
toNormalize - String to normalize.
startingSlash - True if the returned string should have a / in the beginning.
Returns:
toNormalize with unnecessary / removed.

concatenatePaths

public static java.lang.String concatenatePaths(java.lang.String path1,
                                                java.lang.String path2)
Concatenates two parts of a path into 1: returns a string path1/path2, only with the necessary slashes (so running normalizeSlashes(String) won't have any effect on the string).

Parameters:
path1 - First path to concatenate.
path2 - Second path to concatenate.
Returns:
path1/path2

concatenateProperties

public static java.lang.String concatenateProperties(java.lang.String property1,
                                                     java.lang.String property2)
Concatenates two parts of a property name: returns a string property1.property2.

Parameters:
property1 - First property part to concatenate.
property2 - Second property part to concatenate.
Returns:
property1.property2

addPaths

public static java.lang.String addPaths(java.lang.String path1,
                                        java.lang.String path2)
Concatenates two parts of a path into 1: returns a string path1/path2.

Parameters:
path1 - First path to concatenate.
path2 - Second path to concatenate.
Returns:
path1/path2

isEmpty

public static boolean isEmpty(java.lang.String s)
Checks if the given string is empty (null or "").


toString

public static java.lang.String toString(java.lang.Object o)
Converts the given object to a String in a null-safe way.

Parameters:
o - Object to convert.
Returns:
Result of o.toString() or null if o is null.

toStringNotNull

public static java.lang.String toStringNotNull(java.lang.Object o)
Converts the given object to a String in a null-safe way. Never returns a null.

Parameters:
o - Object to convert.
Returns:
Result of o.toString() or an emptys tring if o is null.

encodeURL

public static java.lang.String encodeURL(java.lang.String s)
Encodes the given string to an URL-friendly format (calls URLEncoder.encodeURL).

Parameters:
s - String to encodeURL.
Returns:
Encoded string.

decodeURL

public static java.lang.String decodeURL(java.lang.String s)
Decodes the given string from aa URL-friendly format (calls URLDecoder.decodeURL).

Parameters:
s - String to decodeURL.
Returns:
Decoded string.

objectsEqual

public static boolean objectsEqual(java.lang.Object obj1,
                                   java.lang.Object obj2)
Checks if two objects are equal - either both null, or their equals method returns true.

Parameters:
obj1 - First object to compare.
obj2 - Second object to compare.
Returns:
True iff both objects are equal to null or if their equals method returns true.

isOutsideLink

public static boolean isOutsideLink(java.lang.String link)
Checks if the link is an outside link.

Parameters:
link - Link to check.
Returns:
True iff the given link is an outside link.

transfer

public static void transfer(java.io.InputStream is,
                            java.io.OutputStream os)
                     throws java.io.IOException
Transferes all bytes from the given input stream to the given output stream.

Parameters:
is - Input stream to read from.
os - Output stream to write to.
Throws:
java.io.IOException

transfer

public static void transfer(java.io.InputStream is,
                            java.io.PrintWriter w)
                     throws java.io.IOException
Transferes all bytes from the given input stream to the given output stream.

Parameters:
is - Input stream to read from.
w - Printwriter to write to.
Throws:
java.io.IOException

isTrue

public static boolean isTrue(java.lang.String s)
Checks if the given string represents a true value. For example, "true", "yes", "TrUe", "1" etc will return true.

Parameters:
s - String to check.
Returns:
True iff the given string can be determined to represent "true".

checkName

public static void checkName(java.lang.String name)
                      throws NameFormatException
Throws:
NameFormatException

getFileBytes

public static java.nio.ByteBuffer getFileBytes(java.io.File file)
                                        throws java.io.IOException
Parameters:
file - File to read from.
Returns:
Content of the given file represented as a byte buffer.
Throws:
java.io.IOException

getFileString

public static java.lang.String getFileString(java.io.File file)
                                      throws java.io.IOException
Parameters:
file - File to read from.
Returns:
Content of the given file represented as a String.
Throws:
java.io.IOException

createTemporaryFile

public static java.io.File createTemporaryFile()
Returns:
A new temporary file.

getNameBasedMimeType

public static java.lang.String getNameBasedMimeType(java.lang.String name)

getNameBasedMimeType

public static java.lang.String getNameBasedMimeType(java.io.File file)


Copyright © -2006 . All Rights Reserved.