jet.cs.util
Class APIUtil

java.lang.Object
  extended by jet.cs.util.APIUtil

public class APIUtil
extends java.lang.Object

Class APIUtil provides some utilities for JReport server and client.


Method Summary
static java.lang.String addUrlPath(java.lang.String path1, java.lang.String path2)
          Add a path to a path string and the result path string is non-URL-encoded.
static java.lang.String addUrlPaths(java.lang.String path1, java.lang.String path2)
          Add a path to a URL address string and the result URL string is URL-encoded.
static java.lang.String checkDigitalIDFileAndPassword(java.io.InputStream digitalID, java.lang.String password)
          check the digital ID file is criterion or not.
static boolean checkFileNameWithTemplate(java.lang.String fileName)
          check the user file name is valid for FileNameTemplate
static java.lang.String convertToAbsPath(java.io.File path, java.io.File root)
          Convert the real path of a file to the resource URL path of the report server.
static void deleteDirectory(java.lang.String path)
          delete a specific folder with all files inside (all sub-folders as well).
static java.lang.String escapeHtmlSpecialChars(java.lang.String originalString)
          Escape special characters for HTML page.
static boolean getBoolean(java.lang.String s)
          parse a boolean string to boolean.
static boolean getBoolean(java.lang.String s, boolean defVal)
          parse a boolean string to boolean.
static java.lang.String getDefaultTimeZone()
          Get the default timezone ID.
static java.lang.String getDisplayNameOfTask(java.lang.String taskClass)
          Get the display name through class names of scheduled tasks.
static java.lang.String getEncodingDescriptionByName(java.lang.String strName)
           
static java.lang.String getEncodingNameByDescription(java.lang.String strDesc)
           
static java.lang.String getExtName(java.lang.String file)
          This method return file's extension
static java.lang.String getFileNameWithoutDir(java.lang.String file)
          Remove a filename's path
static java.lang.String getLaunchTypeString(int launchType)
          Get the launch type of display string through the launch type of scheduled tasks.
static java.lang.String[] getLogicalFolderAndName(java.lang.String fileName)
          return logical folder and file name
static java.lang.String getNameWithoutExt(java.lang.String file)
          Remove a filename's extension and path
static java.lang.String getNameWithoutExt(java.lang.String file, boolean removeWholeExt)
          Remove a filename's extension and path
static java.lang.String getNodeNameWithoutExt(java.lang.String name, boolean removeWholeExt)
          Remove a node name's extension
static java.lang.String[] getPathAndName(java.lang.String url)
          Get the path name and its parent path of the url path.
static java.lang.String getPublishRptTaskDisplayName(java.util.Hashtable ht)
          Converts class name to string displays in task type column of schedule table.
static java.util.Vector[] getRptRelatedFiles(java.lang.String folder)
          get reports, catalogs and sub-folders in a specific folder.
static int getScreenResolution()
           
static java.lang.String getStackTraceString(java.lang.Throwable t)
          Get the stack trace string of a Throwable object.
static java.lang.String[] getSupportedEncodingDescriptions()
           
static java.lang.String[] getSupportedEncodingNames()
           
static java.lang.String[][] getSupportedEncodings()
           
static java.lang.Object getTempValueFromHt(java.lang.String key)
          return a certain object from hashtable according to a key
static java.lang.String getTimeElapseString(long milliSeconds)
          Convert milliseconds to display time.
static int[] getYearMonthDate(java.util.Date dt)
           
static boolean isCatalogFile(java.lang.String file)
          judge if the file is catalog file.
static boolean isReportFile(java.lang.String file)
          judge if the file is report file.
static boolean isValidEmailAddress(java.lang.String address)
          Check if input string is a valild email address
static boolean isValidNodeName(java.lang.String name)
          Check if input string is a valid node name
static java.util.Properties makeMailProperty(java.util.Properties propMail, boolean isNormalMail)
          Make APIConst.TAG_JRMAIL or APIConst.TAG_CSMAIL property field by properties of an E-Mail.
