|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object dk.netarkivet.common.webinterface.HTMLUtils
public class HTMLUtils
This is a utility class containing methods for use in the GUI for netarkivet.
Method Summary | |
---|---|
static java.lang.String |
decode(java.lang.String s)
Url decodes a string encoded in UTF-8. |
static java.lang.String |
encode(java.lang.String s)
Url encodes a string in UTF-8. |
static java.lang.String |
encodeAndEscapeHTML(java.lang.String input)
Encode a string for use in a URL, then escape characters that must be escaped in HTML. |
static java.lang.String |
escapeHtmlValues(java.lang.String input)
Escapes HTML special characters ", &, < and > (but not '). |
static java.lang.String |
escapeJavascriptQuotes(java.lang.String input)
Escapes a string for use in javascript. |
static void |
forwardOnEmptyParameter(javax.servlet.jsp.PageContext context,
java.lang.String... parameters)
Checks that the given parameters exist and are not empty. |
static void |
forwardOnIllegalParameter(javax.servlet.jsp.PageContext context,
java.lang.String parameter,
java.lang.String... legalValues)
Checks that the given parameter exists and is one of a set of values. |
static void |
forwardOnMissingParameter(javax.servlet.jsp.PageContext context,
java.lang.String... parameters)
Checks that the given parameters exist. |
static void |
forwardWithErrorMessage(javax.servlet.jsp.PageContext context,
I18n I18N,
java.lang.String label,
java.lang.Object... args)
Forward to our standard error message page with an internationalized message. |
static void |
forwardWithErrorMessage(javax.servlet.jsp.PageContext context,
I18n i18n,
java.lang.Throwable e,
java.lang.String label,
java.lang.Object... args)
Forward to our standard error message page with an internationalized message, in case of exception. |
static void |
forwardWithRawErrorMessage(javax.servlet.jsp.PageContext context,
I18n i18n,
java.lang.String label,
java.lang.Object... args)
Forward to our standard error message page with an internationalized message. |
static void |
generateFooter(javax.servlet.jsp.JspWriter out)
Writes out footer information to close the page. |
static void |
generateHeader(javax.servlet.jsp.PageContext context)
Prints the header information for the webpages in the GUI. |
static void |
generateHeader(javax.servlet.jsp.PageContext context,
long refreshInSeconds)
Prints the header information for the webpages in the GUI. |
static void |
generateHeader(javax.servlet.jsp.PageContext context,
java.lang.String... jsToInclude)
Prints the header information for the webpages in the GUI. |
static void |
generateHeader(java.lang.String title,
long refreshInSeconds,
javax.servlet.jsp.PageContext context)
Prints the header information for the webpages in the GUI. |
static void |
generateHeader(java.lang.String title,
javax.servlet.jsp.PageContext context,
java.lang.String... jsToInclude)
Prints the header information for the webpages in the GUI. |
static java.lang.String |
getLocale(javax.servlet.http.HttpServletRequest request)
Get a locale from cookie, if present. |
static java.util.Locale |
getLocaleObject(javax.servlet.jsp.PageContext context)
Get the locale according to header context information. |
static java.lang.String |
getRowClass(int rowCount)
Get the (CSS) class name for a row in a table. |
static java.lang.String |
getTitle(java.lang.String url,
java.util.Locale locale)
Given a URL in the sitesection hierarchy, returns the corresponding page title. |
static java.lang.String |
localiseLong(long i,
java.util.Locale locale)
Create a localized string representation of the given long. |
static java.lang.String |
localiseLong(long i,
javax.servlet.jsp.PageContext context)
Create a localized string representation of the given long. |
static java.lang.String |
makeDate(java.util.Date d)
Deprecated. Please use |
static java.lang.String |
makeTableElement(java.lang.String s)
Create a table element containing the given string, escaping HTML values in the process. |
static java.lang.String |
makeTableHeader(java.lang.String contents)
Create a table header element containing the given string, escaping HTML values in the process. |
static java.lang.String |
makeTableRow(java.lang.String... contents)
Create a table row. |
static java.lang.String |
nullToHyphen(java.lang.Object o)
Returns the toString() value of an object or a hyphen if the argument is null. |
static int |
parseAndCheckInteger(javax.servlet.jsp.PageContext context,
java.lang.String param,
int minValue,
int maxValue)
Parses a integer request parameter and checks that it lies within a given interval. |
static java.lang.Long |
parseLong(java.util.Locale loc,
java.lang.String paramValue,
java.lang.String parameterName,
java.lang.Long defaultValue)
Parse a given String for a long value. |
static java.util.Date |
parseOptionalDate(javax.servlet.jsp.PageContext context,
java.lang.String param,
java.lang.String format,
java.util.Date defaultValue)
Parse an optionally present date-value from a request parameter. |
static java.lang.Long |
parseOptionalLong(javax.servlet.jsp.PageContext context,
java.lang.String param,
java.lang.Long defaultValue)
Parse an optionally present long-value from a request parameter. |
static void |
setUTF8(javax.servlet.http.HttpServletRequest request)
Sets the character encoding for reading parameters and content from a request in a JSP page. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static java.lang.String encode(java.lang.String s)
s
- the string to encode
public static java.lang.String decode(java.lang.String s)
s
- the string to decode
public static void generateHeader(javax.servlet.jsp.PageContext context) throws java.io.IOException
context
- The context of the web page request.
java.io.IOException
- if an error occurs during writing of output.public static void generateHeader(javax.servlet.jsp.PageContext context, java.lang.String... jsToInclude) throws java.io.IOException
context
- The context of the web page request.
java.io.IOException
- if an error occurs during writing of output.public static void generateHeader(javax.servlet.jsp.PageContext context, long refreshInSeconds) throws java.io.IOException
context
- The context of the web page request.refreshInSeconds
- auto-refresh time in seconds
java.io.IOException
- if an error occurs during writing of output.public static void generateHeader(java.lang.String title, javax.servlet.jsp.PageContext context, java.lang.String... jsToInclude) throws java.io.IOException
title
- An internationalised title of the page.context
- The context of the web page request.jsToInclude
- path(s) to external .js files to include in header.
java.io.IOException
- if an error occurs during writing to output.public static void generateHeader(java.lang.String title, long refreshInSeconds, javax.servlet.jsp.PageContext context) throws java.io.IOException
title
- An internationalised title of the page.context
- The context of the web page request.refreshInSeconds
- auto-refresh time in seconds
java.io.IOException
- if an error occurs during writing to output.public static java.util.Locale getLocaleObject(javax.servlet.jsp.PageContext context)
context
- The context of the web page request.
public static void generateFooter(javax.servlet.jsp.JspWriter out) throws java.io.IOException
out
- the writer to which the information is written
java.io.IOException
- if the output cannot be writtenpublic static java.lang.String makeTableElement(java.lang.String s)
s
- An unescaped string. Any HTML tags in this string will end up
escaped away.
public static java.lang.String makeTableHeader(java.lang.String contents)
contents
- An unescaped string. Any HTML tags in this string will
end up escaped away.
public static java.lang.String makeTableRow(java.lang.String... contents)
contents
- The contents to put into the table row.
The entries will be delimited by newline characters.
public static java.lang.String makeDate(java.util.Date d)
d
- A date
public static java.lang.String nullToHyphen(java.lang.Object o)
o
- the given object
public static java.lang.String escapeHtmlValues(java.lang.String input)
input
- a string
public static java.lang.String encodeAndEscapeHTML(java.lang.String input)
input
- A string
public static java.lang.String escapeJavascriptQuotes(java.lang.String input)
input
- a string
public static void setUTF8(javax.servlet.http.HttpServletRequest request)
request
- The servlet request objectpublic static java.lang.String getTitle(java.lang.String url, java.util.Locale locale)
url
- a given URLlocale
- the current locale
ArgumentNotValid
- if the given url or locale is null or
url is empty.public static java.lang.String getRowClass(int rowCount)
rowCount
- The number of the row
public static java.lang.String getLocale(javax.servlet.http.HttpServletRequest request)
request
- The request to get the locale for.
public static void forwardWithErrorMessage(javax.servlet.jsp.PageContext context, I18n I18N, java.lang.String label, java.lang.Object... args)
context
- The context that the error happened in (the JSP-defined
pageContext, typically)I18N
- The i18n informationlabel
- An i18n label for the error. This label should begin with
"errormsg;".args
- Any extra args for i18n
IOFailure
- If the forward failspublic static void forwardWithRawErrorMessage(javax.servlet.jsp.PageContext context, I18n i18n, java.lang.String label, java.lang.Object... args)
context
- The context that the error happened in (the JSP-defined
pageContext, typically)i18n
- The i18n informationlabel
- An i18n label for the error. This label should begin with
"errormsg;".args
- Any extra args for i18n. These must be valid HTML.
IOFailure
- If the forward fails.public static void forwardWithErrorMessage(javax.servlet.jsp.PageContext context, I18n i18n, java.lang.Throwable e, java.lang.String label, java.lang.Object... args)
context
- The context that the error happened in (the JSP-defined
pageContext, typically)i18n
- The i18n informatione
- The exception that is being handled.label
- An i18n label for the error. This label should begin with
"errormsg;".args
- Any extra args for i18n
IOFailure
- If the forward failspublic static void forwardOnMissingParameter(javax.servlet.jsp.PageContext context, java.lang.String... parameters) throws ForwardedToErrorPage
context
- The context of the current JSP pageparameters
- List of parameters that must exist
IOFailure
- If the forward fails
ForwardedToErrorPage
- If a parameter is missingpublic static void forwardOnEmptyParameter(javax.servlet.jsp.PageContext context, java.lang.String... parameters)
context
- The context of the current JSP pageparameters
- List of parameters that must exist and be non-empty
IOFailure
- If the forward fails
ForwardedToErrorPage
- if a parameter was missing or emptypublic static void forwardOnIllegalParameter(javax.servlet.jsp.PageContext context, java.lang.String parameter, java.lang.String... legalValues) throws ForwardedToErrorPage
context
- The context of the current JSP pageparameter
- parameter that must existlegalValues
- legal values for the parameter
IOFailure
- If the forward fails
ForwardedToErrorPage
- if the parameter is none of the given valuespublic static int parseAndCheckInteger(javax.servlet.jsp.PageContext context, java.lang.String param, int minValue, int maxValue) throws ForwardedToErrorPage
context
- The context this call happens inparam
- A parameter to parse.minValue
- The minimum allowed valuemaxValue
- The maximum allowed value
ForwardedToErrorPage
- if the parameter doesn't exist, is not a
parseable integer, or doesn't lie within the limits.public static java.lang.Long parseOptionalLong(javax.servlet.jsp.PageContext context, java.lang.String param, java.lang.Long defaultValue)
context
- The context of the web request.param
- The name of the parameter to parse.defaultValue
- A value to return if the parameter is not present
(may be null).
ForwardedToErrorPage
- if the parameter is present but not
parseable as a long value.public static java.util.Date parseOptionalDate(javax.servlet.jsp.PageContext context, java.lang.String param, java.lang.String format, java.util.Date defaultValue)
context
- The context of the web request.param
- The name of the parameter to parseformat
- The format of the date, in
the format defined by SimpleDateFormatdefaultValue
- A value to return if the parameter is not present
(may be null)
ForwardedToErrorPage
- if the parameter is present but not
parseable as a datepublic static java.lang.String localiseLong(long i, javax.servlet.jsp.PageContext context)
i
- A long integercontext
- The given JSP context
public static java.lang.String localiseLong(long i, java.util.Locale locale)
i
- A long integerlocale
- The given locale.
public static java.lang.Long parseLong(java.util.Locale loc, java.lang.String paramValue, java.lang.String parameterName, java.lang.Long defaultValue)
loc
- The given Locale.paramValue
- The given parameter valueparameterName
- The given parameter name (used for debugging)defaultValue
- The default value for the parameter,
in case the string cannot be parsed
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |