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() 

Source Link

Document

Creates an empty extended properties object.

Usage

From source file:adalid.commons.properties.PropertiesHandler.java

public static ExtendedProperties getExtendedProperties(File file, Level badFileLogLevel,
        Level goodFileLogLevel) {
    ExtendedProperties extendedProperties = new ExtendedProperties();
    String filename = file == null ? "" : file.getPath();
    if (file == null) {
        logger.error("null properties file");
    } else if (file.isFile()) {
        try {// w w  w . j  a v a 2 s  .  c om
            logger.trace("loading " + filename);
            try (InputStream inStream = new FileInputStream(filename)) {
                extendedProperties.load(inStream);
            }
            logger.log(goodFileLogLevel,
                    "file " + filename + " loaded (" + extendedProperties.size() + " properties)");
            printExtendedProperties(extendedProperties);
        } catch (Exception ex) {
            logger.fatal(ThrowableUtils.getString(ex), ex);
        }
    } else {
        logger.log(badFileLogLevel, filename + " does not exist or is not a normal file");
    }
    return extendedProperties;
}

From source file:adalid.commons.properties.PropertiesHandler.java

public static ExtendedProperties getExtendedProperties(byte[] buffer) {
    ExtendedProperties extendedProperties = new ExtendedProperties();
    if (buffer == null) {
        logger.error("null properties buffer");
    } else {/*from   ww w.j  a  v a  2s .  co  m*/
        try {
            logger.trace("loading buffer " + Arrays.toString(buffer));
            try (InputStream inStream = new ByteArrayInputStream(buffer)) {
                extendedProperties.load(inStream);
            }
            printExtendedProperties(extendedProperties);
        } catch (Exception ex) {
            logger.fatal(ThrowableUtils.getString(ex), ex);
        }
    }
    return extendedProperties;
}

From source file:egovframework.rte.fdl.property.impl.EgovPropertyServiceImpl.java

/**
 * ?  ? egovProperties? /*  w  ww  .  j  a va  2  s .c  om*/
 * @param resources
 *        
 * @param encoding
 *        ?
 * @throws Exception
 */
private void loadPropertyRes(Resource resource, String encoding) throws Exception {
    if (EgovPropertyService.LOGGER.isDebugEnabled()) {
        EgovPropertyService.LOGGER.debug(messageSource.getMessage("debug.properties.filename",
                new String[] { resource.getFilename(), encoding }, Locale.getDefault()));
    }
    ExtendedProperties egovProperty = new ExtendedProperties();
    egovProperty.load(resource.getInputStream(), encoding);
    egovProperties.combine(egovProperty);
}

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

/**
 * Allows an external system to set a property in
 * the Velocity Runtime.//  w ww.j  a v  a 2 s. c om
 *
 * @param key property key
 * @param  value property value
 */
public void setProperty(String key, Object value) {
    if (overridingProperties == null) {
        overridingProperties = new ExtendedProperties();
    }

    overridingProperties.setProperty(key, value);
}

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

/**
 * Add a property to the configuration. If it already
 * exists then the value stated here will be added
 * to the configuration entry. For example, if
 *
 * resource.loader = file/*from   w  w  w.  j  a v a  2s  .c om*/
 *
 * is already present in the configuration and you
 *
 * addProperty("resource.loader", "classpath")
 *
 * Then you will end up with a Vector like the
 * following:
 *
 * ["file", "classpath"]
 *
 * @param  key
 * @param  value
 */
public void addProperty(String key, Object value) {
    if (overridingProperties == null) {
        overridingProperties = new ExtendedProperties();
    }

    overridingProperties.addProperty(key, value);
}

From source file:org.apache.cayenne.access.DataRowStore.java

protected void initWithProperties(Map properties) {
    ExtendedProperties propertiesWrapper = new ExtendedProperties();

    if (properties != null) {
        propertiesWrapper.putAll(properties);
    }//from w ww.j  av a2 s .  c o  m

    long snapshotsExpiration = propertiesWrapper.getLong(SNAPSHOT_EXPIRATION_PROPERTY,
            SNAPSHOT_EXPIRATION_DEFAULT);

    maxSize = propertiesWrapper.getInt(SNAPSHOT_CACHE_SIZE_PROPERTY, SNAPSHOT_CACHE_SIZE_DEFAULT);

    boolean notifyRemote = propertiesWrapper.getBoolean(REMOTE_NOTIFICATION_PROPERTY,
            REMOTE_NOTIFICATION_DEFAULT);

    String eventBridgeFactory = propertiesWrapper.getString(EVENT_BRIDGE_FACTORY_PROPERTY,
            EVENT_BRIDGE_FACTORY_DEFAULT);

    if (logger.isDebugEnabled()) {
        logger.debug("DataRowStore property " + SNAPSHOT_EXPIRATION_PROPERTY + " = " + snapshotsExpiration);
        logger.debug("DataRowStore property " + SNAPSHOT_CACHE_SIZE_PROPERTY + " = " + maxSize);
        logger.debug("DataRowStore property " + REMOTE_NOTIFICATION_PROPERTY + " = " + notifyRemote);
        logger.debug("DataRowStore property " + EVENT_BRIDGE_FACTORY_PROPERTY + " = " + eventBridgeFactory);
    }

    // init ivars from properties
    this.notifyingRemoteListeners = notifyRemote;

    this.snapshots = new ConcurrentLinkedHashMap.Builder<ObjectId, DataRow>().maximumWeightedCapacity(maxSize)
            .build();

    // init event bridge only if we are notifying remote listeners
    if (notifyingRemoteListeners) {
        try {
            EventBridgeFactory factory = (EventBridgeFactory) Class.forName(eventBridgeFactory).newInstance();

            Collection<EventSubject> subjects = Collections.singleton(getSnapshotEventSubject());
            String externalSubject = EventBridge.convertToExternalSubject(getSnapshotEventSubject());
            this.remoteNotificationsHandler = factory.createEventBridge(subjects, externalSubject, properties);
        } catch (Exception ex) {
            throw new CayenneRuntimeException("Error initializing DataRowStore.", ex);
        }

        startListeners();
    }
}

From source file:org.apache.cayenne.modeler.preferences.UpgradeCayennePreference.java

public void upgrade() {
    try {/* ww  w . j  ava2s.  c om*/

        if (!Preferences.userRoot().nodeExists(CAYENNE_PREFERENCES_PATH)) {

            File prefsFile = new File(preferencesDirectory(), PREFERENCES_NAME_OLD);
            if (prefsFile.exists()) {
                ExtendedProperties ep = new ExtendedProperties();
                try {
                    ep.load(new FileInputStream(prefsFile));

                    Preferences prefEditor = Preferences.userRoot().node(CAYENNE_PREFERENCES_PATH).node(EDITOR);

                    prefEditor.putBoolean(ModelerPreferences.EDITOR_LOGFILE_ENABLED,
                            ep.getBoolean(EDITOR_LOGFILE_ENABLED_OLD));
                    prefEditor.put(ModelerPreferences.EDITOR_LOGFILE, ep.getString(EDITOR_LOGFILE_OLD));

                    Preferences frefLastProjFiles = prefEditor.node(LAST_PROJ_FILES);

                    Vector arr = ep.getVector(LAST_PROJ_FILES_OLD);

                    while (arr.size() > ModelerPreferences.LAST_PROJ_FILES_SIZE) {
                        arr.remove(arr.size() - 1);
                    }

                    frefLastProjFiles.clear();
                    int size = arr.size();

                    for (int i = 0; i < size; i++) {
                        frefLastProjFiles.put(String.valueOf(i), arr.get(i).toString());
                    }
                } catch (FileNotFoundException e) {
                    LOGGER.error(e);
                } catch (IOException e) {
                    LOGGER.error(e);
                }
            }
        }
    } catch (BackingStoreException e) {
        // do nothing
    }
}

From source file:org.apache.cayenne.pref.UpgradeCayennePreference.java

public void upgrade() {
    try {/* ww  w.j a v  a 2  s. c o  m*/

        if (!Preferences.userRoot().nodeExists(CAYENNE_PREFERENCES_PATH)) {

            File prefsFile = new File(preferencesDirectory(), PREFERENCES_NAME_OLD);
            if (prefsFile.exists()) {
                ExtendedProperties ep = new ExtendedProperties();
                try {
                    ep.load(new FileInputStream(prefsFile));

                    Preferences prefEditor = Preferences.userRoot().node(CAYENNE_PREFERENCES_PATH).node(EDITOR);

                    prefEditor.putBoolean(ModelerPreferences.EDITOR_LOGFILE_ENABLED,
                            ep.getBoolean(EDITOR_LOGFILE_ENABLED_OLD));
                    prefEditor.put(ModelerPreferences.EDITOR_LOGFILE, ep.getString(EDITOR_LOGFILE_OLD));

                    Preferences frefLastProjFiles = prefEditor.node(LAST_PROJ_FILES);

                    Vector arr = ep.getVector(LAST_PROJ_FILES_OLD);

                    while (arr.size() > ModelerPreferences.LAST_PROJ_FILES_SIZE) {
                        arr.remove(arr.size() - 1);
                    }

                    frefLastProjFiles.clear();
                    int size = arr.size();

                    for (int i = 0; i < size; i++) {
                        frefLastProjFiles.put(String.valueOf(i), arr.get(i).toString());
                    }
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    } catch (BackingStoreException e) {
        // do nothing
    }
}

From source file:org.apache.flex.forks.velocity.texen.ant.TexenTask.java

/**
 * Set the context properties that will be
 * fed into the initial context be the/*from w w  w  .  j  a va2  s.c  o  m*/
 * generating process starts.
 */
public void setContextProperties(String file) {
    String[] sources = StringUtils.split(file, ",");
    contextProperties = new ExtendedProperties();

    // Always try to get the context properties resource
    // from a file first. Templates may be taken from a JAR
    // file but the context properties resource may be a 
    // resource in the filesystem. If this fails than attempt
    // to get the context properties resource from the
    // classpath.
    for (int i = 0; i < sources.length; i++) {
        ExtendedProperties source = new ExtendedProperties();

        try {
            // resolve relative path from basedir and leave
            // absolute path untouched.
            File fullPath = project.resolveFile(sources[i]);
            log("Using contextProperties file: " + fullPath);
            source.load(new FileInputStream(fullPath));
        } catch (Exception e) {
            ClassLoader classLoader = this.getClass().getClassLoader();

            try {
                InputStream inputStream = classLoader.getResourceAsStream(sources[i]);

                if (inputStream == null) {
                    throw new BuildException("Context properties file " + sources[i]
                            + " could not be found in the file system or on the classpath!");
                } else {
                    source.load(inputStream);
                }
            } catch (IOException ioe) {
                source = null;
            }
        }

        Iterator j = source.getKeys();

        while (j.hasNext()) {
            String name = (String) j.next();
            String value = source.getString(name);
            contextProperties.setProperty(name, value);
        }
    }
}

From source file:org.apache.velocity.tools.config.PropertiesFactoryConfiguration.java

/**
 * <p>Reads an properties file from an {@link InputStream}
 * and uses it to configure this {@link FactoryConfiguration}.</p>
 * //w  w w . j  av  a  2 s.c o  m
 * @param input the InputStream to read from
 */
public void read(InputStream input) throws IOException {
    ExtendedProperties props = new ExtendedProperties();
    props.load(input);

    // all factory settings should be prefixed with "tools"
    read(props.subset("tools"));
}