Example usage for java.util Properties values

List of usage examples for java.util Properties values

Introduction

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

Prototype

@Override
    public Collection<Object> values() 

Source Link

Usage

From source file:com.laudandjolynn.mytv.Main.java

/**
 * ???/*w  w  w.j  av  a 2  s . c om*/
 */
private static void initDbData0(MyTvData data) {
    if (data.isDataInited()) {
        logger.info("init data had insert into db.");
        return;
    }
    Properties tvStationProp = new Properties();
    try {
        tvStationProp.load(Main.class.getResourceAsStream("/" + Constant.TV_STATION_INIT_DATA_FILE_NAME));
    } catch (IOException e) {
        throw new MyTvException(
                "error occur while load property file: " + Constant.TV_STATION_INIT_DATA_FILE_NAME, e);
    }

    Collection<Object> values = tvStationProp.values();
    List<String> insertSqlList = new ArrayList<String>(values.size());
    String insertSql = "insert into my_tv (stationName,displayName,classify,channel,sequence)";
    for (Object value : values) {
        insertSqlList.add(insertSql + " values (" + value.toString() + ")");
    }

    Connection conn = null;
    Statement stmt = null;
    try {
        conn = DataSourceManager.getConnection();
        conn.setAutoCommit(false);
        stmt = conn.createStatement();

        for (String sql : insertSqlList) {
            stmt.addBatch(sql);
            logger.info("execute sql: " + sql);
        }
        stmt.executeBatch();
        conn.commit();
        data.writeData(null, Constant.XML_TAG_DATA, "true");
    } catch (SQLException e) {
        if (conn != null) {
            try {
                conn.rollback();
            } catch (SQLException e1) {
                throw new MyTvException("error occur while rollback transaction.", e1);
            }
        }
        throw new MyTvException("error occur while execute sql on db.", e);
    } finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
                throw new MyTvException("error occur while close statement.", e);
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                throw new MyTvException("error occur while close sqlite connection.", e);
            }
        }
    }

}

From source file:org.openbaton.nfvo.system.SystemStartup.java

@Override
public void run(String... args) throws Exception {
    log.info("Initializing OpenBaton");

    log.debug(Arrays.asList(args).toString());

    propFileLocation = propFileLocation.replace("file:", "");
    log.debug("Property file: " + propFileLocation);

    InputStream is = new FileInputStream(propFileLocation);
    Properties properties = new Properties();
    properties.load(is);/* w  ww .  j  av  a  2 s.com*/

    log.debug("Config Values are: " + properties.values());

    Configuration c = new Configuration();

    c.setName("system");
    c.setConfigurationParameters(new HashSet<ConfigurationParameter>());

    /**
     * Adding properties from file
     */
    for (Entry<Object, Object> entry : properties.entrySet()) {
        ConfigurationParameter cp = new ConfigurationParameter();
        cp.setConfKey((String) entry.getKey());
        cp.setValue((String) entry.getValue());
        c.getConfigurationParameters().add(cp);
    }

    /**
     * Adding system properties
     */
    Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
    for (NetworkInterface netint : Collections.list(nets)) {
        ConfigurationParameter cp = new ConfigurationParameter();
        log.trace("Display name: " + netint.getDisplayName());
        log.trace("Name: " + netint.getName());
        cp.setConfKey("ip-" + netint.getName().replaceAll("\\s", ""));
        Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
        for (InetAddress inetAddress : Collections.list(inetAddresses)) {
            if (inetAddress.getHostAddress().contains(".")) {
                log.trace("InetAddress: " + inetAddress.getHostAddress());
                cp.setValue(inetAddress.getHostAddress());
            }
        }
        log.trace("");
        c.getConfigurationParameters().add(cp);
    }

    configurationRepository.save(c);

    if (installPlugin) {
        startPlugins(pluginDir);
    }
}

From source file:de.juwimm.cms.search.res.HtmlDocumentLocator.java

