Package org.dspace.app.util
Class Util
java.lang.Object
org.dspace.app.util.Util
- Direct Known Subclasses:
WorkflowUtils
Miscellaneous utility methods
- Author:
- Robert Tansley, Mark Diggory
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondifferenceInSubmissionFields(Collection fromCollection, Collection toCollection) static StringencodeBitstreamName(String stringIn) Version of encodeBitstreamName with one parameter, uses default encodingstatic StringencodeBitstreamName(String stringIn, String encoding) Encode a bitstream name for inclusion in a URL in an HTML document.static StringformatFileSize(double in) Formats the file size.static booleangetBoolParameter(jakarta.servlet.http.HttpServletRequest request, String param) Obtain a parameter from the given request as a boolean.getControlledVocabulariesDisplayValueLocalized(Item item, List<MetadataValue> values, String schema, String element, String qualifier, Locale locale) 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.xmlstatic intgetIntParameter(jakarta.servlet.http.HttpServletRequest request, String param) Obtain a parameter from the given request as an int.static int[]getIntParameters(jakarta.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.static StringGets Maven version string of the source that built this instance.static StringgetSubmitButton(jakarta.servlet.http.HttpServletRequest request, String def) Get the button the user pressed on a submitted form.static UUIDgetUUIDParameter(jakarta.servlet.http.HttpServletRequest request, String param) Obtain a parameter from the given request as a UUID.getUUIDParameters(jakarta.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.static StringUtility method to convert spaces in a string to HTML non-break space elements.static <T> List<T>[]Split a list in an array of i sub-lists uniformly sized.
-
Constructor Details
-
Util
protected Util()Default constructor. Must be protected as org.dspace.xmlworkflow.WorkflowUtils extends it
-
-
Method Details
-
nonBreakSpace
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 encodeencoding- character encoding, e.g. UTF-8- Returns:
- the encoded string
- Throws:
UnsupportedEncodingException- if encoding error
-
encodeBitstreamName
Version of encodeBitstreamName with one parameter, uses default encoding- Parameters:
stringIn- input string to encode- Returns:
- the encoded string
- Throws:
UnsupportedEncodingException- if encoding error
-
formatFileSize
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
Obtain a parameter from the given request as an int.-1is returned if the parameter is garbled or does not exist.- Parameters:
request- the HTTP requestparam- the name of the parameter- Returns:
- the integer value of the parameter, or -1
-
getUUIDParameter
Obtain a parameter from the given request as a UUID.nullis returned if the parameter is garbled or does not exist.- Parameters:
request- the HTTP requestparam- the name of the parameter- Returns:
- the integer value of the parameter, or -1
-
getUUIDParameters
public static List<UUID> getUUIDParameters(jakarta.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.nullis returned in position of the list if that particular value is garbled.- Parameters:
request- the HTTP requestparam- the name of the parameter- Returns:
- list of UUID or null
-
getIntParameters
Obtain an array of int parameters from the given request as an int. null is returned if parameter doesn't exist.-1is returned in array locations if that particular value is garbled.- Parameters:
request- the HTTP requestparam- the name of the parameter- Returns:
- array of integers or null
-
getBoolParameter
public static boolean getBoolParameter(jakarta.servlet.http.HttpServletRequest request, String param) Obtain a parameter from the given request as a boolean.falseis returned if the parameter is garbled or does not exist.- Parameters:
request- the HTTP requestparam- the name of the parameter- Returns:
- the integer value of the parameter, or -1
-
getSubmitButton
Get the button the user pressed on a submitted form. All buttons should start with the textsubmitfor 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 requestdef- the default button- Returns:
- the button pressed
-
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 Itemvalues- A Metadatum[] array of the specific "stored-value(s)"schema- A String with the schema name of the metadata fieldelement- A String with the element name of the metadata fieldqualifier- A String with the qualifier name of the metadata fieldlocale- locale- Returns:
- A list of the respective "displayed-values"
- Throws:
SQLException- if database errorDCInputsReaderException- if reader error
-
splitList
Split a list in an array of i sub-lists uniformly sized.- Type Parameters:
T- type of objects in the list.- Parameters:
idsList- the list to spliti- the number of sublists to return- Returns:
- an array of sub-lists of fixed size
-
differenceInSubmissionFields
public static List<String> differenceInSubmissionFields(Collection fromCollection, Collection toCollection) throws DCInputsReaderException - Throws:
DCInputsReaderException
-