Package com.jalios.jcms.context
Class AbstractJcmsAjaxContext
java.lang.Object
com.jalios.jcms.context.AbstractJcmsAjaxContext
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
AbstractCtxMenu,JcmsJspAjaxContext
Convenient 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.
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringprotected Caddyprotected Channelprotected Stringprotected Category[]protected Categoryprotected booleanprotected booleanprotected booleanprotected booleanprotected booleanprotected Memberprotected Stringprotected PortalInterfaceprotected Categoryprotected Publicationprotected Stringprotected Stringprotected Stringprotected Stringprotected Localeprotected ZoneIdprotected Workspaceprotected String -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedUse 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.protectedBuild a new JcmsAjaxContext based on information available in the JcmsJspContext. -
Method Summary
Modifier and TypeMethodDescriptionbooleancheckAccess(String resource) Check if the current member is authorized to access the specified resource.booleancheckAccess(String resource, Map<String, Object> ctxt) Check if the current member is authorized to access the specified resource.booleandeflate()final StringRetrieve the base URL of the initial request or any base URL that might have specified usingsetBaseUrl(String).getCaddy()Returns the caddy stored in current session.final StringRetrieve the context path of the initial request or any context path that might have specified usingsetContextPath(String).final Category[]Retrieve the contextual categories to used for refinementRetrieve the current category, either the category available at the time of the initial request or the one overrided bysetCurrentCategory(Category)final MemberRetrieve the logged Member at the time of the initial request.final StringRetrieve the method of the initial request or any base URL that might have specified usingsetMethod(String).Retrieve the map of paramaters available for the original request or map path that might have specified usingsetParameterMap(Map).Returns the stored portal interface for the given requestRetrieve the portal category, either the category available at the time of the initial request or the one overrided bysetPortalCategory(Category)Returns the stored Publication for the given requestfinal StringRetrieve the original request resource path or any resource path that might have specified usingsetResourcePath(String).final StringgetUrl()Retrieve the URL of the initial request or any URL that might have specified usingsetUrl(String).final StringRetrieve the country to use for localized features.final StringRetrieve the language to use for localized message and localized features.final LocaleRetrieve the Locale to use for localized message and localized features.final ZoneIdRetrieve the ZoneId to use for zoned date related features.final WorkspaceRetrieve the workspace, either the workspace available at the time of the initial request or the one overrided bysetWorkspace(Workspace)getZone()Return the zone statusResolve a language property in the current user language.voidbooleanisAdmin()Return the admin status of the logged user.booleanReturn the isInFrontOffice statusbooleanisLogged()Return the user logging status for the initial request.protected voidreadObject(Map<String, Object> map, javax.servlet.http.HttpServletRequest request) final voidsetBaseUrl(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.final voidsetContextPath(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.final 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.final 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.final voidSets the method.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.final voidsetParameterMap(Map<String, 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.voidSet the Publication for the given requestfinal voidsetResourcePath(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.final voidSets the URL.
If this method is called beforesetJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.final voidsetUserCountry(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.final voidsetUserLang(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.final voidsetUserLocale(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.final voidsetUserZoneId(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.final 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(Map<String, Object> map)
-
Field Details
-
channel
-
debug
protected transient boolean debug -
loggedMember
-
userLang
-
userCountry
-
userLocale
-
userZoneId
-
isLogged
protected transient boolean isLogged -
isAdmin
protected transient boolean isAdmin -
workspace
-
currentCategory
-
portalCategory
-
ctxCategories
-
zone
-
isInFrontOffice
protected transient boolean isInFrontOffice -
caddy
-
portal
-
pub
-
url
-
baseUrl
-
contextPath
-
resourcePath
-
parameterMap
-
method
-
isWindows
protected transient boolean isWindows
-
-
Constructor Details
-
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
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 Details
-
setLoggedMember
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:
-
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
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:
-
getUserLang
Retrieve the language to use for localized message and localized features.- Returns:
- an ISO 639 language code (e.g. "en")
-
setUserCountry
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:
-
getUserCountry
Retrieve the country to use for localized features.- Returns:
- an ISO 3166-1 language code (e.g. "FR")
-
setUserLocale
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:
-
getUserLocale
Retrieve the Locale to use for localized message and localized features.- Returns:
- a Locale object
-
setUserZoneId
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:
-
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
Return the zone status- Returns:
- String the zone
-
setWorkspace
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:
-
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
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
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
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
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
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:
-
getCtxCategories
Retrieve the contextual categories to used for refinement- Returns:
- an array of Category (may be null or empty)
-
getCaddy
Returns the caddy stored in current session.- Returns:
- the Caddy of the session
-
getPortal
Returns the stored portal interface for the given request- Returns:
- PortalInterface
-
setPortal
Set the portal interface for the given request- Parameters:
portal-
-
getPublication
Returns the stored Publication for the given request- Returns:
- Publication
-
setPublication
Set the Publication for the given request- Parameters:
pub-
-
setUrl
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:
-
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
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:
-
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
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:
-
getMethod
Retrieve the method of the initial request or any base URL that might have specified usingsetMethod(String).- Returns:
- String method
-
setContextPath
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:
-
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
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:
-
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:
-
setParameterMap
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:
-
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
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
-
inflate
-
writeObject
-
readObject
-
glp
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
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
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
-