Class UtilFunction

java.lang.Object
org.bgerp.app.servlet.jsp.UtilFunction

public class UtilFunction extends Object
Functions defined in util.tld JSP library.
  • Method Details

    • newInstance

      public static Object newInstance(String className, Object... args) throws Exception
      Creates a new instance of a Java class. Generic method with varargs argument, can't be called from JSP.
      Parameters:
      className - the class name.
      args - constructor arguments.
      Returns:
      the created instance
      Throws:
      Exception - if no matching constructor is found or instantiation fails
    • newInstance

      public static Object newInstance(String className) throws Exception
      Non-varargs version of newInstance(String, Object...) for using as a JSP taglib method.
      Parameters:
      className - the class name
      Returns:
      the created instance
      Throws:
      Exception - if no matching constructor is found or instantiation fails
    • newInstance

      public static Object newInstance(String className, Object arg0) throws Exception
      Non-varargs version of newInstance(String, Object...) for using as a JSP taglib method.
      Parameters:
      className - the class name
      arg0 - constructor argument
      Returns:
      the created instance
      Throws:
      Exception - if no matching constructor is found or instantiation fails
    • newInstance

      public static Object newInstance(String className, Object arg0, Object arg1) throws Exception
      Non-varargs version of newInstance(String, Object...) for using as a JSP taglib method.
      Parameters:
      className - the class name
      arg0 - constructor argument
      arg1 - constructor argument
      Returns:
      the created instance
      Throws:
      Exception - if no matching constructor is found or instantiation fails
    • newInstance

      public static Object newInstance(String className, Object arg0, Object arg1, Object arg2) throws Exception
      Non-varargs version of newInstance(String, Object...) for using as a JSP taglib method.
      Parameters:
      className - the class name
      arg0 - constructor argument
      arg1 - constructor argument
      arg2 - constructor argument
      Returns:
      the created instance
      Throws:
      Exception - if no matching constructor is found or instantiation fails
    • checked

      public static String checked(Object collection, Object object)
      checked='1' if the collection contains the object.
      Parameters:
      collection - collection, map or array
      object - looked object
      Returns:
      checked='1' or ""
      See Also:
      • "JSP function checkedFromCollection"
    • checked

      public static String checked(Boolean object)
      checked='1' if the value is true.
      Parameters:
      object - boolean value
      Returns:
      checked='1' or ""
      See Also:
      • "JSP function checkedFromBool"
    • selected

      public static String selected(Object collection, Object object)
      selected='1' if the collection contains the object.
      Parameters:
      collection - collection, map or array
      object - looked object
      Returns:
      selected='1' or ""
      See Also:
      • "JSP function selectedFromCollection"
    • selected

      public static String selected(Boolean object)
      selected='1' if the value is true.
      Parameters:
      object - boolean value
      Returns:
      selected='1' or ""
      See Also:
      • "JSP function checkedFromBool"
    • getInt

      public static Integer getInt(Object value)
      Converts a value to Integer.
      Parameters:
      value - the value
      Returns:
      the int value, or 0
      See Also:
      • "JSP function int"
    • uiid

      public static String uiid()
      Unique identifier for HTML nodes.
      Returns:
      an unique identifier for HTML nodes.
    • urlEncode

      public static String urlEncode(String value) throws UnsupportedEncodingException
      URL-encodes a value in UTF-8.
      Parameters:
      value - the value
      Returns:
      encoded value
      Throws:
      UnsupportedEncodingException - never, UTF-8 is always supported
    • htmlEncode

      public static String htmlEncode(String value)
      Replaces some HTML symbols.

      < to &amp;lt;

      > to &amp;gt;

      \n to &lt;br/>

      \t to 4 whitespaces

      Parameters:
      value - input value.
      Returns:
      string with replacements.
    • httpLinksToHtml

      public static String httpLinksToHtml(String value)
      Recognizes and replaces HTTP links to HTML code. http://blog.codinghorror.com/the-problem-with-urls/
      Parameters:
      value - input value
      Returns:
      value with links wrapped in <a> tags
    • quotEscape

      public static String quotEscape(String value)
      Escapes double quotes, used for preparation JS strings in JSPs.
      Parameters:
      value - input value
      Returns:
      value with escaped double quotes
    • truncateHtml

      public static String truncateHtml(String s, Integer limit)
      Truncates a string with HTML markup to a maximal length without breaking tags. Finds a first position after all tags were closed, so the resulting length may be more than max.
      Parameters:
      s - the initial string
      limit - maximal length
      Returns:
      the truncated string
    • fileNameWithLastModTime

      public static String fileNameWithLastModTime(String path)
      Appends a version query param with the file's last modification time, for cache busting.
      Parameters:
      path - the web path under webapps
      Returns:
      the path with a version query param
    • docUrl

      public static String docUrl(String url)
      Documentation URL for the currently running app version
      Parameters:
      url - the path from documentation's root, or absolute url starting from http (this case it wouldn't be changed)
      Returns:
      the absolute documentation URL
    • actionUrl

      public static String actionUrl(String action) throws javassist.NotFoundException
      Action call URL like actionPath.do?method=methodName out of semicolon separated action class and method actionId:methodName
      Parameters:
      action - the semicolon separated action class and method
      Returns:
      the URL
      Throws:
      javassist.NotFoundException - if the action class is not found
    • toString

      @Deprecated public static final String toString(Collection<?> valuesList)
      Deprecated.
      Comma-joined string of the collection values.
      Parameters:
      valuesList - the values
      Returns:
      comma-joined string
    • objectTitleList

      @Deprecated public static <T extends IdTitle> String objectTitleList(List<T> fullList, Set<Integer> selectedIds)
      Deprecated.
      Comma-joined titles of the selected objects.
      Type Parameters:
      T - object type
      Parameters:
      fullList - all objects
      selectedIds - selected object IDs
      Returns:
      comma-joined titles