Example usage for java.util Properties containsKey

List of usage examples for java.util Properties containsKey

Introduction

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

Prototype

@Override
    public boolean containsKey(Object key) 

Source Link

Usage

From source file:org.jahia.services.usermanager.ldap.LDAPUserGroupProvider.java

@Override
public List<String> searchGroups(Properties searchCriteria, long offset, long limit) {
    if (searchCriteria.containsKey("groupname") && searchCriteria.size() == 1
            && !searchCriteria.getProperty("groupname").contains("*")) {
        try {/*  ww  w.ja v a  2  s  . c  om*/
            JahiaGroup group = getGroup((String) searchCriteria.get("groupname"));
            return Arrays.asList(group.getGroupname());
        } catch (GroupNotFoundException e) {
            return Collections.emptyList();
        }
    }

    List<String> groups = new LinkedList<String>(searchGroups(searchCriteria, false));

    // handle dynamics
    if (groupConfig.isDynamicEnabled()) {
        groups.addAll(searchGroups(searchCriteria, true));
    }

    return groups.subList(Math.min((int) offset, groups.size()),
            limit < 0 ? groups.size() : Math.min((int) (offset + limit), groups.size()));
}

From source file:org.jahia.services.usermanager.ldap.LDAPUserGroupProvider.java

private boolean isOrOperator(Properties ldapfilters, Properties searchCriteria) {
    if (ldapfilters.size() > 1) {
        if (searchCriteria.containsKey(JahiaUserManagerService.MULTI_CRITERIA_SEARCH_OPERATION)) {
            if (((String) searchCriteria.get(JahiaUserManagerService.MULTI_CRITERIA_SEARCH_OPERATION)).trim()
                    .toLowerCase().equals("and")) {
                return false;
            }/*  w w w  . ja va 2  s .c om*/
        }
    }
    return true;
}

From source file:org.colombbus.tangara.Configuration.java

private File getRedirectionPath(File redirectFile) {
    File path = null;//from w ww.j  av  a2  s  .  com
    if (redirectFile.exists()) {
        InputStream redirectStream = null;
        try {
            Properties redirectProperties = new Properties();
            redirectStream = new FileInputStream(redirectFile);
            redirectProperties.load(redirectStream);
            if (redirectProperties.containsKey(REDIRECT_PATH_P)) {
                path = new File(redirectProperties.getProperty(REDIRECT_PATH_P));
            }
        } catch (Exception e) {
            System.err.println(
                    "Error while reading redirect file '" + redirectFile.getAbsolutePath() + "'\n" + e);
        } finally {
            IOUtils.closeQuietly(redirectStream);
        }
    }
    return path;
}

From source file:org.jahia.services.usermanager.ldap.LDAPUserGroupProvider.java

@Override
public List<String> searchUsers(final Properties searchCriteria, long offset, long limit) {
    if (searchCriteria.containsKey("username") && searchCriteria.size() == 1
            && !searchCriteria.getProperty("username").contains("*")) {
        try {//w w w . j  a va  2 s . co  m
            JahiaUser user = getUser((String) searchCriteria.get("username"));
            return Arrays.asList(user.getUsername());
        } catch (UserNotFoundException e) {
            return Collections.emptyList();
        }
    }
    final ContainerCriteria query = buildUserQuery(searchCriteria);
    if (query == null) {
        return Collections.emptyList();
    }
    final UsersNameClassPairCallbackHandler searchNameClassPairCallbackHandler = new UsersNameClassPairCallbackHandler();
    long currentTimeMillis = System.currentTimeMillis();
    ldapTemplateWrapper.execute(new BaseLdapActionCallback<Object>(externalUserGroupService, key) {
        @Override
        public Object doInLdap(LdapTemplate ldapTemplate) {
            ldapTemplate.search(query, searchNameClassPairCallbackHandler);
            return null;
        }
    });
    logger.debug("Search users for {} in {} ms", searchCriteria,
            System.currentTimeMillis() - currentTimeMillis);

    ArrayList<String> l = new ArrayList<String>(searchNameClassPairCallbackHandler.getNames());
    return l.subList(Math.min((int) offset, l.size()),
            limit < 0 ? l.size() : Math.min((int) (offset + limit), l.size()));
}

From source file:info.magnolia.importexport.PropertiesImportExport.java

/**
 * Transforms the keys to the following inner notation: <code>some/path/node.prop</code> or <code>some/path/node.@type</code>.
 *///  w  ww .  j a va 2  s  .  co m
private Properties keysToInnerFormat(Properties properties) {
    Properties cleaned = new OrderedProperties();

    for (Object o : properties.keySet()) {
        String orgKey = (String) o;

        //if this is a node definition (no property)
        String newKey = orgKey;

        // make sure we have a dot as a property separator
        newKey = StringUtils.replace(newKey, "@", ".@");
        // avoid double dots
        newKey = StringUtils.replace(newKey, "..@", ".@");

        String propertyName = StringUtils.substringAfterLast(newKey, ".");
        String keySuffix = StringUtils.substringBeforeLast(newKey, ".");
        String path = StringUtils.replace(keySuffix, ".", "/");
        path = StringUtils.removeStart(path, "/");

        // if this is a path (no property)
        if (StringUtils.isEmpty(propertyName)) {
            // no value --> is a node
            if (StringUtils.isEmpty(properties.getProperty(orgKey))) {
                // make this the type property if not defined otherwise
                if (!properties.containsKey(orgKey + "@type")) {
                    cleaned.put(path + ".@type", ItemType.CONTENTNODE.getSystemName());
                }
                continue;
            }
            propertyName = StringUtils.substringAfterLast(path, "/");
            path = StringUtils.substringBeforeLast(path, "/");
        }
        cleaned.put(path + "." + propertyName, properties.get(orgKey));
    }
    return cleaned;
}

From source file:br.org.indt.ndg.server.survey.SurveyHandlerBean.java

@Override
public String getSpecificPropertySetting(String propertySetting) throws MSMApplicationException {
    Properties settings = getSettings();
    String result = null;/*from ww w  . j  a  v a2 s .co  m*/
    if (settings.containsKey(propertySetting)) {
        result = settings.getProperty(propertySetting);
    } else {
        throw new PropertyNotExistExcpetion();
    }
    return result;
}

From source file:ch.entwine.weblounge.common.impl.site.I18nDictionaryImpl.java

/**
 * Adds the the dictionary found in <code>file</code> to the current i18n
 * definitions.//from   w  ww .j  av  a2  s .  c o  m
 * 
 * @param url
 *          the i18n dictionary
 * @param language
 *          the dictionary language
 */
public void addDictionary(URL url, Language language) {
    DocumentBuilder docBuilder;
    try {
        docBuilder = XMLUtils.getDocumentBuilder();
        Document doc = docBuilder.parse(url.openStream());

        if (language != null)
            logger.debug("Reading i18n dictionary {} ({})", url.getFile(), language);
        else
            logger.debug("Reading default i18n dictionary {}", url.getFile());

        // Get the target properties

        Properties p = null;
        if (language != null) {
            p = i18n.get(language);
            if (p == null) {
                p = new Properties();
                i18n.put(language, p);
            }
        } else {
            p = defaults;
        }

        int invalidKeys = 0;
        int invalidValues = 0;

        // Read and store the messages

        XPath path = XMLUtils.getXPath();
        NodeList nodes = XPathHelper.selectList(doc, "/resources/string", path);
        for (int j = 0; j < nodes.getLength(); j++) {
            Node messageNode = nodes.item(j);
            String key = XPathHelper.valueOf(messageNode, "@name", path);
            String value = XPathHelper.valueOf(messageNode, "text()", path);
            if (key == null) {
                invalidKeys++;
                continue;
            }
            if (value == null) {
                logger.debug("I18n dictionary {} lacks a value for key '{}'", url, key);
                invalidValues++;
                continue;
            }
            if (p.containsKey(key)) {
                logger.warn("I18n key '{}' redefined in {}", key, url);
            }
            p.put(key, value);
        }

        if (invalidKeys > 0)
            logger.warn("I18n dictionary {} contains {} entries withou a key", url, invalidKeys);
        if (invalidValues > 0)
            logger.warn("I18n dictionary {} contains {} keys without values", url, invalidValues);

    } catch (ParserConfigurationException e) {
        logger.warn("Parser configuration error when reading i18n dictionary {}: {}", url, e.getMessage());
    } catch (SAXException e) {
        logger.warn("SAX exception while parsing i18n dictionary {}: {}", url, e.getMessage());
    } catch (IOException e) {
        logger.warn("IO exception while parsing i18n dictionary {}: {}", url, e.getMessage());
    }
}

From source file:com.flexive.shared.FxSharedUtils.java

/**
 * Get the name of the application server [fleXive] is running on
 *
 * @return name of the application server [fleXive] is running on
 * @since 3.1/*from ww w .  j av  a  2  s . c  om*/
 */
public synchronized static String getApplicationServerName() {
    if (appserver != null)
        return appserver;
    if (System.getProperty("product.name") != null) {
        // Glassfish 2 / Sun AS
        String ver = System.getProperty("product.name");
        if (System.getProperty("com.sun.jbi.domain.name") != null)
            ver += " (Domain: " + System.getProperty("com.sun.jbi.domain.name") + ")";
        appserver = ver;
    } else if (System.getProperty("glassfish.version") != null) {
        // Glassfish 3+
        appserver = System.getProperty("glassfish.version");
    } else if (System.getProperty("jboss.home.dir") != null) {
        appserver = "JBoss (unknown version)";
        boolean found = false;
        try {
            final Class<?> cls = Class.forName("org.jboss.Version");
            Method m = cls.getMethod("getInstance");
            Object v = m.invoke(null);
            Method pr = cls.getMethod("getProperties");
            Map props = (Map) pr.invoke(v);
            String ver = inspectJBossVersionProperties(props);
            found = true;
            appserver = ver;
        } catch (ClassNotFoundException e) {
            //ignore
        } catch (NoSuchMethodException e) {
            //ignore
        } catch (IllegalAccessException e) {
            //ignore
        } catch (InvocationTargetException e) {
            //ignore
        }
        if (!found) {
            // try JBoss 7 MBean lookup
            try {
                final ObjectName name = new ObjectName("jboss.as:management-root=server");
                final Object version = ManagementFactory.getPlatformMBeanServer().getAttribute(name,
                        "releaseVersion");
                if (version != null) {
                    appserver = "JBoss (" + version + ")";
                    found = true;
                }
            } catch (Exception e) {
                // ignore
            }
        }
        if (!found) {
            //try again with a JBoss 6.x specific locations
            try {
                final ClassLoader jbossCL = Class.forName("org.jboss.Main").getClassLoader();
                if (jbossCL.getResource(JBOSS6_VERSION_PROPERTIES) != null) {
                    Properties prop = new Properties();
                    prop.load(jbossCL.getResourceAsStream(JBOSS6_VERSION_PROPERTIES));
                    if (prop.containsKey("version.name")) {
                        appserver = inspectJBossVersionProperties(prop);
                        //noinspection UnusedAssignment
                        found = true;
                    }
                }
            } catch (ClassNotFoundException e) {
                //ignore
            } catch (IOException e) {
                //ignore
            }
        }
    } else if (System.getProperty("openejb.version") != null) {
        // try to get Jetty version
        String jettyVersion = "";
        try {
            final Class<?> cls = Class.forName("org.mortbay.jetty.Server");
            jettyVersion = " (Jetty " + cls.getPackage().getImplementationVersion() + ")";
        } catch (ClassNotFoundException e) {
            // no Jetty version...
        }
        appserver = "OpenEJB " + System.getProperty("openejb.version") + jettyVersion;
    } else if (System.getProperty("weblogic.home") != null) {
        String server = System.getProperty("weblogic.Name");
        String wlVersion = "";
        try {
            final Class<?> cls = Class.forName("weblogic.common.internal.VersionInfo");
            Method m = cls.getMethod("theOne");
            Object serverVersion = m.invoke(null);
            Method sv = m.invoke(null).getClass().getMethod("getImplementationVersion");
            wlVersion = " " + String.valueOf(sv.invoke(serverVersion));
        } catch (ClassNotFoundException e) {
            //ignore
        } catch (NoSuchMethodException e) {
            //ignore
        } catch (InvocationTargetException e) {
            //ignore
        } catch (IllegalAccessException e) {
            //ignore
        }
        if (StringUtils.isEmpty(server))
            appserver = "WebLogic" + wlVersion;
        else
            appserver = "WebLogic" + wlVersion + " (server: " + server + ")";
    } else if (System.getProperty("org.apache.geronimo.home.dir") != null) {
        String gVersion = "";
        try {
            final Class<?> cls = Class.forName("org.apache.geronimo.system.serverinfo.ServerConstants");
            Method m = cls.getMethod("getVersion");
            gVersion = " " + String.valueOf(m.invoke(null));
            m = cls.getMethod("getBuildDate");
            gVersion = gVersion + " (" + String.valueOf(m.invoke(null)) + ")";
        } catch (ClassNotFoundException e) {
            //ignore
        } catch (NoSuchMethodException e) {
            //ignore
        } catch (InvocationTargetException e) {
            //ignore
        } catch (IllegalAccessException e) {
            //ignore
        }
        appserver = "Apache Geronimo " + gVersion;
    } else {
        appserver = "unknown";
    }
    return appserver;
}

From source file:com.bol.crazypigs.HBaseStorage15.java

private JobConf initializeLocalJobConfig(Job job) {
    Properties udfProps = getUDFProperties();
    Configuration jobConf = job.getConfiguration();
    JobConf localConf = new JobConf(jobConf);
    if (udfProps.containsKey(HBASE_CONFIG_SET)) {
        for (Entry<Object, Object> entry : udfProps.entrySet()) {
            localConf.set((String) entry.getKey(), (String) entry.getValue());
        }/* w  w  w  . ja v  a  2s  .  co m*/
    } else {
        Configuration hbaseConf = HBaseConfiguration.create();
        for (Entry<String, String> entry : hbaseConf) {
            // JobConf may have some conf overriding ones in hbase-site.xml
            // So only copy hbase config not in job config to UDFContext
            // Also avoids copying core-default.xml and core-site.xml
            // props in hbaseConf to UDFContext which would be redundant.
            if (jobConf.get(entry.getKey()) == null) {
                udfProps.setProperty(entry.getKey(), entry.getValue());
                localConf.set(entry.getKey(), entry.getValue());
            }
        }
        udfProps.setProperty(HBASE_CONFIG_SET, "true");
    }
    return localConf;
}

From source file:com.att.android.arodatacollector.main.AROCollectorService.java

/**
 * Sample file content: FLURRY_API_KEY=YKN7M4TDXRKXH97PX565
 * Each Flurry API Key corresponds to an Application on Flurry site.  It is absolutely 
  * necessary that the Flurry API Key-value from user's device is correct in order to log to the Flurry application.
  * /*w ww  .ja  va  2s . c om*/
  * No validation on the API key allows creation of a new Flurry application by client at any time
  * The API key is communicated to the user group who would put the API key name-value pair into 
  * properties file specified by variable flurryFileName below.
  * 
  * If no key-value is found, the default API key is used below.  Default is intended for users of
  * ATT Developer Program.
 */
private void setFlurryApiKey() {
    if (DEBUG) {
        Log.d(TAG, "entered setFlurryApiKey");
    }
    final String flurryFileName = ARODataCollector.ARO_TRACE_ROOTDIR + ARODataCollector.FLURRY_API_KEY_REL_PATH;

    InputStream flurryFileReaderStream = null;
    try {
        final ClassLoader loader = ClassLoader.getSystemClassLoader();

        flurryFileReaderStream = loader.getResourceAsStream(flurryFileName);

        Properties prop = new Properties();
        try {
            if (flurryFileReaderStream != null) {
                prop.load(flurryFileReaderStream);
                mApp.app_flurry_api_key = prop.containsKey(ARODataCollector.FLURRY_API_KEY_NAME)
                        && !prop.getProperty(ARODataCollector.FLURRY_API_KEY_NAME)
                                .equals(AROCollectorUtils.EMPTY_STRING)
                                        ? prop.getProperty(ARODataCollector.FLURRY_API_KEY_NAME).trim()
                                        : mApp.app_flurry_api_key;
                if (DEBUG) {
                    Log.d(TAG, "flurry Property String: " + prop.toString());
                    Log.d(TAG, "flurry app_flurry_api_key: " + mApp.app_flurry_api_key);
                }
            } else {
                if (DEBUG) {
                    Log.d(TAG, "flurryFileReader stream is null.  Using default: " + mApp.app_flurry_api_key);
                }
            }
        } catch (IOException e) {
            Log.d(TAG, e.getClass().getName() + " thrown trying to load file ");
        }
    } finally {
        try {
            if (flurryFileReaderStream != null) {
                flurryFileReaderStream.close();
            }
        } catch (IOException e) {
            //log and exit method-nothing else to do.
            if (DEBUG) {
                Log.d(TAG,
                        "setFlurryApiKey method reached catch in finally method, trying to close flurryFileReader");
            }
        }
        Log.d(TAG, "exiting setFlurryApiKey");
    }
}