The Common Template

All HTTP requests handled by an Escenic publication are either requests for content items or requests for section pages. Each incoming request is processed by Escenic servlet filters (see Servlet Filters), which add the appropriate beans to the request scope and finally pass it to the "master" template (usually called common.jsp).

common.jsp usually has very little content. Here is temp-dev's common.jsp:

<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="no" lang="no">
  <head>
    <meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" />
    <c:url var="css" value="/css/main.css" scope="request"/>
    <link rel="stylesheet" type="text/css" href="${css}">
    <title>
      ${publication.name}
      <c:if test="${requestScope['com.escenic.context']=='art'}">
        - ${article.fields.title} 
      </c:if>
    </title>
  </head>
  <body> 
    <jsp:include page="wireframe/default.jsp"/>
  </body>
</html>

The first line identifies the file as a JSP file, and the second line is a taglib declaration identifying the JSTL core tag library that is to be used in the file.

The remainder of the file contains a template for generating the outer shell of an XHTML document: the html, head and body elements.

The first things to take note of here are:

  • The JSTL url tag is used to create a variable (contextUrl) containing a context URL (the current folder, "/") that can be used as a base for constructing further URLs. Since it is created with request scope, it can be used in any of the other JSP files called while processing this request.

  • The variable is immediately used to create a link to the CSS file that will determine the appearance of all generated output. The JSP expression language is used to reference the variable: ${contextUrl}.

Three other variables are referenced to create the content of the HTML title element:

requestScope

Is a JSP implicit object, a standard variable available in all JSP requests. It is used to hold request scope attributes: named values that are available for the duration of a request. In this case we are testing the value of the request scope attribute com.escenic.context, which is always present in Escenic requests. It is added to the request by the servlet filters, and it contains either "art" if the current request is a content item (article) request or "sec" if the current request is a section request. (For a fuller explanation of the term request scope attribute, see Bean Scope).

publication

is an Escenic request bean. The Escenic request beans are, like com.escenic.context, request scope attributes that are added to the requestScope by the servlet filters. The publication request bean is a Publication bean that is available in all requests. Here, the bean's name property is retrieved.

article

is also an Escenic request bean (PresentationArticle). However, the article bean is only available in content item requests: if the current request is a content item request, then the content of the article's title field is retrieved for inclusion in the HTML title element.

common.jsp then passes responsibility for generating the body of the HTML document to another template, wireframe/default.jsp.