RE: View Loading and Caching
"Andy Zeneski" <[email protected]> Wed, 26 Feb 2003 16:58:09 -0500
| Newsgroups | gmane.comp.java.jpublish.devel |
|---|---|
| Message-ID | <[email protected]> |
Anthony,
Can I make one suggestion which would make extending view renderers easier,
here is a patch which I made for the FreeMarkerViewHandler which could be
used by the others too.
With this patch, one could change the 'root' context for freemarker by
overloading a single method, then the rest of the code wouldn't have to be
maintained twice.
Let me know what you think.
-Andy
Index: FreeMarkerViewRenderer.java
===================================================================
RCS file:
/cvsroot/jpublish/jpublish/src/org/jpublish/view/freemarker/FreeMarkerViewRe
nderer.java,v
retrieving revision 1.4
diff -u -r1.4 FreeMarkerViewRenderer.java
--- FreeMarkerViewRenderer.java 26 Feb 2003 21:06:15 -0000 1.4
+++ FreeMarkerViewRenderer.java 26 Feb 2003 21:56:00 -0000
@@ -129,8 +129,7 @@
Writer out) throws IOException, ViewRenderException{
try{
Page page = (Page)context.get(JPublishContext.JPUBLISH_PAGE);
- FreeMarkerViewContext viewContext =
- new FreeMarkerViewContext(context);
+ Object viewContext = this.createTemplateContext(context, path);
Template template = fmConfig.getTemplate(path,
page.getLocale());
template.process(viewContext, out);
} catch(IOException e){
@@ -154,6 +153,18 @@
OutputStream out) throws IOException, ViewRenderException{
render(context, path, new InputStreamReader(in),
new OutputStreamWriter(out));
+ }
+
+ /** Create the 'root' context for the template engine
+
+ @param context The JPublishContext
+ @param path The path to the template
+ @return Object The 'root' template context
+ */
+ protected Object createTemplateContext(JPublishContext context, String
path) {
+ FreeMarkerViewContext viewContext =
+ new FreeMarkerViewContext(context);
+ return viewContext;
}
/** Load the configuration for the view.
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of
> Anthony Eden
> Sent: Wednesday, February 26, 2003 4:23 PM
> To: jpublish-developer
> Subject: [JPublish-developer] View Loading and Caching
>
>
> I just wanted to drop a note to the list to mention a new change
> which was just added in to the CVS. I have redesigned the view
> system so that template engine caching of is now possible within
> JPublish. Prior to today the templates were reparsed every time
> through the view engine. With the new changes they should be
> cached by the template engine if possible.
>
> Currently only the FreeMarker view does this (and it is not
> completely tested), but I should have the Velocity view done
> shortly (most of the work of writing a custom ResourceLoader is
> done, I just need to get Velocity to use it). I will also work
> on the WebMacro implementation in the near future.
>
> As an interesting side note, developing this new feature has
> actually given me a possible guide towards developing a unified
> repository system so that a lot of redundant code could be
> removed from JPublish (when dealing with loading stuff from the
> file system/db/web/etc.) I will post another message once I get
> this worked out better. It will probably not be until JPublish
> 3.x though.
>
> Sincerely,
> Anthony Eden
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Scholarships for Techies!
> Can't afford IT training? All 2003 ictp students receive scholarships.
> Get hands-on training in Microsoft, Cisco, Sun, Linux/UNIX, and more.
> www.ictp.com/training/sourceforge.asp
> _______________________________________________
> Jpublish-developer mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/jpublish-developer
>
-------------------------------------------------------
This SF.net email is sponsored by: Scholarships for Techies!
Can't afford IT training? All 2003 ictp students receive scholarships.
Get hands-on training in Microsoft, Cisco, Sun, Linux/UNIX, and more.
www.ictp.com/training/sourceforge.asp