static int parseInt(java.lang.String str)
          parse an interger string to int.
static int parseInt(java.lang.String str, int defVal)
          parse an interger string to int.
static long parseLong(java.lang.String str)
          parse an interger string to long.
static long parseLong(java.lang.String str, int defVal)
          parse a long interger string to long.
static long parseLong(java.lang.String str, long defVal)
           
static java.util.Hashtable parseParamValues(java.io.InputStream input)
          Parse parameters from a parameter file input stream.
static java.util.Properties parseQuery(java.lang.String query)
          Parse a HTTP query string into a Properties object.
static void putTempValueToHt(java.lang.String key, java.lang.String value)
          put a certain value to temp hashtable
static java.lang.String removeExtName(java.lang.String file)
          Remove a filename's extension
static void removeTempValueInHt(java.lang.String key)
          remove a certain value in temp hashtable
static java.lang.String[][] sortAsCol(java.lang.String[][] dataTable, int colIndex, int SDirection)
          Sort the objects in String Array based as the special column which not judge capital and lower
static java.util.Vector sortAsCol(java.util.Vector vectorOfObject, java.util.Vector vectorOfColString, boolean sortDirection)
          Sort the objects in vector based as the special column which not judge capital and lower
static java.lang.String toDateTimeString(java.util.Date dt, java.util.TimeZone tz)
          Convert a Date object to string with format "EEE MMM d HH:mm:ss z yyyy".
static java.lang.String toSortableWinDateString(java.util.Date date)
          Convert a Date object to Windows style date string with format "MM'/'dd'/'yy HH:mm".
static java.lang.String toWinDateSecondString(java.util.Date date)
          Convert a Date object to Windows style date string with format "MM/dd/yy h:mm:ss a".
static java.lang.String toWinDateString(java.util.Date date)
          Convert a Date object to Windows style date string with format "MM/dd/yy h:mm a".
static java.lang.String toWinDateStringShowing(java.util.Date date)
          Convert a Date object to Windows style date string with format "MMM dd, yyyy".
static void transferJRMailProperties(java.util.Properties propMail)
          Deprecated.  
static java.lang.String VectorToURLEncodedString(java.util.Vector v)
          Get the HTTP query string from a Vector.
static java.lang.String writeFileToString(java.io.File strFile)
          read a file content and return content string
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

parseInt

public static int parseInt(java.lang.String str)
parse an interger string to int. The default value is -1.

Parameters:
str - the interger string.
Returns:
the int value. The default value is -1.

parseInt

public static int parseInt(java.lang.String str,
                           int defVal)
parse an interger string to int.

Parameters:
str - the interger string.
defVal - the default int value.
Returns:
the int value.

parseLong

public static long parseLong(java.lang.String str)
parse an interger string to long. The default value is -1L.

Parameters:
str - the long integer string.
Returns:
the long value. The default value is -1L.

parseLong

public static long parseLong(java.lang.String str,
                             int defVal)
parse a long interger string to long.

Parameters:
str - the long interger string.
defVal - the default long value.
Returns:
the long value.

parseLong

public static long parseLong(java.lang.String str,
                             long defVal)

getBoolean

public static boolean getBoolean(java.lang.String s)
parse a boolean string to boolean. The default value is false.

Parameters:
s - the boolean string.
Returns:
the boolean value. The default value is false.

getBoolean

public static boolean getBoolean(java.lang.String s,
                                 boolean defVal)
parse a boolean string to boolean.

Parameters:
s - the boolean string.
defVal - the default boolean value.
Returns:
the boolean value.

getDefaultTimeZone

public static java.lang.String getDefaultTimeZone()
Get the default timezone ID.

Returns:
the default timezone ID.

getStackTraceString

public static java.lang.String getStackTraceString(java.lang.Throwable t)
Get the stack trace string of a Throwable object.

Parameters:
t - the Throwable object.
Returns:
the stack trace string of a Throwable object.

toDateTimeString

public static java.lang.String toDateTimeString(java.util.Date dt,
                                                java.util.TimeZone tz)
