|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.x5.template.TemplateSet
public class TemplateSet
TemplateSet is a Chunk "factory" and an easy way to parse template files into Strings. The default caching behavior is great for high traffic applications.
// Dynamic content in templates is marked with {~...}
//
// Previously the syntax was {$...} but then I had a project where
// some of the templates were shared by a perl script and I got
// tired of escaping the $ signs in inline templates in my perl code.
//
// Before that there was an escaped-HTML-inspired syntax which
// looked like &tag_...; since this was thought to be most
// compatible with HTML editors like DreamWeaver but it was hard
// to read and as it turned out DreamWeaver choked on it.
//
// See TemplateSet.convertTags(...) and .convertToMyTags(...) for
// quick search-and-replace routines for updating tag syntax on
// old templates...
//
// ...Or, if an entire template set uses another syntax just call
// .setTagBoundaries("{$", "}") on the TemplateSet object before
// you use it to make any chunks. All subsequent chunks made from
// that TemplateSet will find and replace the {$...} style tags.
//
// Be careful: for interoperability you will need to call
// .setTagBoundaries() individually on any blank chunks you make
// without the aid of the TemplateSet object, ie with the Chunk
// constructor -- better to use the no-arg .makeChunk() method of
// the TemplateSet instead, since that automatically coerces the
// blank Chunk's tag boundaries correctly.
//
///// In summary, for back-compatibility:
//
// TemplateSet templates = new TemplateSet(...);
// templates.setTagBoundaries("{$", "}");
// ...
//
// *** (A) BAD ***
// ...
// Chunk c = new Chunk(); // will only explode tags like default {~...}
//
// *** (B) NOT AS BAD ***
// ...
// Chunk c = new Chunk();
// c.setTagBoundaries("{$", "}"); // manually match tag format :(
//
// *** (C) BEST ***
// ...
// Chunk c = templates.makeChunk(); // inherits TemplateSet's tag format :)
//
Copyright: waived, free to use
| Field Summary | |
|---|---|
static java.lang.String |
BLOCKEND_LONGHAND
|
static java.lang.String |
BLOCKEND_SHORTHAND
|
static java.lang.String |
DEFAULT_TAG_END
|
static java.lang.String |
DEFAULT_TAG_START
|
static java.lang.String |
INCLUDE_SHORTHAND
|
static java.lang.String |
PROTOCOL_SHORTHAND
|
| Constructor Summary | |
|---|---|
TemplateSet()
|
|
TemplateSet(java.lang.String templatePath)
Makes a template "factory" which reads in template files from the file system in the templatePath folder. |
|
TemplateSet(java.lang.String templatePath,
java.lang.String extension,
int refreshMins)
Makes a template "factory" which reads in template files from the file system in the templatePath folder. |
|
| Method Summary | |
|---|---|
void |
addProtocol(ContentSource src)
|
void |
clearCache()
Forces subsequent template fetching to re-read the template contents from the filesystem instead of the cache. |
static java.lang.String |
convertTags(java.lang.String withOldTags,
java.lang.String oldTagStart,
java.lang.String oldTagEnd)
Converts a template with an alternate tag syntax to one that matches the default tag syntax {~myTag}. |
static java.lang.String |
convertTags(java.lang.String withOldTags,
java.lang.String oldTagStart,
java.lang.String oldTagEnd,
java.lang.String newTagStart,
java.lang.String newTagEnd)
Converts a template from one tag syntax to another. |
java.lang.String |
convertToMyTags(java.lang.String withOldTags,
java.lang.String oldTagStart,
java.lang.String oldTagEnd)
Converts a template with an alternate tag syntax to one that matches this TemplateSet's tags. |
java.lang.String |
fetch(java.lang.String name)
|
java.lang.String |
getDefaultExtension()
|
java.util.Map<java.lang.String,ChunkFilter> |
getFilters()
|
protected Snippet |
getFromCache(java.lang.String name,
java.lang.String extension)
|
java.lang.String |
getProtocol()
|
java.lang.String |
getResourcePath(java.lang.String templateName,
java.lang.String ext)
|
Snippet |
getSnippet(java.lang.String name)
Retrieve as String the template specified by name. |
Snippet |
getSnippet(java.lang.String name,
java.lang.String extension)
Retrieve as String the template specified by name and extension. |
TemplateSet |
getSubset(java.lang.String context)
|
java.lang.String |
getTemplatePath(java.lang.String templateName,
java.lang.String ext)
|
Chunk |
makeChunk()
Creates a Chunk with no starter template and sets its tag boundary markers to match the other templates in this set. |
Chunk |
makeChunk(java.lang.String templateName)
Creates a Chunk with a starting template. |
Chunk |
makeChunk(java.lang.String templateName,
java.lang.String extension)
Creates a Chunk with a starting template. |
boolean |
provides(java.lang.String itemName)
|
static java.lang.String |
removeBlockTagIndents(java.lang.String template)
|
void |
setDirtyInterval(int minutes)
Controls caching behavior. |
void |
setEncoding(java.lang.String encoding)
|
void |
setJarContext(java.lang.Class<?> classInSameJar)
|
void |
setJarContext(java.lang.Object ctx)
|
void |
setLayerName(java.lang.String layerName)
|
void |
signalFailureWithNull()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static java.lang.String DEFAULT_TAG_START
public static java.lang.String DEFAULT_TAG_END
public static final java.lang.String INCLUDE_SHORTHAND
public static final java.lang.String PROTOCOL_SHORTHAND
public static final java.lang.String BLOCKEND_SHORTHAND
public static final java.lang.String BLOCKEND_LONGHAND
| Constructor Detail |
|---|
public TemplateSet()
public TemplateSet(java.lang.String templatePath)
templatePath - folder where template files are located.
public TemplateSet(java.lang.String templatePath,
java.lang.String extension,
int refreshMins)
templatePath - folder where template files are located.extension - appends dot plus this String to a template name stub to find template files.refreshMins - returns template from cache unless this many minutes have passed.| Method Detail |
|---|
public Snippet getSnippet(java.lang.String name)
For example: String myTemplate = templateSet.get("outer_file.inner_template");
will look for {#inner_template}bla bla bla{#} inside the file "outer_file.html" or "outer_file.xml" ie whatever your TemplateSet extension is.
getSnippet in interface ContentSourcename - the location of the template definition.
public java.lang.String fetch(java.lang.String name)
fetch in interface ContentSourcepublic java.lang.String getProtocol()
getProtocol in interface ContentSource
public Snippet getSnippet(java.lang.String name,
java.lang.String extension)
name - the location of the template definition.extension - the nonstandard extension which forms the template filename.
public Chunk makeChunk()
makeChunk in interface ChunkFactorypublic Chunk makeChunk(java.lang.String templateName)
makeChunk in interface ChunkFactorytemplateName - the location of the template definition.
public Chunk makeChunk(java.lang.String templateName,
java.lang.String extension)
makeChunk in interface ChunkFactorytemplateName - the location of the template definition.extension - the nonstandard extension which forms the template filename.
public static java.lang.String removeBlockTagIndents(java.lang.String template)
protected Snippet getFromCache(java.lang.String name,
java.lang.String extension)
public void clearCache()
public void setDirtyInterval(int minutes)
minutes - how long to keep a template in the cache.
public java.lang.String convertToMyTags(java.lang.String withOldTags,
java.lang.String oldTagStart,
java.lang.String oldTagEnd)
withOldTags - Template text which contains tags with the old syntaxoldTagStart - old tag beginning markeroldTagEnd - old tag end marker
public static java.lang.String convertTags(java.lang.String withOldTags,
java.lang.String oldTagStart,
java.lang.String oldTagEnd)
withOldTags - Template text which contains tags with the old syntaxoldTagStart - old tag beginning markeroldTagEnd - old tag end marker
public static java.lang.String convertTags(java.lang.String withOldTags,
java.lang.String oldTagStart,
java.lang.String oldTagEnd,
java.lang.String newTagStart,
java.lang.String newTagEnd)
withOldTags - Template text which contains tags with the old syntaxoldTagStart - old tag beginning markeroldTagEnd - old tag end markernewTagStart - new tag beginning markernewTagEnd - new tag end marker
public TemplateSet getSubset(java.lang.String context)
public void addProtocol(ContentSource src)
public void signalFailureWithNull()
public java.lang.String getTemplatePath(java.lang.String templateName,
java.lang.String ext)
public java.lang.String getResourcePath(java.lang.String templateName,
java.lang.String ext)
public java.lang.String getDefaultExtension()
public boolean provides(java.lang.String itemName)
provides in interface ContentSourcepublic void setJarContext(java.lang.Class<?> classInSameJar)
public void setJarContext(java.lang.Object ctx)
public void setLayerName(java.lang.String layerName)
public void setEncoding(java.lang.String encoding)
public java.util.Map<java.lang.String,ChunkFilter> getFilters()
getFilters in interface ChunkFactory
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||