|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.jalios.jcms.context.JcmsContext
public class JcmsContext
This class keep track of all variables declared in doInitPage and give access
to convenient methods when you are not in a jsp (servlet, tag, custom class
etc) To use methods of this class, You MUST set a valid request and response
(either with the contructor or with the setters).
The current JcmsContext can be retreived either through the variable
jcmsContext in a JSP or through the method
Channel.getCurrentJcmsContext()
.
Field Summary | |
---|---|
protected Browser |
browser
|
protected Caddy |
caddy
|
protected static Channel |
channel
|
protected boolean |
inFO
|
protected boolean |
initDone
|
protected boolean |
initWorkspace
|
protected boolean |
isAdmin
|
protected boolean |
isAjaxRequest
|
protected boolean |
isDBMember
|
protected boolean |
isDebug
|
protected boolean |
isLogged
|
protected Member |
loggedMember
|
protected javax.servlet.http.HttpServletRequest |
request
|
protected javax.servlet.http.HttpServletResponse |
response
|
static String |
REVISION
|
protected String |
userCountry
|
protected String |
userLang
|
protected Locale |
userLocale
|
protected Workspace |
workspace
|
Fields inherited from interface com.jalios.util.JaliosConstants |
---|
CRLF, MILLIS_IN_ONE_DAY, MILLIS_IN_ONE_HOUR, MILLIS_IN_ONE_MINUTE, MILLIS_IN_ONE_MONTH, MILLIS_IN_ONE_SECOND, MILLIS_IN_ONE_WEEK, MILLIS_IN_ONE_YEAR |
Constructor Summary | |
---|---|
JcmsContext()
If you use this constructor, request must be initialized at a later time (This constructor is kept to allow JcmsJspContext to be initialized as a bean, with pageContext parameter) |
|
JcmsContext(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
|
Method Summary | |
---|---|
void |
addCookie(javax.servlet.http.Cookie cookie)
Adds the specified cookie to the response (or in a http-equiv is the response has already been commited, in this case, only for front office use). |
static void |
addMsg(javax.servlet.http.HttpServletRequest request,
JcmsMessage msg)
Add JCMS info message for specified request (displayed through doMessageBox.jsp) |
void |
addMsg(JcmsMessage msg)
Add JCMS info message for specified request (displayed through doMessageBox.jsp) |
static void |
addMsgSession(javax.servlet.http.HttpServletRequest request,
JcmsMessage msg)
Add JCMS info message for specified session (displayed through doMessageBox.jsp) |
void |
addMsgSession(JcmsMessage msg)
Add JCMS info message for current session (displayed through doMessageBox.jsp) |
static List<JcmsMessage> |
applySelector(List<JcmsMessage> msgList,
JcmsMessageSelector selector)
Apply given JcmsMessageSelector by removing non selected
JcmsMessage from the given List . |
void |
forceUpdate()
Will force an update of all JcmsContext variables (retrieve it from the request). |
void |
forceWorkspaceUpdate()
Force Workspace update on next getWorkspace() |
String |
getBaseUrl()
Convenient method which returns ServletUtil.getBaseUrl(request); |
Browser |
getBrowser()
Returns the Client Browser computed for this session identified from userAgent. |
Caddy |
getCaddy()
Returns the caddy stored in current session. |
String |
getContextPath()
Convenient method which returns ServletUtil.getContextPath(request) |
static String |
getErrorMsg(javax.servlet.http.HttpServletRequest request)
Returns the error message in the J2EE request. |
static List<JcmsMessage> |
getErrorMsgList(javax.servlet.http.HttpServletRequest request)
Returns the error message in the J2EE request. |
static String |
getErrorMsgSession(javax.servlet.http.HttpServletRequest request)
Returns the error message in the J2EE session. |
static List<JcmsMessage> |
getErrorMsgSessionList(javax.servlet.http.HttpServletRequest request)
Returns the error message in the J2EE session. |
static String |
getInfoMsg(javax.servlet.http.HttpServletRequest request)
Returns the information message in the J2EE request. |
static List<JcmsMessage> |
getInfoMsgList(javax.servlet.http.HttpServletRequest request)
Returns the information message in the J2EE request. |
static String |
getInfoMsgSession(javax.servlet.http.HttpServletRequest request)
Returns the information message in the J2EE session. |
static List<JcmsMessage> |
getInfoMsgSessionList(javax.servlet.http.HttpServletRequest request)
Returns the information message in the J2EE session. |
Member |
getLoggedMember()
Retrieve the loggedMember variable for this context. |
static List<JcmsMessage> |
getMsgList(javax.servlet.http.HttpServletRequest request)
Returns the information message in the J2EE request. |
static List<JcmsMessage> |
getMsgSessionList(javax.servlet.http.HttpServletRequest request)
Returns the message list in the J2EE session. |
javax.servlet.http.HttpServletRequest |
getRequest()
|
javax.servlet.http.HttpServletResponse |
getResponse()
|
javax.servlet.http.HttpSession |
getSession()
Shorter Method to get Session from request |
Object |
getUploadedFile(String field,
boolean isFileDocument,
boolean override)
Performs upload for the given field to JCMS upload directory. |
List<DocUploadInfo> |
getUploadedFileList(String field,
boolean isFileDocument,
boolean override)
Performs upload for the given field to JCMS upload directory. |
String |
getUrlWithCommonUpdatedParams(String[] names,
String[] values,
boolean encodeParams)
|
String |
getUserCountry()
Retrieves the user country variable for this context. Fast: this method is cached using initDone (it is recomputed only on forceUpdate() or setRequest()). |
String |
getUserLang()
Retrieves the user lang variable for this context. Fast: this method is cached using initDone (it is recomputed only on forceUpdate() or setRequest()). |
Locale |
getUserLocale()
Retrieve the userLocale variable for this context. Fast: this method is cached using initDone (it is retrieved again only on forceUpdate() or setRequest()). |
static String |
getWarningMsg(javax.servlet.http.HttpServletRequest request)
Returns the warning message in the J2EE request. |
static List<JcmsMessage> |
getWarningMsgList(javax.servlet.http.HttpServletRequest request)
Returns the warning message in the J2EE request. |
static String |
getWarningMsgSession(javax.servlet.http.HttpServletRequest request)
Returns the warning message in the J2EE session. |
static List<JcmsMessage> |
getWarningMsgSessionList(javax.servlet.http.HttpServletRequest request)
Returns the warning message in the J2EE session. |
Workspace |
getWorkspace()
Retrieve the current Workspace variable for this context either from request if inFO or from session if in back office. |
String |
glp(String key,
Object... params)
Resolve a language property in the user language of the current request. |
boolean |
isAdmin()
Return the admin status of the current logged user. |
boolean |
isAjaxRequest()
Check if the current request is an Ajax Request (performed through by prototypejs API). |
boolean |
isDBMember()
Return the DB status of the current logged user. |
boolean |
isDebug()
Return the debug state of the request depending on request parameter "debug" |
boolean |
isInFrontOffice()
retrieve the inFO variable for this context. |
boolean |
isLogged()
Return the user logging status for current request. |
boolean |
isWebdavAccess()
Check if the current request is a Webdav Access |
static void |
removeMessage(javax.servlet.http.HttpServletRequest request,
JcmsMessage jcmsMessage)
Remove specified messages from the session and request message list. |
static void |
removeMessage(javax.servlet.http.HttpServletRequest request,
List<JcmsMessage> messages)
Remove specified messages from the session and request message list. |
protected DocUploadInfo |
retrieveUploadedFile(org.apache.commons.fileupload.FileItem item,
boolean isFileDocument,
boolean override)
Performs upload of a given FileItem to JCMS upload directory. |
static List<JcmsMessage> |
select(Collection<? extends JcmsMessage> dataColl,
JcmsMessageSelector selector)
Perform a selection on a Collection of
JcmsMessage using the given JcmsMessageSelector |
void |
sendForbidden()
Send a redirect to the forbidden page |
static void |
sendForbidden(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Send a redirect to the forbidden page if parameter forbidden is set, then redirect to the given url without logging anything. |
void |
sendRedirect(Data data)
Redirect to the given data (eg a publication, a category, ...) Will not redirect if data is null or if response has already been commited, but we put the request attribute "redirect" with the value of the url so that doDisplayBuffer can be able to redirect with the javascript hack. |
void |
sendRedirect(String url)
Redirect current request to given URL. |
static void |
sendRedirect(String url,
boolean checkUrlSecurity,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Redirect current request to given URL. |
static void |
sendRedirect(String url,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Redirect current request to given URL. |
void |
setErrorMsg(String msg)
Set JCMS warning message for current request (displayed through doMessageBox.jsp) |
static void |
setErrorMsg(String msg,
javax.servlet.http.HttpServletRequest request)
Set JCMS warning message for specified request (displayed through doMessageBox.jsp) |
void |
setErrorMsgSession(String msg)
Set JCMS warning message for current session (displayed through doMessageBox.jsp) |
static void |
setErrorMsgSession(String msg,
javax.servlet.http.HttpServletRequest request)
Set JCMS warning message for specified session (displayed through doMessageBox.jsp) |
void |
setInfoMsg(String msg)
Set JCMS info message for current request (displayed through doMessageBox.jsp) |
static void |
setInfoMsg(String msg,
javax.servlet.http.HttpServletRequest request)
Set JCMS info message for specified request (displayed through doMessageBox.jsp) |
void |
setInfoMsgSession(String msg)
Set JCMS info message for current session (displayed through doMessageBox.jsp) |
static void |
setInfoMsgSession(String msg,
javax.servlet.http.HttpServletRequest request)
Set JCMS info message for specified session (displayed through doMessageBox.jsp) |
void |
setLoggedMember(Member mbr)
Set the logged member for this context. |
void |
setRequest(javax.servlet.http.HttpServletRequest request)
Setter for the request. |
void |
setResponse(javax.servlet.http.HttpServletResponse response)
Setter for the response. |
void |
setWarningMsg(String msg)
Set JCMS warning message for current request (displayed through doMessageBox.jsp) |
static void |
setWarningMsg(String msg,
javax.servlet.http.HttpServletRequest request)
Set JCMS warning message for specified request (displayed through doMessageBox.jsp) |
void |
setWarningMsgSession(String msg)
Set JCMS warning message for current session (displayed through doMessageBox.jsp) |
static void |
setWarningMsgSession(String msg,
javax.servlet.http.HttpServletRequest request)
Set JCMS warning message for specified session (displayed through doMessageBox.jsp) |
boolean |
validateRegexp(String regexp)
Validate a pattern as a Perl regexp and set a convienient warning message in the request if not valid. |
boolean |
validateSchedule(String param)
Validate a string as valid Schedule and set a convienient warning message
in the request if not valid. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String REVISION
protected static final Channel channel
protected boolean initDone
protected boolean initWorkspace
protected javax.servlet.http.HttpServletRequest request
protected javax.servlet.http.HttpServletResponse response
protected boolean isLogged
protected boolean isAdmin
protected boolean isDBMember
protected boolean isDebug
protected Member loggedMember
protected Locale userLocale
protected String userLang
protected String userCountry
protected Workspace workspace
protected Browser browser
protected Caddy caddy
protected boolean inFO
protected boolean isAjaxRequest
Constructor Detail |
---|
public JcmsContext()
public JcmsContext(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Method Detail |
---|
public void forceUpdate()
public void setRequest(javax.servlet.http.HttpServletRequest request)
request
- the HttpServletRequest from twhich to retrieve all jcms context
information.public javax.servlet.http.HttpServletRequest getRequest()
public void setResponse(javax.servlet.http.HttpServletResponse response)
sendRedirect(String)
response
- the HttpServletResponse to use when needed.public javax.servlet.http.HttpServletResponse getResponse()
public javax.servlet.http.HttpSession getSession()
public Object getUploadedFile(String field, boolean isFileDocument, boolean override)
field
- the submited fieldisFileDocument
- upload to a FileDocument path upload/docs/...override
- If file already exists, override or rename with current timemillis
UploadManager.getUploadedFile(JcmsContext, String, boolean, boolean)
public List<DocUploadInfo> getUploadedFileList(String field, boolean isFileDocument, boolean override)
field
- the submited fieldisFileDocument
- upload to a FileDocument upload/docs/...override
- If file already exists, override or rename with current timemillis
UploadManager.getUploadedFileList(JcmsContext, String, boolean, boolean)
protected DocUploadInfo retrieveUploadedFile(org.apache.commons.fileupload.FileItem item, boolean isFileDocument, boolean override)
item
- the FileItem handling uploaded file informationisFileDocument
- upload to a FileDocument path upload/docs/...override
- If file already exists, override or rename with current timemillis
UploadManager.retrieveUploadedFile(FileItem, boolean, boolean)
public boolean isLogged()
public boolean isWebdavAccess()
public boolean isDebug()
public boolean isAdmin()
public boolean isDBMember()
public Member getLoggedMember()
public void setLoggedMember(Member mbr)
This methods only changed the logged member for this context instance, this
method is provided in case you want to force the logged member in
bean/handlers.
It will NOT change the logged member of the current request, if you want
to do that, see
AuthenticationHandler
.
mbr
- the Member to set as the currently logged Member.public String getUserLang()
public String getUserCountry()
public Locale getUserLocale()
public boolean isInFrontOffice()
public void forceWorkspaceUpdate()
public Workspace getWorkspace()
public Browser getBrowser()
public Caddy getCaddy()
public boolean isAjaxRequest()
public void sendRedirect(Data data) throws IOException
data
- the data to redirect to.
IOException
- if an error occured while writing in response headerssendRedirect(String, HttpServletRequest, HttpServletResponse)
public void sendRedirect(String url) throws IOException
url
- the url to redirect to.
IOException
- if an error occured while writing in response headerssendRedirect(String, HttpServletRequest, HttpServletResponse)
public void sendForbidden() throws IOException
IOException
- if an error occured while writing in response headerssendForbidden(HttpServletRequest, HttpServletResponse)
public static void sendRedirect(String url, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException
The specified URL must match security configuration of
HttpUtil.isValidHttpUrl(String)
in order for the redirect
to be performed. If the URL does not validate those requirement, the
request is redirected to the webapp root.
As of current implementation,, the redirect will not happen using HTTP if the response has already been commited. Instead a request attribute "redirect" is set with the value of the url, it is later used by doDisplayBuffer to redirect the user with a javascript hack (applies only to front office).
url
- the url to redirect to.request
- the current request from which the redirect is performedresponse
- the response in which to write redirect headers
IOException
- if an error occured while writing in response headerspublic static void sendRedirect(String url, boolean checkUrlSecurity, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException
If checkUrlSecurity
param is set to true, the specified URL must match
security configuration of HttpUtil.isValidHttpUrl(String)
in order
for the redirect to be performed. If the URL does not validate those requirement,
the request is redirected to the webapp root.
It is highly recommended to always use method
sendRedirect(String, HttpServletRequest, HttpServletResponse)
which always
enable this verification. Use this method and checkUrlSecurity=false
only
if you are absolutely sure of the specified URL security and can trust its value.
As of current implementation,, the redirect will not happen using HTTP if the response has already been commited. Instead a request attribute "redirect" is set with the value of the url, it is later used by doDisplayBuffer to redirect the user with a javascript hack (applies only to front office).
url
- the url to redirect to.checkUrlSecurity
- if true, check the URL for validity to prevent phishing, unwanted external
redirect and other forward attack. set to false to disable those verification
(which is not recommended)request
- the current request from which the redirect is performedresponse
- the response in which to write redirect headers
IOException
- if an error occured while writing in response headerssendRedirect(String, HttpServletRequest, HttpServletResponse)
public static void sendForbidden(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException
request
- the current request from which the forbidden redirect is performedresponse
- the response in which to write forbidden redirect headers
IOException
- if an error occured while writing in response headerspublic void addCookie(javax.servlet.http.Cookie cookie)
cookie
- the cookie to be addedpublic String getContextPath()
ServletUtil.getContextPath(HttpServletRequest)
public String getBaseUrl()
ServletUtil.getBaseUrl(HttpServletRequest)
public String getUrlWithCommonUpdatedParams(String[] names, String[] values, boolean encodeParams)
names
- an array of parameter names added or updated the urlvalues
- an array of values added or updated the url corresponding to namesencodeParams
- whether to do a encodeURL on given param (if false, don't forget
to do the encodeURL yourself on the parameters which need it! it
is provided as a performance boost because encodeURL can be slow)
PortalManager.getUrlWithCommonUpdatedParams(HttpServletRequest,
String[], String[], boolean)
public void setInfoMsg(String msg)
msg
- the message to displaypublic void setInfoMsgSession(String msg)
msg
- the message to displaypublic void setWarningMsg(String msg)
msg
- the message to displaypublic void setWarningMsgSession(String msg)
msg
- the message to displaypublic void setErrorMsg(String msg)
msg
- the message to displaypublic void setErrorMsgSession(String msg)
msg
- the message to displaypublic static void setInfoMsg(String msg, javax.servlet.http.HttpServletRequest request)
msg
- the message to displayrequest
- the current request from which the message is being setpublic static void setInfoMsgSession(String msg, javax.servlet.http.HttpServletRequest request)
msg
- the message to displayrequest
- the current request from which the message is being setpublic static void setWarningMsg(String msg, javax.servlet.http.HttpServletRequest request)
msg
- the message to displayrequest
- the current request from which the message is being setpublic static void setWarningMsgSession(String msg, javax.servlet.http.HttpServletRequest request)
msg
- the message to displayrequest
- the current request from which the message is being setpublic static void setErrorMsg(String msg, javax.servlet.http.HttpServletRequest request)
msg
- the message to displayrequest
- the current request from which the message is being setpublic static void setErrorMsgSession(String msg, javax.servlet.http.HttpServletRequest request)
msg
- the message to displayrequest
- the current request from which the message is being setpublic static String getInfoMsg(javax.servlet.http.HttpServletRequest request)
request
- the request to check for
public static String getInfoMsgSession(javax.servlet.http.HttpServletRequest request)
request
- the request to check for
public static String getWarningMsg(javax.servlet.http.HttpServletRequest request)
request
- the request to check for
public static String getWarningMsgSession(javax.servlet.http.HttpServletRequest request)
request
- the request to check for
public static String getErrorMsg(javax.servlet.http.HttpServletRequest request)
request
- the request to check for
public static String getErrorMsgSession(javax.servlet.http.HttpServletRequest request)
request
- the request to check for
public static void removeMessage(javax.servlet.http.HttpServletRequest request, List<JcmsMessage> messages)
request
- the current request must not be nullmessages
- a list of JcmsMessage to removepublic static void removeMessage(javax.servlet.http.HttpServletRequest request, JcmsMessage jcmsMessage)
request
- the current request must not be nulljcmsMessage
- the message to removepublic void addMsg(JcmsMessage msg)
msg
- the message to displaypublic void addMsgSession(JcmsMessage msg)
msg
- the message to displaypublic static void addMsg(javax.servlet.http.HttpServletRequest request, JcmsMessage msg)
msg
- the message to displayrequest
- the current request from which the message is being addedpublic static void addMsgSession(javax.servlet.http.HttpServletRequest request, JcmsMessage msg)
msg
- the message to displayrequest
- the current request from which the message is being addedpublic static List<JcmsMessage> getMsgList(javax.servlet.http.HttpServletRequest request)
request
- the request to check for
public static List<JcmsMessage> getMsgSessionList(javax.servlet.http.HttpServletRequest request)
request
- the request to check for
public static List<JcmsMessage> getInfoMsgList(javax.servlet.http.HttpServletRequest request)
request
- the request to check for
public static List<JcmsMessage> getInfoMsgSessionList(javax.servlet.http.HttpServletRequest request)
request
- the request to check for
public static List<JcmsMessage> getWarningMsgList(javax.servlet.http.HttpServletRequest request)
request
- the request to check for
public static List<JcmsMessage> getWarningMsgSessionList(javax.servlet.http.HttpServletRequest request)
request
- the request to check for
public static List<JcmsMessage> getErrorMsgList(javax.servlet.http.HttpServletRequest request)
request
- the request to check for
public static List<JcmsMessage> getErrorMsgSessionList(javax.servlet.http.HttpServletRequest request)
request
- the request to check for
public String glp(String key, Object... params)
key
- the language property to resolve, for example "ui.com.lbl.contents"params
- an array of parameters to use when resolving the format of the given property
public boolean validateSchedule(String param)
Schedule
and set a convienient warning message
in the request if not valid.
param
- The parameter to validate
Schedule
stringpublic boolean validateRegexp(String regexp)
regexp
- The pattern to validate
public static List<JcmsMessage> select(Collection<? extends JcmsMessage> dataColl, JcmsMessageSelector selector)
Collection
of
JcmsMessage
using the given JcmsMessageSelector
dataColl
- the Collection
of Data
to select.selector
- the DataSelector
to use.
List
of JcmsMessage
.public static List<JcmsMessage> applySelector(List<JcmsMessage> msgList, JcmsMessageSelector selector)
JcmsMessageSelector
by removing non selected
JcmsMessage
from the given List
.
msgList
- a List
of JcmsMessage
from which to
remove non selected data.selector
- the JcmsMessageSelector
to apply
List
that was given but modified.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |