xdoclet.template
public class TemplateEngine extends java.lang.Object
generate(java.lang.String)
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
docEncoding |
protected PrettyPrintWriter |
out
The PrintWriter used for outputing the generated stuff.
|
protected java.io.File |
output |
static java.lang.String |
TAG_MAPPINGS_FILE |
protected static java.lang.String |
XDOCLET_HEAD |
protected static int |
XDOCLET_HEAD_LEN |
protected static java.lang.String |
XDOCLET_PREFIX |
protected static java.lang.String |
XDOCLET_TAIL |
protected static int |
XDOCLET_TAIL_LEN |
Modifier | Constructor and Description |
---|---|
protected |
TemplateEngine() |
Modifier and Type | Method and Description |
---|---|
void |
generate(java.lang.String template)
The main template parsing/processing/running logic.
|
int |
getCurrentLineNum()
Gets the CurrentLineNum attribute of the TemplateEngine object
|
static TemplateEngine |
getEngineInstance()
Gets the EngineInstance attribute of the TemplateEngine class
|
protected static int |
getLineNumber(java.lang.String template,
int tillIndex)
Loops over the
template content till reaching tillIndex index and returns the number of
lines it has encountered. |
java.util.Set |
getNamespaces()
Returns a Set of Strings that represent the registered namespaces
|
java.io.File |
getOutput()
Gets the Output attribute of the TemplateEngine object
|
TemplateTagHandler |
getTagHandlerFor(java.lang.String prefix)
Get the tag handler for the prefix.
|
java.net.URL |
getTemplateURL()
Returns current template URL.
|
protected int |
handleTag(int index,
java.lang.String template)
Handle the tag that starts at
index in the template provided. |
protected java.lang.Object |
invoke(java.lang.reflect.Method m,
java.lang.Object cmdImplProvider,
java.lang.Object[] params1)
Describe what the method does
|
protected void |
invokeContentMethod(java.lang.String cmd,
java.util.Properties attributes,
java.lang.String template,
int i)
Invokes content tag implementation method named
cmd with the specified set of attributes. |
protected java.lang.Object |
invokeMethod(java.lang.String cmd,
java.lang.Object[] params1,
java.lang.Object[] params2,
java.lang.String template,
int i)
Invokes content tag implementation method named
cmd . |
java.lang.String |
outputOf(java.lang.String template)
Calls
generate() of the specified template content but instead of outputing it to the generated
file, it returns the generated content. |
void |
print(java.lang.String output)
Describe what the method does
|
void |
setCurrentLineNum(int currentLineNum)
Sets the CurrentLineNum attribute of the TemplateEngine object
|
void |
setDocEncoding(java.lang.String string)
set output charset;
|
void |
setOutput(java.io.File output)
Sets the Output attribute of the TemplateEngine object
|
void |
setTagHandlerFor(java.lang.String prefix,
TemplateTagHandler tagHandler)
Sets the TagHandlerFor attribute of the TemplateEngine object
|
void |
setTemplateURL(java.net.URL templateURL)
A config parameter settable from Ant build file.
|
void |
setWriter(PrettyPrintWriter out)
Sets the Writer attribute of the TemplateEngine object
|
void |
setXJavaDoc(xjavadoc.XJavaDoc xJavaDoc) |
static int |
skipWhitespace(java.lang.String template,
int i)
Skips whitespaces, starting from index
i till the first non-whitespace character or end of template
and returns the new index. |
void |
start()
A utility method used for generating the dest_file based on template_file template file.
|
public static final java.lang.String TAG_MAPPINGS_FILE
protected static final java.lang.String XDOCLET_PREFIX
protected static final java.lang.String XDOCLET_HEAD
protected static final java.lang.String XDOCLET_TAIL
protected static final int XDOCLET_HEAD_LEN
protected static final int XDOCLET_TAIL_LEN
protected transient PrettyPrintWriter out
PrettyPrintWriter
tries to
pretty format the generated file by removing redundant spaces/lines.PrettyPrintWriter
protected transient java.io.File output
protected transient java.lang.String docEncoding
public static TemplateEngine getEngineInstance()
public static int skipWhitespace(java.lang.String template, int i)
i
till the first non-whitespace character or end of template
and returns the new index.template
- Description of Parameteri
- Description of Parameterprotected static int getLineNumber(java.lang.String template, int tillIndex)
template
content till reaching tillIndex
index and returns the number of
lines it has encountered.template
- Description of ParametertillIndex
- Description of Parameterpublic java.net.URL getTemplateURL()
setTemplateURL(java.net.URL)
public java.io.File getOutput()
public int getCurrentLineNum()
public TemplateTagHandler getTagHandlerFor(java.lang.String prefix) throws TemplateException
prefix
- The prefix that the tag handler is mapped toTemplateException
- If there is no tag handler class for the prefix specified.public java.util.Set getNamespaces()
public void setXJavaDoc(xjavadoc.XJavaDoc xJavaDoc)
public void setWriter(PrettyPrintWriter out)
out
- The new Writer valuepublic void setCurrentLineNum(int currentLineNum)
currentLineNum
- The new CurrentLineNum valuepublic void setTemplateURL(java.net.URL templateURL)
templateURL
,
so thereafter the new template file is used.templateURL
- The new TemplateFile valuegetTemplateURL()
public void setOutput(java.io.File output)
output
- The new Output valuepublic void setTagHandlerFor(java.lang.String prefix, TemplateTagHandler tagHandler) throws TemplateException
prefix
- The new TagHandlerFor valuetagHandler
- The new TagHandlerFor valueTemplateException
- Describe the exceptionpublic void setDocEncoding(java.lang.String string)
string
- public final void print(java.lang.String output)
output
- Describe what the parameter doespublic void generate(java.lang.String template) throws TemplateException
template
- Description of ParameterTemplateException
- Description of ExceptionoutputOf(java.lang.String)
public java.lang.String outputOf(java.lang.String template) throws TemplateException
generate()
of the specified template content but instead of outputing it to the generated
file, it returns the generated content. It's useful for cases where you want to synthesize the result but use it
instead of roughly outputing it, for example it's used for the content tags nested inside an attribute value such
as: <XDoclet:blabla param1="<XDoclet:aContentTag/>"/>
where we obviously don't want to
output the result of aContentTag
but use it as the value of the param1
parameter.template
- Description of ParameterTemplateException
- Description of Exceptiongenerate(java.lang.String)
public void start() throws TemplateException
TemplateException
- Description of Exceptionprotected int handleTag(int index, java.lang.String template) throws TemplateException
index
in the template
provided.index
- The index that the tag to handle starts at.template
- The template the tag is in.TemplateException
- Description of Exceptionprotected java.lang.Object invokeMethod(java.lang.String cmd, java.lang.Object[] params1, java.lang.Object[] params2, java.lang.String template, int i) throws TemplateException
cmd
. It first tries with parameters params1
then if not successful tries param2
. This is used for cases where it's not obvious whether the tag
implementation method expects a Properties object or no parameter at all (the tag takes no attributes).cmd
- The command to be executed. Everything after the <XDoclet:
in the
template.params1
- Description of Parameterparams2
- Description of Parametertemplate
- Description of Parameteri
- Description of ParameterTemplateException
- Description of ExceptioninvokeBlockMethod(java.lang.String,java.lang.String,java.util.Properties,java.lang.String,int)
,
invokeContentMethod(java.lang.String,java.util.Properties,java.lang.String,int)
protected void invokeContentMethod(java.lang.String cmd, java.util.Properties attributes, java.lang.String template, int i) throws TemplateException
cmd
with the specified set of attributes. If attributes
Properties object is not empty it tries to find a method taking one parameter (Properties attributes), otherwise
a method with no parameter.cmd
- Description of Parameterattributes
- Description of Parametertemplate
- Description of Parameteri
- Description of ParameterTemplateException
- Description of ExceptioninvokeMethod(java.lang.String,java.lang.Object[],java.lang.Object[],java.lang.String,int)
protected java.lang.Object invoke(java.lang.reflect.Method m, java.lang.Object cmdImplProvider, java.lang.Object[] params1) throws java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException, TemplateException
m
- Describe what the parameter doescmdImplProvider
- Describe what the parameter doesparams1
- Describe what the parameter doesjava.lang.reflect.InvocationTargetException
- Describe the exceptionjava.lang.IllegalAccessException
- Describe the exceptionTemplateException
- Describe the exception