Example usage for java.util Properties remove

List of usage examples for java.util Properties remove

Introduction

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

Prototype

@Override
    public synchronized Object remove(Object key) 

Source Link

Usage

From source file:com.tesora.dve.standalone.PETest.java

public static DBHelper buildHelper() throws Exception {
    Properties catalogProps = TestCatalogHelper.getTestCatalogProps(resourceRoot);
    Properties tempProps = (Properties) catalogProps.clone();
    tempProps.remove(DBHelper.CONN_DBNAME);
    DBHelper dbHelper = new DBHelper(tempProps);
    dbHelper.connect();//from w ww .j a v a2s .  c o m
    return dbHelper;
}

From source file:com.tesora.dve.standalone.PETest.java

public static void cleanupDatabase(int numSites, String dbName) throws Exception {
    Properties catalogProps = TestCatalogHelper.getTestCatalogProps(PETest.class);
    Properties tempProps = (Properties) catalogProps.clone();
    tempProps.remove(DBHelper.CONN_DBNAME);
    DBHelper myHelper = new DBHelper(tempProps).connect();
    try {/*from  w  w  w . j  ava2 s  . c om*/
        for (int i = 1; i <= numSites; i++) {
            myHelper.executeQuery("DROP DATABASE IF EXISTS site" + i + "_" + dbName);
        }
    } finally {
        myHelper.disconnect();
    }
}

From source file:org.wisdom.maven.osgi.BundlePackager.java

/**
 * This method is used by plugin willing to add custom header to the bundle manifest.
 *
 * @param baseDir the project directory//from w  ww.j  a va2s. c o  m
 * @param header  the header to add
 * @param value   the value to write
 * @throws IOException if the header cannot be added
 */
public static void addExtraHeaderToBundleManifest(File baseDir, String header, String value)
        throws IOException {
    Properties props = new Properties();
    File extra = new File(baseDir, EXTRA_HEADERS_FILE);
    extra.getParentFile().mkdirs();
    // If the file exist it loads it, if not nothing happens.
    props = Instructions.merge(props, extra);
    if (value != null) {
        props.setProperty(header, value);
    } else {
        props.remove(header);
    }
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(extra);
        props.store(fos, "");
    } finally {
        IOUtils.closeQuietly(fos);
    }
}

From source file:edu.ku.brc.af.core.UsageTracker.java

/**
 * Transfers and removes any old statistics from the user prefs to the new location.
 * @param newProps the new statistics//  w  w  w  .  j av a 2 s  .  c om
 */
private static void transferOldStats(final Properties newProps) {
    Properties lpProps = AppPreferences.getLocalPrefs().getProperties(); // not a copy
    for (Object keyObj : new Vector<Object>(lpProps.keySet())) {
        String pName = keyObj.toString();
        if (pName.startsWith(USAGE_PREFIX)) {
            newProps.put(pName.substring(6), lpProps.get(keyObj));
            lpProps.remove(keyObj);
        }
    }
    save();
}

From source file:com.aurel.track.util.emailHandling.MailReader.java

