com.jalios.jcms.context
Class AbstractJcmsAjaxContext

java.lang.Object
  extended by com.jalios.jcms.context.AbstractJcmsAjaxContext
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
AbstractCtxMenu, JcmsJspAjaxContext, TreeCat

public abstract class AbstractJcmsAjaxContext
extends Object
implements Serializable

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.

 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
protected  String baseUrl
           
protected  Caddy caddy
           
protected  Channel channel
           
protected  String contextPath
           
protected  Category[] ctxCategories
           
protected  Category currentCategory
           
protected  boolean debug
           
protected  boolean isAdmin
           
protected  boolean isIE
           
protected  boolean isInFrontOffice
           
protected  boolean isLogged
           
protected  boolean isWindows
           
protected  Member loggedMember
           
protected  String method
           
protected  Map<String,String[]> parameterMap
           
protected  PortalInterface portal
           
protected  Category portalCategory
           
protected  Publication pub
           
protected  String resourcePath
           
protected  String url
           
protected  String userLang
           
protected  Locale userLocale
           
protected  Workspace workspace
           
protected  String zone
           
 
Constructor Summary
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 setter setJcmsContext(JcmsJspContext) after.
protected AbstractJcmsAjaxContext(JcmsJspContext ctxt)
          Build a new JcmsAjaxContext based on information available in the JcmsJspContext.
 
Method Summary
 boolean checkAccess(String resource)
          Check if the current member is authorized to access the specified resource.
 boolean checkAccess(String resource, Map<String,Object> ctxt)
          Check if the current member is authorized to access the specified resource.
 boolean debug(String key)
           
 String deflate()
           
 String getBaseUrl()
          Retrieve the base URL of the initial request or any base URL that might have specified using setBaseUrl(String).
 Caddy getCaddy()
          Returns the caddy stored in current session.
 String getContextPath()
          Retrieve the context path of the initial request or any context path that might have specified using setContextPath(String).
 Category[] getCtxCategories()
          Retrieve the contextual categories to used for refinement
 Category getCurrentCategory()
          Retrieve the current category, either the category available at the time of the initial request or the one overrided by setCurrentCategory(Category)
 Member getLoggedMember()
          Retrieve the logged Member at the time of the initial request.
 String getMethod()
          Retrieve the method of the initial request or any base URL that might have specified using setMethod(String).
 Map<String,String[]> getParameterMap()
          Retrieve the map of paramaters available for the original request or map path that might have specified using setParameterMap(Map).
 PortalInterface getPortal()
          Returns the stored portal interface for the given request
 Category getPortalCategory()
          Retrieve the portal category, either the category available at the time of the initial request or the one overrided by setPortalCategory(Category)
 Publication getPublication()
          Returns the stored Publication for the given request
 String getResourcePath()
          Retrieve the original request resource path or any resource path that might have specified using setResourcePath(String).
 String getUrl()
          Retrieve the URL of the initial request or any URL that might have specified using setUrl(String).
 String getUserLang()
          Retrieve the language to use for localized message and localized features.
 Locale getUserLocale()
          Retrieve the Locale to use for localized message and localized features.
 Workspace getWorkspace()
          Retrieve the workspace, either the workspace available at the time of the initial request or the one overrided by setWorkspace(Workspace)
 String getZone()
          Return the zone status
 String glp(String key, Object... params)
          Resolve a language property in the current user language.
 void inflate(String data, javax.servlet.http.HttpServletRequest request)
           
 boolean isAdmin()
          Return the admin status of the logged user.
 boolean isInFrontOffice()
          Return the isInFrontOffice status
 boolean isLogged()
          Return the user logging status for the initial request.
protected  void readObject(Map<String,Object> map, javax.servlet.http.HttpServletRequest request)
           
 void setBaseUrl(String baseUrl)
          Sets the base URL.
If this method is called before setJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.
 void setContextPath(String contextPath)
          Sets the context path.
If this method is called before setJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.
 void setCtxCategories(Category[] ctxCategories)
          Sets the contextual categories used for refinement.
If this method is called before setJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.
 void setCurrentCategory(Category currentCategory)
          Set the current category.
If this method is called before setJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.
 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.
 void setLoggedMember(Member loggedMember)
          Sets the logged member.
If this method is called before setJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.
 void setMethod(String method)
          Sets the method.
If this method is called before setJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.
 void setParameterMap(Map<String,String[]> parameterMap)
          Sets the request parameter Map.
If this method is called before setJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.
 void setPortal(PortalInterface portal)
          Set the portal interface for the given request
 void setPortalCategory(Category portalCategory)
          Set the portal category.
