|
Re: [XPAND] perform OAW code without creating physical files [message #504044 is a reply to message #503986] |
Wed, 16 December 2009 22:17 |
|
Hello Caroline,
afaik this is not possible out of the box. it may be possible by hooking into some internals of Xpand e.g. like this
import java.io.Reader;
import java.io.StringReader;
import org.eclipse.internal.xpand2.ast.Template;
import org.eclipse.internal.xpand2.parser.XpandParseFacade;
import org.eclipse.xpand2.XpandExecutionContextImpl;
import org.eclipse.xpand2.XpandFacade;
import org.eclipse.xpand2.output.Outlet;
import org.eclipse.xpand2.output.OutputImpl;
import org.eclipse.xtend.expression.Resource;
public class XpandRunner {
public static void main(String[] args) {
OutputImpl out = new OutputImpl();
out.addOutlet(new Outlet("src-gen"));
XpandExecutionContextImpl ctx = new XpandExecutionContextImpl(out, null) {
private Template template;
@Override
public Resource currentResource() {
if (template == null) {
String templateString = "«DEFINE test FOR String»«FILE \"test.txt\"»Hello «this»«ENDFILE»«ENDDEFINE»";
Reader r = new StringReader(templateString );
template = XpandParseFacade.file(r , "sample/test.xpt");
}
return template;
}
};
XpandFacade.create(ctx).evaluate("test", "Welt", new Object[] {});
}
}
but this may not be neccesary. can you tell more about your usecase. that do you mean with "exctracted from a file" ?
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04852 seconds