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:com.floreantpos.license.FiveStarPOSLicenseManager.java

/**
 * Generates a new license file returning the signature for the generated
 * license./*from  w w w . j a  va 2 s. co  m*/
 * 
 * @param templateFile
 * @param privateKey
 * @param licenseFile
 * @return String
 * @throws FileNotFoundException
 * @throws IOException
 * @throws InvalidKeyException
 * @throws NoSuchAlgorithmException
 * @throws InvalidKeySpecException
 * @throws SignatureException
 */
private final String generateNewLicense(File templateFile, InputStream privateKey, File licenseFile)
        throws FileNotFoundException, IOException, InvalidKeyException, NoSuchAlgorithmException,
        InvalidKeySpecException, SignatureException {

    /* reads the template file */
    Properties properties = new OrderedProperties();
    properties.load(new FileInputStream(templateFile));

    /* check if the required properties is filled */
    if (!properties.containsKey(License.LICENSED_TO)) {
        properties.put(License.LICENSED_TO, "************");
    }
    if (!properties.containsKey(License.PURCHASE_ID)) {
        properties.put(License.PURCHASE_ID, UUID.randomUUID().toString());
    }
    if (!properties.containsKey(License.PURCHASE_DATE)) {
        properties.put(License.PURCHASE_DATE, License.DATE_FORMAT.format(new Date()));
    }
    String machineKey = properties.getProperty(License.MACHINE_KEY);
    if (StringUtils.isBlank(machineKey)) {
        properties.put(License.MACHINE_KEY, getMachineKey());
    }
    if (!properties.containsKey(License.EXPIRATION_DATE)) {
        properties.put(License.EXPIRATION_DATE, License.DATE_FORMAT.format(DateUtils.addMonths(new Date(), 1)));
    }
    if (!properties.containsKey(License.BACK_OFFICE)) {
        properties.put(License.BACK_OFFICE, "false");
    }
    if (!properties.containsKey(License.KITCHEN_DISPLAY)) {
        properties.put(License.KITCHEN_DISPLAY, "false");
    }

    /* generates the license.dat file */
    return FiveStarPOSLicenseGenerator.generateLicense(properties, privateKey, licenseFile);
}

From source file:net.ontopia.topicmaps.viz.ResourceBundlesTest.java

/**
 * Checks all properties files in a given directory for consistency
 * against the master file. Note that the properties are loaded from
 * the classpath.//ww w. jav a 2  s.  c  om
 */
public void testTranslationsAreConsistent() throws IOException {
    String languages[] = { "de", "no", "ja" };

    Properties master = loadProperties("messages.properties");
    for (int ix = 0; ix < languages.length; ix++) {
        String file = "messages_" + languages[ix] + ".properties";
        Properties trans = loadProperties(file);
        List missing = new ArrayList();
        List extra = new ArrayList();

        for (Object prop : trans.keySet()) {
            if (!master.containsKey(prop))
                extra.add(prop);
        }

        for (Object prop : master.keySet()) {
            if (!trans.containsKey(prop))
                missing.add(prop);
        }

        assertTrue(buildReport(file, missing, extra), missing.isEmpty() && extra.isEmpty());
    }
}

From source file:gobblin.metastore.DataSourceProvider.java

@Inject
public DataSourceProvider(@Named("dataSourceProperties") Properties properties) {
    this.basicDataSource = new BasicDataSource();
    basicDataSource/*  ww w.j  a va 2  s .  c om*/
            .setDriverClassName(properties.getProperty(ConfigurationKeys.JOB_HISTORY_STORE_JDBC_DRIVER_KEY,
                    ConfigurationKeys.DEFAULT_JOB_HISTORY_STORE_JDBC_DRIVER));
    basicDataSource.setUrl(properties.getProperty(ConfigurationKeys.JOB_HISTORY_STORE_URL_KEY));
    if (properties.containsKey(ConfigurationKeys.JOB_HISTORY_STORE_USER_KEY)
            && properties.containsKey(ConfigurationKeys.JOB_HISTORY_STORE_PASSWORD_KEY)) {
        basicDataSource.setUsername(properties.getProperty(ConfigurationKeys.JOB_HISTORY_STORE_USER_KEY));
        basicDataSource.setPassword(properties.getProperty(ConfigurationKeys.JOB_HISTORY_STORE_PASSWORD_KEY));
    }
}

