JDynamiTe 2.0 Examples
How to use these examples
All these examples have the same structure: a brief description of the example,
followed by a summary of the main interesting implemented concept or feature
(mainly JDynamiTe API different use cases), and finally all the source files
(java code if any, input template file(s), output file, command line to execute
the example) useful to understand, test, and why not to modify the use case.
Note that in these examples, the command outputs results on standard output.
You can redirect output on a file at your convenience.
JDynamiTe QuickStart
This is the primary example, slightly updated for this JDynamiTe release.
It demonstrates how simple it is to populate a template file and then produce a dynamic output.
Simple "Variable" tags, "Dynamic Blocks" (possibly nested),
and finally input coming from an external XML file (new feature) are presented in few lines of code.
The main interest of this example is that it presents step by step the basic JDynamiTe methods.
Each step is commented and the java code is simple to understand.
Note: the template file is here an HTML file, it could be any text file...
it would work the same way. The "bonus" is that you can open the template file with your favorite
navigator, to figure out how the final page could look like.
Note also in the template source the interesting example of "IGNORED block" feature: you can insert
"real" data into this special kind of blocks, simulating a more realistic rendering, which can be
a useful working document for designers. These block contents are completely ignored during template
parsing.
Source file
Template input file
Input directory (template + additional data)
Output result
Usage - command line:
java -cp ./bin cb.jdynamite.examples.JDynamiTeQuickStart examples/QuickStart/input/testTemplateV2_0.html
Code Generator
Similar to the "JDynamiTe Quickstart" example, but shorter, this little example shows
how to programmatically generate a C++ class file or a Java class file from a skeleton code.
Looking at the java source file, you can figure out how to do the job with very few lines of code.
Concerning the template, you can notice that the same Variable tag can be used several times
(e.g. {MEMBER_NAME} ), but you only need to populate it once in the dynamic block iteration.
Note also here one of the main benefit of JDynamiTe: if you change the skeleton template
(either java or cpp in this example), no need to modify the java generator code.
Source file
Template input file
Input directory (template + additional data)
Output result
Usage - command line:
java -cp ./bin cb.jdynamite.examples.SimpleClassGenerator examples/CodeGenerator/input/SimpleClass_template.cpp
Quickstart JSP, classic syntax
This example is a simple implementation of the cb.jdynamite.examples.JDynamiTeQuickStart
class, through a Java Server Page.
It uses here the "classic" JSP syntax (next example uses the XML JSP syntax).
The main interest of this example is to show how simple it is to generate dynamic HTML pages from a Web Server, when coupling JSP and JDynamiTe features.
The output result showed below is a copy of the expected result when running from a Web Server.
If you want to run this example in real situation, you have to deploy it into a Servlets container.
With Apache Tomcat, for example, copy the JSP-Servlets/JDynamiTeExamples
directory into the apache_tomcat_install_dir/webapps
directory.
Source file
Template input file
Input directory (template + additional data)
Output result
Usage - command line:
In case of local tomcat server, load this page into your navigator:
http://localhost:8080/JDynamiTeExamples/QuickStart/testTemplate_ClassicSyntax.jsp
Quickstart JSP 2.0, XML syntax
This example is a simple implementation of the cb.jdynamite.examples.JDynamiTeQuickStart
class, through a Java Server Page.
It uses here the "XML" JSP (version 2.0) syntax (previous example uses the "classic" JSP syntax).
The main interest of this example is to show how simple it is to generate dynamic HTML pages from a Web Server, when coupling JSP and JDynamiTe features.
The output result showed below is a copy of the expected result when running from a Web Server.
If you want to run this example in real situation, you have to deploy it into a Servlets container.
With Apache Tomcat, for example, copy the JSP-Servlets/JDynamiTeExamples
directory into the apache_tomcat_install_dir/webapps
directory.
Source file
Template input file
Input directory (template + additional data)
Output result
Usage - command line:
In case of local tomcat server, load this page into your navigator:
http://localhost:8080/JDynamiTeExamples/QuickStart/testTemplate_XMLSyntax.jsp
Quickstart Servlet
This example is a simple implementation of the cb.jdynamite.examples.JDynamiTeQuickStart
class, through Java Servlet API.
The main interest of this example is to show how simple it is to generate dynamic HTML pages from a Web Server, when coupling Servlet API and JDynamiTe features.
The output result showed below is a copy of the expected result when running from a Web Server.
If you want to run this example in real situation, you have to deploy it into a Servlets container.
With Apache Tomcat, for example, copy the JSP-Servlets/JDynamiTeExamples
directory into the apache_tomcat_install_dir/webapps
directory.
Source file
Template input file
Input directory (template + additional data)
Output result
Usage - command line:
In case of local tomcat server, load this page into your navigator:
http://localhost:8080/JDynamiTeExamples/QuickStartServlet
XML local file input example
This example illustrates the very interesting and powerful new JDynamiTe feature:
the capacity to automatically populate the template taking input from XML files.
In other words: you can add special tags in your template, using standard XPath syntax, which refer to data contained in an XML file.
By this way, no need to programmatically populate this kind of data: JDynamiTe parser automatically does it for you.
This example uses the generic jDynTool command to generate the result file, so no java source code is needed here.
See the "Usage section" below which gives the command line.
The main interest of this example is to illustrate a classic use case:
You have input data into an XML file (computer_mon_data.xml in this example), and you have to get some of these values in
order to put them somewhere into your output file.
The JDynamiTe "XML" special tags allow you to precisely create a "link" between template files and XML input files.
Note that the XML format is used for external input data, but this does not assume that your template and result files are in XML format.
Your template and result files are still in any text format.
Note: for your information, the "Source file" link below targets on JDynTool.java source file.
You can have a look to it if you want to figure out how JDynTool simply implements the JDynamiTe library.
Source file
Template input file
Input directory (template + additional data)
Output result
Usage - command line:
java -cp lib/java-getopt-1.0.14.jar:./bin cb.jdynamite.tool.JDynTool --template examples/XML/input/templ_with_xml.txt -D THE_TITLE=My_Title
Table of Content Generator from Eclipse XML toc file
As previous example, this one illustrates the capacity to automatically populate the template taking input from XML files.
It is very similar than the previous one, except that if you look at the input template, you can see that no input XML path is given for the first level block named "toc_block".
In this case, we use the --XMLdefaultRootDoc URI option of JDynTool in order to set this XML input location.
This example uses the generic jDynTool command to generate the result file, so no java source code is needed here.
See the "Usage section" below which gives the command line.
The main interest of this example is to show that thanks to the --XMLdefaultRootDoc of JDynTool, you could reuse exactly the same input template file
to generate other "Eclipse User Guide Tables of Content" from different Eclipse "toc.xml" files, assuming the fact that they respect the "org.eclipse.help.toc" format.
Note: for your information, the "Source file" link below targets on JDynTool.java source file.
You can have a look to it if you want to figure out how JDynTool simply implements the JDynamiTe library.
Source file
Template input file
Input directory (template + additional data)
Output result
Usage - command line:
java -cp lib/java-getopt-1.0.14.jar:./bin cb.jdynamite.tool.JDynTool --template examples/XML/input/templ_eclipse_toc.html -D THE_TITLE="CDT Tasks" --XMLdefaultRootDoc examples/XML/input/CDT_toc_topics_Tasks.xml
XML RSS Reader
Like the previous example, this one illustrates the very interesting and powerful new JDynamiTe feature:
the capacity to automatically populate the template taking input from XML files.
However, in this example, the XML input data do not come from a local file, but they come from an "RSS feed".
So this example is nothing less than a simple RSS Reader (also known as news aggregator).
This example also uses the generic JDynTool command to generate the result file, so no java source code is needed here.
See the "Usage section" below which gives the command line.
Remark: if you look at the input template, you can see that no URI is given at line 4 for the first level block named "myRSS_Feed".
In this case, we use the --XMLdefaultRootDoc URI option of JDynTool to set this XML input location.
The main interest of this example is to show that the input XML location can be defined as a
Uniform Resource Identifier (URI), e.g. "http://feeds.bbci.co.uk/news/science_and_environment/rss.xml" or
"http://news.google.fr/?output=rss".
In such a case, the JDynamiTe engine uses internet connection to get XML data.
In the same way than for XML local file, you have to know the XML structure of the XML data in order
to build the template file with correct XML elements identification (using XPath syntax, e.g. "/channel/item/title").
Concerning RSS feed format, there is a standardization (e.g. RSS 2.0), so this example can theoretically read
any "RSS feed".
Note: for your information, the "Source file" link below targets on JDynTool.java source file.
You can have a look to it if you want to figure out how JDynTool simply implements the JDynamiTe library.
Source file
Template input file
Input directory (template + additional data)
Output result
Usage - command line:
java -cp lib/java-getopt-1.0.14.jar:./bin cb.jdynamite.tool.JDynTool --template examples/XML/input/templ_with_RSS_Feed.txt -D THE_TITLE="My RSS Feed" --XMLdefaultRootDoc "http://www.louvre.fr/en/rss/latest_news.xml"
XML RSS Reader, HTML output
This example is the same as the previous example, except that the output is in HTML format.
In fact, we only change the input template file, and we set the same URI as RSS feed input data.
Like the other examples, it illustrates the interest of the following principle, which is enabled and supported by JDynamiTe usage:
separation between data processing and data presentation.
Note: for your information, the "Source file" link below targets on JDynTool.java source file.
You can have a look to it if you want to figure out how JDynTool simply implements the JDynamiTe library.
Source file
Template input file
Input directory (template + additional data)
Output result
Usage - command line:
java -cp lib/java-getopt-1.0.14.jar:./bin cb.jdynamite.tool.JDynTool --template examples/XML/input/templ_RSS_Feed.html -D THE_TITLE="My RSS Feed" --XMLdefaultRootDoc "http://www.louvre.fr/en/rss/latest_news.xml"
RSS Reader Servlet
This example is a simple implementation of an RSS Feed Reader, through a Java Servlet calling JDynTool.
The main interest of this example is to show how to simply integrate JDynTool capacities into a Servlet, in order to generate dynamic HTML pages from a Web Server.
Like previous examples, it illustrates the interest of the following principle, which is enabled and supported by JDynamiTe usage:
separation between data collecting and data presentation.
Note the "Clear Cache" check box in this example, which illustrates optimization concerning XML external documents loading:
JDynamiTe manages a global "cache" list of already loaded Documents, in order to optimize performances.
There is an API method to set the maximum size of this list,
as well as an API method to clear this list.
The output result showed below is a copy of the expected result when running from a Web Server.
If you want to run this example in real situation, you have to deploy it into a Servlets container.
With Apache Tomcat, for example, copy the JSP-Servlets/JDynamiTeExamples
directory into the apache_tomcat_install_dir/webapps
directory.
Source file
Template input file
Input directory (template + additional data)
Output result
Usage - command line:
In case of local tomcat server, load this page into your navigator:
http://localhost:8080/JDynamiTeExamples/RSSReaderServlet
XML Variable Expression input
This XML example illustrates another interesting feature provided by the "XML input" feature:
you can use a Variable into the XPath expression of an XML Dynamic block.
If you look at the template input file of this example, you can see that the block named "Players" has the following XPath expression:
//club[@name='{{@title}}']/famousPlayer
which means:
"the famousPlayer node(s) of the input XML file (Football_Players.xml in this case) belonging to the club whose name is {{@title}}".
And {{@title}} is the XML variable (name of clubs, got from "Football_Clubs.xml") from the parent XML block.
This example uses jDynTool to generate the result file, so no java source code is needed here.
See the "Usage section" below which gives the command line.
The main interest of this example is to show that, in such a case of nested XML Dynamic Blocks, you can dynamically use a value computed in the parent Block
in order to iterate on different nodes in a Block, based on a value unknown in advance.
Note: for your information, the "Source file" link below targets on JDynTool.java source file.
You can have a look to it if you want to figure out how JDynTool simply implements the JDynamiTe library.
Source file
Template input file
Input directory (template + additional data)
Output result
Usage - command line:
java -cp lib/java-getopt-1.0.14.jar:./bin cb.jdynamite.tool.JDynTool --template examples/XML_variable_expression/input/Football_templ.txt -D THE_TITLE=Football_World
XML programmatic XPath example
This XML example does almost the same thing than the previous one, but with a little piece of code (so JDynTool is not used here).
If you look at the input template, you can see that there are only few differences with the previous one:
First, some values defining XML Dynamic Block (XML input or XPath expression) have been replaced by "phony" values.
Second, additional variables have been inserted (e.g. {CLUB_NB}).
The main interest of this example is to show how to go further with templates, when specific code is needed
to programmatically set values to block definitions or to template variables.
Source file
Template input file
Input directory (template + additional data)
Output result
Usage - command line:
java -cp ./bin cb.jdynamite.examples.ProgrammaticXPathSetting examples/XML_variable_expression/input/Football_templ_2.txt