private Document parseHtml(Document resource, HTMLParser parser) throws IOException, InterruptedException {
    Reader reader = parser.getReader();
    StringWriter sw = new StringWriter();
    org.apache.commons.io.IOUtils.copy(reader, sw);
    String sresult = sw.toString();

    if (log.isDebugEnabled())
        log.debug("Saving tokenized HTML value into searchengine: " + sresult);
    resource.add(/*from   ww w  .ja  v a 2  s .  com*/
            new Field("contents", stripNonValidXMLCharacters(sresult), Field.Store.YES, Field.Index.ANALYZED));

    Properties prop = parser.getMetaTags();
    Collection metafields = prop.values();
    String metadata = "";
    Iterator it = metafields.iterator();
    while (it.hasNext()) {
        StringTokenizer st = new StringTokenizer((String) it.next(), ",");
        while (st.hasMoreElements()) {
            String token = st.nextToken().trim();
            metadata += token + " ";
        }
    }
    // tidy the metadata
    metadata = XercesHelper.html2utf8string(metadata);
    resource.add(new Field("metadata", metadata, Field.Store.YES, Field.Index.ANALYZED));

    // Add the summary as a field that is stored and returned with
    // hit documents for display.
    resource.add(new Field("summary", parser.getSummary(), Field.Store.YES, Field.Index.ANALYZED_NO_NORMS));

    // Add the title as a field that it can be searched and that is stored.
    resource.add(new Field("title", parser.getTitle(), Field.Store.YES, Field.Index.ANALYZED));
    reader.close();
    return resource;
}

From source file:de.xirp.managers.DeleteManager.java

/**
 * Deletes all files listed in the delete properties file and
 * deletes the properties file itself afterwards.
 *///w  w  w. java 2 s .co m
private void deleteFromPropsFile() {
    Properties props = new Properties();
    File f = new File(Constants.TO_DELETE_FILE);
    try {
        FileReader fr = new FileReader(f);
        props.load(fr);
        fr.close();
        for (Object obj : props.values()) {
            String path = (String) obj;
            try {
                FileUtils.forceDelete(new File(path));
            } catch (IOException e) {
                logClass.warn(I18n.getString("DeleteManager.notDeleted", path) //$NON-NLS-1$
                        + Constants.LINE_SEPARATOR);
            }
        }
        f.delete();
    } catch (FileNotFoundException e) {
        logClass.error("Error: " + e.getMessage() + Constants.LINE_SEPARATOR, e); //$NON-NLS-1$
    } catch (IOException e) {
        logClass.error("Error: " + e.getMessage() + Constants.LINE_SEPARATOR, e); //$NON-NLS-1$
    }
}

From source file:com.agilejava.docbkx.maven.AbstractWebhelpMojo.java

private int retrieveCleanUpProps() {
    // Files for punctuation (only one for now)
    String[] punctuationFiles = new String[] { "punctuation.props" };
    FileInputStream input;//from  w ww  . j  ava 2  s. c o  m

    // Get the list of the props file containing the words to remove (not the punctuation)
    DirList props = new DirList(targetBaseDir, new String[] { "", "^(?!(punctuation)).*\\.props$" }, 1);
    //new String[]{"", "^(?!(punctuation)).*\\.props$"}
    ArrayList wordsList = props.getListFiles();

    //      System.out.println("props files:"+wordsList);epub now handles correctly multiples input files and also zip them correctly
    //TODO all properties are taken to a single arraylist. does it ok?.
    Properties enProps = new Properties();

    try {
        // Retrieve words to remove
        for (int i = 0; i < wordsList.size(); i++) {
            File aWordsList = (File) wordsList.get(i);

            if (aWordsList.exists()) {
                enProps.load(input = new FileInputStream(aWordsList));
                input.close();
                cleanUpStrings.addAll(enProps.values());

                enProps.clear();
            }
        }

        // Retrieve char to remove (punctuation for ex.)
        for (int i = 0; i < punctuationFiles.length; i++) {
            String punctuationFile = punctuationFiles[i];
            File ftemp = new File(searchBaseDir, punctuationFile);

            if (ftemp.exists()) {
                enProps.load(input = new FileInputStream(ftemp));
                input.close();
                cleanUpChars.addAll(enProps.values());
                enProps.clear();
            }
        }
    } catch (IOException e) {
        getLog().error("Unable to read one property file", e);

        return 1;
    }

    return 0;
}

