edu.internet2.middleware.grouper.ui.util
Class GrouperUiUtils

java.lang.Object
  extended by edu.internet2.middleware.grouper.ui.util.GrouperUiUtils

public class GrouperUiUtils
extends Object

utility methods for grouper

Author:
mchyzer

Field Summary
static File classFileDir
          class file dir cached
static String DHTMLX_OPTIONS_END
          dhtmlx option end of xml
static String DHTMLX_OPTIONS_START
          dhtmlx option start of xml
static String[] HTML_REPLACE
          array for converting HTML to string
static String[] HTML_REPLACE_NO_SINGLE
          array for converting HTML to string
static String[] HTML_SEARCH_NO_SINGLE
          array for converting HTML to string
static Pattern subjectPattern
          pattern of a subject: sourceId||||subjectId (slashes escape the pipes)
 
Constructor Summary
GrouperUiUtils()
           
 
Method Summary
static void appendErrorToRequest(String error)
          append an error to the request, will be logged and maybe emailed to admins
static String booleanToStringOneChar(Boolean theBoolean)
          convert a boolean to a T or F
static File classFileDir()
          get the class file dir
static ClassLoader classLoader()
          fast class loader
static
<T> T
cloneShallow(T object)
          clone a collection, shallow, do not clone all objects inside
static int compare(String a, String b, boolean ignoreCase)
           
static URL computeUrl(String resourceName, boolean canBeNull)
          compute a url of a resource
static String convertJspToString(String jspName)
          convert a jsp to string.
static String convertLongToChar(long theLong)
          this method takes a long (less than 62) and converts it to a 1 character string (a-z, A-Z, 0-9)
static String convertLongToCharSmall(long theLong)
          this method takes a long (less than 36) and converts it to a 1 character string (A-Z, 0-9)
static String convertLongToString(long theLong)
          convert a long to a string by converting it to base 62 (26 lower, 26 upper, 10 digits)
static String convertLongToStringSmall(long theLong)
          convert a long to a string by converting it to base 36 (26 upper, 10 digits)
static Set<Subject> convertMembersToSubject(Set<Member> members)
           
static Set<Member> convertSubjectsToMembers(GrouperSession grouperSession, Group group, Set<Subject> subjects, boolean immediateOnly)
          find subjects which are members of a group, and return those members.
static String convertSubjectToLabel(Subject subject)
          convert a subject to string for screen
static String convertSubjectToLabelConfigured(Subject subject)
          get a label from a subject based on media.properties
static String convertSubjectToValue(Subject subject)
          convert a subject to string for screen
static String cookieValue(String cookieName, Cookie[] cookies)
          get a cookie value (null if not there)
static String dateToString(Date date)
          convert a date to a string using the standard web service pattern yyyy/MM/dd HH:mm:ss.SSS Note that HH is 0-23
static void dhtmlxOptionAppend(StringBuilder result, String value, String label, String imageUrl)
          make one dhtmlx option
static String escapeHtml(String input, boolean isEscape)
          Convert an XML string to HTML to display on the screen
static String escapeHtml(String input, boolean isEscape, boolean escapeSingleQuotes)
          Convert an XML string to HTML to display on the screen
static String escapeJavascript(String input, boolean isEscape)
          Escapes XML ( ampersand, lessthan, greater than, double quote), and single quote with slash
static String escapeSingleQuotes(String input)
          escape single quotes for javascript
static List<Cookie> findCookiesByPrefix(String name)
          find a cookie or empty list if cant find
static Subject findSubject(String searchString)
          find a subject based on search string.
static ResourceBundle getNavResourcesStatic(HttpSession session)
          Convenience method to retrieve nav ResourceBundle
static String imageFromSubjectSource(String sourceId)
          get the image name from subject source
static char incrementChar(char theChar)
          increment a character (A-Z then 0-9)
static char[] incrementStringInt(char[] string)
          Increment a string with A-Z and 0-9 (no lower case so case insensitive apps like windows IE will still work)
static void killCookie(String cookieName, Cookie[] cookies, HttpServletResponse httpServletResponse)
          kill a cookie if it is there
static File[] listFilesByExtension(File dir, String extension)
          list files with a certain extension
static List<File> listFilesByExtensionRecursive(File dir, String extension)
          list files with a certain extension.
static void listFilesByExtensionRecursiveHelper(File dir, String extension, List<File> theList)
          list files with a certain extension
static File[] listSubdirs(File dir)
          get the subdirs of a dir (not ..)
