Ah, ok, in the case of Database-loaded templates with Seam Render, that's the reason why I made the <i>TemplateResolver </i>class in the first place. The template path in render is actually an extensible lookup scheme.<br>
<br><b>So:</b><br><br><div style="margin-left: 40px;">@include{"db:users/1/order/12/template"}@end{}</div><br><b>Could be interpreted by a TemplateResolver which would perform the DB lookup and provide the template.</b><br>
<br>You'd need a <i>DatabaseTemplateResolver </i>and <i>DatabaseTemplateResource</i>. Once that's done, and you define your path scheme, you're all set! The resolver will handle lookups automatically! Caching templates so that you don't hammer the database might be a few extra steps.<br>
<b><br>First, you register the resolver in the services file:</b><br><br><div style="margin-left: 40px;">/META-INF/services/org.jboss.seam.render.spi.TemplateResolver<br>com.example.myapp.DatabaseTemplateResolver<br></div>
<br><b>Then it's then as simple as:</b><br><br><div style="margin-left: 40px;">@Inject TemplateCompiler compiler;<br></div><div style="margin-left: 40px;">TemplateResource<?> template = compiler.compile("db:nameOfTemplate/id12/param2/");<br>
<br>template.render(); //already integrated with CDI internally :)<br><br>// or the template lookup can be as simple as a name or id, but I still recommend the use a "prefix:"<br>// "db:passwordRecovery"<br>
<br></div><b>Templates of any resource type can reference templates of another type:<br></b><div style="margin-left: 40px;"><br>TemplateResource<?> template = compiler.compile("db:nameOfTemplate/id12/param2/");<br>
<br>// the template above contains an include statement to a classpath template, which in turn includes another database template.<br><br>@include{"/org/jboss/seam/mail/basicHtmlTemplate.render"} @end{}<br>----> @include{"db:templateThatChangesFrequently"} @end{}<br>
<br>// This from within your database template, will perform a classpath or filesystem lookup (using the included resolvers.) So you can do cool things like cross-resolver referencing of templates.<br></div><br>~Lincoln<br>
<br><br><br><div class="gmail_quote">On Mon, Mar 7, 2011 at 3:57 PM, Cody Lerum <span dir="ltr"><<a href="mailto:cody.lerum@gmail.com">cody.lerum@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
You definitely want the ability to send in the template content via<br>
inputstream however like I do with mail template.<br>
<br>
I for example store my templates in the database.<br>
<font color="#888888"><br>
-C<br>
</font><div><div></div><div class="h5"><br>
On Mon, Mar 7, 2011 at 1:19 PM, Lincoln Baxter, III<br>
<<a href="mailto:lincolnbaxter@gmail.com">lincolnbaxter@gmail.com</a>> wrote:<br>
> :)<br>
><br>
> BTW. RenderTemplate would look something like this... since Render has its<br>
> own TemplateResolver SPI, it wouldn't be very complicated from Seam Mail's<br>
> end.<br>
><br>
> I don't think there's a real way that the MailTemplate interface would go<br>
> with Render, unless an additional render TemplateResource implementation<br>
> were provided to wrap it internally here. The only issue is that Render<br>
> attempts to resolve relative paths in templates, so using MailTemplate<br>
> doesn't really make sense here. Really render already implements a good deal<br>
> of what you are having to do in mail by trying to abstract the template<br>
> input stream from the templating system itself... I believe you'll have a<br>
> similar problem with Freemarker (or even with velocity if folks use any<br>
> @Include("templateName.path") declarations.<br>
><br>
> Thoughts?<br>
><br>
> /*<br>
> * JBoss, Home of Professional Open Source<br>
> * Copyright 2011, Red Hat, Inc., and individual contributors<br>
> * by the @authors tag. See the copyright.txt in the distribution for a<br>
> * full listing of individual contributors.<br>
> *<br>
> * Licensed under the Apache License, Version 2.0 (the "License");<br>
> * you may not use this file except in compliance with the License.<br>
> * You may obtain a copy of the License at<br>
> * <a href="http://www.apache.org/licenses/LICENSE-2.0" target="_blank">http://www.apache.org/licenses/LICENSE-2.0</a><br>
> * Unless required by applicable law or agreed to in writing, software<br>
> * distributed under the License is distributed on an "AS IS" BASIS,<br>
> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<br>
> * See the License for the specific language governing permissions and<br>
> * limitations under the License.<br>
> */<br>
><br>
> package org.jboss.seam.mail.templating.render;<br>
><br>
> import java.io.InputStream;<br>
> import java.util.HashMap;<br>
> import java.util.Map;<br>
><br>
> import org.jboss.seam.mail.templating.MailTemplate;<br>
> import org.jboss.seam.mail.templating.TemplateImpl;<br>
> import org.jboss.seam.render.TemplateCompiler;<br>
> import org.jboss.seam.render.spi.TemplateResolver;<br>
> import org.jboss.seam.render.spi.TemplateResource;<br>
> import org.jboss.seam.render.template.CompiledTemplateResource;<br>
><br>
> /**<br>
> * @author <a href="mailto:<a href="mailto:lincolnbaxter@gmail.com">lincolnbaxter@gmail.com</a>">Lincoln Baxter, III</a><br>
> */<br>
> public class RenderTemplate implements TemplateImpl<br>
> {<br>
> private final CompiledTemplateResource template;<br>
><br>
> public RenderTemplate(TemplateCompiler compiler, final MailTemplate<br>
> template)<br>
> {<br>
> // not sure this integration really makes sense. Render should<br>
> probably be responsible only for delivering a java.lang.String as output.<br>
> TemplateResource<InputStream> resource = new<br>
> TemplateResource<InputStream>()<br>
> {<br>
> @Override<br>
> public String getPath()<br>
> {<br>
> return template.getTemplateName();<br>
> }<br>
><br>
> @Override<br>
> public InputStream getInputStream()<br>
> {<br>
> return template.getInputStream();<br>
> }<br>
><br>
> @Override<br>
> public long getLastModified()<br>
> {<br>
> return 0;<br>
> }<br>
><br>
> @Override<br>
> public InputStream getUnderlyingResource()<br>
> {<br>
> return getInputStream();<br>
> }<br>
><br>
> @Override<br>
> public TemplateResolver<InputStream> getResolvedBy()<br>
> {<br>
> return new TemplateResolver<InputStream>()<br>
> {<br>
> @Override<br>
> public TemplateResource<InputStream> resolve(String target)<br>
> {<br>
> // render will throw an error if this is reached<br>
> return null;<br>
> }<br>
><br>
> @Override<br>
> public TemplateResource<InputStream><br>
> resolveRelative(TemplateResource<InputStream> origin, String target)<br>
> {<br>
> // render will throw an error if this is reached<br>
> return null;<br>
> }<br>
> };<br>
> }<br>
> };<br>
><br>
> this.template = compiler.compile(resource);<br>
> }<br>
><br>
> public RenderTemplate(TemplateCompiler compiler, String path)<br>
> {<br>
> template = compiler.compile(path);<br>
> }<br>
><br>
> public RenderTemplate(TemplateCompiler compiler, TemplateResource<?><br>
> resource)<br>
> {<br>
> template = compiler.compile(resource);<br>
> }<br>
><br>
> public RenderTemplate(CompiledTemplateResource template)<br>
> {<br>
> this.template = template;<br>
> }<br>
><br>
> @Override<br>
> public String merge(Map<String, Object> context)<br>
> {<br>
> Map<Object, Object> map = new HashMap<Object, Object>();<br>
> map.putAll(context);<br>
><br>
> String rendered = template.render(map);<br>
> return rendered;<br>
> }<br>
> }<br>
><br>
><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Lincoln Baxter, III<br><a href="http://ocpsoft.com">http://ocpsoft.com</a><br><a href="http://scrumshark.com">http://scrumshark.com</a><br>"Keep it Simple"<br>