Convert a Date object to string with format "EEE MMM d HH:mm:ss z yyyy".

Parameters:
dt - the Date object.
tz - the timezone.
Returns:
the string with format "EEE MMM d HH:mm:ss z yyyy".

toWinDateString

public static java.lang.String toWinDateString(java.util.Date date)
Convert a Date object to Windows style date string with format "MM/dd/yy h:mm a".

Parameters:
date - the Date object.
Returns:
the Windows style date string with format "MM/dd/yy h:mm a".

toSortableWinDateString

public static java.lang.String toSortableWinDateString(java.util.Date date)
Convert a Date object to Windows style date string with format "MM'/'dd'/'yy HH:mm".

Parameters:
date - the Date object.
Returns:
the Windows style date string with format "MM'/'dd'/'yy HH:mm".

toWinDateStringShowing

public static java.lang.String toWinDateStringShowing(java.util.Date date)
Convert a Date object to Windows style date string with format "MMM dd, yyyy".

Parameters:
date - the Date object.
Returns:
the Windows style date string with format "MMM dd, yyyy".

toWinDateSecondString

public static java.lang.String toWinDateSecondString(java.util.Date date)
Convert a Date object to Windows style date string with format "MM/dd/yy h:mm:ss a".

Parameters:
date - the Date object.
Returns:
the Windows style date string with format "MM/dd/yy h:mm:ss a".

getTimeElapseString

public static java.lang.String getTimeElapseString(long milliSeconds)
Convert milliseconds to display time. For example: convert 170543milliseconds to 2'50".

Parameters:
milliSeconds - the time elapse in milliseconds.
Returns:
the time string. For example: convert 170000milliseconds to 2'50".

getLaunchTypeString

public static java.lang.String getLaunchTypeString(int launchType)
Get the launch type of display string through the launch type of scheduled tasks.

Parameters:
launchType - the launch type of scheduled tasks.
Returns:
the launch type of display string with the launch type of scheduled tasks.

getDisplayNameOfTask

public static java.lang.String getDisplayNameOfTask(java.lang.String taskClass)
Get the display name through class names of scheduled tasks.

Parameters:
taskClass - the class name of scheduled tasks.
Returns:
the display name through the class name of scheduled tasks.

parseParamValues

public static java.util.Hashtable parseParamValues(java.io.InputStream input)
                                            throws java.io.IOException
Parse parameters from a parameter file input stream.

Parameters:
input - the parameter file input stream.
Returns:
the parameters. Keys are parameter names. Values are parameter values.
Throws:
java.io.IOException - if an IOException occurs.

addUrlPath

public static java.lang.String addUrlPath(java.lang.String path1,
                                          java.lang.String path2)
Add a path to a path string and the result path string is non-URL-encoded.

Parameters:
path1 - the path string.
path2 - the path that will be appended to the path1.
Returns:
add the path to the path string and the result path is non-URL-encoded.

addUrlPaths

public static java.lang.String addUrlPaths(java.lang.String path1,
                                           java.lang.String path2)
Add a path to a URL address string and the result URL string is URL-encoded.

Parameters:
path1 - the URL address string.
path2 - the path that will be appended to the URL address.
Returns:
add the path to the URL address string and the result URL string is URL-encoded.

convertToAbsPath

public static java.lang.String convertToAbsPath(java.io.File path,
                                                java.io.File root)
Convert the real path of a file to the resource URL path of the report server. For example: The file is "c:\JREntServer\jreport\SunVMDemo\SunVMDemo.cat" and the server root dir is "c:\JREntServer\jreport", then the method returns "/SunVMDemo/SunVMDemo.cat"

Parameters:
path - the file.
root - the server root dir.
Returns:
the resource URL path of the file in report server.

getPathAndName

public static java.lang.String[] getPathAndName(java.lang.String url)
Get the path name and its parent path of the url path. For example: The url path is "/SunVMDemo/SunVMDemo.cat". Then the String[0] is "/SunVMDemo/", and the String[0] is "SunVMDemo.cat".

Parameters:
url - the URL path.
Returns:
the path name(String[1]) and its parent path(String[0]) of the url path.

VectorToURLEncodedString

public static java.lang.String VectorToURLEncodedString(java.util.Vector v)
Get the HTTP query string from a Vector. For example: The Vector is {"string1", "string2"}. Then returns string1&string2.

Parameters:
v - the Vector.
Returns:
the HTTP query string.

transferJRMailProperties

public static void transferJRMailProperties(java.util.Properties propMail)
Deprecated. 

Transfer properties of an E-Mail to JRMail property field.

Parameters:
propMail - the properties of a e-mail.

makeMailProperty

public static java.util.Properties makeMailProperty(java.util.Properties propMail,
                                                    boolean isNormalMail)
Make APIConst.TAG_JRMAIL or APIConst.TAG_CSMAIL property field by properties of an E-Mail.

Parameters:
propMail - the properties of a e-mail.
isNormalMail - Is a normal e-mail(false: using APIConst.TAG_JRMAIL; true: using APIConst.TAG_CSMAIL).
Returns:
the properties of a e-mail.

getSupportedEncodings

public static java.lang.String[][] getSupportedEncodings()

getSupportedEncodingNames

public static java.lang.String[] getSupportedEncodingNames()

getSupportedEncodingDescriptions

public static java.lang.String[] getSupportedEncodingDescriptions()

getEncodingNameByDescription

public static java.lang.String getEncodingNameByDescription(java.lang.String strDesc)

getEncodingDescriptionByName

public static java.lang.String getEncodingDescriptionByName(java.lang.String strName)

getExtName

public static java.lang.String getExtName(java.lang.String file)
This method return file's extension

Parameters:
file - string of source file name
Returns:
file's extension

removeExtName

public static java.lang.String removeExtName(java.lang.String file)
Remove a filename's extension

Parameters:
file - string of source file name
Returns:
filename string that removed extension

getNameWithoutExt

public static java.lang.String getNameWithoutExt(java.lang.String file)
Remove a filename's extension and path

Parameters:
file - string of source file name
Returns:
filename string that removed extension and path

getNameWithoutExt

public static java.lang.String getNameWithoutExt(java.lang.String file,
                                                 boolean removeWholeExt)
Remove a filename's extension and path

Parameters:
file - string of source file name
removeWholeExt - for some recognized file type, if value is true, remove whole extension, otherwise remove extension after the last dot. For example: test.cat.xml, if value is true, return test, if valude is false, return test.cat.
Returns:
filename string that removed extension and path

getNodeNameWithoutExt

public static java.lang.String getNodeNameWithoutExt(java.lang.String name,
                                                     boolean removeWholeExt)
Remove a node name's extension

Parameters:
name - string of node name
removeWholeExt - for some recognized file type, if value is true, remove whole extension, otherwise remove extension after the last dot. For example: test.cat.xml, if value is true, return test, if valude is false, return test.cat.
Returns:
node name string that removed extension

getFileNameWithoutDir

public static java.lang.String getFileNameWithoutDir(java.lang.String file)
Remove a filename's path

Parameters:
file - string of source file name
Returns:
filename string that removed path

checkFileNameWithTemplate

public static boolean checkFileNameWithTemplate(java.lang.String fileName)
check the user file name is valid for FileNameTemplate

Parameters:
fileName - the user file name.
Returns:
the Boolean value. The default value is false.

writeFileToString

public static java.lang.String writeFileToString(java.io.File strFile)
read a file content and return content string

Parameters:
strFile - the file is read.
Returns:
the String of the content of the file.

parseQuery

public static java.util.Properties parseQuery(java.lang.String query)
Parse a HTTP query string into a Properties object.

Parameters:
query - the HTTP query string.
Returns:
the Properties object that contains the parameter values in the HTTP query string.

escapeHtmlSpecialChars

public static java.lang.String escapeHtmlSpecialChars(java.lang.String originalString)
Escape special characters for HTML page.
                "&" to represent the & sign. 
                "<" to represent the < sign. 
                ">" to represent the > sign. 
                "" to represent the " mark. 
      

