Results 1 to 6 of 6

Thread: XSLT view caching multiple Templates

  1. #1
    Join Date
    Aug 2004
    Location
    San Jose, CA
    Posts
    24

    Default XSLT view caching multiple Templates

    I'd like to have an XSLT view that caches multiple stylesheets set at runtime. It looks like AbstractXsltView only caches a single Templates instance for use across requests. Is this true? Has anyone done anything similar? Can anyone suggest caching strategies for the View layer. Thanks.

    - Justih

  2. #2
    Join Date
    Aug 2004
    Location
    Sydney
    Posts
    503

    Default

    I've done a bit of this. Any variation in the view was handled by the templates within the XSL file generating different output based on the XML supplied, not by the Java view object choosing to run a different XSL file against the XML -- otherwise the controller should have selected a different view.

    Can you give some more details on what you're doing and why you need to cache more than 1 template?

  3. #3
    Join Date
    Aug 2004
    Location
    San Jose, CA
    Posts
    24

    Default

    gmatthews, thanks for your help.
    I'll only know the stylesheets at runtime. I'd like to build a generic View implementation that can can be fed a javax.xml.transform.Source, cache the resulting Templates object, and transform the model. It seems like AbstractXsltView is only good at handling one Source at a time (over many requests, of course). Any help would be much appreciated.

    - Justin

  4. #4
    Join Date
    Aug 2004
    Location
    Sydney
    Posts
    503

    Default

    How do you determine which stylesheet to use?

    Without knowing all the details, I'd still ask along the lines of why you can't define a Spring view for each top level .xsl file, and then have the controller determine which view to use based on whatever runtime technique you use?

    That's probably why the Spring team have built AbstractXsltView the way it is -- so that you get the controller to choose which view to use, not the view choosing which view to use. After all, the view isn't really supposed to contain any logic.

    Other than that, your choices include:

    1. Copy/paste/modify AbstractXsltView to handle multiple managing multiple Templates objects, OR
    2. Somehow encode the view to use in the view name and create a ViewResolver implementation.

    However, both these options would tend to suck, and I'd still think the top option is the way things should be handled.

  5. #5
    Join Date
    Aug 2004
    Location
    San Jose, CA
    Posts
    24

    Default

    I'll never know the top-level stylesheets. They're added at runtime. I've built a view resolver that figures out which stylesheet to get from the app's internal configuration data store based on the request. I've started to implement my own XSLT View that caches multiple stylesheets, but I wanted to (a) verify that I understood AbstractXsltView correctly and (b) see if someone else had already tackled this.
    Your help is greatly appreciated.

    - Justin

  6. #6
    Join Date
    Aug 2004
    Location
    London, UK
    Posts
    339

    Default

    Quote Originally Posted by jmakeig
    I've built a view resolver that figures out which stylesheet to get from the app's internal configuration data store based on the request. I've started to implement my own XSLT View that caches multiple stylesheets
    If you're re-creating a templates cache in a shared bean, be careful not to break thread-safety. The act of one person adding a new template could cause other concurrent users to get corrupted responses.

    I'm pretty sure that you have understood AbstractXsltView correctly - it wasn't designed for this type of use case (which I suspect is pretty rare). My assumption here is that it's some kind of admin interface where new stylesheets are added and not something done by normal users of the app? I've done something very similar myself before but not in a Spring application.
    Darren Davison.
    Public Key: 0xE855B3EA

Similar Threads

  1. Multiple forms on one view?
    By brianstclair in forum Web
    Replies: 16
    Last Post: May 18th, 2012, 02:42 AM
  2. Replies: 9
    Last Post: Nov 1st, 2005, 10:36 PM
  3. Replies: 2
    Last Post: Jul 25th, 2005, 04:51 AM
  4. Content Provider vs View Model
    By Martin Kersten in forum Swing
    Replies: 21
    Last Post: Mar 10th, 2005, 02:25 PM
  5. Replies: 2
    Last Post: Sep 12th, 2004, 09:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •