org.dspace.app.util
Class Util

java.lang.Object
  extended by org.dspace.app.util.Util

public class Util
extends Object

Miscellaneous utility methods

Version:
$Revision: 4743 $
Author:
Robert Tansley, Mark Diggory

Constructor Summary
Util()
           
 
Method Summary
static String encodeBitstreamName(String stringIn)
          Version of encodeBitstreamName with one parameter, uses default encoding
static String encodeBitstreamName(String stringIn, String encoding)
          Encode a bitstream name for inclusion in a URL in an HTML document.
static String formatFileSize(double in)
          Formats the file size.
static boolean getBoolParameter(javax.servlet.http.HttpServletRequest request, String param)
          Obtain a parameter from the given request as a boolean.
static int getIntParameter(javax.servlet.http.HttpServletRequest request, String param)
          Obtain a parameter from the given request as an int.
static int[] getIntParameters(javax.servlet.http.HttpServletRequest request, String param)
          Obtain an array of int parameters from the given request as an int.
static String getSourceVersion()
          Gets Maven version string of the source that built this instance.
static String getSubmitButton(javax.servlet.http.HttpServletRequest request, String def)
          Get the button the user pressed on a submitted form.
static String nonBreakSpace(String s)
          Utility method to convert spaces in a string to HTML non-break space elements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
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

encodeBitstreamName

public static String encodeBitstreamName(String stringIn)
                                  throws UnsupportedEncodingException
Version of encodeBitstreamName with one parameter, uses default encoding

Parameters:
stringIn - input string to encode
Returns:
the encoded string
Throws:
UnsupportedEncodingException

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 covnert
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

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.


Copyright © 2010 DuraSpace. All Rights Reserved.