From source file:com.zb.jcseg.core.JcsegTaskConfig.java

/**
 * reset the value of its options from a propertie file . <br />
 * //from  www .j  a  v a2s .  c o  m
 * @param proFile path of jcseg.properties file. when null is givend, jcseg will look up the default
 * jcseg.properties file. <br />
 * @throws IOException
 */
public void resetFromPropertyFile(String proFile) throws IOException {
    Properties lexPro = new Properties();
    String jarPath = null;
    /* load the mapping from the default property file. */
    if (proFile == null) {
        /**
         * <pre>
         *      0.load the jcseg.properties from the current data.
         *      1.load the jcseg.properties located with the jar file. 
         *      2.load the jcseg.properties from the classpath. 
         *      3.load the jcseg.properties from the user.home.
         * </pre>
         */
        boolean jcseg_properties = false;
        File pro_file = null;
        String fileName = System.getProperty("jcseg.properties.path");
        if (StringUtils.isNotEmpty(fileName)) {
            pro_file = new File(fileName);
            if (pro_file.exists()) {
                lexPro.load(new FileReader(pro_file));
                jcseg_properties = true;
            }
        }

        // File pro_file = stream2file(this.getClass().getResourceAsStream("/data/" + LEX_PROPERTY_FILE));
        // File pro_file = new File(this.getClass().getProtectionDomain().getCodeSource().getLocation().getFile());
        // InputStream in = getClass().getResourceAsStream("/data/" + LEX_PROPERTY_FILE);

        if (!jcseg_properties) {
            lexPro.load(this.getClass().getResourceAsStream("/data/" + LEX_PROPERTY_FILE));
            if (!lexPro.isEmpty()) {
                jcseg_properties = true;
                jarPath = this.getClass().getProtectionDomain().getCodeSource().getLocation().getFile();
                logger.info("resetFromPropertyFile jarPath :" + jarPath);
                // URL jarUrl = new URL(jarPath);
                // JarURLConnection jarCon = (JarURLConnection) jarUrl.openConnection();
                // jarCon.getJarFile();
                jarPath = StringUtils.remove(jarPath, ".jar");
                File workDir = new File(jarPath);
                // File.createTempFile("", "", new File(StringUtils.remove(jarPath, ".jar")));
                workDir.delete();
                workDir.mkdirs();
                if (!workDir.isDirectory()) {
                    logger.info("Mkdirs failed to create " + workDir);
                    throw new IOException("Mkdirs failed to create " + workDir);
                }
                logger.info("resetFromPropertyFile workDir :" + workDir.getPath());
                unJar(new JarFile(jarPath + ".jar"), workDir);
            }
        }
        if (!jcseg_properties) {
            pro_file = new File(JAR_HOME + "/" + LEX_PROPERTY_FILE);
            if (pro_file.exists()) {
                lexPro.load(new FileReader(pro_file));
                jcseg_properties = true;
            }
        }
        if (!jcseg_properties) {
            InputStream is = JcsegDictionaryFactory.class.getResourceAsStream("/" + LEX_PROPERTY_FILE);
            if (is != null) {
                lexPro.load(new BufferedInputStream(is));
                jcseg_properties = true;
            }
        }
        if (!jcseg_properties) {
            pro_file = new File(System.getProperty("user.home") + "/" + LEX_PROPERTY_FILE);
            if (pro_file.exists()) {
                lexPro.load(new FileReader(pro_file));
                jcseg_properties = true;
            }
        }

        /*
         * jcseg properties file loading status report, show the crorrent properties file location information . <br
         * />
         * @date 2014-09-06
         */
        if (!jcseg_properties) {
            String _report = "jcseg properties[jcseg.properties] file loading error: \n";
            _report += "try the follwing ways to solve the problem: \n";
            _report += "1. put jcseg.properties into the classpath.\n";
            _report += "2. put jcseg.properties together with the jcseg-core-{version}.jar file.\n";
            _report += "3. put jcseg.properties in directory " + System.getProperty("user.home") + "\n\n";
            throw new IOException(_report);
        }
    }
    /* load the mapping from the specified property file. */
    else {
        File pro_file = new File(proFile);
        if (!pro_file.exists())
            throw new IOException("property file [" + proFile + "] not found!");
        lexPro.load(new FileReader(pro_file));
    }

    /* about the lexicon */
    // the lexicon path
    logger.info("jcseg.properties :" + lexPro.values());
    lexPath = (StringUtils.isNotEmpty(jarPath) ? jarPath : StringUtils.EMPTY)
            + lexPro.getProperty("lexicon.path");
    logger.info("################ jarPath : " + jarPath);
    logger.info("################ jcseg.properties lexicon.path : " + lexPro.getProperty("lexicon.path"));
    logger.info("################ lexPath : " + lexPath);
    // lexPath = this.getClass().getResource(lexPath).getFile();
    if (lexPath == null) {
        throw new IOException("lexicon.path property not find in jcseg.properties file!!!");
    }
    if (lexPath.indexOf("{jar.dir}") > -1)
        lexPath = lexPath.replace("{jar.dir}", JAR_HOME);
    // System.out.println("path: "+lexPath);

    // the lexicon file prefix and suffix
    if (lexPro.getProperty("lexicon.suffix") != null)
        suffix = lexPro.getProperty("lexicon.suffix");
    if (lexPro.getProperty("lexicon.prefix") != null)
        prefix = lexPro.getProperty("lexicon.prefix");

    // reset all the options
    if (lexPro.getProperty("jcseg.maxlen") != null)
        MAX_LENGTH = Integer.parseInt(lexPro.getProperty("jcseg.maxlen"));
    if (lexPro.getProperty("jcseg.mixcnlen") != null)
        MIX_CN_LENGTH = Integer.parseInt(lexPro.getProperty("jcseg.mixcnlen"));
    if (lexPro.getProperty("jcseg.icnname") != null && lexPro.getProperty("jcseg.icnname").equals("1"))
        I_CN_NAME = true;
    if (lexPro.getProperty("jcseg.cnmaxlnadron") != null)
        MAX_CN_LNADRON = Integer.parseInt(lexPro.getProperty("jcseg.cnmaxlnadron"));
    if (lexPro.getProperty("jcseg.nsthreshold") != null)
        NAME_SINGLE_THRESHOLD = Integer.parseInt(lexPro.getProperty("jcseg.nsthreshold"));
    if (lexPro.getProperty("jcseg.pptmaxlen") != null)
        PPT_MAX_LENGTH = Integer.parseInt(lexPro.getProperty("jcseg.pptmaxlen"));
    if (lexPro.getProperty("jcseg.loadpinyin") != null && lexPro.getProperty("jcseg.loadpinyin").equals("1"))
        LOAD_CJK_PINYIN = true;
    if (lexPro.getProperty("jcseg.loadsyn") != null && lexPro.getProperty("jcseg.loadsyn").equals("1"))
        LOAD_CJK_SYN = true;
    if (lexPro.getProperty("jcseg.loadpos") != null && lexPro.getProperty("jcseg.loadpos").equals("1"))
        LOAD_CJK_POS = true;
    if (lexPro.getProperty("jcseg.clearstopword") != null
            && lexPro.getProperty("jcseg.clearstopword").equals("1"))
        CLEAR_STOPWORD = true;
    if (lexPro.getProperty("jcseg.cnnumtoarabic") != null
            && lexPro.getProperty("jcseg.cnnumtoarabic").equals("0"))
        CNNUM_TO_ARABIC = false;
    if (lexPro.getProperty("jcseg.cnfratoarabic") != null
            && lexPro.getProperty("jcseg.cnfratoarabic").equals("0"))
        CNFRA_TO_ARABIC = false;
    if (lexPro.getProperty("jcseg.keepunregword") != null
            && lexPro.getProperty("jcseg.keepunregword").equals("1"))
        KEEP_UNREG_WORDS = true;
    if (lexPro.getProperty("lexicon.autoload") != null && lexPro.getProperty("lexicon.autoload").equals("1"))
        lexAutoload = true;
    if (lexPro.getProperty("lexicon.polltime") != null)
        polltime = Integer.parseInt(lexPro.getProperty("lexicon.polltime"));
    if (lexPro.getProperty("wiselyUnionWord") != null && lexPro.getProperty("wiselyUnionWord").equals("1"))
        wiselyUnionWord = true;

    // secondary split
    if (lexPro.getProperty("jcseg.ensencondseg") != null
            && lexPro.getProperty("jcseg.ensencondseg").equals("0"))
        EN_SECOND_SEG = false;
    if (lexPro.getProperty("jcseg.stokenminlen") != null)
        STOKEN_MIN_LEN = Integer.parseInt(lexPro.getProperty("jcseg.stokenminlen"));

    // load the keep punctuations.
    if (lexPro.getProperty("jcseg.keeppunctuations") != null)
        KEEP_PUNCTUATIONS = lexPro.getProperty("jcseg.keeppunctuations");
}

