org.ejen
Class EjenTemplateNode

java.lang.Object
  |
  +--org.ejen.EjenChildNode
        |
        +--org.ejen.EjenStylesheetNode
              |
              +--org.ejen.EjenTemplateNode
All Implemented Interfaces:
EjenConstants

public class EjenTemplateNode
extends EjenStylesheetNode

Template node class.

A template node uses the current in memory DOM tree to create resulting text files (XML, HTML, source code, ...).

Usage (ant build file)

  <?xml version="1.0" encoding="UTF-8"?>

  <project name="generate" default="build">

    <taskdef name="ejen" classname="org.ejen.EjenTask"/>

    <target name="build">
      <ejen ...>
        ...
        <template file="filter.xml"
                 [foreach="/ejen/entity-bean"]
                 [filepattern="EJB_{@table-name}Bean.java"]>
          ...
          [<include .../>]
          [<import .../>]
          [<param .../>]
          ...
        </template>
        ...
      </ejen>
    </target>

  </project>
 

Parent nodes:

Version:
1.0
Author:
F. Wolff

Field Summary
protected  String _filepattern
           
protected  String _foreach
           
 
Fields inherited from class org.ejen.EjenStylesheetNode
_childNodes, _file
 
Fields inherited from class org.ejen.EjenChildNode
_messageIndent
 
Fields inherited from interface org.ejen.EjenConstants
CTX_DOM_SOURCE, CTX_STYLESHEET_HANDLER, CTX_STYLESHEET_ROOT, CTX_TRANSFORMER_FACTORY_IMPL, CTX_TRANSFORMER_IMPL, DEFAULT_XML_DATA, DEFAULT_XML_DATA_ENCODING, DEFAULT_XSL_DATA, LOG_INDENT_STR1, LOG_INDENT_STR2, MSG_DEBUG, MSG_ERR, MSG_INFO, MSG_VERBOSE, MSG_WARN, STATE_AFTER_PROCESS, STATE_BEFORE_PROCESS, STATE_CHECK, STATE_IDLE, STATE_PROCESS, STATES
 
Constructor Summary
EjenTemplateNode()
           
 
Method Summary
 Properties getAttributes()
          Returns all non null attributes of this EjenTemplateNode.
 String nodeName()
          Returns the name of this EjenTemplateNode (always "template").
 void process()
          Executes this EjenTemplateNode.
 void setFilepattern(String filepattern)
          [optional/AVT] - sets the filepattern attribute.
 void setForeach(String foreach)
          [optional/AVT] - sets the foreach attribute.
 
Methods inherited from class org.ejen.EjenStylesheetNode
afterProcess, beforeProcess, check, createImport, createInclude, createParam, getChildren, setFile
 
Methods inherited from class org.ejen.EjenChildNode
cloneContext, evaluateAVT, evaluateAVT, getFromContext, getFromContext, getFromGlobalContext, getListener, getState, idle, popContext, pushContext, putInContext, putInGlobalContext, sendMessageEvent, sendMessageEvent, sendStateEvent, sendXSLMessageEvent, sendXSLMessageEvent, setListener, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_foreach

protected String _foreach

_filepattern

protected String _filepattern
Constructor Detail

EjenTemplateNode

public EjenTemplateNode()
Method Detail

nodeName

public String nodeName()
Returns the name of this EjenTemplateNode (always "template").

Specified by:
nodeName in class EjenChildNode
Returns:
the name of this EjenTemplateNode.

getAttributes

public Properties getAttributes()
Returns all non null attributes of this EjenTemplateNode.

Overrides:
getAttributes in class EjenStylesheetNode
Returns:
non null attributes of this EjenTemplateNode.

setForeach

public void setForeach(String foreach)
[optional/AVT] - sets the foreach attribute. This attribute allows iterative applications of this template stylesheet to a sub-nodes set of the current in memory DOM tree.

Suppose you have the following DOM tree in memory:

  <?xml version="1.0" encoding="iso-8859-1"?>
  <ejen>
    <name>Name1</name>
    <name>Name2</name>
    <name>Name3</name>
    ...
  </ejen>
 
You want to generate text files with the following structure:

  Dear <Name...>,
    Obviously, you are reading a meaningless letter.
  Best regards.
 
You can use this template stylesheet (with the foreach attribute set to "/ejen/name"):

  <?xml version="1.0" encoding="iso-8859-1"?>
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  version="1.0">
    <xsl:output method="text" encoding="iso-8859-1"/>
    <xsl:template match="name"><!--
   -->Dear <xsl:value-of select="."/>,
    Obviously, you are reading a meaningless letter.
  Best regards.<!--
   --></xsl:template>
  </xsl:stylesheet>
 
Note that comments in this template are only for carriage return control purposes (we want neither a carriage return before "Dear", nor after "regards.").

If this attribute is used, a parameter whose name is "root" and value is the root node of the current DOM tree is always and automaticaly passed to the template stylesheet (you may have the line "<xsl:param name"root"/>" in the stylesheet).

See the filepattern for output file naming.

Parameters:
foreach - foreach String (default is null, meaning "apply this template stylesheet to the entire current DOM tree").

setFilepattern

public void setFilepattern(String filepattern)
[optional/AVT] - sets the filepattern attribute. This attribute allows basic file output naming setting and is relative to the foreach attribute (if foreach attribute is not used, filepattern will be relative to the root node of the current in memory DOM tree).

Suppose what is supposed here. You want to generate text files whose names are: Name1.txt, Name2.txt, Name3.txt... Then, you can use this filepattern: "{.}.txt".

If this basic file output naming mechanism is not sufficient, you may still use the Xalan Redirect extension.

Parameters:
filepattern - filepattern String (default is null, meaning "let the template do whatever it wants").

process

public void process()
Executes this EjenTemplateNode.

Overrides:
process in class EjenStylesheetNode
Throws:
EjenException - if something goes wrong...