Example usage for java.util Properties keys

List of usage examples for java.util Properties keys

Introduction

In this page you can find the example usage for java.util Properties keys.

Prototype

@Override
    public Enumeration<Object> keys() 

Source Link

Usage

From source file:org.pentaho.mantle.server.MantleServlet.java

public HashMap<String, String> getMantleSettings() {
    HashMap<String, String> settings = new HashMap<String, String>();
    // read properties file
    Properties props = new Properties();
    try {/*  w w w. ja  va2  s.c  om*/
        props.load(getClass().getResourceAsStream("/org/pentaho/mantle/server/MantleSettings.properties")); //$NON-NLS-1$
        Enumeration keys = props.keys();
        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();
            String value = (String) props.getProperty(key);
            settings.put(key, value);
        }

        settings.put("login-show-users-list", PentahoSystem.getSystemSetting("login-show-users-list", "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        settings.put("documentation-url", PentahoSystem.getSystemSetting("documentation-url", "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

        // Check for override of New Analysis View via pentaho.xml
        // Poked in via pentaho.xml entries
        // <new-analysis-view>
        // <command-url>http://www.google.com</command-url>
        // <command-title>Marc Analysis View</command-title>
        // </new-analysis-view>
        // <new-report>
        // <command-url>http://www.yahoo.com</command-url>
        // <command-title>Marc New Report</command-title>
        // </new-report>
        // 
        String overrideNewAnalysisViewCommmand = PentahoSystem.getSystemSetting("new-analysis-view/command-url", //$NON-NLS-1$
                null);
        String overrideNewAnalysisViewTitle = PentahoSystem.getSystemSetting("new-analysis-view/command-title", //$NON-NLS-1$
                null);
        if ((overrideNewAnalysisViewCommmand != null) && (overrideNewAnalysisViewTitle != null)) {
            settings.put("new-analysis-view-command-url", overrideNewAnalysisViewCommmand); //$NON-NLS-1$
            settings.put("new-analysis-view-command-title", overrideNewAnalysisViewTitle); //$NON-NLS-1$
        }
        String overrideNewReportCommmand = PentahoSystem.getSystemSetting("new-report/command-url", null); //$NON-NLS-1$
        String overrideNewReportTitle = PentahoSystem.getSystemSetting("new-report/command-title", null); //$NON-NLS-1$
        if ((overrideNewReportCommmand != null) && (overrideNewReportTitle != null)) {
            settings.put("new-report-command-url", overrideNewReportCommmand); //$NON-NLS-1$
            settings.put("new-report-command-title", overrideNewReportTitle); //$NON-NLS-1$
        }

        // see if we have any plugin settings
        IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class, getPentahoSession()); //$NON-NLS-1$
        if (pluginManager != null) {
            // get the menu customizations for the plugins, if any
            List<IMenuCustomization> customs = (List<IMenuCustomization>) pluginManager.getMenuCustomizations();
            int fileIdx = 0;
            int fileNewIdx = 0;
            int fileManageIdx = 0;
            int viewIdx = 0;
            int toolsIdx = 0;
            int toolsRefreshIdx = 0;
            int aboutIdx = 0;
            int overrideIdx = 0;
            // process each customization
            for (IMenuCustomization custom : customs) {
                // we only support appending children to the first level sub-menus
                if (custom.getCustomizationType() == CustomizationType.LAST_CHILD) {
                    String anchor = custom.getAnchorId();
                    // do we have any additions to the file menu?
                    // TODO: support file->new
                    if ("file-submenu".equals(anchor)) { //$NON-NLS-1$
                        settings.put("fileMenuTitle" + fileIdx, custom.getLabel()); //$NON-NLS-1$
                        settings.put("fileMenuCommand" + fileIdx, custom.getCommand()); //$NON-NLS-1$
                        fileIdx++;
                    } else if ("file-new-submenu".equals(anchor)) { //$NON-NLS-1$
                        settings.put("file-newMenuTitle" + fileNewIdx, custom.getLabel()); //$NON-NLS-1$
                        settings.put("file-newMenuCommand" + fileNewIdx, custom.getCommand()); //$NON-NLS-1$
                        fileNewIdx++;
                    } else if ("file-manage-submenu".equals(anchor)) { //$NON-NLS-1$
                        settings.put("file-manageMenuTitle" + fileManageIdx, custom.getLabel()); //$NON-NLS-1$
                        settings.put("file-manageMenuCommand" + fileManageIdx, custom.getCommand()); //$NON-NLS-1$
                        fileManageIdx++;
                    }
                    // do we have any additions to the view menu?
                    else if ("view-submenu".equals(anchor)) { //$NON-NLS-1$
                        settings.put("viewMenuTitle" + viewIdx, custom.getLabel()); //$NON-NLS-1$
                        settings.put("viewMenuCommand" + viewIdx, custom.getCommand()); //$NON-NLS-1$
                        viewIdx++;
                    }
                    // do we have any additions to the tools menu?
                    else if ("tools-submenu".equals(anchor)) { //$NON-NLS-1$
                        settings.put("toolsMenuTitle" + toolsIdx, custom.getLabel()); //$NON-NLS-1$
                        settings.put("toolsMenuCommand" + toolsIdx, custom.getCommand()); //$NON-NLS-1$
                        toolsIdx++;
                    }
                    // do we have any additions to the refresh menu?
                    else if ("tools-refresh-submenu".equals(anchor)) { //$NON-NLS-1$
                        settings.put("tools-refreshMenuTitle" + toolsRefreshIdx, custom.getLabel()); //$NON-NLS-1$
                        settings.put("tools-refreshMenuCommand" + toolsRefreshIdx, custom.getCommand()); //$NON-NLS-1$
                        toolsRefreshIdx++;
                    }
                    // do we have any additions to the about menu?
                    else if ("about-submenu".equals(anchor)) { //$NON-NLS-1$
                        settings.put("helpMenuTitle" + aboutIdx, custom.getLabel()); //$NON-NLS-1$
                        settings.put("helpMenuCommand" + aboutIdx, custom.getCommand()); //$NON-NLS-1$
                        aboutIdx++;
                    }
                } else if (custom.getCustomizationType() == CustomizationType.REPLACE) {
                    // Support replace of new analysis view and new report only
                    //
                    // Example of overriding via plugin.xml
                    // <menu-item id="waqr_menu_item"
                    // anchor="file-new-submenu-waqr_menu_item"
                    // label="New WAQR"
                    // command="http://www.amazon.com"
                    // type="MENU_ITEM"
                    // how="REPLACE"/>
                    // <menu-item id="new_analysis_view_menu_item"
                    // anchor="file-new-submenu-new_analysis_view_menu_item"
                    // label="New Analysis"
                    // command="http://www.dogpile.com"
                    // type="MENU_ITEM"
                    // how="REPLACE"/>
                    //
                    String anchor = custom.getAnchorId();
                    String anchorStart = "file-new-submenu-"; //$NON-NLS-1$
                    if (anchor.startsWith(anchorStart)) {
                        // Anchor needs to be in two parts
                        // file-new-submenu and the submenu being replaced
                        // e.g. file-new-submenu-waqr_menu_item
                        String overrideMenuItem = anchor.substring(anchorStart.length());
                        settings.put("file-newMenuOverrideTitle" + overrideIdx, custom.getLabel()); //$NON-NLS-1$
                        settings.put("file-newMenuOverrideCommand" + overrideIdx, custom.getCommand()); //$NON-NLS-1$
                        settings.put("file-newMenuOverrideMenuItem" + overrideIdx, overrideMenuItem); //$NON-NLS-1$
                        overrideIdx++;
                    }
                }
            }

            // load content types from IPluginSettings
            int i = 0;
            for (String contentType : pluginManager.getContentTypes()) {
                IContentInfo info = pluginManager.getContentInfoFromExtension(contentType, getPentahoSession());
                if (info != null) {
                    settings.put("plugin-content-type-" + i, "." + contentType); //$NON-NLS-1$ //$NON-NLS-2$
                    settings.put("plugin-content-type-icon-" + i, info.getIconUrl()); //$NON-NLS-1$
                    int j = 0;
                    for (IPluginOperation operation : info.getOperations()) {
                        settings.put("plugin-content-type-" + i + "-command-" + j, operation.getId()); //$NON-NLS-1$
                        settings.put("plugin-content-type-" + i + "-command-url-" + j, operation.getCommand()); //$NON-NLS-1$
                        j++;
                    }
                    i++;
                }

            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    return settings;
}

From source file:org.alfresco.reporting.processor.PropertyProcessor.java

/**
 * Validate if the unique sum of properties exists in the table definition.
 * Update the table definition if columns are not yet defined
 * @param props unique set of columns and their type
 * @throws Exception /*from   www .  j a  v  a 2s  .c o  m*/
 */
public void setTableDefinition(final String tableName, Properties props) throws Exception {
    if (logger.isDebugEnabled())
        logger.debug("Enter setTableDefinition tableName=" + tableName + " with props=" + props);
    // get the existing table definition

    try {
        //props = reportingHelper.propertyKeyToLowerCase(props);   

        Properties tableDesc = dbhb.getTableDescription(tableName);

        if (logger.isDebugEnabled()) {
            propertyLogger("## Object properties", props);
            propertyLogger("## Table description", tableDesc);
        }

        // check if our properties are defined or not
        Enumeration<Object> keys = props.keys();
        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();
            String type = props.getProperty(key, "-");
            // compare the key in lower-case. tableDesc contains lower case, 
            // key should too... Otherwise we happen to run into not-created issues against columns
            if (logger.isDebugEnabled())
                logger.debug("## COMPARE: key=" + key);
            if (tableDesc.containsKey(key /*.toLowerCase() */) || tableDesc.containsKey(key.toUpperCase()) || // Oracle sucks, Oracle sucks
                    tableDesc.containsKey(key.toLowerCase())) { // Oracle sucks, Oracle sucks
                // column exists... do nothing
                if (logger.isDebugEnabled())
                    logger.debug("DEFINITION Column " + key + " already exists.");
            } else {
                // column does NOT exist, accordingly.
                // if type is known, alter/extend the table 
                if (!"-".equals(type) && !"".equals(type)) {
                    if (logger.isDebugEnabled())
                        logger.debug("DEFINITION Adding column: " + key + "=" + type);
                    dbhb.extendTable(tableName, key, type);
                } else {
                    if (logger.isDebugEnabled())
                        logger.debug("DEFINITION Column " + key + " is empty. Type=" + type);
                }
            }
        } // end while
    } catch (Exception e) {
        logger.fatal("Exception setTableDefinition: " + e.getMessage());
        throw new Exception(e);
    }
    logger.debug("Exit setTableDefinition");
}

From source file:com.adito.server.DefaultAditoServerFactory.java

private void loadSystemProperties() {
    getBootProgressMonitor().updateMessage("Loading system properties");
    getBootProgressMonitor().updateProgress(1);

    /*//w w  w  .j a  va2s. c o m
     * Read in system properties from a resource, more a debugging aid than
     * anything else
     */
    InputStream in = null;
    try {
        File f = new File(CONF_DIR, "system.properties");
        in = new FileInputStream(f);
        Properties p = new Properties();
        p.load(in);
        for (Enumeration e = p.keys(); e.hasMoreElements();) {
            String k = (String) e.nextElement();
            System.getProperties().setProperty(k, p.getProperty(k).trim());
        }
    } catch (IOException e) {
        // Dont care
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException ioe) {

            }
        }
    }

    /**
     * Set the prefix if any.
     */
    SystemProperties.setPrefix(System.getProperty("boot.propertyPrefix"));

    /**
     * Are we in development mode?
     */
    useDevConfig = "true".equalsIgnoreCase(SystemProperties.get("adito.useDevConfig"));

    if (!"".equals(SystemProperties.get("adito.extensions", ""))) {
        appDir = new File(SystemProperties.get("adito.extensions"));
    }

    //
    System.setProperty("org.mortbay.jetty.servlet.SessionCookie",
            SystemProperties.get("adito.cookie", "JSESSIONID"));
    System.setProperty("org.mortbay.jetty.servlet.SessionURL",
            SystemProperties.get("adito.cookie", "JSESSIONID").toLowerCase());
}

