DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=29036>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=29036

[configuration] Load file configurations from the classpath





------- Additional Comments From [EMAIL PROTECTED]  2004-05-18 08:53 -------
I came up with a solution for XML files but I can't get it to work for 
properties, it breaks the tests.  For XML I did this:

public class HierarchicalDOM4JConfiguration ...

   /**
    * Loads and parses an XML document. The file to be loaded must have
    * been specified before.
    * @throws Exception if an error occurs
    */
   public void load() throws ConfigurationException {

                  // first try to find file on the classpath
      URL url = getClass().getResource("/" + file);
      if (url != null) {
         File f = new File(url.getFile());
         if (f.exists()) {
            load(url);
         }
      } else {
                           // file is not on the classpath, so use the old 
method
         try {
            load(ConfigurationUtils.getURL(getBasePath(), getFileName()));
         } catch (MalformedURLException mue) {
            throw new ConfigurationException("Could not load from " + 
getBasePath() + ", " + getFileName());
         }
      }
   }

and for properties:

public class PropertiesConfiguration ...

   protected InputStream getPropertyStream(String resourceName) throws 
IOException {
      InputStream resource = null;

      resource = getClass().getResourceAsStream("/" + extractFileName
(resourceName));
      if (resource != null) {
         return resource;
      }

      URL url = null;
      try {
         url = ConfigurationUtils.getURL(getBasePath(), resourceName);
      } /* try */
      catch (MalformedURLException uex) {
         throw new IOException("Cannot obtain URL for resource " + 
resourceName);
      } /* catch */

      resource = url.openStream();

      setBasePath(url.toString());
      setIncludesAllowed(true);

      return resource;
   }


I hope that helps.  I think some serious design rethinking needs to take place 
to implement this.  I really hope this will be come a priority, I don't find it 
very useful that all the config files must be located in the same directory as 
the configuration.xml.  For now we can work around this by copying our config 
files and not embedding them in the JARs but I really don't like this approach.

Michael

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

Reply via email to