Class AbstractJcmsAjaxContext

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

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:
  • Field Details

    • channel

      protected transient Channel channel
    • debug

      protected transient boolean debug
    • loggedMember

      protected transient Member loggedMember
    • userLang

      protected transient String userLang
    • userCountry

      protected transient String userCountry
    • userLocale

      protected transient Locale userLocale
    • userZoneId

      protected transient 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 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
  • 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 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 Details

    • 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:
    • 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:
    • 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")
    • setUserCountry

      public final void setUserCountry(String userCountry)
      Sets the user country.
      If this method is called before setJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.
      Parameters:
      userCountry - the user country
      See Also:
    • getUserCountry

      public final 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(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:
    • getUserLocale

      public final Locale getUserLocale()
      Retrieve the Locale to use for localized message and localized features.
      Returns:
      a Locale object
    • setUserZoneId

      public final void setUserZoneId(ZoneId userZoneId)
      Sets the user ZoneId.
      If this method is called before setJcmsContext(JcmsJspContext), its value won't be overiden by values retrieved from the JcmsJspContext.
      Parameters:
      userZoneId - the user ZoneId
      See Also:
    • getUserZoneId

      public final 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 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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.
      • Logged Member
      • User Lang
      • Workspace
      • Ctx Categories
      • Resource Path
      • Parameter Map
      • Redirect
      • forceAdminIcon and printview
      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 optional context map
      Returns:
      true if the access is authorized, false otherwise
      Since:
      jcms-7.0
    • debug

      public boolean debug(String key)