• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Accessing xslt files from EJB

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I'm currently writing an EJB that needs to transform an xml file using xslt. It does this using another object that actually does the transforming process. What I need to know is where to place the xml/xslt files in the EAR file as the xslt file may change at a later date and so I don't want to wrap it up in a jar file if at all possible.

Thanks in advance

Angus
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Angus,
I recommend placing the path to the XSLT file in a property file. That way, you can change the path later on when/if a different XSLT file is needed.
 
Angus Rose
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks,
where would I place the properties file though - within the ejb-jar or elsewhere within the .ear file? I need to do it this way so that I can use a relative URL.

Angus
 
Angus Rose
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jeanne,
could you supply a code snippet to show how I would access a properties file named xmlxsl.properties that is placed in a dir named 'properties' which in turn resides under the enterprise app root dir. This access is from an ejb running in oc4j.

Thanks in advance

Angus
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rose,


You need to make sure that the classpath contains the xmlxsl.properties (check your container classloading architecture). This is a quick and dirty solution and there are several problems with this approach, since different containers have different classloading strategies. It also could result in very subtle bugs if different versions of the same file are part of the classpath, etc. This are few of the reasons why people prefer using the java.util.ResourceBundle. I personally used the getResourceAsStream approache several times now and I learned how to leave with it :-) Unfortunately for the latest I have no code samples to share with you, but I�m pretty sure you might find some good examples on the net.
Regards.
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I doubt whether any of this should be done in an EJB container. An EJB should deal with objects. I would normally expect an EJB to return a transfer object which a servlet would marshall to XML for rendering with an XSLT stylesheet. After all, this is stuff for the presentation layer, not the business logic layer.

You will still build and deploy an EAR file containing the servlet and EJB code.
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Angus,

Instead of doing this with loading a property file:



I cut out the whole property thing by doing this:



You won't have to change a property file when your deployment environment changes. You cut out the step of having to read a property file just to find the path (then you have to go load that too). You can put your xsl in your package structure and manage it with your code.

I use a package structure like this: com.mycompany.resources.xsl. Then I put my xsl files in there.

If you are doing J2EE development with EJBs you will need to add each xsl file to the ejb-jar as an external resource. Then they will show up in the package structure.

Cheers!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic