|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.croftsoft.apps.template.Template
public class Template
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:
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 |
---|
public Template(String templateText)
Method Detail |
---|
public static void main(String[] args) throws Exception
args
- First command-line argument is the document root directory;
defaults to ".".
Exception
public static void generateFilesInBranch(Template parentTemplate, File dir) throws IOException
IOException
public String[] getKeys()
public String generate(Map substitutionMap)
|
CroftSoft Javadoc | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |