com.pmease.quickbuild.util
Class Util

java.lang.Object
  extended by com.pmease.quickbuild.util.Util

public class Util
extends java.lang.Object

This class provides utility functions which can be used in expressions and velocity templates.


Constructor Summary
Util()
           
 
Method Summary
 java.lang.Long assignIdFor(java.io.File file)
           
 void cleanDir(java.io.File dir)
           
 void copyDir(java.io.File from, java.io.File to)
           
 void copyFile(java.io.File from, java.io.File to)
           
 java.lang.String decrypt(java.lang.String secret)
           
 void deleteDir(java.io.File dir)
           
 void deleteFile(java.io.File file)
           
 void deleteFiles(java.io.File dir, java.lang.String patterns)
           
 java.lang.String encrypt(java.lang.String plain)
           
 int execute(java.lang.String command)
           
 int execute(java.lang.String command, java.io.File workingDir)
           
 java.lang.String formatDate(java.util.Date date)
           
 java.lang.String formatDate(java.util.Date date, java.lang.String pattern)
           
 java.lang.String formatDuration(long durationMillis)
           
 java.lang.String formatErrorMessage(java.lang.String errorMessage)
          Deprecated. 
 java.lang.String formatString(java.lang.String string)
           
 SimpleCalendar getCalendar()
           
 java.io.File getFile(java.lang.String path)
           
 java.lang.String join(java.util.Collection<java.lang.String> collection)
           
 java.lang.String obj2string(java.io.Serializable obj)
           
 java.lang.String readFileAsString(java.io.File file)
           
 java.lang.String readFileAsString(java.io.File file, java.lang.String pattern, int range)
           
 java.lang.String readOutput(java.lang.String command)
           
 java.lang.String readOutput(java.lang.String command, java.io.File workingDir)
           
 java.util.List<java.lang.String> split(java.lang.String joined)
           
 java.io.Serializable string2obj(java.lang.String string)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
Method Detail

formatDuration

public java.lang.String formatDuration(long durationMillis)
Format duration as H:m:s. The passed param should be milli-seconds.


formatDate

public java.lang.String formatDate(java.util.Date date)
Format date to be suitable for display in html according to date format setting in QuickBuild. A html space ( ) will be returned if the date param is null.


formatDate

public java.lang.String formatDate(java.util.Date date,
                                   java.lang.String pattern)
Format specified date using specified pattern.


readFileAsString

public java.lang.String readFileAsString(java.io.File file,
                                         java.lang.String pattern,
                                         int range)
Read portion of the file around specified pattern with specified range. The second param should be a Java pattern matching lines of the file, and the third param should be a range indicating how many lines (both before and after) around the matched line should be read.


readFileAsString

public java.lang.String readFileAsString(java.io.File file)
Read file content as string.


formatString

public java.lang.String formatString(java.lang.String string)
Format specified string to be suitable for display in html. The line break character will be replaced with <br>. Null string is acceptable and   will be returned in that case.


formatErrorMessage

@Deprecated
public java.lang.String formatErrorMessage(java.lang.String errorMessage)
Deprecated. 

Format error message to be suitable for display in html. If the message is of multiple lines, second lines will be padded with white spaces at the beginning.


encrypt

public java.lang.String encrypt(java.lang.String plain)
Encrypt specified string. Null will be returned if a null string is passed as parameter.


decrypt

public java.lang.String decrypt(java.lang.String secret)
Decrypt specified string. Null will be returned if a null string is passed as parameter.


getCalendar

public SimpleCalendar getCalendar()
Get calendar object from which year, month and day can be retrieved.


readOutput

public java.lang.String readOutput(java.lang.String command)
Execute specified command and get the output. Multiple lines of output are separated by line terminators. The string param is the command to execute. The command should be composed of an executable part and optionally several parameters part separated by spaces. If the execution part or param parts themselves contain spaces, they should be quoted. For example: util.readOutput("/path/to/command \"param1 with space\" \"param2 with space\"")


readOutput

public java.lang.String readOutput(java.lang.String command,
                                   java.io.File workingDir)
Execute specified command and get the output. The first param is the command to execute, and the second param is working directory of the command. The command should be composed of an executable part and optionally several parameters part separated by spaces. If the execution part or param parts themselves contain spaces, they should be quoted. For example: util.readOutput("/path/to/command \"param1 with space\" \"param2 with space\"")


execute

public int execute(java.lang.String command)
Execute specified command and get the command return code. The string param is the command to execute. The command should be composed of an executable part and optionally several parameters part separated by spaces. If the execution part or param parts themselves contain spaces, they should be quoted. For example: util.execute("/path/to/command \"param1 with space\" \"param2 with space\"")


execute

public int execute(java.lang.String command,
                   java.io.File workingDir)
Execute specified command and get the command return code. The first param is the command to execute and the second param is the working directory for the command. The command should be composed of an executable part and optionally several parameters part separated by spaces. If the execution part or param parts themselves contain spaces, they should be quoted. For example: util.execute("/path/to/command \"param1 with space\" \"param2 with space\"")


getFile

public java.io.File getFile(java.lang.String path)
Get file object of specified path


deleteDir

public void deleteDir(java.io.File dir)
Delete specified directory.


deleteFile

public void deleteFile(java.io.File file)
Delete specified file.


deleteFiles

public void deleteFiles(java.io.File dir,
                        java.lang.String patterns)
Delete files matching specified patterns (2nd param) from specified directory (1st param). Refer to the file patterns reference for details of the file patterns.


cleanDir

public void cleanDir(java.io.File dir)
Clean specified directory.


join

public java.lang.String join(java.util.Collection<java.lang.String> collection)
Join values of specified collection with comma character.


split

public java.util.List<java.lang.String> split(java.lang.String joined)
Split specified string into a list of strings using new line or comma character as separator.


copyFile

public void copyFile(java.io.File from,
                     java.io.File to)
Copy file. The first argument represents the file to be copied, and the second argument represents the destination file.


copyDir

public void copyDir(java.io.File from,
                    java.io.File to)
Copy directory. The first argument represents the directory to be copied, and the second argument represents the destination directory.


assignIdFor

public java.lang.Long assignIdFor(java.io.File file)
Assign an unique integer identifier for path of specified file.


obj2string

public java.lang.String obj2string(java.io.Serializable obj)
Convert an object to string.


string2obj

public java.io.Serializable string2obj(java.lang.String string)
Convert a string to object.



Copyright © 2005-2010 PMEase Inc. All Rights Reserved.