OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

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

[ Lists Home | Date Index | Thread Index ]
  • From: John Cowan <cowan@locke.ccil.org>
  • To: XML Dev <xml-dev@ic.ac.uk>
  • Date: Fri, 26 Jun 1998 12:22:33 -0400

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@ccil.org
	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@ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/
To (un)subscribe, mailto:majordomo@ic.ac.uk the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo@ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa@ic.ac.uk)





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS