org.apache.wiki.ui
Class TemplateManager

java.lang.Object
  extended by org.apache.wiki.modules.ModuleManager
      extended by org.apache.wiki.ui.TemplateManager

public class TemplateManager
extends ModuleManager

This class takes care of managing JSPWiki templates. This class also provides the ResourceRequest mechanism.

Since:
2.1.62

Field Summary
static String DEFAULT_TEMPLATE
          The name of the default template.
static String DIRECTORY
          The default directory for the properties.
static String I18NDEFAULT_LOCALE
          I18N string to mark the default locale
static String I18NRESOURCE_EN
          The default (en) RESOURCE name and id.
static String I18NRESOURCE_EN_ID
           
static String I18NRESOURCE_PREFIX
          Location of I18N Resource bundles, and path prefix and suffixes
static String I18NRESOURCE_SUFFIX
           
static String I18NSERVER_TIMEZONE
          I18N string to mark the server timezone
protected static org.apache.log4j.Logger log
           
static String PROPERTYFILE
          Name of the file that contains the properties.
static String RESOURCE_HTTPHEADER
          Requests a HTTP header.
static String RESOURCE_INCLUDES
          The name under which the resource includes map is stored in the WikiContext.
static String RESOURCE_INLINECSS
          Requests inlined CSS.
static String RESOURCE_JSFUNCTION
          Requests a JavaScript function to be called during window.onload.
static String RESOURCE_JSLOCALIZEDSTRINGS
          Requests a JavaScript associative array with all localized strings.
static String RESOURCE_SCRIPT
          Requests a script to be loaded.
static String RESOURCE_STYLESHEET
          Requests a stylesheet to be inserted.
static String TIMEFORMATPROPERTIES
          Prefix of the default timeformat properties.
 
Fields inherited from class org.apache.wiki.modules.ModuleManager
m_engine, PLUGIN_RESOURCE_LOCATION
 
Constructor Summary
TemplateManager(WikiEngine engine, Properties properties)
          Creates a new TemplateManager.
 
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 resource under the given template.
 String findResource(WikiContext ctx, String template, String name)
          Attempts to locate a resource under the given template.
static String getMarker(WikiContext context, 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.
 Map listLanguages(javax.servlet.jsp.PageContext pageContext)
          List all installed i18n language properties by classpath searching for files like : templates/default_*.properties templates/default.properties
 Set listSkins(javax.servlet.jsp.PageContext pageContext, String template)
          Lists the skins available under this template.
 Map listTimeFormats(javax.servlet.jsp.PageContext pageContext)
          List all available timeformats, read from the jspwiki.properties
 Map listTimeZones(javax.servlet.jsp.PageContext pageContext)
          List all timezones, with special marker for server timezone
 Collection modules()
          Returns an empty collection, since at the moment the TemplateManager does not manage any modules.
 boolean templateExists(String templateName)
          Check the existence of a template.
 
Methods inherited from class org.apache.wiki.modules.ModuleManager
checkCompatibility
 
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. Value is "jsfunction".

See Also:
Constant Field Values

RESOURCE_JSLOCALIZEDSTRINGS

public static final String RESOURCE_JSLOCALIZEDSTRINGS
Requests a JavaScript associative array with all localized strings.

See Also:
Constant Field Values

RESOURCE_STYLESHEET

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

See Also:
Constant Field Values

RESOURCE_SCRIPT

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

See Also:
Constant Field Values

RESOURCE_INLINECSS

public static final String RESOURCE_INLINECSS
Requests inlined CSS. Value is "inlinecss".

See Also:
Constant Field Values

DIRECTORY

public static final String DIRECTORY
The default directory for the properties. Value is "templates".

See Also:
Constant Field Values

DEFAULT_TEMPLATE

public static final String DEFAULT_TEMPLATE
The name of the default template. Value is "default".

See Also:
Constant Field Values

PROPERTYFILE

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

See Also:
Constant Field Values

I18NRESOURCE_PREFIX

public static final String I18NRESOURCE_PREFIX
Location of I18N Resource bundles, and path prefix and suffixes

See Also:
Constant Field Values

I18NRESOURCE_SUFFIX

public static final String I18NRESOURCE_SUFFIX
See Also:
Constant Field Values

I18NRESOURCE_EN

public static final String I18NRESOURCE_EN
The default (en) RESOURCE name and id.

See Also:
Constant Field Values

I18NRESOURCE_EN_ID

public static final String I18NRESOURCE_EN_ID
See Also:
Constant Field Values

I18NDEFAULT_LOCALE

public static final String I18NDEFAULT_LOCALE
I18N string to mark the default locale

See Also:
Constant Field Values

I18NSERVER_TIMEZONE

public static final String I18NSERVER_TIMEZONE
I18N string to mark the server timezone

See Also:
Constant Field Values

TIMEFORMATPROPERTIES

public static final String TIMEFORMATPROPERTIES
Prefix of the default timeformat properties.

See Also:
Constant Field Values

RESOURCE_INCLUDES

public static final String RESOURCE_INCLUDES
The name under which the resource includes map is stored in the WikiContext.

See Also:
Constant Field Values

log

protected static final org.apache.log4j.Logger log

RESOURCE_HTTPHEADER

public static final String RESOURCE_HTTPHEADER
Requests a HTTP header. Value is "httpheader".

See Also:
Constant Field Values
Constructor Detail

TemplateManager

public TemplateManager(WikiEngine engine,
                       Properties properties)
Creates a new TemplateManager. There is typically one manager per engine.

Parameters:
engine - The owning engine.
properties - The property list used to initialize this.
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.

Parameters:
pageContext - the JSP PageContext
name - The name of the JSP page to look for (e.g "Wiki.jsp")
Returns:
The context path to the resource

findJSP

public String findJSP(javax.servlet.jsp.PageContext pageContext,
                      String template,
                      String name)
Attempts to locate a resource 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.

Even though the name suggests only JSP files can be located, but in fact this method can find also other resources than JSP files.

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.

findResource

public String findResource(WikiContext ctx,
                           String template,
                           String name)
Attempts to locate a resource under the given template. This matches the functionality findJSP(), but uses the WikiContext as the argument. If there is no servlet context (i.e. this is embedded), will just simply return a best-guess.

This method is typically used to locate any resource, including JSP pages, images, scripts, etc.

Parameters:
ctx - the wiki context
template - the name of the template to use
name - the name of the resource to fine
Returns:
the path to the resource
Since:
2.6

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:
pageContext - the JSP PageContext
template - The template to search
Returns:
Set of Strings with the skin names.
Since:
2.3.26

listLanguages

public Map listLanguages(javax.servlet.jsp.PageContext pageContext)
List all installed i18n language properties by classpath searching for files like : templates/default_*.properties templates/default.properties

Parameters:
pageContext -
Returns:
map of installed Languages
Since:
2.7.x

listTimeFormats

public Map listTimeFormats(javax.servlet.jsp.PageContext pageContext)
List all available timeformats, read from the jspwiki.properties

Parameters:
pageContext -
Returns:
map of TimeFormats
Since:
2.7.x

listTimeZones

public Map listTimeZones(javax.servlet.jsp.PageContext pageContext)
List all timezones, with special marker for server timezone

Parameters:
pageContext -
Returns:
map of TimeZones
Since:
2.7.x

getMarker

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

Parameters:
context - the wiki context
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 WikiJSPFilter.

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.

Parameters:
ctx - WikiContext
type - The resource request type
Returns:
a String array for the resource requests

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

modules

public Collection modules()
Returns an empty collection, since at the moment the TemplateManager does not manage any modules.

Specified by:
modules in class ModuleManager
Returns:
A Collection of WikiModuleInfo instances.


Copyright © {inceptionYear}-2014 The Apache Software Foundation. All rights reserved.