Example usage for org.apache.commons.configuration ConfigurationFactory setBasePath

List of usage examples for org.apache.commons.configuration ConfigurationFactory setBasePath

Introduction

In this page you can find the example usage for org.apache.commons.configuration ConfigurationFactory setBasePath.

Prototype

public void setBasePath(String basePath) 

Source Link

Document

Sets the basePath for all file references from this Configuration Factory.

Usage

From source file:gda.configuration.properties.JakartaPropertiesConfig.java

/**
 * Workaround for an apparent bug with factory base path default of ".". Configuration descriptor file (config.xml)
 * contains references to one or more property data sources. Files should work with relative pathnames. However just
 * specifying "java.properties" doesnt find the file! So need to fixup the factory base path with the location of
 * the config.xml file. This appears to fix the problem - eg "java.properties" is now found.
 * //w w  w  .  j  a  v a2 s  . c o m
 * @param factory
 *            the current configuration factory in use
 * @param listName
 *            file path name of the property data source
 */
private void configFactoryBasePathBugWorkaround(ConfigurationFactory factory, String listName) {
    // String basePath = factory.getBasePath(); // retain for debugging

    // work out length of path excluding filename
    int pathEndIndex = 0;
    pathEndIndex = Math.max(pathEndIndex, listName.lastIndexOf('\\'));
    pathEndIndex = Math.max(pathEndIndex, listName.lastIndexOf('/'));

    // set the path into factory, since its default of "." doesnt
    // successfully fetch files from the same folder as config.xml!!
    String p = listName.substring(0, pathEndIndex);
    factory.setBasePath(p);

    // String setBasePath = factory.getBasePath(); // retain for debugging
}