Re: reading the xml file

2003-10-19 Thread Larry Meadors
Doing it the way you describe will only work from a servlet. If that is
ok, stop reading and do it that way. :-)

A more general way would be to use a classloader instead. There are many
good articles on how to do this (google for 'classloader resource'), but
 one simple way is this:

  InputStream is = 
getClass().getClassLoader().
getResourceAsStream("foo.xml");

To do this, the resource foo.xml *must* be on your classpath. If it is
in a package, you need to specify that in the call made to the
getResourceAsStream() method. Also this cannot be done in a static
context. If you are in a static block of code, you can use this instead:

  InputStream is = 
Thread.currentThread().getContextClassLoader().
getResourceAsStream("foo.xml");

Larry

>>> [EMAIL PROTECTED] 10/19/03 10:22 AM >>>
Hallo,
I thinkin how I can read the xml file from /WEB-INF directory.

I found something as 
InputStream is =
servletContext.getResourceAsStream("/WEB-INF/something.xml")

but how I can get servletContext?. Or, is t good way to read data, as 
datasource names, from xml file and store it as instance of config file
in 
session? is there any better way?

Thanks for help,
Jiri


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: reading the xml file

2003-10-19 Thread Craig R. McClanahan
Jiri Chaloupka wrote:

Hallo,
I thinkin how I can read the xml file from /WEB-INF directory.
I found something as 
InputStream is = servletContext.getResourceAsStream("/WEB-INF/something.xml")

but how I can get servletContext?.

From inside an Action, you can call getServlet().getServletContext().

Or, is t good way to read data, as 
datasource names, from xml file and store it as instance of config file in 
session? is there any better way?

 

It had *better* be a good way to read data, because Struts uses this 
technique itself to read your struts-config.xml file :-).

A common technique is to read configuration information from a resource 
like this at the startup time of your web application (in Struts, you 
could use a PlugIn for this and put the reading code in the init() 
method).  After reading, you would typically store the resulting data 
into servlet context attributes (also known as application scope) so 
that they are available to all users.  Indeed, this is exactly what 
Struts does -- for example, the ModuleConfig for the default application 
module is stored under servlet context attribute key 
"org.apache.struts.action.Module" (normally referenced by the symbolic 
constant Globals.MODULE_KEY) so that all parts of Struts have access to it.

Thanks for help,
Jiri
 

Craig



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: reading the xml file

2003-10-19 Thread James Mitchell
Take a look at the DigestingPlugin:

http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=digestingplugin&b
tnG=Google+Search



--
James Mitchell
Software Engineer / Struts Evangelist
http://www.struts-atlanta.org
678.910.8017
AIM:jmitchtx




> -Original Message-
> From: Jiri Chaloupka [mailto:[EMAIL PROTECTED] 
> Sent: Sunday, October 19, 2003 12:23 PM
> To: [EMAIL PROTECTED]
> Subject: reading the xml file
> 
> 
> Hallo,
> I thinkin how I can read the xml file from /WEB-INF directory.
> 
> I found something as 
> InputStream is = 
> servletContext.getResourceAsStream("/WEB-INF/something.xml")
> 
> but how I can get servletContext?. Or, is t good way to read data, as 
> datasource names, from xml file and store it as instance of 
> config file in 
> session? is there any better way?
> 
> Thanks for help,
> Jiri
> 
> 
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]