Class AbstractJcmsAjaxContext

  • All Implemented Interfaces:
    java.io.Serializable
    Direct Known Subclasses:
    AbstractCtxMenu, JcmsJspAjaxContext

    public abstract class AbstractJcmsAjaxContext
    extends java.lang.Object
    implements java.io.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 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
      • 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 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

      • 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 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 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 before setJcmsContext(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 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 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 before setJcmsContext(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
      • 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​(java.lang.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 java.lang.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​(java.lang.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 java.lang.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​(java.lang.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 java.lang.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​(java.lang.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 java.lang.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​(java.lang.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)
      • 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 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 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 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 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)