Parameters:
originalString - original string
Returns:
escaped string

sortAsCol

public static java.util.Vector sortAsCol(java.util.Vector vectorOfObject,
                                         java.util.Vector vectorOfColString,
                                         boolean sortDirection)
Sort the objects in vector based as the special column which not judge capital and lower

Parameters:
vectorOfObject - is the vector of sorting Object.
vectorOfColString - is the vector of column which sorting as.
sortDirection - is the direction of sorting, false is asending,true is disasending.
Returns:
the vector which the object has been sorted in.

sortAsCol

public static java.lang.String[][] sortAsCol(java.lang.String[][] dataTable,
                                             int colIndex,
                                             int SDirection)
Sort the objects in String Array based as the special column which not judge capital and lower

Parameters:
dataTable - is the array of sorting Object.
colIndex - is the number of column which sorting as.
SDirection - is the direction of sorting, 0 is asending,1 is disasending.
Returns:
the String Array which the object has been sorted in.

getPublishRptTaskDisplayName

public static java.lang.String getPublishRptTaskDisplayName(java.util.Hashtable ht)
Converts class name to string displays in task type column of schedule table.

Parameters:
ht - is properties of tasks
Returns:
string displays in task type column of schedule table

isValidEmailAddress

public static boolean isValidEmailAddress(java.lang.String address)
Check if input string is a valild email address

Parameters:
address - input string to be tested
Returns:
true if input string is a valid email address, otherwise false.

isValidNodeName

public static boolean isValidNodeName(java.lang.String name)
Check if input string is a valid node name

Parameters:
name - string to be tested
Returns:
true if input string is a valid node name, otherwise false. A valid node name contains char '0' to '9', 'a' to 'z', 'A' to 'Z', white space, '_', '-', '.', '(', and ')'.

getYearMonthDate

public static int[] getYearMonthDate(java.util.Date dt)

deleteDirectory

public static void deleteDirectory(java.lang.String path)
                            throws java.lang.SecurityException
delete a specific folder with all files inside (all sub-folders as well).

Parameters:
path - the full path of the file or folder which will be deleted.
Throws:
java.lang.SecurityException

getRptRelatedFiles

public static java.util.Vector[] getRptRelatedFiles(java.lang.String folder)
                                             throws java.lang.SecurityException
get reports, catalogs and sub-folders in a specific folder.

Parameters:
folder - the full path of the folder.
Returns:
an array contains three Vectors. Vector[0]: all reports in the folder Vector[1]: all catalogs in the folder Vector[2]: all sub-folders in the folder
Throws:
java.lang.SecurityException

isReportFile

public static boolean isReportFile(java.lang.String file)
judge if the file is report file.

Parameters:
file - the full path of the file.
Returns:
if the file is report file.

isCatalogFile

public static boolean isCatalogFile(java.lang.String file)
judge if the file is catalog file.

Parameters:
file - the full path of the file.
Returns:
if the file is catalog file.

getLogicalFolderAndName

public static java.lang.String[] getLogicalFolderAndName(java.lang.String fileName)
return logical folder and file name


putTempValueToHt

public static void putTempValueToHt(java.lang.String key,
                                    java.lang.String value)
put a certain value to temp hashtable

Parameters:
key - the key
value - the certain value

getTempValueFromHt

public static java.lang.Object getTempValueFromHt(java.lang.String key)
return a certain object from hashtable according to a key

Parameters:
key - the key
Returns:
object in hashtable

removeTempValueInHt

public static void removeTempValueInHt(java.lang.String key)
remove a certain value in temp hashtable

Parameters:
key - the key

checkDigitalIDFileAndPassword

public static java.lang.String checkDigitalIDFileAndPassword(java.io.InputStream digitalID,
                                                             java.lang.String password)
check the digital ID file is criterion or not.

Parameters:
digitalID - the inputstream of digital ID file
password - the digital id file open password
Returns:
the string about check result message

getScreenResolution

public static int getScreenResolution()