javawebparts.core
Class JWPHelpers

java.lang.Object
  |
  +--javawebparts.core.JWPHelpers

public final class JWPHelpers
extends java.lang.Object

This class contains miscellaneous methods that are used by classes in multiple packages.

This class depends on the following extra packages, beyond the JDK, to compile and run: None.

Author:
Frank W. Zammetti.

Constructor Summary
private JWPHelpers()
          This is a utility class, so we want a private noarg constructor so instances cannot be created.
 
Method Summary
static java.lang.String encodeEntities(java.lang.String str, java.lang.String exclusions)
          This method replaces any character in a given string that has a corresponding HTML entity with that entity.
static java.lang.Object getFieldWithPrivilege(java.lang.reflect.Field fld, java.lang.Object obj)
          This method is used by the serializiableTest() method to get the needed priveleges on a given field of a given object needed to perform the serializable test.
static int randomNumber(int low, int high)
          This method is used to generate a random number in a given range and the number should be more random than the standard Java random number generator and also should guarantee that a random number generated on two different machines at the exact same time will yield a different number.
static java.lang.String[] readFromFile(java.lang.String pathToFile)
          Read a file and return its contents as an array of Strings.
static java.lang.String serializiableTest(java.lang.Object obj)
          This method is used by the getContextSize() method to determine if a given object is serializable.
static void writeToFile(java.lang.String pathToFile, java.lang.String[] lines, boolean append)
          Write an array of lines out to file a file, overwriting the file if it already exists.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JWPHelpers

private JWPHelpers()
This is a utility class, so we want a private noarg constructor so instances cannot be created.

Method Detail

serializiableTest

public static java.lang.String serializiableTest(java.lang.Object obj)
This method is used by the getContextSize() method to determine if a given object is serializable.

Parameters:
obj - The object to test.
Returns:
A response string detailing the outcome of the test.

getFieldWithPrivilege

public static java.lang.Object getFieldWithPrivilege(java.lang.reflect.Field fld,
                                                     java.lang.Object obj)
This method is used by the serializiableTest() method to get the needed priveleges on a given field of a given object needed to perform the serializable test.

Parameters:
fld - The field to get priveleges on.
obj - The object to test.
Returns:
A Priveleged reference to the field essentially.

writeToFile

public static void writeToFile(java.lang.String pathToFile,
                               java.lang.String[] lines,
                               boolean append)
                        throws java.io.IOException
Write an array of lines out to file a file, overwriting the file if it already exists. Note that this method is synchronized! If performance rather than safety is a concern, don't use this!

Parameters:
pathToFile - Path to file to write.
lines - Array of lines to be saved to the file.
append - True to append to an existing file, if it exists, or false to overwrite an existing file, if it exists.
Throws:
java.io.IOException - If any problems are encountered.

readFromFile

public static java.lang.String[] readFromFile(java.lang.String pathToFile)
                                       throws java.io.IOException
Read a file and return its contents as an array of Strings. Note that this method is synchronized! If performance rather than safety is a concern, don't use this!

Parameters:
pathToFile - Path to file to write.
Returns:
An array of lines read from the file.
Throws:
java.io.IOException - If any other problems are encountered.

randomNumber

public static int randomNumber(int low,
                               int high)
This method is used to generate a random number in a given range and the number should be more random than the standard Java random number generator and also should guarantee that a random number generated on two different machines at the exact same time will yield a different number.

Parameters:
low - Lowest numeber allowed.
high - Highest number allowed.
Returns:
A number between low and high, inclusive.

encodeEntities

public static java.lang.String encodeEntities(java.lang.String str,
                                              java.lang.String exclusions)
This method replaces any character in a given string that has a corresponding HTML entity with that entity. You can also pass it a string containing characters you DO NOT want entities inserted for.

Parameters:
str - The string to insert entities into.
exclusions - Characters you DO NOT wanted entities inserted for. Pass null for no exclusions.
Returns:
A new string with HTML entities replacing all charactercs, except those excluded, that have corresponding entities.


Copyright 2005 Frank W. Zammetti