unsw.cse.mica.util
Class MicaUtils

java.lang.Object
  extended by unsw.cse.mica.util.MicaUtils

public class MicaUtils
extends java.lang.Object

Utility methods used by MICA

Author:
waleed

Field Summary
static java.lang.String MICA_TIMESTAMP_FORMAT
          The MICA timestamp format.
 
Constructor Summary
MicaUtils()
           
 
Method Summary
static java.lang.String currentTimeToString()
          Convert the current time into a mica time string
static java.lang.String escape(java.lang.String input)
          convert a string into an form suitable for transmission in XML.
static java.util.Properties load(java.lang.String resource)
          Wrapper for the load(String,String,boolean,boolean) method below, allowing both user dir and local dir to override.
static java.util.Properties load(java.lang.String resource, java.lang.String location, boolean homeOverride, boolean localOverride)
          Load a java properties file from the given resource.
static java.lang.String replaceAll(java.lang.String str, java.util.Properties properties)
          Replaces each occurrence of "${PROPERTY}" with VALUE, where PROPERTY is a property defined in 'properties' and VALUE is its corresponding value.
static java.lang.String replaceAll(java.lang.String target, java.lang.String oldStr, java.lang.String newStr)
          Replace all occurrences of oldStr in target by newStr.
static long stringToTime(java.lang.String str)
          Convert a Mica time string into a time ms.
static java.lang.String timeToString(long time)
          Convert a time into a mica time string Taken from the old Blackboard getTime() method
static java.lang.String toString(org.xml.sax.Attributes atts)
          Create a String representation of an Attributes object.
static java.lang.String unescape(java.lang.String input)
          converts escaped XML characters back to their original form.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MICA_TIMESTAMP_FORMAT

public static final java.lang.String MICA_TIMESTAMP_FORMAT
The MICA timestamp format. Whwever MICA transmits a date it uses this format.

See Also:
Constant Field Values
Constructor Detail

MicaUtils

public MicaUtils()
Method Detail

currentTimeToString

public static java.lang.String currentTimeToString()
Convert the current time into a mica time string


timeToString

public static java.lang.String timeToString(long time)
Convert a time into a mica time string Taken from the old Blackboard getTime() method

Parameters:
time - the time to be converted
Returns:
a string representation of the given time

stringToTime

public static long stringToTime(java.lang.String str)
Convert a Mica time string into a time ms. Taken from the old Mob.getCreationTime

Parameters:
str - a string representing a time in the Mica time format
Returns:
the given time in absolute milliseconds

escape

public static java.lang.String escape(java.lang.String input)
convert a string into an form suitable for transmission in XML. This is done by escaping the characters "&","<",">","'" and """ into &amp;,&lt;,&gt;,&apos; and &quot; respectively.

Parameters:
input - the string to be escaped
Returns:
the escaped form of the string

unescape

public static java.lang.String unescape(java.lang.String input)
converts escaped XML characters back to their original form. This methos is the opposite of escape(String input).

Parameters:
input - the string to be unescaped
Returns:
the unescaped form of the given string.

replaceAll

public static java.lang.String replaceAll(java.lang.String target,
                                          java.lang.String oldStr,
                                          java.lang.String newStr)
Replace all occurrences of oldStr in target by newStr. This is needed for J2ME devices wanting to use MICA since J2SE 1.3 does not have a String#replaceAll(String) method.

Parameters:
target - the string to have its contents replaced
oldStr - the substring to be replaced
newStr - the replacement for each occurrence of the substring
Returns:
a string in which each occurrence of oldStr in target has beemn replaced by newStr

replaceAll

public static java.lang.String replaceAll(java.lang.String str,
                                          java.util.Properties properties)
Replaces each occurrence of "${PROPERTY}" with VALUE, where PROPERTY is a property defined in 'properties' and VALUE is its corresponding value. System.

Parameters:
str -
properties -
Returns:
str with all properties replaced with their values

toString

public static java.lang.String toString(org.xml.sax.Attributes atts)
Create a String representation of an Attributes object. Useful for debugging.

Parameters:
atts - the attributes object
Returns:
a string representation of the attributes object given

load

public static java.util.Properties load(java.lang.String resource)
Wrapper for the load(String,String,boolean,boolean) method below, allowing both user dir and local dir to override.

Parameters:
resource - the name of the resource file to load.
Returns:
The properties file created from the filename given, and overridden by files in the user's home directory and the local directory if applicable

load

public static java.util.Properties load(java.lang.String resource,
                                        java.lang.String location,
                                        boolean homeOverride,
                                        boolean localOverride)
Load a java properties file from the given resource. Also provides an option for the properties file to be over-ridden by lookgin for a file with the same name in the user's home directory and/or the current directory

Parameters:
resource - the name of the resource file
location - the location of the resource file
homeOverride - a flag specifiying whether or not the properties file can be overridden by a file in the user's home directory with the same name (if such a file exists)
localOverride - a flag specifiying whether or not the properties file can be overridden by a file in the local directory with the same name (if such a file exists)