In answer to your first question, you do not have to write your own ClassLoader -- the
Class object will load the resource using its ClassLoader -- in other words in your
Action you would have ...
InputStream xmlStream = this.getClass().getResourceAsStream("/resources/xyz.xml");
I don't know the answer to the second question -- I guess it depends on how are you
planning on parsing the XML. If you are using Digester I suggest starting with
http://jakarta.apache.org/commons/digester.html - there are links to the API
documentation as well as a couple of good online articles.
-----Original Message-----
From: Simon Kelly [mailto:[EMAIL PROTECTED]]
Sent: Friday, January 10, 2003 10:47 AM
To: Struts Users Mailing List
Subject: Re: Getting the full path of the context from within an Action
class
Cool.
Looks like the thing I'm after. But I have a couple of questions.
Will I have to write the ClassLoader for this? If so, do you know of any
examples I could have a look at?
Will the fact that the .xml file has recursive tags ( ie I can have
<X><X></X></X>) in the structure cause any major headaches in turning this
into a loaded bean?
Cheers
Simon
----- Original Message -----
From: "Siggelkow, Bill" <[EMAIL PROTECTED]>
To: "'Struts Users Mailing List'" <[EMAIL PROTECTED]>
Sent: Friday, January 10, 2003 4:29 PM
Subject: RE: Getting the full path of the context from within an Action
class
> Simon,
> You should load this resource using the Class object. Take a look at
the following:
>
>
http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Class.html#getResourceAsSt
ream(java.lang.String)
>
> -----Original Message-----
> From: Simon Kelly [mailto:[EMAIL PROTECTED]]
> Sent: Friday, January 10, 2003 10:19 AM
> To: Struts Users Mailing List
> Subject: Re: Getting the full path of the context from within an Action
> class
>
>
> Thanks Geir, that was quite useful to know.
>
> What I am trying to do is read in a .xml file from the classes/resources
> directory in an Action class and then to load a bean with it's contents.
I
> have had a look at the ResourceBundle class, but I can't see if that would
> be of any use to me.
>
> Any thoughts??
>
> Cheers, and thanks again,
>
> Simon.
>
> ----- Original Message -----
> From: "Arnesen, Geir" <[EMAIL PROTECTED]>
> To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> Sent: Friday, January 10, 2003 3:44 PM
> Subject: SV: Getting the full path of the context from within an Action
> class
>
>
> If you ned the path for the WEB-INF, - use a servlet, - which is loaded
> before the struts, by configuring it in the WEB.XML.
>
> In the servlet you execute...
> public static String directory =
> getServletContext().getRealPath("conf");
>
> This returns the physical location of the WEB-INF. You get the location
> from the action classes by accessing the servlet' static variable.
>
> Geir
>
>
>
> -----Opprinnelig melding-----
> Fra: Simon Kelly [mailto:[EMAIL PROTECTED]]
> Sendt: 10. januar 2003 15:24
> Til: Struts Users Mailing List
> Emne: Getting the full path of the context from within an Action class
>
>
> Hi,
>
> Which would be the better and more portable solution for getting the
> actual path of the API context from within a
> org.apache.struts.action.Action class?
>
> I am looking at either using
> mapping.getPath()
> or
> request.getContextPath()
>
> Are either of these going to give me an absolute (ie
> C:\xxx\yyy\WEB-INF\) path to the context on the local machine? Or will
> it be a relative URL?
>
> Cheers
>
> Simon
>
> Institut fuer
> Prozessdatenverarbeitung
> und Elektronik,
> Forschungszentrum Karlsruhe GmbH,
> Postfach 3640,
> D-76021 Karlsruhe,
> Germany.
>
> Tel: (+49)/7247 82-4042
> E-mail : [EMAIL PROTECTED]
>
>
> --
> To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
>
>
> --
> To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
>
>
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
>
>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>