From source file:ca.weblite.contacts.webservice.RESTServiceConfiguration.java

private static void loadRuntimeSettings() {
    Properties p = new Properties();
    Map props = new HashMap();
    try {/*from  ww  w  .ja  v a2  s  .c o m*/
        InputStream in = RESTServiceConfiguration.class.getResourceAsStream("/runtime.properties");
        if (in != null) {
            try {
                p.load(in);
                props.putAll(p);
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (Throwable t) {
                    }
                }
            }
        }
        in = RESTServiceConfiguration.class.getResourceAsStream("/runtime.override.properties");
        if (in != null) {
            try {
                p.load(in);
                props.putAll(p);
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (Throwable t) {
                    }
                }
            }
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    System.out.println("In LoadRuntimeSettings");
    System.out.println(p);
    if (p.containsKey("DB_URL")) {
        DB_URL = (String) p.get("DB_URL");
        DB_PASSWORD = (String) p.get("DB_PASSWORD");
        DB_USERNAME = (String) p.get("DB_USERNAME");
    }
    if (p.containsKey("GCM_SERVER_API_KEY")) {
        GCM_SERVER_API_KEY = (String) p.get("GCM_SERVER_API_KEY");
    }
    if (p.containsKey("PUSH_TOKEN")) {
        PUSH_TOKEN = (String) p.get("PUSH_TOKEN");
    }
    if (p.containsKey("IOS_PUSH_CERT_URL")) {
        IOS_PUSH_CERT_URL = (String) p.getProperty("IOS_PUSH_CERT_URL");
    }
    if (p.containsKey("IOS_PUSH_CERT_PASSWORD")) {
        IOS_PUSH_CERT_PASSWORD = (String) p.getProperty("IOS_PUSH_CERT_PASSWORD");
    }

}

From source file:org.vietspider.crawl.crepo.WebClientInit.java

public void setup() throws Throwable {
    WebClient webClient = executor.getResource(WebClient.class);
    Properties properties = source.getProperties();

    methodHandler = new HttpMethodHandler(webClient);

    String userAgent = null;/*from  w  w w  .  ja v  a 2 s  .  c o m*/
    if (properties.containsKey(SourceProperties.USER_AGENT)) {
        userAgent = properties.getProperty(SourceProperties.USER_AGENT).trim();
        if (userAgent != null && userAgent.trim().isEmpty())
            userAgent = null;
    }

    webClient.setUserAgent(userAgent);

    String[] addresses = source.getHome();

    //    System.out.println(" step  1");
    //    for(int i = 0; i < addresses.length; i++) {
    //      System.out.println("home "+ addresses[i]);
    //    }

    List<Object> linkGenerator = source.getLinkGenerators();
    List<String> listHomepage = new ArrayList<String>();
    invoke(linkGenerator, HOMEPAGE_GENERATOR, listHomepage);
    if (listHomepage.size() > 0) {
        addresses = listHomepage.toArray(new String[listHomepage.size()]);
    }

    //    System.out.println(" step  2");
    //    for(int i = 0; i < addresses.length; i++) {
    //      System.out.println("home "+ addresses[i]);
    //    }

    URL url = null;
    try {
        url = new URL(addresses[0]);
    } catch (Exception e) {
        LinkLogStorages.getInstance().save(source, e, addresses[0]);
        //      LogWebsite.getInstance().setMessage(source, e, addresses[0]);
    }
    if (url == null)
        return;

    LinkCreator linkCreator = (LinkCreator) source.getLinkBuilder();
    String referer = linkCreator.getRefererURL();
    String proxy = properties.getProperty(HttpSessionUtils.PROXY);
    RefererFormHandler refererFormHandler = new RefererFormHandler(webClient);

    if (referer != null && referer.trim().length() > 0) {
        timeout += 2 * 60 * 1000;
    }
    String loginValue = properties.getProperty("Login");
    if (loginValue != null && !loginValue.trim().isEmpty())
        timeout += 3 * 60 * 1000;

    TimerMonitor timerMonitor = new TimerMonitor(this);
    timerMonitor.startSession();

    try {
        if (proxy != null && proxy.trim().startsWith("blind")) {
            refererFormHandler.execute(referer, webClient.setURL(referer, url, proxy));
            proxy = null;
        } else {
            refererFormHandler.execute(referer, webClient.setURL(referer, url));
        }

        if (referer != null && referer.trim().length() > 0) {
            methodHandler.execute(referer, "");
        }

    } catch (MalformedChunkCodingException e) {
        LinkLogStorages.getInstance().save(source, e, addresses[0]);
        //      LogWebsite.getInstance().setMessage(source, e, addresses[0]);
        return;
    } catch (IllegalStateException e) {
        LinkLogStorages.getInstance().save(source, e, addresses[0]);
        //      LogWebsite.getInstance().setMessage(source, e, addresses[0]);
        return;
    } catch (UnknownHostException e) {
        LinkLogStorages.getInstance().save(source, e, addresses[0]);
        //      LogWebsite.getInstance().setMessage(source, e, addresses[0]);
        CrawlerPoolPing.getInstance().increaTime();
    } catch (SocketException e) {
        LinkLogStorages.getInstance().save(source, e, addresses[0]);
        //      LogWebsite.getInstance().setMessage(source, e, addresses[0]);
        return;
    } catch (Exception e) {
        LinkLogStorages.getInstance().save(source, e, addresses[0]);
        //      LogWebsite.getInstance().setMessage(source, e, addresses[0]);
        return;
    }

    //    System.out.println(" step  2");
    //    for(int i = 0; i < addresses.length; i++) {
    //      System.out.println("home "+ addresses[i]);
    //    }

    //set proxy and login to site 
    Properties systemProperties = SystemProperties.getInstance().getProperties();
    HttpSessionUtils httpSessionUtils = new HttpSessionUtils(methodHandler, source);
    httpSessionUtils.setProxy(systemProperties, proxy);
    try {
        if (!httpSessionUtils.login(loginValue, source.getEncoding(), url, referer)) {
            LinkLogStorages.getInstance().save(source, "Cann't login to website", url.toString());
            //        LogWebsite.getInstance().setMessage(source, null, "Cann't login to website");
        }
    } catch (Exception e) {
        LinkLogStorages.getInstance().save(source, e, url.toString());
        //      LogWebsite.getInstance().setMessage(source, e, "Cann't login to website");
    }

    String host = webClient.getHost();

    //    System.out.println(" step  3");
    //    for(int i = 0; i < addresses.length; i++) {
    //      System.out.println("home "+ addresses[i]);
    //    }

    //    store.loadFile(source);
    //    LinkQueue linkQueue = store.getQueue();
    //    System.out.println(" chuan bi load them mot mo "+ addresses);
    //    if(linkQueue.size() >= SessionTempLinkHandler.MAX_SIZE_LINK) return;
    //      System.out.println(" load vao "+ addresses.length);
    store.addHomepages(host, referer, addresses);
}

From source file:org.apache.ivory.cli.IvoryCLI.java

