Announcement Announcement Module
Collapse
No announcement yet.
XSLT view caching multiple Templates Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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?

    Comment


    • #3
      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

      Comment


      • #4
        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.

        Comment


        • #5
          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

          Comment


          • #6
            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.

            Comment

            Working...
            X