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

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

Introduction

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

Prototype

public Object getProperty(String key) 

Source Link

Document

Gets a property from the configuration.

Usage

From source file:autohit.common.Utils.java

/**
 *  Test and get property.  Return null if not found or something went wrong.
 *  Traps all exceptions/*from www . j a  v  a 2  s .  co m*/
 * @param key key for the property
 * @param props the property set
 * @return the property object
 */
public static Object testGetProperty(String key, ExtendedProperties props) {
    Object thing = null;
    try {
        thing = props.getProperty(key);
    } catch (Exception e) {
        thing = null;
    }
    return thing;
}

From source file:autohit.common.Utils.java

/**
 *  Test and get property for truth.  If will return true if the property
 *  containts 'true', otherwise it will return false;
 *  Traps all exceptions//from   w w w.j  a v  a  2 s .co  m
 * @param key key for the property
 * @param props the property set
 * @return true if the proprerty is 'true', otherwise false.
 */
public static boolean testGetPropertyTruth(String key, ExtendedProperties props) {
    boolean thing = false;
    String thang;
    try {
        thang = (String) props.getProperty(key);
        thing = thang.equals(Constants.TRUE);
    } catch (Exception e) {
    }
    return thing;
}

From source file:com.appspot.socialinquirer.server.service.template.VelocityResourceLoader.java

@SuppressWarnings("unchecked")
@Override//from www . jav  a 2 s .  co  m
public void init(ExtendedProperties configuration) {
    path = (String) configuration.getProperty("path");
}

From source file:autohit.vm.VMLoader.java

/**
 * Gets a property from the SystemContext.  Normally, you should handle
 * all system interaction through a Universe.  Don't use this unless you
 * have no choice.//from  w w  w . jav  a 2 s. c om
 *  Returns the value or null if it does not exist
 * @param name of the property
 * @return the value as a String or null if it doesn't exist
 */
public String property(String name) {

    String thang = null;
    try {
        ExtendedProperties ep = sc.getPropertiesSet();
        thang = (String) ep.getProperty(name);
    } catch (Exception e) {
        // nothing.  null will return
    }
    return thang;
}

From source file:com.alibaba.citrus.service.velocity.impl.PreloadedResourceLoader.java

/** ?resource loader. */
@Override/* w ww .j a v a2  s.  c  om*/
public void init(ExtendedProperties configuration) {
    rsvc.getLog().info(getLogID() + " : initialization starting.");

    preloadedResources = createTreeMap();

    @SuppressWarnings("unchecked")
    Map<String, Resource> resources = assertNotNull(
            (Map<String, Resource>) configuration.getProperty(PRELOADED_RESOURCES_KEY),
            PRELOADED_RESOURCES_KEY);

    for (Map.Entry<String, Resource> entry : resources.entrySet()) {
        String templateName = normalizeTemplateName(entry.getKey());
        Resource resource = entry.getValue();

        preloadedResources.put(templateName, resource);
    }

    rsvc.getLog()
            .info(getLogID() + " : preloaded resources: " + new MapBuilder().appendAll(preloadedResources));
    rsvc.getLog().info(getLogID() + " : initialization complete.");
}

From source file:org.dspace.app.xmlui.aspect.discovery.json.JSONSolrSearcher.java

@Override
public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
        throws ProcessingException, SAXException, IOException {
    //Retrieve all the given parameters
    Request request = ObjectModelHelper.getRequest(objectModel);
    this.response = ObjectModelHelper.getResponse(objectModel);

    query = request.getParameter(CommonParams.Q);
    if (query == null) {
        query = "*:*";
    }//from w  ww  . ja  va2 s.  c om

    //Retrieve all our filter queries
    filterQueries = request.getParameterValues(CommonParams.FQ);

    //Retrieve our facet fields
    facetFields = request.getParameterValues(FacetParams.FACET_FIELD);

    //Retrieve our facet limit (if any)
    if (request.getParameter(FacetParams.FACET_LIMIT) != null) {
        try {
            facetLimit = Integer.parseInt(request.getParameter(FacetParams.FACET_LIMIT));
        } catch (Exception e) {
            //Should an invalid value be supplied use -1
            facetLimit = -1;
        }
    } else {
        facetLimit = -1;
    }

    //Retrieve our sorting value
    facetSort = request.getParameter(FacetParams.FACET_SORT);
    //Make sure we have a valid sorting value
    if (!FacetParams.FACET_SORT_INDEX.equals(facetSort) && !FacetParams.FACET_SORT_COUNT.equals(facetSort)) {
        facetSort = null;
    }

    //Retrieve our facet min count
    facetMinCount = 1;
    try {
        facetMinCount = Integer.parseInt(request.getParameter(FacetParams.FACET_MINCOUNT));
    } catch (Exception e) {
        facetMinCount = 1;
    }
    jsonWrf = request.getParameter("json.wrf");

    //Retrieve our discovery solr path
    ExtendedProperties props = null;
    //Method that will retrieve all the possible configs we have

    props = ExtendedProperties.convertProperties(ConfigurationManager.getProperties());

    InputStream is = null;
    try {
        File config = new File(props.getProperty("dspace.dir") + "/config/dspace-solr-search.cfg");
        if (config.exists()) {
            props.combine(new ExtendedProperties(config.getAbsolutePath()));
        } else {
            is = SolrServiceImpl.class.getResourceAsStream("dspace-solr-search.cfg");
            ExtendedProperties defaults = new ExtendedProperties();
            defaults.load(is);
            props.combine(defaults);
        }
    } catch (Exception e) {
        log.error("Error while retrieving solr url", e);
        e.printStackTrace();
    } finally {
        if (is != null) {
            is.close();
        }
    }

    if (props.getProperty("solr.search.server") != null) {
        this.solrServerUrl = props.getProperty("solr.search.server").toString();
    }

}

From source file:org.kalypso.metadoc.impl.FileExportTarget.java

@Override
public IStatus commitDocument(final IExportableObject document, final ExtendedProperties conf,
        final IProgressMonitor monitor) throws InvocationTargetException {
    monitor.beginTask("Export von " + document.getPreferredDocumentName(), IProgressMonitor.UNKNOWN);

    FileOutputStream stream = null;
    try {/*from  w w  w .  j a v a  2 s.  c om*/
        final File file = (File) conf.getProperty(CONF_FILEEXPORT_FILE);
        final File docFile;
        if (file.isDirectory())
            docFile = new File(file, document.getPreferredDocumentName());
        else
            docFile = file;

        stream = new FileOutputStream(docFile);
        return document.exportObject(stream, monitor);
    } catch (final FileNotFoundException e) {
        throw new InvocationTargetException(e);
    } finally {
        IOUtils.closeQuietly(stream);

        monitor.done();
    }
}

From source file:org.kalypso.ui.editor.mapeditor.MapExportableObjectFactory.java

@Override
public IExportableObject[] createExportableObjects(final ExtendedProperties conf) {
    final String preferredDocumentName = m_mapPanel.getMapModell().getName().getValue();
    final int width = conf.getInt(ImagePropertiesWizardPage.CONFIG_IMAGE_WIDTH, m_mapPanel.getWidth());
    final int height = conf.getInt(ImagePropertiesWizardPage.CONFIG_IMAGE_HEIGHT, m_mapPanel.getHeight());
    final Insets insets = (Insets) conf.getProperty(ImagePropertiesWizardPage.CONFIG_INSETS);
    final boolean border = conf.getBoolean(ImagePropertiesWizardPage.CONFIG_HAS_BORDER, false);
    final int borderWidth = border ? 1 : 0;
    final String format = conf.getString(ImagePropertiesWizardPage.CONFIG_IMAGE_FORMAT, "PNG"); //$NON-NLS-1$

    return new IExportableObject[] { new MapExportableObject(m_mapPanel, preferredDocumentName, width, height,
            insets, borderWidth, format) };
}

From source file:org.opencms.configuration.TestParameterConfiguration.java

/**
 * Test reading the parameter configuration.<p>
 * /*from ww  w  .  j  a va  2  s. co  m*/
 * @throws Exception
 */
public void testReadParameterConfiguration() throws Exception {

    String testPropPath = "org/opencms/configuration/opencms-test.properties";
    URL url = this.getClass().getClassLoader().getResource(testPropPath);
    File file = new File(url.getPath());
    System.out.println("URL: " + url);
    System.out.println("File: " + file);
    // make sure the test properties file is found
    assertTrue("Test property file '" + file.getAbsolutePath() + "' not found", file.exists());

    CmsParameterConfiguration cmsProp = new CmsParameterConfiguration(file.getAbsolutePath());
    assertEquals("C:\\dev\\workspace\\opencms-core\\test\\data", cmsProp.get("test.path.one"));

    // test some of the more advanced features
    assertEquals(4, cmsProp.getList("test.list").size());
    assertEquals(3, cmsProp.getList("test.otherlist").size());
    assertEquals("comma, escaped with \\ backslash", cmsProp.get("test.escaping"));
    assertEquals("this is a long long long long long long line!", cmsProp.get("test.multiline"));

    // test compatibility with Collection Extended Properties
    ExtendedProperties extProp = new ExtendedProperties(file.getAbsolutePath());
    assertEquals(extProp.size(), cmsProp.size());
    for (String key : cmsProp.keySet()) {
        Object value = cmsProp.getObject(key);
        assertTrue("Key '" + key + "' not found in CmsConfiguration", extProp.containsKey(key));
        assertTrue("Objects for '" + key + "' not equal", value.equals(extProp.getProperty(key)));
    }
}

From source file:org.sakaiproject.vm.VelocityServlet.java

/**
 * Called by the VelocityServlet init(). We want to set a set of properties so that templates will be found in the webapp root. This makes this easier to work with as an example, so a new user doesn't have to worry about config issues when first
 * figuring things out/*from w  w w .j a va 2 s.  c om*/
 */
protected ExtendedProperties loadConfiguration(ServletConfig config) throws IOException, FileNotFoundException {
    // This is to support old config property.
    String configPath = config.getInitParameter("properties");
    ExtendedProperties p;
    if (configPath != null && configPath.length() > 0) {
        p = new ExtendedProperties();
        if (!configPath.startsWith("/")) {
            configPath = "/" + configPath;
        }
        p.load(getServletContext().getResourceAsStream(configPath));
    } else {
        // load the properties as configured in the servlet init params
        p = super.loadConfiguration(config);
    }

    /*
     * first, we set the template path for the FileResourceLoader to the root of the webapp. This probably won't work under in a WAR under WebLogic, but should under tomcat :)
     */

    String path = config.getServletContext().getRealPath("/");

    if (path == null) {
        getVelocityEngine().getLog().debug(" VelocityServlet.loadConfiguration() : unable to "
                + "get the current webapp root.  Using '/'. Please fix.");
        path = "/";
    }

    p.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, path);

    /**
     * and the same for the log file
     */
    p.setProperty("runtime.log", path + p.getProperty("runtime.log"));

    return p;
}