Example usage for org.apache.commons.collections ExtendedProperties ExtendedProperties

List of usage examples for org.apache.commons.collections ExtendedProperties ExtendedProperties

Introduction

In this page you can find the example usage for org.apache.commons.collections ExtendedProperties ExtendedProperties.

Prototype

public ExtendedProperties(String file) throws IOException 

Source Link

Document

Creates and loads the extended properties from the specified file.

Usage

From source file:net.sf.zekr.engine.template.TemplateEngine.java

private TemplateEngine() {
    try {/*from  w w  w  .  j av  a2s .  c om*/
        System.setProperty("zekr.home", Naming.getWorkspace());
        Velocity.setExtendedProperties(new ExtendedProperties("res/config/lib/velocity.properties"));
        Velocity.init();
        context = new VelocityContext();
    } catch (Exception e) {
        Logger.getLogger(this.getClass()).log(e);
    }
}

From source file:autohit.server.BasicBootstrap.java

/**
 * Properties constructor.  Give it a full path to the 
 * properties file.//from w w  w. j a  v a  2s. c  o  m
 * @param rootProps path to properties for System Context
 */
public BasicBootstrap(String rootProps) throws Exception {

    // Build the properties
    ExtendedProperties ep = new ExtendedProperties(rootProps);

    // Build a context
    String logprop = (String) Utils.testGetProperty(AutohitProperties.BOOTSTRAP_CONTEXT_CLASS, ep);
    if (logprop == null) {
        throw new Exception("SystemContext class for bootstrap not specified in properties.");
    }
    try {
        Class t = Class.forName(logprop);
        sc = (SystemContext) t.newInstance();
    } catch (Exception ec) {
        throw new Exception("Specified SystemContext class for bootstrap not found.  class name=" + logprop
                + ".  message=" + ec.getMessage());
    }
    sc.init(ep);

    // Services set
    services = new HashSet();
}

From source file:AloneService.java

/**
 * init and destroy were added in jakarta-tomcat-daemon.
 *///from www .ja v a 2s  .  c  om
public void init(String[] arguments) throws Exception {
    /* Set the err */
    System.setErr(new PrintStream(new FileOutputStream(new File("/ServiceDaemon.err"), true)));
    System.err.println("ServiceDaemon: instance " + this.hashCode() + " init");

    /* read the properties file */
    prop = new ExtendedProperties("startfile");

    /* create an array to store the processes */
    int i = 0;
    for (Iterator e = prop.getKeys(); e.hasNext();) {
        e.next();
        i++;
    }
    System.err.println("ServiceDaemon: init for " + i + " processes");
    proc = new Process[i];
    readout = new ServiceDaemonReadThread[i];
    readerr = new ServiceDaemonReadThread[i];
    for (i = 0; i < proc.length; i++) {
        proc[i] = null;
        readout[i] = null;
        readerr[i] = null;
    }

    System.err.println("ServiceDaemon: init done ");

}

From source file:autohit.universe.UniverseProperties.java

/**
 *  Constructor.  Build from a file.  We will propagate any exception.
 * @param propsPath path to properties file
 *///from   w w w .j av a2  s .  c  o  m
public UniverseProperties(String propsPath) throws Exception {
    try {
        prop = new ExtendedProperties(propsPath);
        completeConstruction();
    } catch (Exception e) {
        // FUBAR.  kill the properties.
        prop = null;
        throw e;
    }
}

From source file:bboss.org.apache.velocity.anakia.AnakiaTask.java

/**
 * Main body of the application//from ww w.  j a va 2 s. c o  m
 * @throws BuildException
 */
public void execute() throws BuildException {
    DirectoryScanner scanner;
    String[] list;

    if (baseDir == null) {
        baseDir = project.resolveFile(".");
    }
    if (destDir == null) {
        String msg = "destdir attribute must be set!";
        throw new BuildException(msg);
    }
    if (style == null) {
        throw new BuildException("style attribute must be set!");
    }

    if (velocityPropertiesFile == null) {
        velocityPropertiesFile = new File("velocity.properties");
    }

    /*
     * If the props file doesn't exist AND a templatePath hasn't
     * been defined, then throw the exception.
     */
    if (!velocityPropertiesFile.exists() && templatePath == null) {
        throw new BuildException("No template path and could not " + "locate velocity.properties file: "
                + velocityPropertiesFile.getAbsolutePath());
    }

    log("Transforming into: " + destDir.getAbsolutePath(), Project.MSG_INFO);

    // projectFile relative to baseDir
    if (projectAttribute != null && projectAttribute.length() > 0) {
        projectFile = new File(baseDir, projectAttribute);
        if (projectFile.exists()) {
            projectFileLastModified = projectFile.lastModified();
        } else {
            log("Project file is defined, but could not be located: " + projectFile.getAbsolutePath(),
                    Project.MSG_INFO);
            projectFile = null;
        }
    }

    Document projectDocument = null;
    try {
        if (velocityPropertiesFile.exists()) {
            String file = velocityPropertiesFile.getAbsolutePath();
            ExtendedProperties config = new ExtendedProperties(file);
            ve.setExtendedProperties(config);
        }

        // override the templatePath if it exists
        if (templatePath != null && templatePath.length() > 0) {
            ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templatePath);
        }

        ve.init();

        // get the last modification of the VSL stylesheet
        styleSheetLastModified = ve.getTemplate(style).getLastModified();

        // Build the Project file document
        if (projectFile != null) {
            projectDocument = builder.build(projectFile);
        }
    } catch (Exception e) {
        log("Error: " + e.toString(), Project.MSG_INFO);
        throw new BuildException(e);
    }

    // find the files/directories
    scanner = getDirectoryScanner(baseDir);

    // get a list of files to work on
    list = scanner.getIncludedFiles();
    for (int i = 0; i < list.length; ++i) {
        process(list[i], projectDocument);
    }

}

From source file:autohit.common.deployment.DeploymentConfigure.java

/**config config [config name] [root] [prop file]
 * Process a configuration//from  w  w w .  j  a  va 2 s .  c  o  m
 * @param config config file name
 * @param root directory root
 * @param vars variable replacement set.  a properties file.
 * @return true if successful, false if there is an error
 */
public boolean configure(String config, String root, String vars) {

    ExtendedProperties varprops;

    // Get variables file and load into varprops
    String varPath = new String(root + AutohitProperties.vVAR_ROOT + vars);
    File varFile = new File(varPath);
    if (!varFile.exists()) {
        System.out.println("Configuration values file does not exist= " + vars
                + ".  It should be under the /etc directory.");
        return false;
    }
    try {
        varprops = new ExtendedProperties(varPath);
    } catch (Exception e) {
        System.out.println("Configuration values file is unreadable.");
        return false;
    }
    return configure(config, root, varprops);
}

From source file:bboss.org.apache.velocity.runtime.RuntimeInstance.java

/**
 * Add all properties contained in the file fileName to the RuntimeInstance properties
 *//*from w  w w . j  ava2  s  . c o m*/
public void setProperties(String fileName) {
    ExtendedProperties props = null;
    try {
        props = new ExtendedProperties(fileName);
    } catch (IOException e) {
        throw new VelocityException("Error reading properties from '" + fileName + "'", e);
    }

    Enumeration en = props.keys();
    while (en.hasMoreElements()) {
        String key = en.nextElement().toString();
        setProperty(key, props.get(key));
    }
}

From source file:com.arcbees.plugin.velocity.RuntimeInstanceCustom.java

/**
 * Initialize the Velocity Runtime with the name of
 * ExtendedProperties object.//w  w  w.j  ava 2 s  . com
 *
 * @param configurationFile
 * @throws Exception When an error occurs during initialization.
 */
public void init(String configurationFile) throws Exception {
    overridingProperties = new ExtendedProperties(configurationFile);
    init();
}

From source file:bboss.org.apache.velocity.runtime.RuntimeInstance.java

/**
 * Initialize the Velocity Runtime with the name of
 * ExtendedProperties object./*from  w  ww  .j  a  v  a 2 s  . co m*/
 *
 * @param configurationFile
 */
public void init(String configurationFile) {
    try {
        setProperties(new ExtendedProperties(configurationFile));
    } catch (IOException e) {
        throw new VelocityException("Error reading properties from '" + configurationFile + "'", e);
    }
    init();
}

From source file:org.apache.cayenne.unit.di.server.ServerCaseDataSourceInfoProvider.java

public ServerCaseDataSourceInfoProvider() throws IOException {

    File file = connectionPropertiesFile();
    ExtendedProperties properties = file.exists() ? new ExtendedProperties(file.getAbsolutePath())
            : new ExtendedProperties();

    this.connectionProperties = new ConnectionProperties(properties);
    logger.info("Loaded  " + connectionProperties.size() + " DataSource configurations from properties file");

    this.inMemoryDataSources = new HashMap<>();

    // preload default in-memory DataSources. Will use them as defaults if
    // nothing is configured in ~/.cayenne/connection.properties
    DataSourceInfo hsqldb = new DataSourceInfo();
    hsqldb.setAdapterClassName(HSQLDBAdapter.class.getName());
    hsqldb.setUserName("sa");
    hsqldb.setPassword("");
    hsqldb.setDataSourceUrl("jdbc:hsqldb:mem:aname");
    hsqldb.setJdbcDriver("org.hsqldb.jdbcDriver");
    hsqldb.setMinConnections(ConnectionProperties.MIN_CONNECTIONS);
    hsqldb.setMaxConnections(ConnectionProperties.MAX_CONNECTIONS);
    inMemoryDataSources.put("hsql", hsqldb);

    DataSourceInfo h2 = new DataSourceInfo();
    h2.setAdapterClassName(H2Adapter.class.getName());
    h2.setUserName("sa");
    h2.setPassword("");
    h2.setDataSourceUrl("jdbc:h2:mem:aname;MVCC=TRUE;DB_CLOSE_DELAY=-1");
    h2.setJdbcDriver("org.h2.Driver");
    h2.setMinConnections(ConnectionProperties.MIN_CONNECTIONS);
    h2.setMaxConnections(ConnectionProperties.MAX_CONNECTIONS);
    inMemoryDataSources.put("h2", h2);

    DataSourceInfo derby = new DataSourceInfo();
    derby.setAdapterClassName(DerbyAdapter.class.getName());
    derby.setUserName("sa");
    derby.setPassword("");
    derby.setDataSourceUrl("jdbc:derby:target/testdb;create=true");
    derby.setJdbcDriver("org.apache.derby.jdbc.EmbeddedDriver");
    derby.setMinConnections(ConnectionProperties.MIN_CONNECTIONS);
    derby.setMaxConnections(ConnectionProperties.MAX_CONNECTIONS);
    inMemoryDataSources.put("derby", derby);

    DataSourceInfo sqlite = new DataSourceInfo();
    sqlite.setAdapterClassName(SQLiteAdapter.class.getName());
    sqlite.setUserName("sa");
    sqlite.setPassword("");
    sqlite.setDataSourceUrl("jdbc:sqlite:file:memdb?mode=memory&cache=shared&date_class=text");
    sqlite.setJdbcDriver("org.sqlite.JDBC");
    sqlite.setMinConnections(ConnectionProperties.MIN_CONNECTIONS);
    sqlite.setMaxConnections(ConnectionProperties.MAX_CONNECTIONS);
    inMemoryDataSources.put("sqlite", sqlite);
}