If this method is called before setJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.
 void setPublication(Publication pub)
          Set the Publication for the given request
 void setResourcePath(String resourcePath)
          Sets the resource path.
If this method is called before setJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.
 void setUrl(String url)
          Sets the URL.
If this method is called before setJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.
 void setUserLang(String userLang)
          Sets the user lang.
If this method is called before setJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.
 void setUserLocale(Locale userLocale)
          Sets the user Locale.
If this method is called before setJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.
 void setWorkspace(Workspace workspace)
          Sets the workspace.
If this method is called before setJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.
protected  void writeObject(Map<String,Object> map)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

channel

protected transient Channel channel

debug

protected transient boolean debug

loggedMember

protected transient Member loggedMember

userLang

protected transient String userLang

userLocale

protected transient Locale userLocale

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 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 String url

baseUrl

protected transient String baseUrl

contextPath

protected transient String contextPath

resourcePath

protected transient String resourcePath

parameterMap

protected transient Map<String,String[]> parameterMap

method

protected transient 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 setter setJcmsContext(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 before setJcmsContext(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(String userLang)
Sets the user lang.
If this method is called before setJcmsContext(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 String getUserLang()
Retrieve the language to use for localized message and localized features.

Returns:
an ISO 639 language code (e.g. "en")

setUserLocale

public final void setUserLocale(Locale userLocale)
Sets the user Locale.
If this method is called before setJcmsContext(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 Locale getUserLocale()
Retrieve the Locale to use for localized message and localized features.

Returns:
a Locale 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 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 before setJcmsContext(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 by setWorkspace(Workspace)

Returns:
a Workspace or null if not available

setCurrentCategory

public void setCurrentCategory(Category currentCategory)
Set the current category.
If this method is called before setJcmsContext(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 by setCurrentCategory(Category)

Returns:
the current category (if set) or null.

setPortalCategory

public void setPortalCategory(Category portalCategory)
Set the portal category.
If this method is called before setJcmsContext(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 by setPortalCategory(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 before setJcmsContext(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(String url)
Sets the URL.
If this method is called before setJcmsContext(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 String getUrl()
Retrieve the URL of the initial request or any URL that might have specified using setUrl(String).

Returns:
an abolute URL (such as "http://domain.tld/webapp/servlet?querystring")

setBaseUrl

public final void setBaseUrl(String baseUrl)
Sets the base URL.
If this method is called before setJcmsContext(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 String getBaseUrl()
Retrieve the base URL of the initial request or any base URL that might have specified using setBaseUrl(String).

Returns:
an abolute URL (such as "http://domain.tld/webapp/")

setMethod

public final void setMethod(String method)
Sets the method.
If this method is called before setJcmsContext(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 String getMethod()
Retrieve the method of the initial request or any base URL that might have specified using setMethod(String).

Returns:
String method

setContextPath

public final void setContextPath(String contextPath)
Sets the context path.
If this method is called before setJcmsContext(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 String getContextPath()
Retrieve the context path of the initial request or any context path that might have specified using setContextPath(String).

Returns:
a path (such as "/webapp" or "" for a webapp in the root context)

setResourcePath

public final void setResourcePath(String resourcePath)
Sets the resource path.
If this method is called before setJcmsContext(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 String getResourcePath()
Retrieve the original request resource path or any resource path that might have specified using setResourcePath(String).

Returns:
a relative path such as "/servlet/path/info"
See Also:
ServletUtil.getResourcePath(HttpServletRequest)

setParameterMap

public final void setParameterMap(Map<String,String[]> parameterMap)
Sets the request parameter Map.
If this method is called before setJcmsContext(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 Map<String,String[]> getParameterMap()
Retrieve the map of paramaters available for the original request or map path that might have specified using setParameterMap(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. This method MUST be called when this object is created during the inital request (as opposed to other AJAX request occuring after).

Parameters:
jcmsContext - the JcmsJspContext

deflate

public String deflate()

inflate

public void inflate(String data,
                    javax.servlet.http.HttpServletRequest request)

writeObject

protected void writeObject(Map<String,Object> map)

readObject

protected void readObject(Map<String,Object> map,
                          javax.servlet.http.HttpServletRequest request)

glp

public String glp(String key,
                  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(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(String resource,
                           Map<String,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 optionnal context map
Returns:
true if the access is authorized, false otherwise
Since:
jcms-7.0

debug

public boolean debug(String key)


Copyright © 2001-2010 Jalios SA. All Rights Reserved.