Class JcmsJspContext

  • All Implemented Interfaces:
    JcmsConstants, JaliosConstants
    Direct Known Subclasses:
    CaddyPopinHandler, JcmsFormHandler, MediaBrowserHandler

    public class JcmsJspContext
    extends JcmsContext
    This class allows you to keep track of variables declare and initialized by JCMS.

    You can either :

    1. Use the one declared in request attributes with :

       

      JcmsJspContext jspCtx = request.getAttribute("jcmsContext")

       

    2. Instantiate a new one with :

       

      JcmsJspContext jspCtx = new JcmsJspContext(pageContext)

       

    3. Create your own bean/handler classes by extending this class.

       

      In your class:
       package custom;
      
       public class HelloUser extends com.jalios.jcms.JcmsPageContext {
         private static final Logger logger = Logger.getLogger(HelloUser.class);
         public doHelloUser() throws java.io.IOException {
           logger.debug("doHelloUser()");
           if (isLogged) {
             out.println(glp("myhello.welcome-msg", loggedMember.getFriendlyName()));
           } else {
             out.println(glp("myhello.welcome-guest-msg"));
           }
         }
       }
       
      Declare your class as JavaBean in your JSP with the pageContext param set:
       
       <%@ include file="/doInitPage.jsp" %>
      
       <jsp:useBean id="welcomeUserBean" scope="page" class="custom.WelcomeUser">
         <jsp:setProperty name="welcomeUserBean" property="pageContext" value="<%= pageContext %>"/>
       </jsp:useBean>
       <% welcomeUserBean.doHelloUser(); %>
       
       
    Since:
    jcms-5.0.0
    Author:
    Olivier Jaquemet
    • Field Detail

      • pageContext

        protected javax.servlet.jsp.PageContext pageContext
      • out

        protected javax.servlet.jsp.JspWriter out
      • initEditIcon

        protected boolean initEditIcon
      • editIcon

        protected boolean editIcon
      • AJAX_REQUEST_ATTRIBUTES

        public static final java.lang.String AJAX_REQUEST_ATTRIBUTES
        See Also:
        Constant Field Values
      • HTTPEQUIV_HEADER

        public static final java.lang.String HTTPEQUIV_HEADER
        See Also:
        Constant Field Values
      • httpequivMap

        public static final java.util.LinkedHashMap<java.lang.String,​java.lang.String> httpequivMap
      • httpnameMap

        public static final java.util.LinkedHashMap<java.lang.String,​java.lang.String> httpnameMap
      • cssfoMap

        public static final java.util.LinkedHashMap<java.lang.String,​java.lang.String> cssfoMap
      • cssboMap

        public static final java.util.LinkedHashMap<java.lang.String,​java.lang.String> cssboMap
      • jsfoSet

        public static final java.util.LinkedHashSet<java.lang.String> jsfoSet
      • jsboSet

        public static final java.util.LinkedHashSet<java.lang.String> jsboSet
    • Constructor Detail

      • JcmsJspContext

        public JcmsJspContext()
        If you use this constructor, pageContext or request must be initialized at a later time
      • JcmsJspContext

        public JcmsJspContext​(javax.servlet.jsp.PageContext pageContext)
    • Method Detail

      • forceUpdate

        public void forceUpdate()
        Will force an update of all JcmsContext variables (retrieve it from the request) Update the protected variable initDone (to false at begining of method, and true on end).
        Overrides:
        forceUpdate in class JcmsContext
      • setPageContext

        public void setPageContext​(javax.servlet.jsp.PageContext pageContext)
        Page context setter, will initialize the following members : - page context - out - request - response then force an update of all variables
        Parameters:
        pageContext - the jsp PageContext to be used for initialization of this JcmsJspContext
      • getPageContext

        public javax.servlet.jsp.PageContext getPageContext()
      • getPublication

        public Publication getPublication()
        Returns:
        the current Content or Form if not null, or the Portlet (or null). Slow: we DO NOT cache this value (so do not use this getter every 2millisecs).
      • getContentForm

        public Publication getContentForm()
        Returns:
        the current Content or Form (if set in publication) or null. Slow: we DO NOT cache this value (so do not use this getter every 2millisecs).
      • getPortlet

        public PortalElement getPortlet()
        Returns:
        the current portlet (if set) or null. Slow: portlet can change during the request, we DO NOT cache this value (so do not use this getter every 2millisecs)
      • getPortal

        public PortalInterface getPortal()
        Returns:
        the current portal (if set) or null. Fast: portal do not change during all the request, first time we have it, we cache it.
      • getCurrentCategory

        public Category getCurrentCategory()
        Returns:
        the current category (if set) or null. Fast: current category do not change during all the request, first time we have it, we cache it.
      • getPortalCategory

        public Category getPortalCategory()
        Returns:
        the current portal category (if set) or null. Fast: current portal category do not change during all the request, first time we have it, we cache it.
      • getCtxCategories

        public Category[] getCtxCategories()
        Returns:
        the current portal category (if set) or null. current portal category do not change during all the request, first time we have it, we cache it.
      • getTemplateUsage

        public java.lang.String getTemplateUsage()
        Returns:
        the current template usage use to find which template to include. Slow: template usage can change during the request, we DO NOT cache this value (so do not use this getter every 2millisecs)
      • isPrintView

        public boolean isPrintView()
        Returns:
        true if the current page is displayed with printView.
        Since:
        jcms-6.0.0
      • setTemplateUsage

        public void setTemplateUsage​(java.lang.String usage)
        Set the current template usage. If kin is empty then remove usage value (this will default to default value).
        Parameters:
        usage - the current template usage
      • registerDisplayContext

        public void registerDisplayContext​(DisplayContext ctxt)
        Register the given DisplayContext into the JcmsContext
        Parameters:
        ctxt - the DisplayContext
      • debugDisplayContext

        public void debugDisplayContext()
      • isEditIcon

        @Deprecated
        public boolean isEditIcon()
        Deprecated.
        Use new method isEditIcon with workspace and data as parameters
        Returns true if edit area must be displayed.
        • Check property channel.default-show-adminicon
        • Check logged member and if it is worker
        • Check if it is a print view
        • Check if sothing has been forced in request or session
        Returns:
        boolean true if the edit area must be displayed
      • isEditIconForPublish

        public boolean isEditIconForPublish​(Workspace ws,
                                            java.util.Set<java.lang.Class<?>> classSet)
        Parameters:
        ws - the Workspace used to check rights
        classSet - the Set of Publication class to edit used to check publish rights Returns true if edit area must be displayed.
        • Check property channel.default-show-adminicon
        • Check logged member and if it is worker of the workspace or if it can publish a instance of the specified classes
        • Check if it is a print view
        • Check if sothing has been forced in request or session
        Returns:
        boolean true if the edit area must be displayed
      • isEditIconForPublish

        public boolean isEditIconForPublish​(Workspace ws,
                                            java.lang.Class clazz)
        Parameters:
        ws - the Workspace used to check rights
        clazz - the Publication class to edit used to check publish rights Returns true if edit area must be displayed.
        • Check property channel.default-show-adminicon
        • Check logged member and if it is worker of the workspace or if it can publish an instance of the class
        • Check if it is a print view
        • Check if sothing has been forced in request or session
        Returns:
        boolean true if the edit area must be displayed
      • isEditIcon

        public boolean isEditIcon​(Workspace ws,
                                  Publication pub)
        Parameters:
        ws - the Workspace used to check rights
        pub - the Publication to edit used to check rights Returns true if edit area must be displayed.
        • Check property channel.default-show-adminicon
        • Check logged member and if it is worker of the workspace
        • Check if it is a print view
        • Check if sothing has been forced in request or session
        Returns:
        boolean true if the edit area must be displayed
      • showEditIcon

        public boolean showEditIcon​(Workspace ws,
                                    Data pub)
        Parameters:
        ws - the Workspace used to check rights
        pub - the Data to edit used to check rights Returns true if edit area must be displayed.
        • Check property channel.default-show-adminicon
        • Check logged member and if it is worker of the workspace
        • Check if it is a print view
        • Check if sothing has been forced in request or session
        Returns:
        boolean true if the edit area must be displayed
      • showEditIcon

        public boolean showEditIcon​(Workspace ws,
                                    Data pub,
                                    java.lang.Class clazz)
        Parameters:
        ws - the Workspace used to check rights
        pub - the Data to edit used to check rights
        clazz - the class of Data to edit used to check rights Returns true if edit area must be displayed.
        • Check property channel.default-show-adminicon
        • Check logged member and if it is worker of the workspace
        • Check if it is a print view
        • Check if sothing has been forced in request or session
        Returns:
        boolean true if the edit area must be displayed
      • showEditIcon

        public boolean showEditIcon()
        Returns editIcon state. If false EditArea should be hidden.
        Returns:
        boolean true to display EditArea
      • setShowEditIcon

        public void setShowEditIcon​(boolean show)
        Set the editIcon state to define if the EditArea must be hidden
        Parameters:
        show - boolean true to display EditArea
      • setEditIcon

        public void setEditIcon​(boolean editIcon,
                                boolean request,
                                boolean session)
        Force the editIcon stat to the given value for the current request or session.
        Parameters:
        editIcon - the new edit Icon state
        request - store in request
        session - store in session
      • forceEditIcon

        public void forceEditIcon​(boolean editIcon)
        Force the editIcon stat to the given value for the current request.
        Parameters:
        editIcon - the new edit Icon state
      • setAjaxRequestId

        public void setAjaxRequestId​(java.lang.String ajaxReqId)
        Set the Ajax Request Id for the current JcmsContext
        Parameters:
        ajaxReqId - the Ajax Request Id
      • getAjaxRequestId

        public java.lang.String getAjaxRequestId()
        Retrieve the Ajax Request Id for the current request
        Returns:
        ajaxReqId the Ajax Request Id
      • setAjaxRequestAttribute

        public void setAjaxRequestAttribute​(java.lang.String key,
                                            java.lang.Object value)
        Set a request attribute persistent in the AJAX request Scope
        Parameters:
        key - the key
        value - the value
      • getAjaxRequestAttribute

        public java.lang.Object getAjaxRequestAttribute​(java.lang.String key)
        Returns the attribute value associated to given key if the attribute has been stored for the ajax scope
        Parameters:
        key - the key
        Returns:
        value the value
      • removeAjaxRequestAttribute

        public java.lang.Object removeAjaxRequestAttribute​(java.lang.String key)
        Remove a request attribute persistent in the AJAX request Scope. Also removed if present in standard request.
        Parameters:
        key - the key
        Returns:
        value the value
      • getJSONBridge

        public org.jabsorb.JSONRPCBridge getJSONBridge()
        Returns the JSON-RPC Bridge declared by the InitFilter
        Returns:
        JSONRPCBridge the JSON-RPC Bridge
      • setPageTitle

        public void setPageTitle​(java.lang.String title)
        This method set custom page title to append to header tag. Store it in the request attribute "title"
        Parameters:
        title - the custom title header
        Since:
        jcms-5.6.0
      • getPageTitle

        public java.lang.String getPageTitle​(java.lang.String defaultValue)
        This method return the title of the page
        Parameters:
        defaultValue - the default value to return
        Returns:
        String pageTitle
        Since:
        jcms-5.6.0
      • setPageZone

        public void setPageZone​(java.lang.String zone)
        This method set page zone then store it in the request attribute "zone" The zone is used to define groups of pages. It may be used in stats to filter on a given zone.
        Parameters:
        zone - the custom zone
        Since:
        jcms-5.6.0
      • getPageZone

        public java.lang.String getPageZone​(java.lang.String defaultValue)
        This method return the zone of the page. It can be Public, WorkArea, AdminArea, ...
        Parameters:
        defaultValue - the default zone
        Returns:
        String zone
        Since:
        jcms-5.6.0
      • setDocType

        public void setDocType​(java.lang.String docType)
        This method set the doctype of the page. Store it in the request attribute "docType"
        Parameters:
        docType - the doc type
        Since:
        jcms-5.6.0
      • getDocType

        public java.lang.String getDocType​(java.lang.String defaultValue)
        This method return the doc type set in request attribute "docType" Otherwise use the default value. doEmptyHeader call it with : <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        Parameters:
        defaultValue - the default value if there is no doctype
        Returns:
        String the doctype to use
        Since:
        jcms-5.6.0
      • addHttpEquivHeader

        public void addHttpEquivHeader​(java.lang.String httpequiv,
                                       java.lang.String content)
        Adds http-equiv header.
        Parameters:
        httpequiv - the header key
        content - the header value
        Since:
        jcms-5.6.0
      • getHttpEquivHeaders

        public java.util.Map<java.lang.String,​java.lang.String> getHttpEquivHeaders()
        Returns a map of Meta httpequiv headers.
        Returns:
        Map a map of Http-equiv Headers
        Since:
        jcms-5.6.0
      • addHttpNameHeader

        public void addHttpNameHeader​(java.lang.String name,
                                      java.lang.String content)
        Adds http-name header.
        Parameters:
        name - the header key
        content - the header value
        Since:
        jcms-5.6.0
      • getHttpNameHeaders

        public java.util.Map<java.lang.String,​java.lang.String> getHttpNameHeaders()
        Returns a map of Meta name headers.
        Returns:
        Map a map of Http-name Headers
        Since:
        jcms-5.6.0
      • addBodyAttributes

        public void addBodyAttributes​(java.lang.String name,
                                      java.lang.String value)
        Adds body attributes.
        Parameters:
        name - the attribute name
        value - the attribute value
        Since:
        jcms-5.7.0
      • getBodyAttributes

        public java.util.Map<java.lang.String,​java.lang.String> getBodyAttributes()
        Returns a map of body attributes
        Returns:
        Map a map of Http-name Headers
        Since:
        jcms-5.7.0
      • addCustomHeader

        public void addCustomHeader​(java.lang.String content)
        Adds inline content header.
        Parameters:
        content - the inline content to add
        Since:
        jcms-5.7.0
      • getCustomHeaders

        public java.util.Collection getCustomHeaders()
        Returns a Map of Custom headers.
        Returns:
        Set a set of Custom Headers
        Since:
        jcms-5.7.0
      • addStyleHeader

        public void addStyleHeader​(java.lang.String cssquery)
        Adds inline style header. All styles will be written between <style type="text/css" media="screen"><!-- --></style>
        Parameters:
        cssquery - the inline style to add
      • addStyleHeader

        public void addStyleHeader​(java.lang.String cssquery,
                                   java.lang.String media)
        Adds inline style header. All styles will be written between <style type="text/css" media="screen"><!-- --></style>
        Parameters:
        cssquery - the inline style to add
        media - the css media
      • getStyleHeaders

        public java.util.Map<java.lang.String,​java.lang.String> getStyleHeaders()
        Returns a Map of Style headers. All styles will be written between <style type="text/css" media="screen"><!-- --></style>
        Returns:
        Map a map of Style Headers
      • addPrefetchHeader

        public void addPrefetchHeader​(java.lang.String path)
        Adds a prefetch header.
        Parameters:
        path - the prefetch path
      • addCSSHeader

        public void addCSSHeader​(java.lang.String path)
        Adds a css header.
        Parameters:
        path - the CSS path
      • addCSSHeader

        public void addCSSHeader​(java.lang.String path,
                                 java.lang.String media)
        Adds a css header.
        Parameters:
        path - the CSS path
        media - the Media path
        Since:
        jcms-5.6.0
      • addCSSHeader

        public void addCSSHeader​(java.lang.String[] paths)
        Adds css headers.
        Parameters:
        paths - the CSS path
      • addCSSHeader

        public void addCSSHeader​(java.util.Map<java.lang.String,​java.lang.String> paths)
        Adds css headers.
        Parameters:
        paths - the CSS path
      • getCSSHeaders

        public java.util.Map<java.lang.String,​java.lang.String> getCSSHeaders()
        Returns a map of CSS headers. Key: the css file Value: the media type
        Returns:
        Map a map of CSS Headers
      • getFrontOfficeCSSHeader

        public static java.util.Map<java.lang.String,​java.lang.String> getFrontOfficeCSSHeader()
        Returns FronOffice CSS header. Usefull for JSP in BackOffice displaying Front Office stuff.
        Returns:
        Map the FrontOffice CSS Headers
        Since:
        jcms-5.6.0
      • getBackOfficeCSSHeader

        public static java.util.Map<java.lang.String,​java.lang.String> getBackOfficeCSSHeader()
        Returns BackOffice CSS header. Usefull for JSP in FrontOffice displaying Back Office stuff.
        Returns:
        Map the BackOffice CSS Headers
        Since:
        jcms-5.6.0
      • getFrontOfficeJavaScriptSet

        public static java.util.Set<java.lang.String> getFrontOfficeJavaScriptSet()
        Returns FronOffice JavaScript files. Useful for JSP in BackOffice displaying Front Office stuff.
        Returns:
        Set the BackOffice JavaScript
        Since:
        jcms-6.0
      • getBackOfficeJavaScriptSet

        public static java.util.Set<java.lang.String> getBackOfficeJavaScriptSet()
        Returns BackOffice JavaScript files. Useful for JSP in FrontOffice displaying Back Office stuff.
        Returns:
        Set the BackOffice JavaScript
        Since:
        jcms-6.0
      • internalSetupEmptyHeader

        public void internalSetupEmptyHeader()
        Convenient method to setup all headers and delegate to policy filters This method must be called before printing headers
        Since:
        jcms-5.7.0
      • getFinalCSSMap

        public java.util.LinkedHashMap<java.lang.String,​java.lang.String> getFinalCSSMap()
        Retrieve the final (ultimate) map of CSS files (and media to be used in the page).

        If csspacker is enabled (property "channel.css-packer.enabled"), the existing css map is converted into a new map of packed resources.

        Returns:
        a LinkedHashMap of path, either css path or csspacker path and relative media.
      • getFinalCSSFooterMap

        public java.util.LinkedHashMap<java.lang.String,​java.lang.String> getFinalCSSFooterMap()
        Retrieve the final (ultimate) map of CSS files to be added in footer if addCSSheader was invoked after doEmptyHeader.jspf execution

        If csspacker is enabled (property "channel.css-packer.enabled"), the existing css map is converted into a new map of packed resources.

        Returns:
        a LinkedHashMap of path, either css path or csspacker path and relative media.
      • disablePacker

        public void disablePacker()
        Force disable CSS & JS packer for all CSS & JS of the current request only.

        This method must be invoked prior to inclusion of doEmptyHeader.jsp (for CSS) and doEmptyFooter (for JS).

        Since:
        jcms-7.1.1 (JCMS-2914)
      • getAllHeadersMap

        public java.util.Map getAllHeadersMap()
        Returns a Map of "Header Name" / "Header Map" that contains all current headers.
        Returns:
        Map the map of headers
        Since:
        jcms 5.7.0
      • getAllHeadersDiffMap

        public java.util.Map getAllHeadersDiffMap​(java.util.Map oldMap)
        Returns a Map of "Header Name" / "Header Map" that contains added items since given map
        Parameters:
        oldMap - the map to diff with
        Returns:
        Map the map of headers
        Since:
        jcms 5.7.0
      • setAllHeadersDiffMap

        public void setAllHeadersDiffMap​(java.util.Map oldMap)
        Adds header diff map to current context
        Parameters:
        oldMap - the Map to work with
      • addWebAssets

        public void addWebAssets​(java.lang.String feature)
        Adds web assets (JS/CSS resources) for given feature.
        Parameters:
        feature - a feature id, declared using properties
        Since:
        jcms-10.0.2
        See Also:
        WebAssetsUtils.addWebAssets(JcmsJspContext, String)
      • addJavaScript

        public void addJavaScript​(java.lang.String path)
        Adds a javascript file to the current page.
        Parameters:
        path - a relative JavaScript path (e.g "plugins/MyPlugin/js/plugin.js")
        Since:
        jcms-6.0
      • addJavaScript

        public void addJavaScript​(java.lang.String[] paths)
        Adds several javascript files to the current page.
        Parameters:
        paths - an array of relative JavaScript path (e.g { "plugins/MyPlugin/js/myscript1.js", "plugins/MyPlugin/js/myscript2.js" })
        Since:
        jcms-6.0
      • addJavaScript

        public void addJavaScript​(java.util.Collection<java.lang.String> pathsColl)
        Adds several javascript files to the current page.
        Parameters:
        pathsColl - a collection of relative JavaScript path (e.g { "plugins/MyPlugin/js/myscript1.js", "plugins/MyPlugin/js/myscript2.js" })
        Since:
        jcms-6.0
      • getJavaScriptSet

        public java.util.LinkedHashSet<java.lang.String> getJavaScriptSet()
        Retrieves the javascript files that have been setup for current page.

        The returned set will only contains file that have been added prior to invocation of this method. Some files may be added after.

        Returns:
        the LinkedHashSet of relative JavaScript path in use for the current request. Return null if the request of this JcmsJspContext has not been set.
        Since:
        jcms-6.0
      • getFinalJavaScriptSet

        public java.util.LinkedHashSet<java.lang.String> getFinalJavaScriptSet()
        Retrieve the final (ultimate) set of JavaScript file to be used in the page.

        If jspacker is enabled, the existing javascript set is converted into a new set of packed resources (unless resource contain a 'nopack' querystring argument).

        Returns:
        a LinkedHashSet of path, either javascript path or jspacker path.
      • workaroundBrowserBaseHrefBug

        public java.lang.String workaroundBrowserBaseHrefBug​(java.lang.String path)
        If needed, apply workaround for specified path. Convert a relative URL into a full URL if needed to workaround IE 8 bug.
        Parameters:
        path - the path to convert to absolute URL, if needed
        Returns:
        the path/URL to use: absolute URL if workaround must be applied, unmodified otherwise.
      • addJavaScriptCode

        public void addJavaScriptCode​(java.lang.String code)
        Adds some javascript CODE to be executed on page load (or an after an ajax update).
           jcmsContext.addJavaScriptCodeOnLoad("someMethod(); alert('Page has been loaded by browser'); ");
         
        Parameters:
        code - some javascript code
      • getJavaScriptCodeSet

        public java.util.LinkedHashSet<java.lang.String> getJavaScriptCodeSet()
        Retrieves the javascript CODE that have been setup to be called on current page load.

        The returned set will only contains code that have been added prior to invocation of this method. Some code may be added after.

        Returns:
        the LinkedHashSet being used for the current request to store JavaScript code. Return null if the request of this JcmsJspContext has not been set.
        Since:
        jcms-6.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
      • checkCSRF

        public boolean checkCSRF()
        Check that the current request validates CSRF prevention requirements.

        This method does not check that CSRF is enabled, see HttpUtil.isCSRFEnabled().

        Returns:
        true if the request is safe (or null), false if the request cannot be guaranteed for safety
      • addHandlebarTemplate

        public java.lang.String addHandlebarTemplate​(java.lang.String name,
                                                     java.lang.String template)
        Adds an handlebar template to the current page In case of an ajax request, if the template is not already in the map of existing template, add it directly in the ajax footer. The template will then be moved with js to the bottom of the body
        Parameters:
        name - the template name
        template - the template content (Html)
        Returns:
        the handlebar template as a String
      • getHandlebarTemplates

        public java.lang.String getHandlebarTemplates()
        Returns:
        all handlebar templates declared in current page
      • addAvoidanceLink

        public void addAvoidanceLink​(java.lang.String target,
                                     java.lang.String label)
        Adds an avoidance link on the page
        Parameters:
        target - the target
        label - the label of the avoidance link
      • getAvoidanceLinks

        public java.util.Map<java.lang.String,​java.lang.String> getAvoidanceLinks()
        Returns:
        all avoidance links for current page