From source file:org.canova.api.conf.Configuration.java

/**
 * Write out the non-default properties in this configuration to the give
 * {@link OutputStream}.//  w  ww .  jav a  2  s.  c o  m
 *
 * @param out the output stream to write to.
 */
public void writeXml(OutputStream out) throws IOException {
    Properties properties = getProps();
    try {
        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
        Element conf = doc.createElement("configuration");
        doc.appendChild(conf);
        conf.appendChild(doc.createTextNode("\n"));
        for (Enumeration e = properties.keys(); e.hasMoreElements();) {
            String name = (String) e.nextElement();
            Object object = properties.get(name);
            String value;
            if (object instanceof String) {
                value = (String) object;
            } else {
                continue;
            }
            Element propNode = doc.createElement("property");
            conf.appendChild(propNode);

            Element nameNode = doc.createElement("name");
            nameNode.appendChild(doc.createTextNode(name));
            propNode.appendChild(nameNode);

            Element valueNode = doc.createElement("value");
            valueNode.appendChild(doc.createTextNode(value));
            propNode.appendChild(valueNode);

            conf.appendChild(doc.createTextNode("\n"));
        }

        DOMSource source = new DOMSource(doc);
        StreamResult result = new StreamResult(out);
        TransformerFactory transFactory = TransformerFactory.newInstance();
        Transformer transformer = transFactory.newTransformer();
        transformer.transform(source, result);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.cyberway.issue.crawler.Heritrix.java

/**
 * Load the heritrix.properties file./*from   w  w  w  .java  2  s .  c o m*/
 * 
 * Adds any property that starts with
 * <code>HERITRIX_PROPERTIES_PREFIX</code>
 * or <code>ARCHIVE_PACKAGE</code>
 * into system properties (except logging '.level' directives).
 * @return Loaded properties.
 * @throws IOException
 */
protected static Properties loadProperties() throws IOException {
    if (Heritrix.propertiesLoaded) {
        return System.getProperties();
    }
    Heritrix.propertiesLoaded = true;

    Properties properties = new Properties();
    properties.load(getPropertiesInputStream());

    // Any property that begins with ARCHIVE_PACKAGE, make it
    // into a system property. While iterating, check to see if anything
    // defined on command-line, and if so, it overrules whats in
    // heritrix.properties.
    for (Enumeration e = properties.keys(); e.hasMoreElements();) {
        String key = ((String) e.nextElement()).trim();
        if (key.startsWith(ARCHIVE_PACKAGE) || key.startsWith(HERITRIX_PROPERTIES_PREFIX)) {
            // Don't add the heritrix.properties entries that are
            // changing the logging level of particular classes.
            String value = properties.getProperty(key).trim();
            if (key.indexOf(".level") < 0) {
                copyToSystemProperty(key, value);
            }
        } else if (key.startsWith(SYSTEM_PREFIX)) {
            String value = properties.getProperty(key).trim();
            copyToSystemProperty(key.substring(SYSTEM_PREFIX.length()), value);
        }
    }
    return properties;
}

From source file:org.apache.hadoop.conf.Configuration.java

/** 
 * Write out the non-default properties in this configuration to the give
 * {@link OutputStream}.//w w w . j ava 2 s.  c  o  m
 * 
 * @param out the output stream to write to.
 */
public void writeXml(OutputStream out) throws IOException {
    Properties properties = getProps();
    try {
        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
        Element conf = doc.createElement("configuration");
        doc.appendChild(conf);
        conf.appendChild(doc.createTextNode("\n"));
        for (Enumeration e = properties.keys(); e.hasMoreElements();) {
            String name = (String) e.nextElement();
            Object object = properties.get(name);
            String value = null;
            if (object instanceof String) {
                value = (String) object;
            } else {
                continue;
            }
            Element propNode = doc.createElement("property");
            conf.appendChild(propNode);

            Element nameNode = doc.createElement("name");
            nameNode.appendChild(doc.createTextNode(name));
            propNode.appendChild(nameNode);

            Element valueNode = doc.createElement("value");
            valueNode.appendChild(doc.createTextNode(value));
            propNode.appendChild(valueNode);

            conf.appendChild(doc.createTextNode("\n"));
        }

        DOMSource source = new DOMSource(doc);
        StreamResult result = new StreamResult(out);
        TransformerFactory transFactory = TransformerFactory.newInstance();
        Transformer transformer = transFactory.newTransformer();
        transformer.transform(source, result);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:conf.Configuration.java

/** 
 * Write out the non-default properties in this configuration to the given
 * {@link Writer}./*from  w  w  w .  j a v  a  2 s .c o m*/
 * 
 * @param out the writer to write to.
 */
public synchronized void writeXml(Writer out) throws IOException {
    Properties properties = getProps();
    try {
        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
        Element conf = doc.createElement("configuration");
        doc.appendChild(conf);
        conf.appendChild(doc.createTextNode("\n"));
        for (Enumeration e = properties.keys(); e.hasMoreElements();) {
            String name = (String) e.nextElement();
            Object object = properties.get(name);
            String value = null;
            if (object instanceof String) {
                value = (String) object;
            } else {
                continue;
            }
            Element propNode = doc.createElement("property");
            conf.appendChild(propNode);

            if (updatingResource != null) {
                Comment commentNode = doc.createComment("Loaded from " + updatingResource.get(name));
                propNode.appendChild(commentNode);
            }
            Element nameNode = doc.createElement("name");
            nameNode.appendChild(doc.createTextNode(name));
            propNode.appendChild(nameNode);

            Element valueNode = doc.createElement("value");
            valueNode.appendChild(doc.createTextNode(value));
            propNode.appendChild(valueNode);

            conf.appendChild(doc.createTextNode("\n"));
        }

        DOMSource source = new DOMSource(doc);
        StreamResult result = new StreamResult(out);
        TransformerFactory transFactory = TransformerFactory.newInstance();
        Transformer transformer = transFactory.newTransformer();
        transformer.transform(source, result);
    } catch (TransformerException te) {
        throw new IOException(te);
    } catch (ParserConfigurationException pe) {
        throw new IOException(pe);
    }
}

From source file:org.quartz.impl.StdSchedulerFactory.java

private void setBeanProps(Object obj, Properties props) throws NoSuchMethodException, IllegalAccessException,
        java.lang.reflect.InvocationTargetException, IntrospectionException, SchedulerConfigException {
    props.remove("class");

    BeanInfo bi = Introspector.getBeanInfo(obj.getClass());
    PropertyDescriptor[] propDescs = bi.getPropertyDescriptors();
    PropertiesParser pp = new PropertiesParser(props);

    java.util.Enumeration keys = props.keys();
    while (keys.hasMoreElements()) {
        String name = (String) keys.nextElement();
        String c = name.substring(0, 1).toUpperCase(Locale.US);
        String methName = "set" + c + name.substring(1);

        java.lang.reflect.Method setMeth = getSetMethod(methName, propDescs);

        try {//from w  w w .  j  a  va2 s.c om
            if (setMeth == null) {
                throw new NoSuchMethodException("No setter for property '" + name + "'");
            }

            Class[] params = setMeth.getParameterTypes();
            if (params.length != 1) {
                throw new NoSuchMethodException("No 1-argument setter for property '" + name + "'");
            }
            if (params[0].equals(int.class)) {
                setMeth.invoke(obj, new Object[] { new Integer(pp.getIntProperty(name)) });
            } else if (params[0].equals(long.class)) {
                setMeth.invoke(obj, new Object[] { new Long(pp.getLongProperty(name)) });
            } else if (params[0].equals(float.class)) {
                setMeth.invoke(obj, new Object[] { new Float(pp.getFloatProperty(name)) });
            } else if (params[0].equals(double.class)) {
                setMeth.invoke(obj, new Object[] { new Double(pp.getDoubleProperty(name)) });
            } else if (params[0].equals(boolean.class)) {
                setMeth.invoke(obj, new Object[] { new Boolean(pp.getBooleanProperty(name)) });
            } else if (params[0].equals(String.class)) {
                setMeth.invoke(obj, new Object[] { pp.getStringProperty(name) });
            } else {
                throw new NoSuchMethodException("No primitive-type setter for property '" + name + "'");
            }
        } catch (NumberFormatException nfe) {
            throw new SchedulerConfigException(
                    "Could not parse property '" + name + "' into correct data type: " + nfe.toString());
        }
    }
}

From source file:com.adito.server.Main.java

private void loadSystemProperties() {
    getBootProgressMonitor().updateMessage("Loading system properties");
    getBootProgressMonitor().updateProgress(1);

    /*/*w  w  w.  jav  a 2 s  .c  om*/
     * Read in system properties from a resource, more a debugging aid than
     * anything else
     */
    InputStream in = null;
    try {
        File f = new File(CONF_DIR, "system.properties");
        in = new FileInputStream(f);
        Properties p = new Properties();
        p.load(in);
        for (Enumeration e = p.keys(); e.hasMoreElements();) {
            String k = (String) e.nextElement();
            System.getProperties().setProperty(k, p.getProperty(k).trim());
        }
    } catch (IOException e) {
        // Dont care
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException ioe) {

            }
        }
    }

    /**
     * Set the prefix if any. 
     */
    SystemProperties.setPrefix(System.getProperty("boot.propertyPrefix"));

    /**
     * Are we in development mode?
     */
    useDevConfig = "true".equalsIgnoreCase(SystemProperties.get("adito.useDevConfig"));

    if (!"".equals(SystemProperties.get("adito.extensions", ""))) {
        appDir = new File(SystemProperties.get("adito.extensions"));
    }

    //
    System.setProperty("org.mortbay.jetty.servlet.SessionCookie",
            SystemProperties.get("adito.cookie", "JSESSIONID"));
    System.setProperty("org.mortbay.jetty.servlet.SessionURL",
            SystemProperties.get("adito.cookie", "JSESSIONID").toLowerCase());
}

From source file:com.sslexplorer.server.Main.java

private void loadSystemProperties() {
    getBootProgressMonitor().updateMessage("Loading system properties");
    getBootProgressMonitor().updateProgress(1);

    /*//ww w .j  a v  a2 s  .c om
     * Read in system properties from a resource, more a debugging aid than
     * anything else
     */
    InputStream in = null;
    try {
        File f = new File(CONF_DIR, "system.properties");
        in = new FileInputStream(f);
        Properties p = new Properties();
        p.load(in);
        for (Enumeration e = p.keys(); e.hasMoreElements();) {
            String k = (String) e.nextElement();
            System.getProperties().setProperty(k, p.getProperty(k).trim());
        }
    } catch (IOException e) {
        // Dont care
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException ioe) {

            }
        }
    }

    /**
     * Set the prefix if any. 
     */
    SystemProperties.setPrefix(System.getProperty("boot.propertyPrefix"));

    /**
     * Are we in development mode?
     */
    useDevConfig = "true".equalsIgnoreCase(SystemProperties.get("sslexplorer.useDevConfig"));

    if (!"".equals(SystemProperties.get("sslexplorer.extensions", ""))) {
        appDir = new File(SystemProperties.get("sslexplorer.extensions"));
    }

    //
    System.setProperty("org.mortbay.jetty.servlet.SessionCookie",
            SystemProperties.get("sslexplorer.cookie", "JSESSIONID"));
    System.setProperty("org.mortbay.jetty.servlet.SessionURL",
            SystemProperties.get("sslexplorer.cookie", "JSESSIONID").toLowerCase());
}