com.croftsoft.apps.template
Class Template

java.lang.Object
  extended by com.croftsoft.apps.template.Template

public class Template
extends Object

Creates web pages from a template file and substitution map files.

Wherever the <subst key="key"></subst> occurs in the template file, it is replaced with a value parsed from the content mapping file to create a new *.html file.

Note that the key name is case-senstive.

Example Template File "template.html":

 <HTML>
 <HEAD>
 <SUBST KEY="HEAD"></SUBST>
 </HEAD>
 </HTML>
 <BODY BGCOLOR="Blue">
 <CENTER>
 <IMG SRC="/adbanner.gif">
 </CENTER>
 <P>
 <SUBST KEY="BODY"></SUBST>
 </BODY>
 </HTML>
 
Example Content Mapping File "filename.smap":
 <HTML>
 <HEAD>
 <TITLE>
 Welcome to my home page!
 </TITLE>
 </HEAD>
 </HTML>
 <BODY>
 My Home page
 </BODY>
 </HTML>
 
Example Resultant HTML File "filename.html":
 <HTML>
 <HEAD>
 <TITLE>
 Welcome to my home page!
 </TITLE>
 </HEAD>
 </HTML>
 <BODY BGCOLOR="Blue">
 <CENTER>
 <IMG SRC="/adbanner.gif">
 </CENTER>
 <P>
 My Home page
 </BODY>
 </HTML>
 

Execute with the document root directory name as the command-line argument (defaults to "."). It will traverse subdirectories as needed to create corresponding *.html files for each *.smap file. The template file in the current directory will be used. Subdirectories will use their parent template files unless they have template files of their own.

Intended to operate like the JavaWebServer templating mechanism except that the files are preprocessed. Note that I am using SUBST KEY="..." instead of SUBST DATA="..." as I intend to make this more general-purpose over time.

Current implementation limitations to be fixed later:

Version:
2000-05-05
Author:
David W. Croft

Constructor Summary
Template(String templateText)
           
 
Method Summary
 String generate(Map substitutionMap)
           
static void generateFilesInBranch(Template parentTemplate, File dir)
           
 String[] getKeys()
           
static void main(String[] args)
          Recursively creates *.html files for each *.smap file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Template

public Template(String templateText)
Method Detail

main

public static void main(String[] args)
                 throws Exception
Recursively creates *.html files for each *.smap file.

Parameters:
args - First command-line argument is the document root directory; defaults to ".".
Throws:
Exception

generateFilesInBranch

public static void generateFilesInBranch(Template parentTemplate,
                                         File dir)
                                  throws IOException
Throws:
IOException

getKeys

public String[] getKeys()

generate

public String generate(Map substitutionMap)

CroftSoft Javadoc

CroftSoft Apps Javadoc (2008-09-28 21:15:07)