Run generate method for a single JET2 template [message #40791] |
Tue, 22 January 2008 17:21  |
Eclipse User |
|
|
|
Is there a way to run a single template's generate method?
I'm trying:
public void testJETTrans() throws Exception
{
JET2Context jetcontext = new JET2Context(null, Collections.EMPTY_MAP);
JET2Writer jetwriter = new BodyContentWriter();
_jet_main test = new _jet_main();
test.generate(jetcontext, jetwriter);
}
But I get a java.lang.NullPointerException for the TagFactory of context.
Looking at the API for TagFactory, I'm not sure how to create and set it
to my context. Is what I'm trying to do possible? I'm creating the unit
test and want to run templates one at a time and be able to compare my
expected result to the in memory result of the template.
|
|
|
|
Re: Run generate method for a single JET2 template [message #40886 is a reply to message #40824] |
Wed, 23 January 2008 13:01  |
Eclipse User |
|
|
|
Originally posted by: pankaj.surti.accenture.com
Hi Roshan,
I use the following way to get what you need, this is based on the post
http://dev.eclipse.org/newslists/news.eclipse.modeling.m2t/m sg00364.html
Can someone confirm which method is better?
String[] jetTransformsToSearch = { "com.x1.t1.transform" }; // plug-in name
final String templatePath = "src/main/templates/MyTemplate.jet"; //
template name
final JET2Context context1 = new JET2Context( null ); // create a context
context1.setTagFactory(new TagFactoryImpl(context1)); // attach the
tagfactory
context1.setVariables(); // set all the varibles required by the template
final BufferedJET2Writer out1 = new BodyContentWriter(); // create a writer
// tricky code below, watch out, but works...
JET2TemplateManager.run
(
jetTransformsToSearch,
new JET2TemplateManager.ITemplateOperation() {
public void run(JET2TemplateManager.ITemplateRunner templateRunner)
{
templateRunner.generate( templatePath, context1, out1 );
}
}
);
// do something with the result
String testOutputXML = out1.getContent();
Thanks,
- Pankaj.
|
|
|
Powered by
FUDForum. Page generated in 0.08704 seconds