From source file:org.apache.falcon.extensions.Extension.java

private static void validateProperties(final Properties extensionProperties) throws FalconException {
    for (ExtensionProperties option : ExtensionProperties.values()) {
        if (extensionProperties.getProperty(option.getName()) == null && option.isRequired()) {
            throw new FalconException("Missing extension property: " + option.getName());
        }/*ww  w.ja  v a2s .  c om*/
    }
}

From source file:org.apache.lucene.benchmark.byTask.feeds.LineDocSourceTest.java

private void writeDocsToFile(BufferedWriter writer, boolean addHeader, Properties otherFields)
        throws IOException {
    if (addHeader) {
        writer.write(WriteLineDocTask.FIELDS_HEADER_INDICATOR);
        writer.write(WriteLineDocTask.SEP);
        writer.write(DocMaker.TITLE_FIELD);
        writer.write(WriteLineDocTask.SEP);
        writer.write(DocMaker.DATE_FIELD);
        writer.write(WriteLineDocTask.SEP);
        writer.write(DocMaker.BODY_FIELD);
        if (otherFields != null) {
            // additional field names in the header 
            for (Object fn : otherFields.keySet()) {
                writer.write(WriteLineDocTask.SEP);
                writer.write(fn.toString());
            }//from   ww w  . j a  va  2 s .com
        }
        writer.newLine();
    }
    StringBuilder doc = new StringBuilder();
    doc.append("title").append(WriteLineDocTask.SEP).append("date").append(WriteLineDocTask.SEP)
            .append(DocMaker.BODY_FIELD);
    if (otherFields != null) {
        // additional field values in the doc line 
        for (Object fv : otherFields.values()) {
            doc.append(WriteLineDocTask.SEP).append(fv.toString());
        }
    }
    writer.write(doc.toString());
    writer.newLine();
}

