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

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

Introduction

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

Prototype

@SuppressWarnings("unchecked")
public synchronized V get(Object key) 

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:com.liferay.util.velocity.ServletResourceLoader.java

public void init(ExtendedProperties props) {
    _ctx = (ServletContext) props.get(CTX);
}

From source file:com.liferay.portal.template.velocity.internal.LiferayResourceLoader.java

@Override
public void init(ExtendedProperties extendedProperties) {
    int resourceModificationCheckInterval = GetterUtil
            .getInteger(extendedProperties.get("resourceModificationCheckInterval"), 60);

    setModificationCheckInterval(resourceModificationCheckInterval);

    _templateResourceLoader = (TemplateResourceLoader) extendedProperties
            .get(VelocityTemplateResourceLoader.class.getName());
}

From source file:com.liferay.portal.template.velocity.internal.FastExtendedProperties.java

public FastExtendedProperties(ExtendedProperties extendedProperties) throws IOException {

    // Do not call putAll. See LPS-61927.

    //putAll(extendedProperties);

    Enumeration keys = extendedProperties.keys();

    while (keys.hasMoreElements()) {
        String key = (String) keys.nextElement();

        Object value = extendedProperties.get(key);

        addProperty(key, value);/*from w  ww  . j  a  va  2 s .co m*/
    }
}

From source file:com.liferay.portal.template.velocity.internal.LiferayResourceManager.java

@Override
public synchronized void initialize(RuntimeServices runtimeServices) throws Exception {

    ExtendedProperties extendedProperties = runtimeServices.getConfiguration();

    Field field = ReflectionUtil.getDeclaredField(RuntimeInstance.class, "configuration");

    field.set(runtimeServices, new FastExtendedProperties(extendedProperties));

    _macroTemplateIds = StringPlus.asList(extendedProperties.get(VelocityEngine.VM_LIBRARY));
    _resourceModificationCheckInterval = GetterUtil.getInteger(extendedProperties
            .get("liferay." + VelocityEngine.RESOURCE_LOADER + ".resourceModificationCheckInterval"), 60);
    _templateResourceLoader = (TemplateResourceLoader) extendedProperties
            .get(VelocityTemplateResourceLoader.class.getName());

    super.initialize(runtimeServices);
}

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

/**
 * Initialize the ResourceManager.//  w  w w .  java  2s. co  m
 *
 * @param  rsvc  The Runtime Services object which is associated with this Resource Manager.
 *
 * @throws  Exception
 */
public synchronized void initialize(final RuntimeServices rsvc) throws Exception {
    if (isInit) {
        log.warn("Re-initialization of ResourceLoader attempted!");
        return;
    }

    ResourceLoader resourceLoader = null;

    this.rsvc = rsvc;
    log = rsvc.getLog();

    log.debug("Default ResourceManager initializing. (" + this.getClass() + ")");

    assembleResourceLoaderInitializers();

    for (Iterator it = sourceInitializerList.iterator(); it.hasNext();) {
        /**
         * Resource loader can be loaded either via class name or be passed
         * in as an instance.
         */
        ExtendedProperties configuration = (ExtendedProperties) it.next();

        String loaderClass = StringUtils.nullTrim(configuration.getString("class"));
        ResourceLoader loaderInstance = (ResourceLoader) configuration.get("instance");

        if (loaderInstance != null) {
            resourceLoader = loaderInstance;
        } else if (loaderClass != null) {
            resourceLoader = ResourceLoaderFactory.getLoader(rsvc, loaderClass);
        } else {
            log.error("Unable to find '" + configuration.getString(RESOURCE_LOADER_IDENTIFIER)
                    + ".resource.loader.class' specification in configuration."
                    + " This is a critical value.  Please adjust configuration.");

            continue; // for(...
        }

        resourceLoader.commonInit(rsvc, configuration);
        resourceLoader.init(configuration);
        resourceLoaders.add(resourceLoader);
    }

    /*
     * now see if this is overridden by configuration
     */

    logWhenFound = rsvc.getBoolean(RuntimeConstants.RESOURCE_MANAGER_LOGWHENFOUND, true);

    /*
     *  now, is a global cache specified?
     */

    String cacheClassName = rsvc.getString(RuntimeConstants.RESOURCE_MANAGER_CACHE_CLASS);

    Object cacheObject = null;

    if (org.apache.commons.lang.StringUtils.isNotEmpty(cacheClassName)) {

        try {
            cacheObject = ClassUtils.getNewInstance(cacheClassName);
        } catch (ClassNotFoundException cnfe) {
            log.error("The specified class for ResourceCache (" + cacheClassName
                    + ") does not exist or is not accessible to the current classloader.");
            cacheObject = null;
        }

        if (!(cacheObject instanceof ResourceCache)) {
            log.error("The specified class for ResourceCache (" + cacheClassName + ") does not implement "
                    + ResourceCache.class.getName()
                    + " ResourceManager. Using default ResourceCache implementation.");
            cacheObject = null;
        }
    }

    /*
     *  if we didn't get through that, just use the default.
     */
    if (cacheObject == null) {
        cacheObject = new ResourceCacheImpl();
    }

    globalCache = (ResourceCache) cacheObject;

    globalCache.initialize(rsvc);

    log.trace("Default ResourceManager initialization complete.");
}

From source file:bboss.org.apache.velocity.runtime.resource.ResourceManagerImpl.java

/**
 * Initialize the ResourceManager.//from   w  w  w  .  j a v  a 2  s .  c  o  m
 *
 * @param  rsvc  The Runtime Services object which is associated with this Resource Manager.
 */
public synchronized void initialize(final RuntimeServices rsvc) {
    if (isInit) {
        log.debug("Re-initialization of ResourceLoader attempted and ignored.");
        return;
    }

    ResourceLoader resourceLoader = null;

    this.rsvc = rsvc;
    log = rsvc.getLog();

    log.trace("Default ResourceManager initializing. (" + this.getClass() + ")");

    assembleResourceLoaderInitializers();

    for (Iterator it = sourceInitializerList.iterator(); it.hasNext();) {
        /**
         * Resource loader can be loaded either via class name or be passed
         * in as an instance.
         */
        ExtendedProperties configuration = (ExtendedProperties) it.next();

        String loaderClass = StringUtils.nullTrim(configuration.getString("class"));
        ResourceLoader loaderInstance = (ResourceLoader) configuration.get("instance");

        if (loaderInstance != null) {
            resourceLoader = loaderInstance;
        } else if (loaderClass != null) {
            resourceLoader = ResourceLoaderFactory.getLoader(rsvc, loaderClass);
        } else {
            String msg = "Unable to find '" + configuration.getString(RESOURCE_LOADER_IDENTIFIER)
                    + ".resource.loader.class' specification in configuration."
                    + " This is a critical value.  Please adjust configuration.";
            log.error(msg);
            throw new VelocityException(msg);
        }

        resourceLoader.commonInit(rsvc, configuration);
        resourceLoader.init(configuration);
        resourceLoaders.add(resourceLoader);
    }

    /*
     * now see if this is overridden by configuration
     */

    logWhenFound = rsvc.getBoolean(RuntimeConstants.RESOURCE_MANAGER_LOGWHENFOUND, true);

    /*
     *  now, is a global cache specified?
     */

    String cacheClassName = rsvc.getString(RuntimeConstants.RESOURCE_MANAGER_CACHE_CLASS);

    Object cacheObject = null;

    if (org.apache.commons.lang.StringUtils.isNotEmpty(cacheClassName)) {
        try {
            cacheObject = ClassUtils.getNewInstance(cacheClassName);
        } catch (ClassNotFoundException cnfe) {
            String msg = "The specified class for ResourceCache (" + cacheClassName
                    + ") does not exist or is not accessible to the current classloader.";
            log.error(msg, cnfe);
            throw new VelocityException(msg, cnfe);
        } catch (IllegalAccessException ae) {
            throw new VelocityException("Could not access class '" + cacheClassName + "'", ae);
        } catch (InstantiationException ie) {
            throw new VelocityException("Could not instantiate class '" + cacheClassName + "'", ie);
        }

        if (!(cacheObject instanceof ResourceCache)) {
            String msg = "The specified resource cache class (" + cacheClassName + ") must implement "
                    + ResourceCache.class.getName();
            log.error(msg);
            throw new RuntimeException(msg);
        }
    }

    /*
     *  if we didn't get through that, just use the default.
     */
    if (cacheObject == null) {
        cacheObject = new ResourceCacheImpl();
    }

    globalCache = (ResourceCache) cacheObject;

    globalCache.initialize(rsvc);

    log.trace("Default ResourceManager initialization complete.");
}

From source file:autohit.common.Utils.java

/**
 *  Merge a file with properties.  It will overwrite an existing file.
 *  This is not exactly FAST.//from ww  w  .ja  v  a2 s.co m
 * @param source source file
 * @param dest destination file
 * @param props properties that are candidates for substitution
 * @return string containing errors or messages
 */
public static String merge(String source, String dest, ExtendedProperties props) {

    int state = STATE_FRESH;
    BufferedReader inBR = null;
    BufferedWriter outT = null;
    int workingC;
    StringBuffer cBuf = null;
    String theVar = null;
    String ts = null;
    StringBuffer messages = new StringBuffer();
    String overwrite = " ";

    // Read and fix
    try {
        // Clear an existing file
        File destf = new File(dest);
        if (destf.exists()) {
            destf.delete();
            overwrite = " [overwrite] ";
        }
        inBR = new BufferedReader(new FileReader(source));
        outT = new BufferedWriter(new FileWriter(dest));

        // start the engine
        workingC = inBR.read();
        while ((workingC >= 0) && (workingC < MORONIC_TOP_VALUE)) {

            switch (state) {

            case STATE_FRESH:
                if (workingC == Constants.CONFIG_OPEN)
                    state = STATE_FRONT;
                else
                    outT.write(workingC);
                break;

            case STATE_FRONT:
                if (workingC == Constants.CONFIG_OPEN) {
                    state = STATE_READ;
                    cBuf = new StringBuffer();
                } else {
                    state = STATE_FRESH;
                    outT.write(Constants.CONFIG_OPEN);
                    outT.write(workingC);
                }
                break;

            case STATE_READ:
                if (workingC == Constants.CONFIG_CLOSE) {
                    state = STATE_TAIL;
                } else {
                    cBuf.append((char) workingC);
                }
                break;

            case STATE_TAIL:
                if (workingC == Constants.CONFIG_CLOSE) {
                    state = STATE_FRESH;
                    theVar = cBuf.toString();

                    if (props.containsKey(theVar)) {
                        ts = (String) props.get(theVar);
                        outT.write(ts, 0, ts.length());
                    } else {
                        outT.write(Constants.CONFIG_BLANK);
                    }
                } else {
                    outT.write(Constants.CONFIG_CLOSE);
                    outT.write(workingC);
                }
                break;
            } // end case
            workingC = inBR.read();
        }
    } catch (Exception e) {
        // Might just be EOF
        //System.out.println(e);         
    } finally {
        try {
            inBR.close();
            outT.close();
            if (state != STATE_FRESH) {
                messages.append(
                        "Bad File.  Incomplete escape <<>> in file=" + source + Constants.CRUDE_SEPERATOR);
                messages.append(".........  Destination file might be corrupt.  file=" + dest
                        + Constants.CRUDE_SEPERATOR);
            }
            messages.append("Merged file to=" + dest + overwrite + Constants.CRUDE_SEPERATOR);
        } catch (Exception e) {
            messages.append("Catastrophic error merging" + source + Constants.CRUDE_SEPERATOR);
            messages.append(
                    ".........  Destination file might be corrupt.  file=" + dest + Constants.CRUDE_SEPERATOR);
        }

    }
    return messages.toString();
}

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  av a  2  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:org.apache.velocity.runtime.resource.ResourceManagerImpl.java

/**
 * Initialize the ResourceManager./*w w  w .  j  a  v  a 2  s. c  om*/
 *
 * @param  rsvc  The Runtime Services object which is associated with this Resource Manager.
 */
public synchronized void initialize(final RuntimeServices rsvc) {
    if (isInit) {
        Logger.debug(this, "Re-initialization of ResourceLoader attempted and ignored.");
        return;
    }

    ResourceLoader resourceLoader = null;

    this.rsvc = rsvc;

    Logger.debug(this, "Default ResourceManager initializing. (" + this.getClass() + ")");

    assembleResourceLoaderInitializers();

    for (Iterator it = sourceInitializerList.iterator(); it.hasNext();) {
        /**
         * Resource loader can be loaded either via class name or be passed
         * in as an instance.
         */
        ExtendedProperties configuration = (ExtendedProperties) it.next();

        String loaderClass = StringUtils.nullTrim(configuration.getString("class"));
        ResourceLoader loaderInstance = (ResourceLoader) configuration.get("instance");

        if (loaderInstance != null) {
            resourceLoader = loaderInstance;
        } else if (loaderClass != null) {
            resourceLoader = ResourceLoaderFactory.getLoader(rsvc, loaderClass);
        } else {
            String msg = "Unable to find '" + configuration.getString(RESOURCE_LOADER_IDENTIFIER)
                    + ".resource.loader.class' specification in configuration."
                    + " This is a critical value.  Please adjust configuration.";
            Logger.error(this, msg);
            throw new VelocityException(msg);
        }

        resourceLoader.commonInit(rsvc, configuration);
        resourceLoader.init(configuration);
        resourceLoaders.add(resourceLoader);
    }

    /*
     * now see if this is overridden by configuration
     */

    logWhenFound = rsvc.getBoolean(RuntimeConstants.RESOURCE_MANAGER_LOGWHENFOUND, true);

    /*
     *  now, is a global cache specified?
     */

    String cacheClassName = rsvc.getString(RuntimeConstants.RESOURCE_MANAGER_CACHE_CLASS);

    Object cacheObject = null;

    if (org.apache.commons.lang.StringUtils.isNotEmpty(cacheClassName)) {
        try {
            cacheObject = ClassUtils.getNewInstance(cacheClassName);
        } catch (ClassNotFoundException cnfe) {
            String msg = "The specified class for ResourceCache (" + cacheClassName
                    + ") does not exist or is not accessible to the current classloader.";
            Logger.error(this, msg, cnfe);
            throw new VelocityException(msg, cnfe);
        } catch (IllegalAccessException ae) {
            throw new VelocityException("Could not access class '" + cacheClassName + "'", ae);
        } catch (InstantiationException ie) {
            throw new VelocityException("Could not instantiate class '" + cacheClassName + "'", ie);
        }

        if (!(cacheObject instanceof ResourceCache)) {
            String msg = "The specified resource cache class (" + cacheClassName + ") must implement "
                    + ResourceCache.class.getName();
            Logger.error(this, msg);
            throw new RuntimeException(msg);
        }
    }

    /*
     *  if we didn't get through that, just use the default.
     */
    if (cacheObject == null) {
        cacheObject = new ResourceCacheImpl();
    }

    globalCache = (ResourceCache) cacheObject;

    globalCache.initialize(rsvc);

    Logger.debug(this, "Default ResourceManager initialization complete.");
}

From source file:org.jpublish.view.velocity.JPublishResourceLoader.java

/**
 * Common init method for ResourceLoaders.
 *
 * @param rs            The RuntimeServices
 * @param configuration The configuration
 *//*  w  ww .j a  va  2s  .co  m*/

public void commonInit(RuntimeServices rs, ExtendedProperties configuration) {

    if (log.isDebugEnabled())
        log.debug("commonInit()");

    super.commonInit(rs, configuration);

    Object siteContext = rs.getProperty("jpublish.resource.loader.siteContext");
    if (log.isDebugEnabled())
        log.debug("SiteContext from rs: " + siteContext);

    if (siteContext == null) {
        siteContext = configuration.get("jpublish.resource.loader.siteContext");

        if (log.isDebugEnabled())
            log.debug("SiteContext from configuration: " + siteContext);
    }

    setSiteContext((SiteContext) siteContext);
}