protected String validateIvoryUrl(CommandLine commandLine) throws IvoryCLIException {
    String url = commandLine.getOptionValue(URL_OPTION);
    if (url == null) {
        try {//from   ww w .j ava  2s. c  o  m
            InputStream input = IvoryCLI.class.getResourceAsStream("/client.properties");
            if (input == null) {
                ERR_STREAM.println("client.properties file does not exist, Ivory URL is "
                        + "neither available in command option nor in the client.properties file");
                throw new IvoryCLIException("Ivory URL not specified");

            }
            Properties prop = new Properties();
            prop.load(input);
            if (prop.containsKey("ivory.url"))
                url = prop.getProperty("ivory.url");
            else {
                throw new IvoryCLIException("ivory.url property not present in client.properties");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return url;
}

From source file:org.apache.juddi.v3.client.transport.JAXWSTransport.java

/**
 * Sets the credentials on the RequestContext if the services are
 * protected by Basic Authentication. The username and password are
 * obtained from the uddi.xml./* w ww.j ava  2s . co m*/
 *
 * @param requestContext
 * @throws ConfigurationException
 */
private void setCredentials(Map<String, Object> requestContext) throws ConfigurationException {
    UDDIClient client = UDDIClientContainer.getUDDIClient(clientName);
    Properties properties = client.getClientConfig().getUDDINode(nodeName).getProperties();
    if (properties != null) {
        String username = null;
        String password = null;
        if (properties.containsKey(Property.BASIC_AUTH_USERNAME)) {
            username = properties.getProperty(Property.BASIC_AUTH_USERNAME);
        }
        if (properties.containsKey(Property.BASIC_AUTH_PASSWORD)) {
            password = properties.getProperty(Property.BASIC_AUTH_PASSWORD);
        }
        String cipher = null;
        boolean isEncrypted = false;
        if (properties.containsKey(Property.BASIC_AUTH_PASSWORD_CP)) {
            cipher = properties.getProperty(Property.BASIC_AUTH_PASSWORD_CP);
        }
        if (properties.containsKey(Property.BASIC_AUTH_PASSWORD_IS_ENC)) {
            isEncrypted = Boolean.parseBoolean(properties.getProperty(Property.BASIC_AUTH_PASSWORD_IS_ENC));
        }
        if (username != null && password != null) {
            requestContext.put(BindingProvider.USERNAME_PROPERTY, username);
            if (isEncrypted) {
                try {
                    requestContext.put(BindingProvider.PASSWORD_PROPERTY,
                            CryptorFactory.getCryptor(cipher).decrypt(password));
                } catch (Exception ex) {
                    logger.error("Unable to decrypt password!", ex);
                }
            } else {
                requestContext.put(BindingProvider.PASSWORD_PROPERTY, password);
            }
        }
    }
}

From source file:org.commonjava.maven.ext.io.ModelIO.java

/**
 * Recursively resolve a property value.
 *
 * @param userProperties// w ww . j  a  v  a 2s.  co  m
 * @param p
 * @param key
 * @return the value of the key
 */
private String resolveProperty(Properties userProperties, Properties p, String key) {
    String result = "";
    String child = (isEmpty(key) ? "" : key.substring(2, key.length() - 1));

    if (p.containsKey(child) && !userProperties.containsKey(child)) {
        result = p.getProperty(child);

        if (result.startsWith("${")) {
            result = resolveProperty(userProperties, p, result);
        }
    }
    return result;
}

From source file:org.apache.qpid.server.Main.java

private Map<String, String> calculateConfigContext(final String[] configPropPairs) {
    Map<String, String> context = new HashMap<>();

    if (configPropPairs != null && configPropPairs.length > 0) {
        for (String s : configPropPairs) {
            int firstEquals = s.indexOf("=");
            if (firstEquals == -1) {
                throw new IllegalArgumentException(
                        "Configuration property argument is not of the format name=value: " + s);
            }/*from ww  w.j a v  a 2 s  .  co m*/
            String name = s.substring(0, firstEquals);
            String value = s.substring(firstEquals + 1);

            if (name.equals("")) {
                throw new IllegalArgumentException(
                        "Configuration property argument is not of the format name=value: " + s);
            }

            context.put(name, value);
        }
    }
    if (!context.containsKey(QPID_HOME_DIR)) {
        Properties systemProperties = System.getProperties();
        final Map<String, String> environment = System.getenv();
        if (systemProperties.containsKey(QPID_HOME_DIR)) {
            context.put(QPID_HOME_DIR, systemProperties.getProperty(QPID_HOME_DIR));
        } else if (environment.containsKey(QPID_HOME_DIR)) {
            context.put(QPID_HOME_DIR, environment.get(QPID_HOME_DIR));
        } else if (context.containsKey(PROPERTY_QPID_HOME)) {
            context.put(QPID_HOME_DIR, context.get(PROPERTY_QPID_HOME));
        } else if (systemProperties.containsKey(PROPERTY_QPID_HOME)) {
            context.put(QPID_HOME_DIR, systemProperties.getProperty(PROPERTY_QPID_HOME));
        } else if (environment.containsKey(PROPERTY_QPID_HOME)) {
            context.put(QPID_HOME_DIR, environment.get(PROPERTY_QPID_HOME));
        }
    }
    return context;
}

From source file:cn.vlabs.duckling.vwb.service.config.impl.DomainServiceImpl.java

private void refineDomain(int siteId) {
    Map<String, String> domains = siteConfig.getPropertyStartWith(siteId, KeyConstants.SITE_DOMAIN_KEY);
    Properties prop = compact(domains);
    if (prop.size() != domains.size()) {
        log.info("Domain name's config is inconsist. it will be refined...");
        for (String key : domains.keySet()) {
            if (!prop.containsKey(key)) {
                siteConfig.removeProperty(siteId, key);
                cache.removeEntry(GLOBAL_SITE_ID, domains.get(key));
            }/*from w  ww . ja  v a2  s  .  c  o m*/
        }
        siteConfig.setProperty(siteId, prop);
    }
}