private static void updateSecurityProps(String protocol, String server, int securityConnection,
        Properties props) {
    props.remove("mail.pop3.socketFactory.class");
    props.remove("mail.imap.socketFactory.class");
    String oldTrustStore = (String) props.remove("javax.net.ssl.trustStore");
    switch (securityConnection) {
    case TSiteBean.SECURITY_CONNECTIONS_MODES.TLS_IF_AVAILABLE:
        if ("pop3".equalsIgnoreCase(protocol)) {
            props.put("mail.pop3.starttls.enable", "true");
            props.put("mail.pop3.ssl.protocols", "SSLv3 TLSv1");
        }// www  .  j av  a 2 s.  c  o m
        if ("imap".equalsIgnoreCase(protocol)) {
            props.put("mail.imap.starttls.enable", "true");
            props.put("mail.imap.ssl.protocols", "SSLv3 TLSv1");
        }
        break;
    case TSiteBean.SECURITY_CONNECTIONS_MODES.TLS:
        if ("pop3".equalsIgnoreCase(protocol)) {
            props.put("mail.pop3.starttls.enable", "true");
            props.put("mail.pop3.starttls.required", "true");
            props.put("mail.pop3.ssl.protocols", "SSLv3 TLSv1");
        }
        if ("imap".equalsIgnoreCase(protocol)) {
            props.put("mail.imap.starttls.enable", "true");
            props.put("mail.imap.starttls.required", "true");
            props.put("mail.imap.ssl.protocols", "SSLv3 TLSv1");
        }
        MailBL.setTrustKeyStore(server);
        break;
    case TSiteBean.SECURITY_CONNECTIONS_MODES.SSL: {
        LOGGER.debug("Update security   to SSL...");
        LOGGER.debug("oldTrustStore=" + oldTrustStore);
        final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
        MailBL.setTrustKeyStore(server);
        if ("pop3".equalsIgnoreCase(protocol)) {
            LOGGER.debug("Use SSL pop3 protocol");
            props.setProperty("mail.pop3.socketFactory.class", SSL_FACTORY);
        }
        if ("imap".equalsIgnoreCase(protocol)) {
            LOGGER.debug("Use SSL imap protocol");
            props.setProperty("mail.imap.socketFactory.class", SSL_FACTORY);
        }
        break;
    }
    default:
        break;
    }
}

From source file:org.omegat.core.team2.TeamSettings.java

/**
 * Update setting.//from  w w w.  j a v a 2 s  .com
 */
public static synchronized void set(String key, String newValue) {
    try {
        Properties p = new Properties();
        File f = getConfigFile();
        File fNew = new File(getConfigFile().getAbsolutePath() + ".new");
        if (f.exists()) {
            FileInputStream in = new FileInputStream(f);
            try {
                p.load(in);
            } finally {
                in.close();
            }
        } else {
            f.getParentFile().mkdirs();
        }
        if (newValue != null) {
            p.setProperty(key, newValue);
        } else {
            p.remove(key);
        }
        FileOutputStream out = new FileOutputStream(fNew);
        try {
            p.store(out, null);
        } finally {
            out.close();
        }
        f.delete();
        FileUtils.moveFile(fNew, f);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:org.wisdom.maven.utils.BundlePackager.java

/**
 * This method is used by plugin willing to add custom header to the bundle manifest.
 *
 * @param baseDir the project directory// www. j  av a  2s . c  o m
 * @param header  the header to add
 * @param value   the value to write
 * @throws IOException if the header cannot be added
 */
public static void addExtraHeaderToBundleManifest(File baseDir, String header, String value)
        throws IOException {
    Properties props = new Properties();
    File extra = new File(baseDir, EXTRA_HEADERS_FILE);
    extra.getParentFile().mkdirs();
    // If the file exist it loads it, if not nothing happens.
    merge(props, extra);
    if (value != null) {
        props.setProperty(header, value);
    } else {
        props.remove(header);
    }
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(extra);
        props.store(fos, "");
    } finally {
        IOUtils.closeQuietly(fos);
    }
}

From source file:dk.hippogrif.prettyxml.PrettyPrint.java

/**
 * Checks known properties -/* w w  w .j a  va2s . c  o  m*/
 * present boolean properties are set to either "true" or "false",
 * indent=0 is removed,
 * string properties are trimmed and empty properties removed -
 * however, TEXT_MODE is checked when format is initialized
 * and ENCODING when used.
 *
 * @param prop holds the properties
 * @param extended to include in/out properties
 * @throws Exception if property error
 */
public static void checkProperties(Properties prop, boolean extended) throws Exception {
    for (Enumeration elements = prop.propertyNames(); elements.hasMoreElements();) {
        String s = (String) elements.nextElement();
        if (!keys.contains(s)) {
            prop.remove(s);
        }
    }
    checkBoolean(EXPAND_EMPTY_ELEMENTS, prop);
    checkBoolean(OMIT_DECLARATION, prop);
    checkBoolean(OMIT_ENCODING, prop);
    checkBoolean(INDENT_ATTRIBUTES, prop);
    checkBoolean(SORT_ATTRIBUTES, prop);
    if (prop.containsKey(INDENT)) {
        try {
            int i = Integer.parseInt(prop.getProperty(INDENT));
            if (i == 0) {
                prop.remove(INDENT);
            } else if (i < 1 || i > 99) {
                throw new Exception(INDENT + " must be an integer >= 0 and < 100");
            }
        } catch (NumberFormatException e) {
            throw new Exception(INDENT + " must be an integer >= 0 and < 100");
        }
    }
    if (prop.containsKey(LINE_SEPARATOR)) {
        String s = prop.getProperty(LINE_SEPARATOR);
        boolean err = true;
        for (int i = 0; i < LINE_SEPARATORS.length; i++) {
            if (LINE_SEPARATORS[i].equals(s)) {
                err = false;
                break;
            }
        }
        if (err) {
            throw new Exception(LINE_SEPARATOR + " must be \\r, \\n or \\r\\n");
        }
    }
    checkString(TRANSFORM, prop);
    if (extended) {
        checkString(INPUT, prop);
        checkString(URL, prop);
        checkString(OUTPUT, prop);
        if (prop.containsKey(INPUT) && prop.containsKey(URL)) {
            throw new Exception("do not use " + INPUT + " and " + URL + " at the same time");
        }
    } else {
        prop.remove(INPUT);
        prop.remove(URL);
        prop.remove(OUTPUT);
    }
}

From source file:com.jkoolcloud.tnt4j.streams.custom.kafka.interceptors.reporters.trace.MsgTraceReporter.java

protected static void pollConfigQueue(Map<String, ?> config, Properties kafkaProperties,
        Map<String, TraceCommandDeserializer.TopicTraceCommand> traceConfig) {
    Properties props = new Properties();
    if (config != null) {
        props.putAll(config);/*from  w  w w .  j  a  va2 s  .c  om*/
    }
    if (kafkaProperties != null) {
        props.putAll(extractKafkaProperties(kafkaProperties));
    }
    if (!props.isEmpty()) {
        props.put(ConsumerConfig.CLIENT_ID_CONFIG, "kafka-x-ray-message-trace-reporter-config-listener"); // NON-NLS
        props.remove(ConsumerConfig.INTERCEPTOR_CLASSES_CONFIG);
        KafkaConsumer<String, TraceCommandDeserializer.TopicTraceCommand> consumer = getKafkaConsumer(props);
        while (true) {
            ConsumerRecords<String, TraceCommandDeserializer.TopicTraceCommand> records = consumer.poll(100);
            if (records.count() > 0) {
                LOGGER.log(OpLevel.DEBUG, StreamsResources.getBundle(KafkaStreamConstants.RESOURCE_BUNDLE_NAME),
                        "MsgTraceReporter.polled.commands", records.count(), records.iterator().next());
                for (ConsumerRecord<String, TraceCommandDeserializer.TopicTraceCommand> record : records) {
                    if (record.value() != null) {
                        traceConfig.put(record.value().topic, record.value());
                    }
                }
                break;
            }
        }
    }
}

From source file:org.apache.hadoop.hdfs.server.namenode.FSImageTestUtil.java

/**
 * Corrupt the given VERSION file by replacing a given
 * key with a new value and re-writing the file.
 * /*w  ww. ja va 2s. co m*/
 * @param versionFile the VERSION file to corrupt
 * @param key the key to replace
 * @param value the new value for this key
 */
public static void corruptVersionFile(File versionFile, String key, String value) throws IOException {
    Properties props = new Properties();
    FileInputStream fis = new FileInputStream(versionFile);
    FileOutputStream out = null;
    try {
        props.load(fis);
        IOUtils.closeStream(fis);

        if (value == null || value.isEmpty()) {
            props.remove(key);
        } else {
            props.setProperty(key, value);
        }

        out = new FileOutputStream(versionFile);
        props.store(out, null);

    } finally {
        IOUtils.cleanup(null, fis, out);
    }
}