Class JcmsJspContext

java.lang.Object
com.jalios.jcms.context.JcmsContext
com.jalios.jcms.context.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(Channel.JCMS_CONTEXT_REQUEST_ATTRIBUTE)

     

  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.jspf" %>
    
     <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 Details

  • Constructor Details

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

    • 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 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(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, Set<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, 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, 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(String ajaxReqId)
      Set the Ajax Request Id for the current JcmsContext
      Parameters:
      ajaxReqId - the Ajax Request Id
    • getAjaxRequestId

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

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

      public Object getAjaxRequestAttribute(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 Object removeAjaxRequestAttribute(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
    • setPageTitle

      public void setPageTitle(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 String getPageTitle(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(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 String getPageZone(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(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 String getDocType(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(String httpequiv, String content)
      Adds http-equiv header.
      Parameters:
      httpequiv - the header key
      content - the header value
      Since:
      jcms-5.6.0
    • getHttpEquivHeaders

      public Map<String,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(String name, String content)
      Adds http-name header.
      Parameters:
      name - the header key
      content - the header value
      Since:
      jcms-5.6.0
    • getHttpNameHeaders

      public Map<String,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(String name, String value)
      Adds body attributes.
      Parameters:
      name - the attribute name
      value - the attribute value
      Since:
      jcms-5.7.0
    • getBodyAttributes

      public Map<String,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(String content)
      Adds inline content header.
      Parameters:
      content - the inline content to add
      Since:
      jcms-5.7.0
    • getCustomHeaders

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

      public void addStyleHeader(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(String cssquery, 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 Map<String,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(String path)
      Adds a prefetch header.
      Parameters:
      path - the prefetch path
    • addCSSHeader

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

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

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

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

      public Map<String,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 Map<String,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 Map<String,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 Set<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 Set<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 LinkedHashMap<String,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 LinkedHashMap<String,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 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 Map getAllHeadersDiffMap(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(Map oldMap)
      Adds header diff map to current context
      Parameters:
      oldMap - the Map to work with
    • addWebAssets

      public void addWebAssets(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:
    • addJavaScriptModule

      public void addJavaScriptModule(String path)
      Add a javacript module to the current page
      Parameters:
      path - a relative JavaScript path (e.g "plugins/MyPlugin/js/plugin.js")
      Since:
      jcms-11.0.0
    • addJavaScript

      public void addJavaScript(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(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(Collection<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
    • getJavaScriptModuleSet

      public LinkedHashSet<String> getJavaScriptModuleSet()
      Retrieves the javascript module files that have been setup for current page
      Returns:
    • getFinalJavaScriptModuleSet

      public LinkedHashSet<String> getFinalJavaScriptModuleSet()
    • getJavaScriptSet

      public LinkedHashSet<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 LinkedHashSet<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.
    • addJavaScriptCode

      public void addJavaScriptCode(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 LinkedHashSet<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(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
    • canAccessAdminArea

      public boolean canAccessAdminArea()
      Returns:
      true if loggedMember has access of resource "admin/" and request is valid admin IP.
      Since:
      jcms-11.0
      See Also:
    • checkCSRF

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

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

      public String addHandlebarTemplate(String name, 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 String getHandlebarTemplates()
      Returns:
      all handlebar templates declared in current page
    • addSvgSpriteIcon

      public void addSvgSpriteIcon(String spriteFolderName, String iconId)
    • getSvgSprites

      public Map<String,Set<String>> getSvgSprites()
      Retrieve the map of SVG included in THIS request.
      Returns:
      a Map, never return nul
    • getSvgSpritesHtml

      public String getSvgSpritesHtml()
    • addAvoidanceLink

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

      public Map<String,String> getAvoidanceLinks()
      Returns:
      all avoidance links for current page