com.ecyrd.jspwiki.ui
Class TemplateManager

java.lang.Object
  extended by com.ecyrd.jspwiki.modules.ModuleManager
      extended by com.ecyrd.jspwiki.ui.TemplateManager

public class TemplateManager
extends ModuleManager

This class takes care of managing JSPWiki templates.

Since:
2.1.62
Author:
Janne Jalkanen

Field Summary
static String DEFAULT_TEMPLATE
           
static String DIRECTORY
          The default directory for the properties.
protected static org.apache.log4j.Logger log
           
static String PROPERTYFILE
          Name of the file that contains the properties.
static String RESOURCE_INCLUDES
           
static String RESOURCE_INLINECSS
          Requests inlined CSS.
static String RESOURCE_JSFUNCTION
          Requests a JavaScript function to be called during window.onload.
static String RESOURCE_SCRIPT
          Requests a script to be loaded.
static String RESOURCE_STYLESHEET
          Requests a stylesheet to be inserted.
 
Fields inherited from class com.ecyrd.jspwiki.modules.ModuleManager
PLUGIN_RESOURCE_LOCATION
 
Constructor Summary
TemplateManager(WikiEngine engine, Properties properties)
           
 
Method Summary
static void addResourceRequest(WikiContext ctx, String type, String resource)
          Adds a resource request to the current request context.
 String findJSP(javax.servlet.jsp.PageContext pageContext, String name)
          An utility method for finding a JSP page.
 String findJSP(javax.servlet.jsp.PageContext pageContext, String template, String name)
          Attempts to locate a JSP page under the given template.
static String getMarker(String type)
          Returns the include resources marker for a given type.
static String[] getResourceRequests(WikiContext ctx, String type)
          Returns resource requests for a particular type.
static String[] getResourceTypes(WikiContext ctx)
          returns all those types that have been requested so far.
 String getTemplateProperty(WikiContext context, String key)
          Returns a property, as defined in the template.
 Set listSkins(javax.servlet.jsp.PageContext pageContext, String template)
          Lists the skins available under this template.
 boolean templateExists(String templateName)
          Check the existence of a template.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESOURCE_JSFUNCTION

public static final String RESOURCE_JSFUNCTION
Requests a JavaScript function to be called during window.onload.

See Also:
Constant Field Values

RESOURCE_STYLESHEET

public static final String RESOURCE_STYLESHEET
Requests a stylesheet to be inserted.

See Also:
Constant Field Values

RESOURCE_SCRIPT

public static final String RESOURCE_SCRIPT
Requests a script to be loaded.

See Also:
Constant Field Values

RESOURCE_INLINECSS

public static final String RESOURCE_INLINECSS
Requests inlined CSS.

See Also:
Constant Field Values

DIRECTORY

public static final String DIRECTORY
The default directory for the properties.

See Also:
Constant Field Values

DEFAULT_TEMPLATE

public static final String DEFAULT_TEMPLATE
See Also:
Constant Field Values

PROPERTYFILE

public static final String PROPERTYFILE
Name of the file that contains the properties.

See Also:
Constant Field Values

RESOURCE_INCLUDES

public static final String RESOURCE_INCLUDES
See Also:
Constant Field Values

log

protected static org.apache.log4j.Logger log
Constructor Detail

TemplateManager

public TemplateManager(WikiEngine engine,
                       Properties properties)
Method Detail

templateExists

public boolean templateExists(String templateName)
Check the existence of a template.


findJSP

public String findJSP(javax.servlet.jsp.PageContext pageContext,
                      String name)
An utility method for finding a JSP page. It searches only under either current context or by the absolute name.


findJSP

public String findJSP(javax.servlet.jsp.PageContext pageContext,
                      String template,
                      String name)
Attempts to locate a JSP page under the given template. If that template does not exist, or the page does not exist under that template, will attempt to locate a similarly named file under the default template.

Parameters:
pageContext - The JSP PageContext
template - From which template we should seek initially?
name - Which resource are we looking for (e.g. "ViewTemplate.jsp")
Returns:
path to the JSP page; null, if it was not found.

getTemplateProperty

public String getTemplateProperty(WikiContext context,
                                  String key)
Returns a property, as defined in the template. The evaluation is lazy, i.e. the properties are not loaded until the template is actually used for the first time.


listSkins

public Set listSkins(javax.servlet.jsp.PageContext pageContext,
                     String template)
Lists the skins available under this template. Returns an empty Set, if there are no extra skins available. Note that this method does not check whether there is anything actually in the directories, it just lists them. This may change in the future.

Parameters:
template -
Returns:
Set of Strings with the skin names.
Since:
2.3.26

getMarker

public static String getMarker(String type)
Returns the include resources marker for a given type. This is in a HTML comment format.

Parameters:
type - the marker
Returns:
the generated marker comment

addResourceRequest

public static void addResourceRequest(WikiContext ctx,
                                      String type,
                                      String resource)
Adds a resource request to the current request context. The content will be added at the resource-type marker (see IncludeResourcesTag) in WikiServletFilter.

The resources can be of different types. For RESOURCE_SCRIPT and RESOURCE_STYLESHEET this is an URI path to the resource (a script file or an external stylesheet) that needs to be included. For RESOURCE_INLINECSS the resource should be something that can be added between <style></style> in the header file (commonheader.jsp). For RESOURCE_JSFUNCTION it is the name of the Javascript function that should be run at page load.

The IncludeResourceTag inserts code in the template files, which is then filled by the WikiFilter after the request has been rendered but not yet sent to the recipient.

Note that ALL resource requests get rendered, so this method does not check if the request already exists in the resources. Therefore, if you have a plugin which makes a new resource request every time, you'll end up with multiple resource requests rendered. It's thus a good idea to make this request only once during the page life cycle.

Parameters:
ctx - The current wiki context
type - What kind of a request should be added?
resource - The resource to add.

getResourceRequests

public static String[] getResourceRequests(WikiContext ctx,
                                           String type)
Returns resource requests for a particular type. If there are no resources, returns an empty array.


getResourceTypes

public static String[] getResourceTypes(WikiContext ctx)
returns all those types that have been requested so far.

Parameters:
ctx - the wiki context
Returns:
the array of types requested