From source file:org.intermine.webservice.server.WebService.java

private void setHeaders() {
    Properties headerProps = PropertiesUtil.getPropertiesStartingWith(WS_HEADERS_PREFIX, webProperties);
    for (Object o : headerProps.values()) {
        String h = o.toString();/*  w w w  . j  a v a  2  s. c o  m*/
        String[] parts = StringUtils.split(h, ":", 2);
        if (parts.length != 2) {
            LOG.warn("Ignoring invalid response header: " + h);
        } else {
            response.setHeader(parts[0].trim(), parts[1].trim());
        }
    }
}

From source file:org.opennms.features.newts.converter.NewtsConverter.java

private void processStoreByGroupResource(final Path path) {
    // Load the 'ds.properties' for the current path
    final Properties ds = new Properties();
    try (final BufferedReader r = Files.newBufferedReader(path.resolve("ds.properties"))) {
        ds.load(r);//w  w w. j av a  2s .c o  m

    } catch (final IOException e) {
        LOG.error("No group information found - please verify storageStrategy settings");
        return;
    }

    // Get all groups declared in the ds.properties and process the RRD files
    Sets.newHashSet(Iterables.transform(ds.values(), Object::toString))
            .forEach(group -> this.executor.execute(() -> processResource(path, group, group)));
}