Java Virtal Machine.net

[ News ] rss

February 01, 2011

Mark Wielaard: New GPG key. Finally created a new GPG key using gnupg. The old one was a DSA/1024 bits one and 8 years old. The new one is a RSA/2048 bits one. I will use the new one in the future to sign any release tarballs I might create. pub 2048R/57816A6A 2011-01-29 Key f...

More »

February 01, 2011

Andrew Hughes: [SECURITY] IcedTea6 1.7.8, 1.8.5, 1.9.5 Released!. We are pleased to announce a new set of security releases, IcedTea6 1.7.8, IcedTea6 1.8.5 and IcedTea6 1.9.5. This update contains the following security updates: The IcedTea project provides a harness to build the source code from OpenJDK6 u...

More »

March/2024
SunMonTueWedThuFriSat
     12
3456789
10111213141516
17181920212223
242526272829 30
31      

[ Archives News
for 'Java Technology' ]

home > news > java technology > trivial templating

Trivial Templating

Nothingstanding the fact that anyone in their right mind would use Apache Velocity or FreeMarker for templating, we present a trivial templating helper class, where for instance we have an HTML template as follows. Hey ${displayName} Your Travelstart reference: ${bookingReference} ${travelerName} We invoke the "templating engine" as follows. public String generate(String resourceName) { HtmlTemplate template = new HtmlTemplate(getClass().getResourceAsStream(resourceName)); template.setProperty("displayName", "Evan"); template.setProperty("bookingReference", "555555"); template.setProperty("bookingDate", "16 Jul 2010"); template.setProperty("amount", "R 1,200.00"); template.setProperty("travelerRow", 0, "travelerName", "Evan Summers"); template.setProperty("travelerRow", 1, "travelerName", "Tootie Milburn"); return template.getText(); } which uses the trivial helper class below to read the HTML template, and substitute the given values into the template, etc. public class HtmlTemplate { List lineList = new ArrayList(); InputStream inputStream; StringBuilder templateBuilder = new StringBuilder(); String trClass = null; StringBuilder rowBuilder = new StringBuilder(); String line; EntryList entryList = new EntryList(); public HtmlTemplate(InputStream inputStream) { this.inputStream = inputStream; } public void...


Date: July, 09 2010
Url: http://www.java.net/blog/evanx/archive/2010/07/09/trivial-templating


Others News

©2002-2019Java-Virtual-Machine.net mobirise | free web design software | Free Bootstrap Template | formoid.com | css menu maker