Class Util

  • Direct Known Subclasses:
    WorkflowUtils

    public class Util
    extends Object
    Miscellaneous utility methods
    Version:
    $Revision$
    Author:
    Robert Tansley, Mark Diggory
    • Constructor Detail

      • Util

        protected Util()
        Default constructor. Must be protected as org.dspace.xmlworkflow.WorkflowUtils extends it
    • Method Detail

      • nonBreakSpace

        public static String nonBreakSpace​(String s)
        Utility method to convert spaces in a string to HTML non-break space elements.
        Parameters:
        s - string to change spaces in
        Returns:
        the string passed in with spaces converted to HTML non-break spaces
      • encodeBitstreamName

        public static String encodeBitstreamName​(String stringIn,
                                                 String encoding)
                                          throws UnsupportedEncodingException
        Encode a bitstream name for inclusion in a URL in an HTML document. This differs from the usual URL-encoding, since we want pathname separators to be passed through verbatim; this is required so that relative paths in bitstream names and HTML references work correctly.

        If the link to a bitstream is generated with the pathname separators escaped (e.g. "%2F" instead of "/") then the Web user agent perceives it to be one pathname element, and relative URI paths within that document containing ".." elements will be handled incorrectly.

        Parameters:
        stringIn - input string to encode
        encoding - character encoding, e.g. UTF-8
        Returns:
        the encoded string
        Throws:
        UnsupportedEncodingException - if encoding error
      • formatFileSize

        public static String formatFileSize​(double in)
        Formats the file size. Examples: - 50 = 50B - 1024 = 1KB - 1,024,000 = 1MB etc The numbers are formatted using java Locales
        Parameters:
        in - The number to convert
        Returns:
        the file size as a String
      • getIntParameter

        public static int getIntParameter​(javax.servlet.http.HttpServletRequest request,
                                          String param)
        Obtain a parameter from the given request as an int. -1 is returned if the parameter is garbled or does not exist.
        Parameters:
        request - the HTTP request
        param - the name of the parameter
        Returns:
        the integer value of the parameter, or -1
      • getUUIDParameter

        public static UUID getUUIDParameter​(javax.servlet.http.HttpServletRequest request,
                                            String param)
        Obtain a parameter from the given request as a UUID. null is returned if the parameter is garbled or does not exist.
        Parameters:
        request - the HTTP request
        param - the name of the parameter
        Returns:
        the integer value of the parameter, or -1
      • getUUIDParameters

        public static List<UUID> getUUIDParameters​(javax.servlet.http.HttpServletRequest request,
                                                   String param)
        Obtain a List of UUID parameters from the given request as an UUID. null is returned if parameter doesn't exist. null is returned in position of the list if that particular value is garbled.
        Parameters:
        request - the HTTP request
        param - the name of the parameter
        Returns:
        list of UUID or null
      • getIntParameters

        public static int[] getIntParameters​(javax.servlet.http.HttpServletRequest request,
                                             String param)
        Obtain an array of int parameters from the given request as an int. null is returned if parameter doesn't exist. -1 is returned in array locations if that particular value is garbled.
        Parameters:
        request - the HTTP request
        param - the name of the parameter
        Returns:
        array of integers or null
      • getBoolParameter

        public static boolean getBoolParameter​(javax.servlet.http.HttpServletRequest request,
                                               String param)
        Obtain a parameter from the given request as a boolean. false is returned if the parameter is garbled or does not exist.
        Parameters:
        request - the HTTP request
        param - the name of the parameter
        Returns:
        the integer value of the parameter, or -1
      • getSubmitButton

        public static String getSubmitButton​(javax.servlet.http.HttpServletRequest request,
                                             String def)
        Get the button the user pressed on a submitted form. All buttons should start with the text submit for this to work. A default should be supplied, since often the browser will submit a form with no submit button pressed if the user presses enter.
        Parameters:
        request - the HTTP request
        def - the default button
        Returns:
        the button pressed
      • getSourceVersion

        public static String getSourceVersion()
        Gets Maven version string of the source that built this instance.
        Returns:
        string containing version, e.g. "1.5.2"; ends in "-SNAPSHOT" for development versions.
      • getControlledVocabulariesDisplayValueLocalized

        public static List<String> getControlledVocabulariesDisplayValueLocalized​(Item item,
                                                                                  List<MetadataValue> values,
                                                                                  String schema,
                                                                                  String element,
                                                                                  String qualifier,
                                                                                  Locale locale)
                                                                           throws SQLException,
                                                                                  DCInputsReaderException
        Get a list of all the respective "displayed-value(s)" from the given "stored-value(s)" for a specific metadata field of a DSpace Item, by reading submission-forms.xml
        Parameters:
        item - The Dspace Item
        values - A Metadatum[] array of the specific "stored-value(s)"
        schema - A String with the schema name of the metadata field
        element - A String with the element name of the metadata field
        qualifier - A String with the qualifier name of the metadata field
        locale - locale
        Returns:
        A list of the respective "displayed-values"
        Throws:
        SQLException - if database error
        DCInputsReaderException - if reader error
      • splitList

        public static <T> List<T>[] splitList​(List<T> idsList,
                                              int i)
        Split a list in an array of i sub-lists uniformly sized
        Parameters:
        idsList - the list to split
        i - the number of sublists to return
        Returns:
        an array of sub-lists of fixed size