Class WebUtil


  • public abstract class WebUtil
    extends java.lang.Object
    Utility methods for the web package.
    Author:
    Kim Rutherford, Julie Sullivan
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  WebUtil.HeadResource
      A bean encapsulating a resource (js or css).
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static org.apache.log4j.Logger LOG  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean contains​(java.util.Collection<?> things, java.lang.Object o)
      So we can test set membership in JSPs.
      static boolean containsKey​(java.util.Map<?,​?> mapping, java.lang.Object o)
      So we can test map membership in JSPs.
      static java.lang.String formatClass​(ClassDescriptor cd, WebConfig config)
      Formats a class name, using the web-config to produce configured labels.
      static java.lang.String formatColumnName​(java.lang.String original)
      Formats column name.
      static java.lang.String formatField​(java.lang.String s, InterMineAPI api, WebConfig webConfig)
      Format a path into a displayable field name.
      static java.lang.String formatField​(Path p, WebConfig webConfig)
      Format a path into a displayable field name.
      static java.lang.String formatFieldChain​(java.lang.String s, InterMineAPI api, WebConfig webConfig)
      Format a path represented as a string to the formatted fields, without the class name.
      static java.lang.String formatFieldChain​(Path p, WebConfig config)
      Format a sequence of fields in a chain.
      static java.lang.String formatPath​(java.lang.String original, javax.servlet.http.HttpServletRequest request)
      Formats a column name, using the webconfig to produce configured labels.
      static java.lang.String formatPath​(java.lang.String pathString, InterMineAPI api, WebConfig webConfig)
      Formats a column name, using the webconfig to produce configured labels.
      static java.lang.String formatPath​(java.lang.String original, Model model, WebConfig webConfig)
      Formats a column name, using the webconfig to produce configured labels.
      static java.lang.String formatPath​(java.lang.String path, PathQuery pq, WebConfig config)
      Formats a column name, using the given query to construct a path according to the current state of its subclasses.
      static java.lang.String formatPath​(Path viewColumn, WebConfig webConfig)
      Formats a column name, using the webconfig to produce configured labels.
      static java.lang.String formatPathDescription​(java.lang.String s, PathQuery pq, WebConfig config)
      Return a string suitable for displaying a PathQuery's path, taking any path descriptions it has configured into account.
      static java.lang.String formatPathDescription​(Path p, PathQuery pq, WebConfig config)
      Return a string suitable for displaying a PathQuery's path, taking any path descriptions it has configured into account.
      static java.util.List<java.lang.String> formatPathQueryView​(PathQuery pq, javax.servlet.http.HttpServletRequest request)
      Format a query's view into a list of displayable strings, taking both the query's path descriptions and the application's web configuration into account.
      static java.util.List<java.lang.String> formatPathQueryView​(PathQuery pq, WebConfig wc)
      Format a query's view into a list of displayable strings, taking both the query's path descriptions and the application's web configuration into account.
      static java.util.List<WebUtil.HeadResource> getHeadResources​(java.lang.String section, java.util.Map<java.lang.String,​java.lang.String> userPreferences)
      Returns the resources for a particular section of the head element.
      static java.lang.String[] getHelpPage​(javax.servlet.http.HttpServletRequest request)
      Look at the current webapp page and subtab and return the help page and tab.
      static int getIntSessionProperty​(javax.servlet.http.HttpSession session, java.lang.String propertyName, int defaultValue)
      Lookup an Integer property from the SessionContext and return it.
      static java.lang.String getStaticPage​(java.lang.String prefixURLString, java.lang.String path)
      Return the contents of the page given by prefixURLString + '/' + path as a String.
      static boolean hasValidPath​(java.lang.Object obj, java.lang.String path, InterMineAPI api)
      Check whether the runtime type of an object supports a particular path.
      static <V> java.util.Map<java.lang.String,​V> shuffle​(java.util.Map<java.lang.String,​V> map, int max)
      takes a map and puts it in random order also shortens the list to be map.size() = max
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOG

        protected static final org.apache.log4j.Logger LOG
    • Method Detail

      • getIntSessionProperty

        public static int getIntSessionProperty​(javax.servlet.http.HttpSession session,
                                                java.lang.String propertyName,
                                                int defaultValue)
        Lookup an Integer property from the SessionContext and return it.
        Parameters:
        session - the current session
        propertyName - the property to find
        defaultValue - the value to return if the property isn't present
        Returns:
        the int value of the property
      • shuffle

        public static <V> java.util.Map<java.lang.String,​V> shuffle​(java.util.Map<java.lang.String,​V> map,
                                                                          int max)
        takes a map and puts it in random order also shortens the list to be map.size() = max
        Type Parameters:
        V - the value type
        Parameters:
        map - The map to be randomised - the Map will be unchanged after the call
        max - the number of items to be in the final list
        Returns:
        the newly randomised, shortened map
      • getStaticPage

        public static java.lang.String getStaticPage​(java.lang.String prefixURLString,
                                                     java.lang.String path)
                                              throws java.io.IOException
        Return the contents of the page given by prefixURLString + '/' + path as a String. Any relative links in the page will be modified to go via showStatic.do
        Parameters:
        prefixURLString - the prefix (including "http://...") of the web site to read from. eg. http://www.flymine.org/doc/help
        path - the page to retrieve eg. manualFlyMineHome.shtml
        Returns:
        the contents of the page
        Throws:
        java.io.IOException - if there is a problem while reading
      • getHelpPage

        public static java.lang.String[] getHelpPage​(javax.servlet.http.HttpServletRequest request)
        Look at the current webapp page and subtab and return the help page and tab.
        Parameters:
        request - the request object
        Returns:
        the help page and tab
      • getHeadResources

        public static java.util.List<WebUtil.HeadResource> getHeadResources​(java.lang.String section,
                                                                            java.util.Map<java.lang.String,​java.lang.String> userPreferences)
        Returns the resources for a particular section of the head element.
        Parameters:
        section - The section this resource belongs in.
        userPreferences - The preferences of the current user.
        Returns:
        A list of page resources, which are the urls for these resources.
      • formatColumnName

        public static java.lang.String formatColumnName​(java.lang.String original)
        Formats column name. Replaces " > " with "&nbsp;&gt; ".
        Parameters:
        original - original column name
        Returns:
        modified string
      • formatPath

        public static java.lang.String formatPath​(java.lang.String original,
                                                  javax.servlet.http.HttpServletRequest request)
        Formats a column name, using the webconfig to produce configured labels. EG: MRNA.scoreType --> mRNA > Score Type
        Parameters:
        original - The column name (a path string) to format
        request - The request to use to get the configuration off.
        Returns:
        A formatted column name
      • formatPathQueryView

        public static java.util.List<java.lang.String> formatPathQueryView​(PathQuery pq,
                                                                           javax.servlet.http.HttpServletRequest request)
        Format a query's view into a list of displayable strings, taking both the query's path descriptions and the application's web configuration into account.
        Parameters:
        pq - The query to format
        request - The request to use to look up configuration from
        Returns:
        A list of displayable strings
      • formatPathQueryView

        public static java.util.List<java.lang.String> formatPathQueryView​(PathQuery pq,
                                                                           WebConfig wc)
        Format a query's view into a list of displayable strings, taking both the query's path descriptions and the application's web configuration into account.
        Parameters:
        pq - The query to format
        wc - The configuration to use to find labels in
        Returns:
        A list of displayable strings
      • formatPath

        public static java.lang.String formatPath​(java.lang.String original,
                                                  Model model,
                                                  WebConfig webConfig)
        Formats a column name, using the webconfig to produce configured labels. EG: MRNA.scoreType --> mRNA > Score Type
        Parameters:
        original - The column name (a path string) to format
        model - The model to use to parse the string
        webConfig - The configuration to find labels in
        Returns:
        A formatted column name
      • formatPath

        public static java.lang.String formatPath​(java.lang.String pathString,
                                                  InterMineAPI api,
                                                  WebConfig webConfig)
        Formats a column name, using the webconfig to produce configured labels. EG: MRNA.scoreType --> mRNA > Score Type
        Parameters:
        pathString - A string representing a path to format
        api - the webapp configuration to aquire a model from
        webConfig - The configuration to find labels in
        Returns:
        A formatted column name
      • formatPath

        public static java.lang.String formatPath​(java.lang.String path,
                                                  PathQuery pq,
                                                  WebConfig config)
        Formats a column name, using the given query to construct a path according to the current state of its subclasses.
        Parameters:
        path - The path to format.
        pq - The query to use for path construction.
        config - The configuration to find labels in.
        Returns:
        A nicely formatted string.
      • formatPath

        public static java.lang.String formatPath​(Path viewColumn,
                                                  WebConfig webConfig)
        Formats a column name, using the webconfig to produce configured labels. EG: MRNA.scoreType --> mRNA > Score Type
        Parameters:
        viewColumn - A path representing a column name
        webConfig - The configuration to find labels in
        Returns:
        A formatted column name
      • formatClass

        public static java.lang.String formatClass​(ClassDescriptor cd,
                                                   WebConfig config)
        Formats a class name, using the web-config to produce configured labels.
        Parameters:
        cd - The class to display.
        config - The web-configuration.
        Returns:
        A nicely labelled string.
      • formatField

        public static java.lang.String formatField​(java.lang.String s,
                                                   InterMineAPI api,
                                                   WebConfig webConfig)
        Format a path into a displayable field name. eg: Employee.fullTime → Full Time
        Parameters:
        s - A path represented as a string
        api - The InterMine settings bundle
        webConfig - The Web Configuration
        Returns:
        A displayable string
      • formatField

        public static java.lang.String formatField​(Path p,
                                                   WebConfig webConfig)
        Format a path into a displayable field name. eg: Employee.fullTime → Full Time
        Parameters:
        p - A path
        webConfig - The Web Configuration
        Returns:
        A displayable string
      • formatFieldChain

        public static java.lang.String formatFieldChain​(Path p,
                                                        WebConfig config)
        Format a sequence of fields in a chain.
        Parameters:
        p - The path representing the fields to format.
        config - The web-configuration.
        Returns:
        A formatted string, without the root class.
      • formatFieldChain

        public static java.lang.String formatFieldChain​(java.lang.String s,
                                                        InterMineAPI api,
                                                        WebConfig webConfig)
        Format a path represented as a string to the formatted fields, without the class name. So Employee.department.manager.age becomes Department > Manager > Years Alive
        Parameters:
        s - The path string
        api - The InterMine API to use for model lookup.
        webConfig - The class name configuration.
        Returns:
        A nicely formatted string.
      • formatPathDescription

        public static java.lang.String formatPathDescription​(java.lang.String s,
                                                             PathQuery pq,
                                                             WebConfig config)
        Return a string suitable for displaying a PathQuery's path, taking any path descriptions it has configured into account.
        Parameters:
        s - The path to display
        pq - The PathQuery it relates to
        config - The Web-Configuration to use to lookup labels
        Returns:
        A string suitable for external display.
      • contains

        public static boolean contains​(java.util.Collection<?> things,
                                       java.lang.Object o)
        So we can test set membership in JSPs.
        Parameters:
        things - The things
        o - The thing
        Returns:
        Whether the thing is one of the things.
      • containsKey

        public static boolean containsKey​(java.util.Map<?,​?> mapping,
                                          java.lang.Object o)
        So we can test map membership in JSPs.
        Parameters:
        mapping - The things
        o - The thing
        Returns:
        Whether the thing is one of the keys in things.
      • formatPathDescription

        public static java.lang.String formatPathDescription​(Path p,
                                                             PathQuery pq,
                                                             WebConfig config)
        Return a string suitable for displaying a PathQuery's path, taking any path descriptions it has configured into account.
        Parameters:
        p - The path to display
        pq - The PathQuery it relates to
        config - The Web-Configuration to use to lookup labels
        Returns:
        A string suitable for external display.
      • hasValidPath

        public static boolean hasValidPath​(java.lang.Object obj,
                                           java.lang.String path,
                                           InterMineAPI api)
        Check whether the runtime type of an object supports a particular path. E.g.: An Employee supports the "department.name" path.
        Parameters:
        obj - The object we want to inspect.
        path - The headless path we want to use.
        api - A reference to the API object.
        Returns:
        true if the path is valid for this object.