com.ca.pki.util
Class StaticUtil

java.lang.Object
  |
  +--com.ca.pki.util.StaticUtil

public class StaticUtil
extends java.lang.Object

This class provides utility functions as static methods.


Field Summary
static boolean debugFlag
          will be set to true if the app is started with -DDEBUG=yes
static java.lang.String[] revocationReasons
           
 
Constructor Summary
StaticUtil()
           
 
Method Summary
static java.lang.String bytes2Hex(byte[] in)
          Converts 'in' to a hexadecimal character string.
static java.lang.String bytes2Hex(byte[] in, int offset, int len)
          Converts 'len' bytes to a hexadecimal character string.
static java.lang.String bytes2HexSplit(byte[] in, int wordlength)
           
static java.lang.String bytes2HexSplit(byte[] in, int wordlength, int linelength)
           
static void center(java.awt.Component centerMe, java.awt.Component positioner)
          This positions a component to the center of another component.
static java.lang.String checkDate(java.lang.String dateString)
          Check if a date is in correct MM/dd/yyyy format
static void checkDirectory(java.lang.String directoryPath)
          Checks for the existence of a directory; if it doesn't already exist creates it
static int checkDrive(char drive)
          check if a drive is ready (windows specific code) return 0 if success
static java.lang.String chooseFileToLoad(java.awt.Component parent, java.lang.String title)
          Show file chooser to get a file location for data loading.
static java.lang.String chooseFileToLoad(java.awt.Component parent, java.lang.String title, java.lang.String[] filter, java.lang.String fileType)
          Show file chooser to get a file location for data loading.
static java.lang.String chooseFileToSave(java.awt.Component parent, java.lang.String title)
          Show file chooser to get a file location for saving data.
static java.lang.String chooseFileToSave(java.awt.Component parent, java.lang.String title, java.lang.String[] filter, java.lang.String fileType)
          Show file chooser to get a file location for saving data.
static void configLogger(Logger logger, java.util.Properties props, java.lang.String logSuffix)
          Method copied from RAServer: used to configure our customised Log4J writer
static java.util.Date getDate(java.lang.String value)
          Parses a date field, accept both "MM/dd/yyyy" or "now +/- years" format
static java.awt.Frame getFrame(java.awt.Component c)
          Return the parent frame of the component c.
static java.lang.String getGeneralizedTime(java.util.Date adate)
           
static java.awt.Window getWindow(java.awt.Component c)
          Return the parent window of the component c.
static byte[] hex2Bytes(java.lang.String in)
          Converts a hexadecimal character string to a byte array.
static boolean isSameDay(java.util.Date date1, java.util.Date date2)
          Checks if two (yyyy,MM,dd) dates are the same
static boolean isToday(java.util.Date date)
          Checks a date if it is today's date by matching yyyy, MM, dd
static java.util.Properties loadProperties(java.lang.String filename)
          Loads properties from a file
static void logAndDialog(Logger logger, Priority logLevel, java.lang.String message, java.awt.Frame parentFrame, int dialogType)
          Write a log item and also pop an error dialog
static boolean okToWriteFile(java.awt.Frame parent, java.lang.String fileName)
           
static java.lang.String parseDate(java.lang.String value)
          Parses a "MM/dd/yyyy" or "now +/- years" date field, returns a date string in format "MM/dd/yyyy"
static boolean pkiConfigured()
          Checks the value of the property 'Configuration' in %pkihome%\path_properties.config If the configuration has run successfully, this will be >0; if not pki still needs to be configured.
static void printDebug(java.lang.String message)
          will be set to true if the app is started with -DDEBUG=yes
static int reasonCode(java.lang.String reason)
          Returns revocation code from reason text
static java.lang.String reasonText(int code)
          Returns revocation text from reason code
static java.lang.String removeCommas(java.lang.String inputDN)
          Replace all commas (i.e. ',') enclosed in quotes (for example OU="CA, Glen Iris") by '~' so that the entry can be created in the publishing directory
static java.lang.String replace(java.lang.String source, java.lang.String oldPattern, java.lang.String newPattern)
          Replace all the appreances of oldPattern in a source string by newPattern.
static void setBounds(java.awt.Component me, int width, int height, java.awt.Component parent)
          Locate component at the middle of the parent frame.
static void setDefaultFont(java.awt.Font afont)
          Set default system font.
static void setLookAndFeel()
           
static void setLookAndFeelC(java.awt.Component comp)
           
static void storeProperties(java.lang.String filename, java.util.Properties check, java.lang.String header)
           
static java.util.Date toGMT(java.util.Date localTime)
          convert a local time to GMT
static java.lang.String toGMTDateString(java.lang.String dateString)
          convert a local time to GMT date string which can be understood by OpenSSLWrap make it accurate to seconds if the given date is today's date
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

revocationReasons

public static final java.lang.String[] revocationReasons

debugFlag

public static boolean debugFlag
will be set to true if the app is started with -DDEBUG=yes

Constructor Detail

StaticUtil

public StaticUtil()
Method Detail

getFrame

public static java.awt.Frame getFrame(java.awt.Component c)
Return the parent frame of the component c.


getWindow

public static java.awt.Window getWindow(java.awt.Component c)
Return the parent window of the component c.


setBounds

public static void setBounds(java.awt.Component me,
                             int width,
                             int height,
                             java.awt.Component parent)
Locate component at the middle of the parent frame.

Parameters:
me - the component we are setting bounds for.
width - the preferred width of this component.
parent - the parent component.

setLookAndFeelC

public static void setLookAndFeelC(java.awt.Component comp)

setLookAndFeel

public static void setLookAndFeel()

setDefaultFont

