aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Accessing xslt files from EJB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Accessing xslt files from EJB" Watch "Accessing xslt files from EJB" New topic
Author

Accessing xslt files from EJB

Angus Rose
Ranch Hand

Joined: Jun 21, 2002
Posts: 56
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
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30764
    
156

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Angus Rose
Ranch Hand

Joined: Jun 21, 2002
Posts: 56
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

Joined: Jun 21, 2002
Posts: 56
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
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
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.


I think, therefore I exist -- Rene Descartes
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
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.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Rusty Enisin
Ranch Hand

Joined: May 26, 2005
Posts: 107
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!


The squeaky wheel gets the grease. Well, that or replaced...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing xslt files from EJB