com.plumtree.uiinfrastructure.statichelpers
Class GeneralHelpers

java.lang.Object
  extended by com.plumtree.uiinfrastructure.statichelpers.GeneralHelpers

public class GeneralHelpers
extends java.lang.Object

Author:
robertz Static helper functions

Field Summary
static java.lang.String WILDCARD_ANCHOR
           
 
Constructor Summary
GeneralHelpers()
           
 
Method Summary
static java.lang.String BreakDownLongWordsInString(java.lang.String strIn, int maxCharsPerWord)
          Adds spaces into long strings so that it can be displayed with wrapping in HTML without having to truncate.
static boolean CompareStringWithWildCard(java.lang.String input, java.lang.String check)
          Compares two string with wildcard support for beginning and end of string using '^' defined in WILDCARD_ANCHOR.
static boolean ContainsUnsafeCharacters(java.lang.String _strStringIn, boolean bLogErrors)
          Helper method that checks whether or not a string contains unsafe characters, such as angle braces for HTML or curly braces for javascript.
static int[] ConvertToInts(java.lang.String data)
          This method takes a String with numbers separated by ','s and splits it into an int array.
static java.lang.String ConvertToString(int[] nInts)
          This method converts the expanded object types int[] into a comma separated String
static java.lang.String EscapeJavascript(java.lang.String strInput)
          This method escapes a String for use in Javascript.
static java.lang.String FormatPath(java.lang.String _strPath, java.lang.String _strDelimiter, boolean _bForceEndsWith)
           
static java.lang.String Replace(java.lang.String s, java.lang.String sub, java.lang.String with)
          replace substrings within string.
static void SetUIError(AActivitySpace asOwner, OpenLogComponent uiComponent, java.lang.String strFunctionName, java.lang.Exception e, boolean bThrow, UIErrorLevel uiErrorLevel, java.lang.String strErrorMessage)
          This helper function sets a UI Error with the messages specified, and optionally throws an exception.
static java.lang.String TruncateLongString(java.lang.String strInput, int nMaxChars, boolean bMaximumWordLength)
          Description: This function returns a shortened version of a string that is too long.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WILDCARD_ANCHOR

public static final java.lang.String WILDCARD_ANCHOR
See Also:
Constant Field Values
Constructor Detail

GeneralHelpers

public GeneralHelpers()
Method Detail

FormatPath

public static final java.lang.String FormatPath(java.lang.String _strPath,
                                                java.lang.String _strDelimiter,
                                                boolean _bForceEndsWith)

Replace

public static final java.lang.String Replace(java.lang.String s,
                                             java.lang.String sub,
                                             java.lang.String with)
replace substrings within string.

Parameters:
s - string to be modified
sub - sub-string to search for
with - string to replace sub-string
Returns:
string replaced with new sub-string or the unmodified string if no match could be found

BreakDownLongWordsInString

public static java.lang.String BreakDownLongWordsInString(java.lang.String strIn,
                                                          int maxCharsPerWord)
Adds spaces into long strings so that it can be displayed with wrapping in HTML without having to truncate.


TruncateLongString

public static java.lang.String TruncateLongString(java.lang.String strInput,
                                                  int nMaxChars,
                                                  boolean bMaximumWordLength)
Description: This function returns a shortened version of a string that is too long. It will shorten the string to intMaxNumberOfCharacters and append a "..."

Parameters:
strInput - String to check.
nMaxChars - Maximum number of characters in a string before truncation. The length truncated string will be no longer than this number plus an additional 3 characters for the '...'.
bMaximumWordLength - variable is to specify that you want to shorten the string only if it has a word in it longer than nMaxChars. bMaximumWordLength is used to determine whether or not any word in the string will be too long and cause the HTML to look bad. Warning: If the string is going to be HTML Encoded, remember to truncate it first, and then HTML encode it. Otherwise you can get truncated international language codes such as &#... instead of an actual character. Examples -------- TruncateLongString("123456789 123456 12345678 123", 10, True) Returns: "123456789 123456 12345678 123" TruncateLongString("123456789 123456 12345678 123", 10, False) Returns: "123456789..." TruncateLongString("123456789 123456 1234567890123 123", 12, True) Returns: "123456789 12..." TruncateLongString("123456789 123456 1234567890123 123", 10, False) Returns: "123456789..." TruncateLongString("123456789 123456 1234567890123 123", 70, False) Returns: "123456789 123456 1234567890123 123" TruncateLongString("1234", 2, False) Returns: "12..."

EscapeJavascript

public static java.lang.String EscapeJavascript(java.lang.String strInput)
This method escapes a String for use in Javascript. This code was adapted from Studio's code (Patrick Corcoran)

Parameters:
String - the String to be escaped
Returns:
String the escaped version of the input

ConvertToInts

public static int[] ConvertToInts(java.lang.String data)
This method takes a String with numbers separated by ','s and splits it into an int array. If there is an error, the rest of the array is filled with 0s.

Parameters:
String - the comma separated string of numbers to convert
Returns:
int[] the result

ConvertToString

public static final java.lang.String ConvertToString(int[] nInts)
This method converts the expanded object types int[] into a comma separated String

Parameters:
int[] -
Returns:
String

SetUIError

public static void SetUIError(AActivitySpace asOwner,
                              OpenLogComponent uiComponent,
                              java.lang.String strFunctionName,
                              java.lang.Exception e,
                              boolean bThrow,
                              UIErrorLevel uiErrorLevel,
                              java.lang.String strErrorMessage)
This helper function sets a UI Error with the messages specified, and optionally throws an exception. The UI Error will contain the strings specified only, but the Debug log entry will also contain the text of the exception (e.getMessage())

Parameters:
asOwner - - The activity space in which the error was thrown
strFunctionName - - The function that trapped the error (e.g. MyModel::CheckEditorAccessAndStart)
uiComponent - - The UI component in which the error occurred, e.g. OpenLogService.GetComponent("Portal_UI_Infrastructure")
e - - The exception that has been thrown
bThrow - - Throw an XPException in addition to setting the error?
uiErrorLevel - - The error level (e.g. UIErrorLevel.SERIOUS)
strErrorMessage - - The error message string to be displayed

ContainsUnsafeCharacters

public static final boolean ContainsUnsafeCharacters(java.lang.String _strStringIn,
                                                     boolean bLogErrors)
Helper method that checks whether or not a string contains unsafe characters, such as angle braces for HTML or curly braces for javascript. This is useful for determining if someone is trying to do a javascript hack.

Parameters:
String - the string to process
Returns:
boolean true implies log a message in PTSpy if the string contains unsafe characters.

CompareStringWithWildCard

public static boolean CompareStringWithWildCard(java.lang.String input,
                                                java.lang.String check)
Compares two string with wildcard support for beginning and end of string using '^' defined in WILDCARD_ANCHOR.

Parameters:
input - Input string. '^' at the start of the string means string begins with, and '^' at the end means string ends with.
check - The string to compare against
Returns:



Copyright © 2002,2003,2004,2005 Plumtree Software, Inc., All Rights Reserved.