static void memberRemoveDuplicates(List<Member> members)
          remove duplicates
static Set<Member> membersSortedPaged(Set<Member> members, QueryPaging queryPaging)
           
static String message(String key)
          lookup something in nav.properties (localized)
static String message(String key, boolean blankIfNotFound)
          lookup something in nav.properties (localized)
static String message(String key, boolean blankIfNotFound, boolean escapeHtmlArgs, Object... args)
          lookup something in nav.properties (localized), substitute args
static void printToScreen(String string, HttpContentType httpContentType, boolean includeXmlTag, boolean includeHtmlTag)
          Print some text to the screen
static Properties propertiesFromResourceName(String resourceName)
          read properties from a resource, dont modify the properties returned since they are cached
static void removeCookiesByPrefix(String prefix)
          get a cookie value by name, null if not there
static Set<Member> removeOverlappingSubjects(List<Member> first, List<Subject> second)
          remove overlapping subjects from two lists.
static String requestParams()
          get request params (e.g.
static Cookie retrieveCookie(String cookieName, Cookie[] cookies)
          get a cookie based on name or null if not there
static String stripNonFilenameChars(String string)
          keep a-z, A-Z, 0-9, underscore, dash
static void subjectRemoveDuplicates(List<Subject> subjects)
          remove duplicates
static Set<Subject> subjectsSortedPaged(Set<Subject> subjects, QueryPaging queryPaging)
           
static String uniqueId()
          get a unique string identifier based on the current time, this is not globally unique, just unique for as long as this server is running...
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

subjectPattern

public static Pattern subjectPattern
pattern of a subject: sourceId||||subjectId (slashes escape the pipes)


DHTMLX_OPTIONS_END

public static final String DHTMLX_OPTIONS_END
dhtmlx option end of xml

See Also:
Constant Field Values

DHTMLX_OPTIONS_START

public static final String DHTMLX_OPTIONS_START
dhtmlx option start of xml

See Also:
Constant Field Values

classFileDir

public static File classFileDir
class file dir cached


HTML_REPLACE

public static final String[] HTML_REPLACE
array for converting HTML to string


HTML_REPLACE_NO_SINGLE

public static final String[] HTML_REPLACE_NO_SINGLE
array for converting HTML to string


HTML_SEARCH_NO_SINGLE

public static final String[] HTML_SEARCH_NO_SINGLE
array for converting HTML to string

Constructor Detail

GrouperUiUtils

public GrouperUiUtils()
Method Detail

computeUrl

public static URL computeUrl(String resourceName,
                             boolean canBeNull)
compute a url of a resource

Parameters:
resourceName -
canBeNull - if cant be null, throw runtime
Returns:
the URL

classLoader

public static ClassLoader classLoader()
fast class loader

Returns:
the class loader

propertiesFromResourceName

public static Properties propertiesFromResourceName(String resourceName)
read properties from a resource, dont modify the properties returned since they are cached

Parameters:
resourceName -
Returns:
the properties

uniqueId

public static String uniqueId()
get a unique string identifier based on the current time, this is not globally unique, just unique for as long as this server is running...

Returns:
String

convertLongToChar

public static String convertLongToChar(long theLong)
this method takes a long (less than 62) and converts it to a 1 character string (a-z, A-Z, 0-9)

Parameters:
theLong - is the long (less than 62) to convert to a 1 character string
Returns:
a one character string

convertLongToCharSmall

public static String convertLongToCharSmall(long theLong)
this method takes a long (less than 36) and converts it to a 1 character string (A-Z, 0-9)

Parameters:
theLong - is the long (less than 36) to convert to a 1 character string
Returns:
a one character string

convertLongToString

public static String convertLongToString(long theLong)
convert a long to a string by converting it to base 62 (26 lower, 26 upper, 10 digits)

Parameters:
theLong - is the long to convert
Returns:
the String conversion of this

convertLongToStringSmall

public static String convertLongToStringSmall(long theLong)
convert a long to a string by converting it to base 36 (26 upper, 10 digits)

Parameters:
theLong - is the long to convert
Returns:
the String conversion of this

incrementChar

public static char incrementChar(char theChar)
increment a character (A-Z then 0-9)

Parameters:
theChar -
Returns:
the value

incrementStringInt

public static char[] incrementStringInt(char[] string)
Increment a string with A-Z and 0-9 (no lower case so case insensitive apps like windows IE will still work)

Parameters:
string -
Returns:
the value

retrieveCookie

public static Cookie retrieveCookie(String cookieName,
                                    Cookie[] cookies)
get a cookie based on name or null if not there

Parameters:
cookieName -
cookies - (from httprequest)
Returns:
the cookie

cookieValue

public static String cookieValue(String cookieName,
                                 Cookie[] cookies)
get a cookie value (null if not there)

Parameters:
cookieName -
cookies - (from httprequest)
Returns:
the cookie value

killCookie

public static void killCookie(String cookieName,
                              Cookie[] cookies,
                              HttpServletResponse httpServletResponse)
kill a cookie if it is there

Parameters:
cookieName -
cookies - (from httprequest)
httpServletResponse - is response for adding cookies

requestParams

public static String requestParams()
get request params (e.g. for logging), in one string, abbreviated

Returns:
request params

appendErrorToRequest

public static void appendErrorToRequest(String error)
append an error to the request, will be logged and maybe emailed to admins

Parameters:
error -

convertSubjectsToMembers

public static Set<Member> convertSubjectsToMembers(GrouperSession grouperSession,
                                                   Group group,
                                                   Set<Subject> subjects,
                                                   boolean immediateOnly)
find subjects which are members of a group, and return those members. Do this in few queries since we might run out of bind variables NOTE, I DONT THINK IMMEDIATE ONLY AS FALSE WILL WORK, WILL ONLY WORK WITH IMMEDIATE ONLY

Parameters:
grouperSession -
group -
subjects -
immediateOnly - true for only immediate, false for immediate and effective
Returns:
the members or none if not allowed

memberRemoveDuplicates

public static void memberRemoveDuplicates(List<Member> members)
remove duplicates

Parameters:
members -

subjectRemoveDuplicates

public static void subjectRemoveDuplicates(List<Subject> subjects)
remove duplicates

Parameters:
subjects -

removeOverlappingSubjects

public static Set<Member> removeOverlappingSubjects(List<Member> first,
                                                    List<Subject> second)
remove overlapping subjects from two lists. i.e. if first is existing, and second is new, then if we are replacing all members of the group, then the first would end up being the ones to remove, and the second is the one to add. this will also remove dupes

Parameters:
first -
second -
Returns:
the overlap, never null

convertMembersToSubject

public static Set<Subject> convertMembersToSubject(Set<Member> members)
Parameters:
members -
Returns:
the subjects

compare

public static int compare(String a,
                          String b,
                          boolean ignoreCase)
Parameters:
a -
b -
ignoreCase - if case shoul dbe ignored
Returns:
0, 1,-1

stripNonFilenameChars

public static String stripNonFilenameChars(String string)
keep a-z, A-Z, 0-9, underscore, dash

Parameters:
string -
Returns:
the string (or empty if nothing left

message

public static String message(String key,
                             boolean blankIfNotFound,
                             boolean escapeHtmlArgs,
                             Object... args)
lookup something in nav.properties (localized), substitute args

Parameters:
key -
blankIfNotFound - true if null or blank if not found, else it will return ???key???
escapeHtmlArgs - if html should be escaped from args
args -
Returns:
the message

message

public static String message(String key)
lookup something in nav.properties (localized)

Parameters:
key -
Returns:
the message

message

public static String message(String key,
                             boolean blankIfNotFound)
lookup something in nav.properties (localized)

Parameters:
key -
blankIfNotFound - true if null or blank if not found, else it will return ???key???
Returns:
the message

getNavResourcesStatic

public static ResourceBundle getNavResourcesStatic(HttpSession session)
Convenience method to retrieve nav ResourceBundle

Parameters:
session -
Returns:
the bundle

subjectsSortedPaged

public static Set<Subject> subjectsSortedPaged(Set<Subject> subjects,
                                               QueryPaging queryPaging)
Parameters:
subjects - to sort and page
queryPaging -
Returns:
the set of subject, or empty set (never null)

membersSortedPaged

public static Set<Member> membersSortedPaged(Set<Member> members,
                                             QueryPaging queryPaging)
Parameters:
members - to sort and page
queryPaging -
Returns:
the set of subject, or empty set (never null)

convertSubjectToValue

public static String convertSubjectToValue(Subject subject)
convert a subject to string for screen

Parameters:
subject -
Returns:
the string

convertSubjectToLabel

public static String convertSubjectToLabel(Subject subject)
convert a subject to string for screen

Parameters:
subject -
Returns:
the string

findSubject

public static Subject findSubject(String searchString)
                           throws SubjectNotFoundException,
                                  SubjectNotUniqueException,
                                  SourceUnavailableException
find a subject based on search string. must be sourceId||||subjectId or a subjectId or subjectIdentifier which is unique

Parameters:
searchString -
Returns:
the subject
Throws:
SubjectNotFoundException
SubjectNotUniqueException
SourceUnavailableException

dhtmlxOptionAppend

public static void dhtmlxOptionAppend(StringBuilder result,
                                      String value,
                                      String label,
                                      String imageUrl)
make one dhtmlx option

Parameters:
result - to append to
value -
label -
imageUrl -

printToScreen

public static void printToScreen(String string,
                                 HttpContentType httpContentType,
                                 boolean includeXmlTag,
                                 boolean includeHtmlTag)
Print some text to the screen

Parameters:
string -
httpContentType - e.g. "text/html", "text/xml"
includeXmlTag -
includeHtmlTag -

escapeSingleQuotes

public static String escapeSingleQuotes(String input)
escape single quotes for javascript

Parameters:
input -
Returns:
the escaped string

removeCookiesByPrefix

public static void removeCookiesByPrefix(String prefix)
get a cookie value by name, null if not there

Parameters:
prefix -

findCookiesByPrefix

public static List<Cookie> findCookiesByPrefix(String name)
find a cookie or empty list if cant find

Parameters:
name -
Returns:
the cookies or empty list if not found

imageFromSubjectSource

public static String imageFromSubjectSource(String sourceId)
get the image name from subject source

Parameters:
sourceId -
Returns:
the relative path to image path

convertSubjectToLabelConfigured

public static String convertSubjectToLabelConfigured(Subject subject)
get a label from a subject based on media.properties

Parameters:
subject -
Returns:
the relative path to image path

classFileDir

public static File classFileDir()
get the class file dir

Returns:
the class file dir

listFilesByExtensionRecursive

public static List<File> listFilesByExtensionRecursive(File dir,
                                                       String extension)
list files with a certain extension. Note, there cannot be more than 10000 files or exception will be throws

Parameters:
dir -
extension - if this is the empty string it should list all
Returns:
the array of files

listFilesByExtensionRecursiveHelper

public static void listFilesByExtensionRecursiveHelper(File dir,
                                                       String extension,
                                                       List<File> theList)
list files with a certain extension

Parameters:
dir -
extension - if this is the empty string it should list all
theList - is the current list to append to

listSubdirs

public static File[] listSubdirs(File dir)
get the subdirs of a dir (not ..)

Parameters:
dir -
Returns:
the dirs

listFilesByExtension

public static File[] listFilesByExtension(File dir,
                                          String extension)
list files with a certain extension

Parameters:
dir -
extension - if this is the empty string it should list all
Returns:
the array of files

booleanToStringOneChar

public static String booleanToStringOneChar(Boolean theBoolean)
convert a boolean to a T or F

Parameters:
theBoolean -
Returns:
the one char booloean string

dateToString

public static String dateToString(Date date)
convert a date to a string using the standard web service pattern yyyy/MM/dd HH:mm:ss.SSS Note that HH is 0-23

Parameters:
date -
Returns:
the string, or null if the date is null

convertJspToString

public static String convertJspToString(String jspName)
convert a jsp to string. This doesnt work from unit tests, but will work from web requests or daemons

Parameters:
jspName - e.g. whatever.jsp, or /somePath/something.jsp
Returns:
the eval version of the jsp

escapeHtml

public static String escapeHtml(String input,
                                boolean isEscape)
Convert an XML string to HTML to display on the screen

Parameters:
input - is the XML to convert
isEscape - true to escape chars, false to unescape
Returns:
the HTML converted string

escapeHtml

public static String escapeHtml(String input,
                                boolean isEscape,
                                boolean escapeSingleQuotes)
Convert an XML string to HTML to display on the screen

Parameters:
input - is the XML to convert
isEscape - true to escape chars, false to unescape
escapeSingleQuotes - true to escape single quotes too
Returns:
the HTML converted string

escapeJavascript

public static String escapeJavascript(String input,
                                      boolean isEscape)
Escapes XML ( ampersand, lessthan, greater than, double quote), and single quote with slash

Parameters:
input - is the XML to convert
isEscape - true to escape chars, false to unescape
Returns:
the Javascript converted string

cloneShallow

public static <T> T cloneShallow(T object)
clone a collection, shallow, do not clone all objects inside

Type Parameters:
T -
Parameters:
object -
Returns:
the cloned collection