[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Configuration files (was Re: IBM XML for Java 1.0.0)

  • From: John Cowan <cowan@l...>
  • To: XML Dev <xml-dev@i...>
  • Date: Fri, 26 Jun 1998 12:22:33 -0400

sax configuration
I sent this off-list to Peter, but since Michael Kay's post,
I think I'd better broadcast it.

Peter Murray-Rust writes:

> The installation involved re-compilation because the program holds a list
> of SAXDriver classes internally (6 so far). I'd really like to do this sort
> of thing (including menu re-generation) driven by declarative files from
> outside the program (so recompilation isn't necessary). My question is:
> *What is the best way of associating files with Java applications in a
> platform independent manner?*

I'll talk about that point below, but I'm not sure why you need it
for this use.  You can create parsers with the
class method "org.xml.sax.helpers.ParserFactory.makeParser()":
it will return a SAX parser of the class whose name is specified
by the "org.xml.sax.parser" system property.  If you want to give
the user a choice within the program, there is also a method
"makeParser(aString)", where the argument is the class name
of the parser.  This class is supplied with SAX and should be
supplied with every SAX-compatible parser.

> Traditionally I would use a different method for each OS (.jumborc for
> UNIX, C:\jumbo.ini, etc.) I would like to avoid having to tell installers
> what they have to do. So - assume I have files myResource.xml,
> icons/jumbo.gif, etc. which I wish to make available to the application.
>         - is there a standard place to put these?
>         - is it a good idea to use a jar file - if so how do I reference them from
> the program? [The *.class are referenced by classpath - but what about the
> others?]

To read an arbitrary resource from the CLASSPATH, call the static method
ClassLoader.getSystemResource(aString) where aString is the file name
relative to one of the directories or {jar,zip}files in the path.
That returns a java.net.URL.  If you want an InputStream instead,
call getSystemResourceAsStream instead.

Here's a sample Java class which fetches a resource (residing in the
same directory as the .class file), first as an URL object so as
to print the URL (what it prints is system-dependent); second as
an InputStream so that the contents can be printed.  You can test
it by moving ibtwsh.dtd (or substitute your own file name) to any
directory on the CLASSPATH.


-------cut here--------
import java.io.*;
import java.util.*;
import java.net.*;
class testres {

public static void main(String[] argv) {
	URL u = ClassLoader.getSystemResource("ibtwsh.dtd");
	InputStream i = ClassLoader.getSystemResourceAsStream("ibtwsh.dtd");

	System.out.println(u.toExternalForm());
	BufferedReader b = new BufferedReader(new InputStreamReader(i));
	String s;

	try {
	while ((s = b.readLine()) != null)
		System.out.println(s);
	}
	catch (IOException e) {}
	}
}
-------cut here--------
 
-- 
John Cowan	http://www.ccil.org/~cowan		cowan@c...
	You tollerday donsk?  N.  You tolkatiff scowegian?  Nn.
	You spigotty anglease?  Nnn.  You phonio saxo?  Nnnn.
		Clear all so!  'Tis a Jute.... (Finnegans Wake 16.5)

xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@i...
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/
To (un)subscribe, mailto:majordomo@i... the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo@i... the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa@i...)


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.