[JET] [message #915682] |
Mon, 17 September 2012 18:47 |
vinay Missing name Messages: 1 Registered: September 2012 |
Junior Member |
|
|
I am new to JET. I am looking to use it as a alternative to velocity as a templating framework in a java app.
From what I understand, you need to create a JET project to create java classes for the template, then you can 'run' the template (ie the generated java class for the template) - there could be one JET project which requires eclipse, however, one could run the template from a simple java project.
Came across http://wiki.eclipse.org/M2T-JET-FAQ/How_do_I_run_a_JET_template_from_Java%3F
However, am not sure if I am following it correctly.
I was wondering if there were any samples that showed how to get it working in a java project (with info on which jars I would need to use in the java app)
I tried this in the java app, but get class not found exception in
TransformContextExtender.getInstance(context);
/**
* @param args
*/
public static void main(final String[] args) {
_jet_banner htmlpage = new _jet_banner();
FileWriter output;
BufferedWriter writer;
JET2Context context = createJETContext(null, null);
JET2Writer out = new BodyContentWriter();
htmlpage.generate(context, out);
finalizeContent(out, null, null);
System.out.println(out);
}
public static JET2Context createJETContext(final Object modelRoot, final Map<String, ?> variables) {
Map<String, Object> copiedVariables = new HashMap<String, Object>(variables != null ? variables
: Collections.<String, Object> emptyMap());
// ensure that c:iterate can set the XPath context object
copiedVariables.put("org.eclipse.jet.taglib.control.iterateSetsContext", Boolean.TRUE); //$NON-NLS-1$
final JET2Context context = new JET2Context(modelRoot, copiedVariables);
// this statement has the side effect of initializing tag handling
TransformContextExtender.getInstance(context);
return context;
}
private static final void finalizeContent(final JET2Writer writer, final Object committedObject, final String existingContent)
throws JET2TagException {
final IWriterListener[] eventListeners = writer.getEventListeners();
for (IWriterListener eventListener : eventListeners) {
if (existingContent != null && eventListener instanceof IWriterListenerExtension) {
((IWriterListenerExtension) eventListener).finalizeContent(writer, committedObject, existingContent);
} else {
eventListener.finalizeContent(writer, committedObject);
}
}
}
Thanks,
Vinay
|
|
|
Powered by
FUDForum. Page generated in 0.05755 seconds