Package com.jalios.jcms.context
Class AbstractJcmsAjaxContext
- java.lang.Object
-
- com.jalios.jcms.context.AbstractJcmsAjaxContext
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
AbstractCtxMenu,JcmsJspAjaxContext
public abstract class AbstractJcmsAjaxContext extends java.lang.Object implements java.io.SerializableConvenient abstract class to easily develops AJAX handlers in JCMS.
This class tracks variables and various request information available during the initial request of user (as opposed to other AJAX request in which the information is either not available or not the same).
To develop your AJAX handler :
1. Create your own AJAX java class by extending this class.
package custom; public class MyAjaxClass extends com.jalios.jcms.AbstractJcmsAjaxContext { public String saySomething(String str) { if (isLogged) { return str + " " + loggedMember.getFriendlyName() + "!"; } return str + "!"; } }2. Instanciate your class using the jcmsContext variable available in the any jsp and register this new instance using JSON.
json_bridge.registerObject("MyAjaxClass", new MyAjaxClass(jcmsContext));3. Call your methods from javascript using JSON.
<script type="text/javascript"> function saySomething(str) { var msg; try { msg = JcmsJsContext.getJsonRPC().MyAjaxClass.saySomething(str); } catch(ex) { alert(I18N.glp('warn.json.sessiontimeout')); return; } alert(msg); } </script> <a href="#" onclick="saySomething('Hello'); return false;">Say Hello</a>- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringbaseUrlprotected Caddycaddyprotected Channelchannelprotected java.lang.StringcontextPathprotected Category[]ctxCategoriesprotected CategorycurrentCategoryprotected booleandebugprotected booleanisAdminprotected booleanisIEprotected booleanisInFrontOfficeprotected booleanisLoggedprotected booleanisWindowsprotected MemberloggedMemberprotected java.lang.Stringmethodprotected java.util.Map<java.lang.String,java.lang.String[]>parameterMapprotected PortalInterfaceportalprotected CategoryportalCategoryprotected Publicationpubprotected java.lang.StringresourcePathprotected java.lang.Stringurlprotected java.lang.StringuserCountryprotected java.lang.StringuserLangprotected java.util.LocaleuserLocaleprotected java.time.ZoneIduserZoneIdprotected Workspaceworkspaceprotected java.lang.Stringzone
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractJcmsAjaxContext()Use this constructor when you need to override some values available in JcmsJspContext by calling setters of this object but still want to benefit from other values already available in the JcmsContext.
But Make sure you call the settersetJcmsContext(JcmsJspContext)after.protectedAbstractJcmsAjaxContext(JcmsJspContext ctxt)Build a new JcmsAjaxContext based on information available in the JcmsJspContext.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancheckAccess(java.lang.String resource)Check if the current member is authorized to access the specified resource.booleancheckAccess(java.lang.String resource, java.util.Map<java.lang.String,java.lang.Object> ctxt)Check if the current member is authorized to access the specified resource.booleandebug(java.lang.String key)java.lang.Stringdeflate()java.lang.StringgetBaseUrl()Retrieve the base URL of the initial request or any base URL that might have specified usingsetBaseUrl(String).CaddygetCaddy()Returns the caddy stored in current session.java.lang.StringgetContextPath()Retrieve the context path of the initial request or any context path that might have specified usingsetContextPath(String).Category[]getCtxCategories()Retrieve the contextual categories to used for refinementCategorygetCurrentCategory()Retrieve the current category, either the category available at the time of the initial request or the one overrided bysetCurrentCategory(Category)MembergetLoggedMember()Retrieve the logged Member at the time of the initial request.java.lang.StringgetMethod()Retrieve the method of the initial request or any base URL that might have specified usingsetMethod(String).java.util.Map<java.lang.String,java.lang.String[]>getParameterMap()Retrieve the map of paramaters available for the original request or map path that might have specified usingsetParameterMap(Map).PortalInterfacegetPortal()Returns the stored portal interface for the given requestCategorygetPortalCategory()Retrieve the portal category, either the category available at the time of the initial request or the one overrided bysetPortalCategory(Category)PublicationgetPublication()Returns the stored Publication for the given requestjava.lang.StringgetResourcePath()Retrieve the original request resource path or any resource path that might have specified usingsetResourcePath(String).java.lang.StringgetUrl()Retrieve the URL of the initial request or any URL that might have specified usingsetUrl(String).java.lang.StringgetUserCountry()Retrieve the country to use for localized features.java.lang.StringgetUserLang()Retrieve the language to use for localized message and localized features.java.util.LocalegetUserLocale()Retrieve the Locale to use for localized message and localized features.java.time.ZoneIdgetUserZoneId()Retrieve the ZoneId to use for zoned date related features.WorkspacegetWorkspace()Retrieve the workspace, either the workspace available at the time of the initial request or the one overrided bysetWorkspace(Workspace)java.lang.StringgetZone()Return the zone statusjava.lang.Stringglp(java.lang.String key, java.lang.Object... params)Resolve a language property in the current user language.voidinflate(java.lang.String data, javax.servlet.http.HttpServletRequest request)booleanisAdmin()Return the admin status of the logged user.booleanisInFrontOffice()Return the isInFrontOffice statusbooleanisLogged()Return the user logging status for the initial request.protected voidreadObject(java.util.Map<java.lang.String,java.lang.Object> map, javax.servlet.http.HttpServletRequest request)voidsetBaseUrl(java.lang.String baseUrl)Sets the base URL.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.voidsetContextPath(java.lang.String contextPath)Sets the context path.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.voidsetCtxCategories(Category[] ctxCategories)Sets the contextual categories used for refinement.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.voidsetCurrentCategory(Category currentCategory)Set the current category.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.voidsetJcmsContext(JcmsJspContext jcmsContext)Sets the following values from values found in the specified JcmsJspContext.
Values are not retrieved from context if they have already been set through their setter.voidsetLoggedMember(Member loggedMember)Sets the logged member.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.voidsetMethod(java.lang.String method)Sets the method.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.voidsetParameterMap(java.util.Map<java.lang.String,java.lang.String[]> parameterMap)Sets the request parameter Map.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.voidsetPortal(PortalInterface portal)Set the portal interface for the given requestvoidsetPortalCategory(Category portalCategory)Set the portal category.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.voidsetPublication(Publication pub)Set the Publication for the given requestvoidsetResourcePath(java.lang.String resourcePath)Sets the resource path.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.voidsetUrl(java.lang.String url)Sets the URL.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.voidsetUserCountry(java.lang.String userCountry)Sets the user country.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.voidsetUserLang(java.lang.String userLang)Sets the user lang.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.voidsetUserLocale(java.util.Locale userLocale)Sets the user Locale.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.voidsetUserZoneId(java.time.ZoneId userZoneId)Sets the user ZoneId.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.voidsetWorkspace(Workspace workspace)Sets the workspace.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.protected voidwriteObject(java.util.Map<java.lang.String,java.lang.Object> map)
-
-
-
Field Detail
-
channel
protected transient Channel channel
-
debug
protected transient boolean debug
-
loggedMember
protected transient Member loggedMember
-
userLang
protected transient java.lang.String userLang
-
userCountry
protected transient java.lang.String userCountry
-
userLocale
protected transient java.util.Locale userLocale
-
userZoneId
protected transient java.time.ZoneId userZoneId
-
isLogged
protected transient boolean isLogged
-
isAdmin
protected transient boolean isAdmin
-
workspace
protected transient Workspace workspace
-
currentCategory
protected transient Category currentCategory
-
portalCategory
protected transient Category portalCategory
-
ctxCategories
protected transient Category[] ctxCategories
-
zone
protected transient java.lang.String zone
-
isInFrontOffice
protected transient boolean isInFrontOffice
-
caddy
protected transient Caddy caddy
-
portal
protected transient PortalInterface portal
-
pub
protected transient Publication pub
-
url
protected transient java.lang.String url
-
baseUrl
protected transient java.lang.String baseUrl
-
contextPath
protected transient java.lang.String contextPath
-
resourcePath
protected transient java.lang.String resourcePath
-
parameterMap
protected transient java.util.Map<java.lang.String,java.lang.String[]> parameterMap
-
method
protected transient java.lang.String method
-
isWindows
protected transient boolean isWindows
-
isIE
protected transient boolean isIE
-
-
Constructor Detail
-
AbstractJcmsAjaxContext
protected AbstractJcmsAjaxContext()
Use this constructor when you need to override some values available in JcmsJspContext by calling setters of this object but still want to benefit from other values already available in the JcmsContext.
But Make sure you call the settersetJcmsContext(JcmsJspContext)after.
-
AbstractJcmsAjaxContext
protected AbstractJcmsAjaxContext(JcmsJspContext ctxt)
Build a new JcmsAjaxContext based on information available in the JcmsJspContext.- Parameters:
ctxt- the JcmsJspContext available in the first "standard" request prior to calling AJAX methods.
-
-
Method Detail
-
setLoggedMember
public final void setLoggedMember(Member loggedMember)
Sets the logged member.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.- Parameters:
loggedMember- the Logged Member- See Also:
setJcmsContext(JcmsJspContext)
-
getLoggedMember
public final Member getLoggedMember()
Retrieve the logged Member at the time of the initial request.- Returns:
- the logged Member or null if no Member was logged in.
-
setUserLang
public final void setUserLang(java.lang.String userLang)
Sets the user lang.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.- Parameters:
userLang- the user lang- See Also:
setJcmsContext(JcmsJspContext)
-
getUserLang
public final java.lang.String getUserLang()
Retrieve the language to use for localized message and localized features.- Returns:
- an ISO 639 language code (e.g. "en")
-
setUserCountry
public final void setUserCountry(java.lang.String userCountry)
Sets the user country.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.- Parameters:
userCountry- the user country- See Also:
setJcmsContext(JcmsJspContext)
-
getUserCountry
public final java.lang.String getUserCountry()
Retrieve the country to use for localized features.- Returns:
- an ISO 3166-1 language code (e.g. "FR")
-
setUserLocale
public final void setUserLocale(java.util.Locale userLocale)
Sets the user Locale.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.- Parameters:
userLocale- the user Locale- See Also:
setJcmsContext(JcmsJspContext)
-
getUserLocale
public final java.util.Locale getUserLocale()
Retrieve the Locale to use for localized message and localized features.- Returns:
- a Locale object
-
setUserZoneId
public final void setUserZoneId(java.time.ZoneId userZoneId)
Sets the user ZoneId.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.- Parameters:
userZoneId- the user ZoneId- See Also:
setJcmsContext(JcmsJspContext)
-
getUserZoneId
public final java.time.ZoneId getUserZoneId()
Retrieve the ZoneId to use for zoned date related features.- Returns:
- a ZoneId object
-
isLogged
public boolean isLogged()
Return the user logging status for the initial request.- Returns:
- true if a member is logged, false otherwise.
-
isAdmin
public boolean isAdmin()
Return the admin status of the logged user.- Returns:
- true if the logged member is admin, false otherwise.
-
isInFrontOffice
public boolean isInFrontOffice()
Return the isInFrontOffice status- Returns:
- boolean true it is in front office
-
getZone
public java.lang.String getZone()
Return the zone status- Returns:
- String the zone
-
setWorkspace
public final void setWorkspace(Workspace workspace)
Sets the workspace.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.- Parameters:
workspace- the workspace- See Also:
setJcmsContext(JcmsJspContext)
-
getWorkspace
public final Workspace getWorkspace()
Retrieve the workspace, either the workspace available at the time of the initial request or the one overrided bysetWorkspace(Workspace)- Returns:
- a Workspace or null if not available
-
setCurrentCategory
public void setCurrentCategory(Category currentCategory)
Set the current category.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.- Parameters:
currentCategory- Category
-
getCurrentCategory
public Category getCurrentCategory()
Retrieve the current category, either the category available at the time of the initial request or the one overrided bysetCurrentCategory(Category)- Returns:
- the current category (if set) or null.
-
setPortalCategory
public void setPortalCategory(Category portalCategory)
Set the portal category.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.- Parameters:
portalCategory- Category
-
getPortalCategory
public Category getPortalCategory()
Retrieve the portal category, either the category available at the time of the initial request or the one overrided bysetPortalCategory(Category)- Returns:
- the current portal category (if set) or null.
-
setCtxCategories
public final void setCtxCategories(Category[] ctxCategories)
Sets the contextual categories used for refinement.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.- Parameters:
ctxCategories- Category[] of contextual categories- See Also:
setJcmsContext(JcmsJspContext)
-
getCtxCategories
public final Category[] getCtxCategories()
Retrieve the contextual categories to used for refinement- Returns:
- an array of Category (may be null or empty)
-
getCaddy
public Caddy getCaddy()
Returns the caddy stored in current session.- Returns:
- the Caddy of the session
-
getPortal
public PortalInterface getPortal()
Returns the stored portal interface for the given request- Returns:
- PortalInterface
-
setPortal
public void setPortal(PortalInterface portal)
Set the portal interface for the given request- Parameters:
portal-
-
getPublication
public Publication getPublication()
Returns the stored Publication for the given request- Returns:
- Publication
-
setPublication
public void setPublication(Publication pub)
Set the Publication for the given request- Parameters:
pub-
-
setUrl
public final void setUrl(java.lang.String url)
Sets the URL.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.- Parameters:
url- the full URL of the page accessed initially- See Also:
setJcmsContext(JcmsJspContext)
-
getUrl
public final java.lang.String getUrl()
Retrieve the URL of the initial request or any URL that might have specified usingsetUrl(String).- Returns:
- an abolute URL (such as "http://domain.tld/webapp/servlet?querystring")
-
setBaseUrl
public final void setBaseUrl(java.lang.String baseUrl)
Sets the base URL.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.- Parameters:
baseUrl- the base URL of the page accessed initially- See Also:
setJcmsContext(JcmsJspContext)
-
getBaseUrl
public final java.lang.String getBaseUrl()
Retrieve the base URL of the initial request or any base URL that might have specified usingsetBaseUrl(String).- Returns:
- an abolute URL (such as "http://domain.tld/webapp/")
-
setMethod
public final void setMethod(java.lang.String method)
Sets the method.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.- Parameters:
method- the method of the page accessed initially- See Also:
setJcmsContext(JcmsJspContext)
-
getMethod
public final java.lang.String getMethod()
Retrieve the method of the initial request or any base URL that might have specified usingsetMethod(String).- Returns:
- String method
-
setContextPath
public final void setContextPath(java.lang.String contextPath)
Sets the context path.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.- Parameters:
contextPath- the base URL of the page accessed initially- See Also:
setJcmsContext(JcmsJspContext)
-
getContextPath
public final java.lang.String getContextPath()
Retrieve the context path of the initial request or any context path that might have specified usingsetContextPath(String).- Returns:
- a path (such as "/webapp" or "" for a webapp in the root context)
-
setResourcePath
public final void setResourcePath(java.lang.String resourcePath)
Sets the resource path.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.- Parameters:
resourcePath- the resource path- See Also:
setJcmsContext(JcmsJspContext)
-
getResourcePath
public final java.lang.String getResourcePath()
Retrieve the original request resource path or any resource path that might have specified usingsetResourcePath(String).- Returns:
- a relative path such as "/servlet/path/info"
- See Also:
ServletUtil.getResourcePath(HttpServletRequest)
-
setParameterMap
public final void setParameterMap(java.util.Map<java.lang.String,java.lang.String[]> parameterMap)
Sets the request parameter Map.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.- Parameters:
parameterMap- a Map containing parameter names as keys and parameter values as map values. This map will be cloned to make sure any modification does not impact your original map and vice versa.- See Also:
setJcmsContext(JcmsJspContext)
-
getParameterMap
public final java.util.Map<java.lang.String,java.lang.String[]> getParameterMap()
Retrieve the map of paramaters available for the original request or map path that might have specified usingsetParameterMap(Map).- Returns:
- a Map containing parameter names as keys and parameter values as map values. The keys in the parameter map are of type String. The values in the parameter map are of type String array.
-
setJcmsContext
public void setJcmsContext(JcmsJspContext jcmsContext)
Sets the following values from values found in the specified JcmsJspContext.
Values are not retrieved from context if they have already been set through their setter.- Logged Member
- User Lang
- Workspace
- Ctx Categories
- Resource Path
- Parameter Map
- Redirect
- forceAdminIcon and printview
- Parameters:
jcmsContext- the JcmsJspContext
-
deflate
public java.lang.String deflate()
-
inflate
public void inflate(java.lang.String data, javax.servlet.http.HttpServletRequest request)
-
writeObject
protected void writeObject(java.util.Map<java.lang.String,java.lang.Object> map)
-
readObject
protected void readObject(java.util.Map<java.lang.String,java.lang.Object> map, javax.servlet.http.HttpServletRequest request)
-
glp
public java.lang.String glp(java.lang.String key, java.lang.Object... params)Resolve a language property in the current user language.- Parameters:
key- the language property to resolve, for example"ui.com.lbl.contents"params- the parameters to use when resolving the format of the given property- Returns:
- the resolved property
- Since:
- jcms-5.0.0
-
checkAccess
public boolean checkAccess(java.lang.String resource)
Check if the current member is authorized to access the specified resource.boolean isAuthorized = checkAccess(loggedMember, "admin/dev/store-cleaner");
- Parameters:
resource- a resource URI using a path representation, eg "admin/dev/store-cleaner"- Returns:
- true if the access is authorized, false otherwise
- Since:
- jcms-7.0
-
checkAccess
public boolean checkAccess(java.lang.String resource, java.util.Map<java.lang.String,java.lang.Object> ctxt)Check if the current member is authorized to access the specified resource.boolean isAuthorized = checkAccess(loggedMember, "admin-ws/types/content", ctxtMap);
- Parameters:
resource- a resource URI using a path representation, eg "admin/dev/store-cleaner"ctxt- an optional context map- Returns:
- true if the access is authorized, false otherwise
- Since:
- jcms-7.0
-
debug
public boolean debug(java.lang.String key)
-
-