Basic Restlet integration is handled by the org.sarugo.xtc.restlet.TemplateRepresentation class. This class is similar to those for Velocity and FreeMarker.
Example usage:
Template template = factory.getTemplate("/restlet.xhtml"); // path is resolved by the classloader TemplateRepresentation rep = new TemplateRepresentation(template, MediaType.APPLICATION_XHTML_XML); rep.setVariable("message", "Hello World!");
The path to the template can be any valid URI, e.g.
Template template = factory.getTemplate("file:///restlet.xhtml"); // full path to file system
Also supported is compilation of templates from the filesystem using the org.sarugo.xtc.restlet.TemplateDirectory class, an extension of org.restlet.Directory.
Example usage (.xhtml files in /var/www will be processed by XTC):
String dirUri = "file:///var/www/"; Component component = new Component(); component.getServers().add(Protocol.HTTP, 9684); component.getClients().add(Protocol.FILE); TemplateDirectory directory = new TemplateDirectory(component .getContext(), dirUri); component.getDefaultHost().attach("", directory); component.start();
If you are running under a servlet, you will need to replace the default (classpath based) resource resolver in the template factory:
ServletContextAdapter adapter = (ServletContextAdapter) getContext();
factory.setResolver(new ServletResolver(adapter.getServletContext()));