public static void setDefaultFont(java.awt.Font afont)
Set default system font.


pkiConfigured

public static boolean pkiConfigured()
Checks the value of the property 'Configuration' in %pkihome%\path_properties.config If the configuration has run successfully, this will be >0; if not pki still needs to be configured.

Returns:
boolean - whether PKI's has been configured yet

chooseFileToSave

public static java.lang.String chooseFileToSave(java.awt.Component parent,
                                                java.lang.String title)
Show file chooser to get a file location for saving data.


chooseFileToSave

public static java.lang.String chooseFileToSave(java.awt.Component parent,
                                                java.lang.String title,
                                                java.lang.String[] filter,
                                                java.lang.String fileType)
Show file chooser to get a file location for saving data.


chooseFileToLoad

public static java.lang.String chooseFileToLoad(java.awt.Component parent,
                                                java.lang.String title)
Show file chooser to get a file location for data loading.


chooseFileToLoad

public static java.lang.String chooseFileToLoad(java.awt.Component parent,
                                                java.lang.String title,
                                                java.lang.String[] filter,
                                                java.lang.String fileType)
Show file chooser to get a file location for data loading.


center

public static void center(java.awt.Component centerMe,
                          java.awt.Component positioner)
This positions a component to the center of another component. If both components are showing on the sceen, it uses absolute screen co-ordinates, otherwise if only the positioner component is showing, it uses relative co-ordinates (since it is unable to obtain screen co-ords). If the components share a reference frame, these two actions are equivalent (i.e. if they both have the same parent). If nothing is showing, the component is unchanged.

Parameters:
positioner - the component used as the reference center.

loadProperties

public static java.util.Properties loadProperties(java.lang.String filename)
Loads properties from a file


storeProperties

public static void storeProperties(java.lang.String filename,
                                   java.util.Properties check,
                                   java.lang.String header)

checkDirectory

public static void checkDirectory(java.lang.String directoryPath)
Checks for the existence of a directory; if it doesn't already exist creates it


bytes2Hex

public static java.lang.String bytes2Hex(byte[] in)
Converts 'in' to a hexadecimal character string.


bytes2Hex

public static java.lang.String bytes2Hex(byte[] in,
                                         int offset,
                                         int len)
Converts 'len' bytes to a hexadecimal character string.


bytes2HexSplit

public static java.lang.String bytes2HexSplit(byte[] in,
                                              int wordlength)

bytes2HexSplit

public static java.lang.String bytes2HexSplit(byte[] in,
                                              int wordlength,
                                              int linelength)

hex2Bytes

public static byte[] hex2Bytes(java.lang.String in)
Converts a hexadecimal character string to a byte array.


checkDrive

public static int checkDrive(char drive)
check if a drive is ready (windows specific code) return 0 if success


okToWriteFile

public static boolean okToWriteFile(java.awt.Frame parent,
                                    java.lang.String fileName)

reasonCode

public static int reasonCode(java.lang.String reason)
Returns revocation code from reason text

Parameters:
reason - revocation reason in text format, should be one of the revocationReasons
Returns:
0 to 6 if the reason is valid, or -1 otherwise

reasonText

public static java.lang.String reasonText(int code)
Returns revocation text from reason code

Parameters:
code - revocation reason code, should be from 0 to 7

toGMT

public static java.util.Date toGMT(java.util.Date localTime)
convert a local time to GMT


toGMTDateString

public static java.lang.String toGMTDateString(java.lang.String dateString)
convert a local time to GMT date string which can be understood by OpenSSLWrap make it accurate to seconds if the given date is today's date


isToday

public static boolean isToday(java.util.Date date)
Checks a date if it is today's date by matching yyyy, MM, dd


isSameDay

public static boolean isSameDay(java.util.Date date1,
                                java.util.Date date2)
Checks if two (yyyy,MM,dd) dates are the same


getDate

public static java.util.Date getDate(java.lang.String value)
Parses a date field, accept both "MM/dd/yyyy" or "now +/- years" format


checkDate

public static java.lang.String checkDate(java.lang.String dateString)
                                  throws java.lang.Exception
Check if a date is in correct MM/dd/yyyy format

java.lang.Exception

parseDate

public static java.lang.String parseDate(java.lang.String value)
Parses a "MM/dd/yyyy" or "now +/- years" date field, returns a date string in format "MM/dd/yyyy"


replace

public static java.lang.String replace(java.lang.String source,
                                       java.lang.String oldPattern,
                                       java.lang.String newPattern)
Replace all the appreances of oldPattern in a source string by newPattern.


removeCommas

public static java.lang.String removeCommas(java.lang.String inputDN)
Replace all commas (i.e. ',') enclosed in quotes (for example OU="CA, Glen Iris") by '~' so that the entry can be created in the publishing directory


getGeneralizedTime

public static java.lang.String getGeneralizedTime(java.util.Date adate)

printDebug

public static void printDebug(java.lang.String message)
will be set to true if the app is started with -DDEBUG=yes


configLogger

public static void configLogger(Logger logger,
                                java.util.Properties props,
                                java.lang.String logSuffix)
Method copied from RAServer: used to configure our customised Log4J writer

Parameters:
logger - the logger object to be configured
props - a Properties object that store information as where to write log info to, which log level is used, and if there is a key for signing log entries
logSuffix - an application might have multiple log files, the props object only stores the location of the principle log file, other log file names can be specified by appending this suffix to the principle log file.

logAndDialog

public static void logAndDialog(Logger logger,
                                Priority logLevel,
                                java.lang.String message,
                                java.awt.Frame parentFrame,
                                int dialogType)
Write a log item and also pop an error dialog