Package jmri.web.servlet
Class ServletUtil
- java.lang.Object
-
- jmri.web.servlet.ServletUtil
-
- All Implemented Interfaces:
InstanceManagerAutoDefault
public class ServletUtil extends java.lang.Object implements InstanceManagerAutoDefault
Utility methods to reduce code duplication in servlets.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
APPLICATION_JAVASCRIPT
static java.lang.String
APPLICATION_JSON
static java.lang.String
APPLICATION_XML
static java.lang.String
HIDDEN
static java.lang.String
IMAGE_PNG
static java.lang.String
TEXT_HTML
static java.lang.String
UTF8
static java.lang.String
UTF8_APPLICATION_JAVASCRIPT
static java.lang.String
UTF8_APPLICATION_JSON
static java.lang.String
UTF8_APPLICATION_XML
static java.lang.String
UTF8_CHARSET
static java.lang.String
UTF8_TEXT_HTML
-
Constructor Summary
Constructors Constructor Description ServletUtil()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getFooter(java.util.Locale locale, java.lang.String context)
Create a common footer.java.lang.String
getNavBar(java.util.Locale locale, java.lang.String context)
Create a common navigation header.java.lang.String
getRailroadName(boolean inComments)
Get the railroad name for HTML documents.java.lang.String
getTitle(java.util.Locale locale, java.lang.String title)
Return the complete title for an HTML document given the portion of the title specific to the document.java.util.Date
setNonCachingHeaders(javax.servlet.http.HttpServletResponse response)
Set HTTP headers to prevent caching.void
writeFile(javax.servlet.http.HttpServletResponse response, java.io.File file, java.lang.String contentType)
Write a file to the given response.
-
-
-
Field Detail
-
UTF8
public static final java.lang.String UTF8
-
APPLICATION_JAVASCRIPT
public static final java.lang.String APPLICATION_JAVASCRIPT
- See Also:
- Constant Field Values
-
APPLICATION_JSON
public static final java.lang.String APPLICATION_JSON
- See Also:
- Constant Field Values
-
APPLICATION_XML
public static final java.lang.String APPLICATION_XML
- See Also:
- Constant Field Values
-
IMAGE_PNG
public static final java.lang.String IMAGE_PNG
- See Also:
- Constant Field Values
-
TEXT_HTML
public static final java.lang.String TEXT_HTML
- See Also:
- Constant Field Values
-
UTF8_CHARSET
public static final java.lang.String UTF8_CHARSET
- See Also:
- Constant Field Values
-
UTF8_APPLICATION_JAVASCRIPT
public static final java.lang.String UTF8_APPLICATION_JAVASCRIPT
- See Also:
- Constant Field Values
-
UTF8_APPLICATION_JSON
public static final java.lang.String UTF8_APPLICATION_JSON
- See Also:
- Constant Field Values
-
UTF8_APPLICATION_XML
public static final java.lang.String UTF8_APPLICATION_XML
- See Also:
- Constant Field Values
-
UTF8_TEXT_HTML
public static final java.lang.String UTF8_TEXT_HTML
- See Also:
- Constant Field Values
-
HIDDEN
public static final java.lang.String HIDDEN
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ServletUtil
public ServletUtil()
-
-
Method Detail
-
getRailroadName
public java.lang.String getRailroadName(boolean inComments)
Get the railroad name for HTML documents.- Parameters:
inComments
- Return the railroad name prepended and appended by closing and opening comment markers- Returns:
- the Railroad name, possibly with formatting
-
getFooter
public java.lang.String getFooter(java.util.Locale locale, java.lang.String context) throws java.io.IOException
Create a common footer.- Parameters:
locale
- If a template is not available in locale, will return US English.context
- divs included in footer template with classcontext-<context>-only
will be shown.- Returns:
- an HTML footer
- Throws:
java.io.IOException
- if template cannot be located
-
getNavBar
public java.lang.String getNavBar(java.util.Locale locale, java.lang.String context) throws java.io.IOException
Create a common navigation header.- Parameters:
locale
- If a template is not available in locale, will return US English.context
- divs included in navigation bar template with classcontext-<context>-only
will be shown.- Returns:
- an HTML navigation bar
- Throws:
java.io.IOException
- if template cannot be located
-
setNonCachingHeaders
public java.util.Date setNonCachingHeaders(javax.servlet.http.HttpServletResponse response)
Set HTTP headers to prevent caching.- Parameters:
response
- the response to set headers in- Returns:
- the date used for headers setting expiration and modification times
-
writeFile
public void writeFile(javax.servlet.http.HttpServletResponse response, java.io.File file, java.lang.String contentType) throws java.io.IOException
Write a file to the given response.- Parameters:
response
- the response to write the file intofile
- file to writecontentType
- file mime content type- Throws:
java.io.IOException
- if communications lost with client
-
getTitle
public java.lang.String getTitle(java.util.Locale locale, java.lang.String title)
Return the complete title for an HTML document given the portion of the title specific to the document.- Parameters:
locale
- The requested Localetitle
- Portion of title specific to page- Returns:
- The complete title
-
-