|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.mizar.faces.javax.ServletUtils
public class ServletUtils
A collection of static classes that provide convenient interfaces to
HttpSession
,
HttpServletRequest
, and
ServletContext
methods.
Constructor Summary | |
---|---|
ServletUtils()
|
Method Summary | |
---|---|
static java.lang.String |
getAbsoluteFileName(java.lang.String fileUrl)
|
static java.lang.String |
getAbsoluteStem()
Retreive the complete path to the application root for the current HttpServletRequest. |
static java.lang.String |
getContextPath()
|
static java.lang.String |
getContextRoot()
Gets the context root from the current HttpSessions in a null safe manner. |
static java.util.ArrayList<java.lang.String> |
getFileURLs(java.io.File folder)
|
static java.util.ArrayList<java.lang.String> |
getFileURLs(java.lang.String relativeFolder)
|
static javax.servlet.http.HttpServletRequest |
getHttpRequest()
|
static javax.servlet.http.HttpServletResponse |
getHttpResponse()
|
static javax.servlet.http.HttpSession |
getHttpSession()
Gets the current HTTP Session from the FacesContext/ExternalContext |
static java.lang.String |
getIpAddress()
|
static java.lang.String |
getMimeType(java.lang.String fileName)
Just a wrapper for ServletContext.getMimeType() |
static int |
getPort()
|
static java.io.InputStream |
getResourceAsStream(java.lang.String fileName)
|
static java.lang.Object |
getServletAttribute(java.lang.String name)
|
static javax.servlet.ServletContext |
getServletContext()
Gets the current ServletContext from the FacesContext in a null safe manner. |
static java.lang.String |
getServletContextName()
The method traverses FacesContext.getCurrentInstance().getExternalContext().getRequest().getContextPath() in a null safe manner. |
static java.lang.Object |
getSessionAttribute(java.lang.String name)
|
static int |
getSessionTimeOut()
|
static java.lang.String |
getTimestampedFileName(java.lang.String prefix,
java.lang.String type)
Create a unique file name derived from a timestamp. |
static java.lang.String |
getTimestampedFileName(java.lang.String relativePath,
java.lang.String prefix,
java.lang.String type)
Create a unique file name derived from a timestamp. |
static java.lang.String |
getUniqueFileNameForUser(java.lang.String relativePath,
java.lang.String userName,
java.lang.String type)
Generate a unique filename for recipient. |
static java.lang.String |
getUserAgent()
|
static java.lang.String |
readFromRelativeFile(java.lang.String fileName)
|
static void |
sendFile(java.lang.String filePath)
This method may or may not differ from sendFile2(java.lang.String) . |
static void |
sendFile2(java.lang.String filePath)
Sends the contents of filePath to the client using filePath to determine the mime type. |
static boolean |
sendHtml(java.lang.String content)
|
static boolean |
sendOutputStream(java.io.OutputStream baos,
java.lang.String fileName)
Sends the OutputStream contents to the client using fileName to determine the mime type. |
static boolean |
sendOutputStream(java.lang.String content,
java.lang.String fileName)
|
static java.lang.Object |
setServletAttribute(java.lang.String name,
java.lang.Object value)
|
static java.lang.Object |
setSessionAttribute(java.lang.String name,
java.lang.Object value)
|
static void |
setSessionTimeOut(int timeout)
|
static java.lang.String |
stripContextRoot(java.lang.String absoluteFilePath)
The method converts an absolute file name to a relative file name be removing the portion that is equal to the ContextRoot. |
static javax.servlet.http.HttpSession |
validateHttpSession(javax.servlet.http.HttpSession httpSession)
The method is used to test if a httpSession is still valid. |
static int |
writeContentToRelativeFile(byte[] byteStream,
java.lang.String fileUrl)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ServletUtils()
Method Detail |
---|
public static java.lang.String getAbsoluteStem()
public static java.lang.String getContextPath()
public static javax.servlet.http.HttpSession getHttpSession()
ExternalContext.getRequest()
,
HttpServletRequest.getSession(boolean)
public static javax.servlet.http.HttpServletRequest getHttpRequest()
ExternalContext.getRequest()
public static java.lang.String getUserAgent()
public static javax.servlet.http.HttpServletResponse getHttpResponse()
public static java.lang.String getIpAddress()
getHttpRequest()
,
ServletRequest.getRemoteHost()
public static int getPort()
public static javax.servlet.http.HttpSession validateHttpSession(javax.servlet.http.HttpSession httpSession)
The method is used to test if a httpSession is still valid. It does this by executing a getter within a try block and catching the Exception that occurs if the session is no longer valid. This would typically be used within a servlet monitor that keeps track of HTTP sessions. If a session times out, it becomes invalid.
public HttpSession getHttpSession(){ return ServletUtils.validateHttpSession(httpSession); }
httpSession
-
httpSession
if valid, else nullpublic static java.lang.Object setServletAttribute(java.lang.String name, java.lang.Object value)
public static java.lang.Object getServletAttribute(java.lang.String name)
public static java.lang.Object setSessionAttribute(java.lang.String name, java.lang.Object value)
public static java.lang.Object getSessionAttribute(java.lang.String name)
public static java.lang.String getServletContextName()
public static java.io.InputStream getResourceAsStream(java.lang.String fileName)
public static java.lang.String getContextRoot()
getServletContext()
public static javax.servlet.ServletContext getServletContext()
public static java.lang.String getMimeType(java.lang.String fileName)
ServletContext.getMimeType()
fileName
-
ServletContext.getMimeType(String)
public static boolean sendHtml(java.lang.String content)
public static boolean sendOutputStream(java.lang.String content, java.lang.String fileName) throws java.io.IOException
java.io.IOException
public static boolean sendOutputStream(java.io.OutputStream baos, java.lang.String fileName) throws java.io.IOException
fileName
to determine the mime type.
baos
- an OutputStream that is castable to a ByteArrayOutputStreamfileName
- a file name to include in the response header
java.io.IOException
getMimeType(String)
,
sendFile(String)
public static void sendFile(java.lang.String filePath) throws java.io.IOException
sendFile2(java.lang.String)
. It looks like they just take different paths to the same write
Sends the contents of filePath
to the client using filePath
to determine the mime type.
filePath
- an absolute path to a file
java.io.IOException
sendFile2(java.lang.String)
public static void sendFile2(java.lang.String filePath) throws java.io.IOException
filePath
to the client using filePath
to determine the mime type.
filePath
- an absolute path to a file
java.io.IOException
sendOutputStream(OutputStream, String)
,
sendFile(java.lang.String)
public static java.lang.String getUniqueFileNameForUser(java.lang.String relativePath, java.lang.String userName, java.lang.String type)
The generated filename will have the form
[contextRoot]/[relativePath]/[recipient]-yyyy-MM-dd-kk-mm.[type]
relativePath
- Path relative to the ContextRoot to useuserName
- User to associate with the filenametype
- file extension
public static java.lang.String getTimestampedFileName(java.lang.String prefix, java.lang.String type)
The generated filename will have the form:
[prefix]-yyyy-MM-dd-kk-mm.[type]
prefix
- prefix to add to the unique filenametype
- file extension type to use
which gets the absolute file name
public static java.lang.String getAbsoluteFileName(java.lang.String fileUrl)
fileUrl
- a file path and name relative to the context root
fileUrl
getContextRoot()
public static java.lang.String getTimestampedFileName(java.lang.String relativePath, java.lang.String prefix, java.lang.String type)
The generated filename will have the form:
[contextRoot]/[relativePath]/[prefix]-yyyy-MM-dd-kk-mm.[type]
relativePath
- Path relative to the context rootprefix
- prefix to add to the unique filenametype
- file extension type to use
which gets just the simple file name
public static java.lang.String readFromRelativeFile(java.lang.String fileName) throws java.io.FileNotFoundException, java.io.IOException
fileName
- name of a file relative to the ContextRoot
fileName
java.io.FileNotFoundException
java.io.IOException
FileUtils.readFromAbsoluteFile(String)
,
getContextRoot()
public static java.lang.String stripContextRoot(java.lang.String absoluteFilePath)
absoluteFilePath
-
getContextRoot()
public static int writeContentToRelativeFile(byte[] byteStream, java.lang.String fileUrl) throws java.io.FileNotFoundException, java.io.IOException
fileUrl
- a relative URL for the file. This is prepended with the context root to form an absolute path to the file.byteStream
- the binary content to write to docUrl
java.io.FileNotFoundException
java.io.IOException
FileUtils.writeContentToAbsoluteFile(byte[], String)
public static int getSessionTimeOut()
HttpSession.getMaxInactiveInterval()
,
getHttpSession()
public static void setSessionTimeOut(int timeout)
timeout
- a new session timeout in seconds.HttpSession.setMaxInactiveInterval(int)
,
getHttpSession()
public static java.util.ArrayList<java.lang.String> getFileURLs(java.lang.String relativeFolder)
public static java.util.ArrayList<java.lang.String> getFileURLs(java.io.File folder)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |