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:org.sakaiproject.portal.render.portlet.services.state.EnhancedPortletStateEncoder.java

public PortletState decode(String uri) {
    byte[] bits = urlSafeEncoder.decode(uri);
    ByteArrayInputStream in = new ByteArrayInputStream(bits);

    Properties p = new Properties();
    try {/*from  w  w w .  j ava  2 s.  co m*/
        p.load(in);
    } catch (IOException e) {
        throw new IllegalStateException("This should never occor");
    }

    String id = p.getProperty(ID_PARAM);
    PortletState state = new PortletState(id);
    state.setAction(Boolean.valueOf(p.getProperty(ACTION_PARAM)).booleanValue());
    state.setSecure(Boolean.valueOf(p.getProperty(SECURE_PARAM)).booleanValue());
    state.setWindowState(new WindowState(p.getProperty(WINDOW_STATE_PARAM)));
    state.setPortletMode(new PortletMode(p.getProperty(PORTLET_MODE_PARAM)));

    p.remove(ID_PARAM);
    p.remove(ACTION_PARAM);
    p.remove(SECURE_PARAM);
    p.remove(WINDOW_STATE_PARAM);
    p.remove(PORTLET_MODE_PARAM);

    Map map = new HashMap();
    Iterator i = p.entrySet().iterator();
    while (i.hasNext()) {
        Map.Entry parm = (Map.Entry) i.next();
        String key = parm.getKey().toString();
        String val = parm.getValue().toString();

        StringTokenizer st = new StringTokenizer(val, ",");
        String[] parms = new String[st.countTokens()];
        int j = 0;
        while (st.hasMoreTokens()) {
            parms[j++] = st.nextToken();
        }
        map.put(key, parms);
    }

    state.setParameters(map);

    if (LOG.isDebugEnabled()) {
        LOG.debug("Decoded PortletState for Tool '" + state.getId() + "'");
    }

    return state;
}

From source file:org.cryptable.zap.mavenplugin.ProcessMojo.java

/**
 * /*w w w. j a v a2s .  c o m*/
 * This method overwrites the super class implementation.
 * @throws IOException Throws exception when file access to property file failes
 */
private void restoreProperties() throws IOException {
    Properties properties = new Properties();
    FileInputStream fi = new FileInputStream(propertyFile);
    properties.load(fi);
    fi.close();
    if ((properties.getProperty("zapperdepap" + propertyFileProxyHost) == null)
            || properties.getProperty("zapperdepap" + propertyFileProxyHost).isEmpty()) {
        getLog().info("Delete Propery [" + propertyFileProxyHost + "]");
        properties.remove(propertyFileProxyHost);
        getLog().info("Delete Propery [" + propertyFileProxyPort + "]");
        properties.remove(propertyFileProxyPort);
    } else {
        getLog().info("Restore Propery [" + propertyFileProxyHost + "] with value ["
                + properties.getProperty(propertyFileProxyHost) + "] to ["
                + properties.getProperty("zapperdepap" + propertyFileProxyHost) + "]");
        properties.setProperty(propertyFileProxyHost,
                properties.getProperty("zapperdepap" + propertyFileProxyHost));
        properties.remove("zapperdepap" + propertyFileProxyHost);
        getLog().info("Restore Propery [" + propertyFileProxyPort + "] with value ["
                + properties.getProperty(propertyFileProxyPort) + "] to ["
                + properties.getProperty("zapperdepap" + propertyFileProxyPort) + "]");
        properties.setProperty(propertyFileProxyPort,
                properties.getProperty("zapperdepap" + propertyFileProxyPort));
        properties.remove("zapperdepap" + propertyFileProxyPort);
    }

    FileOutputStream fo = new FileOutputStream(propertyFile);
    properties.store(fo, null);
    fo.close();
}

From source file:org.vmguys.reflect.BeanSearchUtil.java

/** Processes entire properties list, evokes setter values on the bean, and optionally removes
 * <code>Properties</code> keys  that are found.
 * @param properties object to analyze.// w w w . j av  a2 s. c  om
 * @param prefix optional prefix value; the method name will be assumed data passed the prefix and
 * separator.  For example, "com.stuff.x.RunWork". If "com.stuff.x." is the prefix, "RunWork" will
 * be called.  All properties that do not start with the prefix will be ignored.
 * @param obj bean to call setters.
 * @param removeFoundKeys if <code>true</code>, keys that are found will be removed from the
 * <code>Properties</code> instance.
 * @throws IllegalArgumentException if error occurs calling set method.
 */
public void processProperties(Properties p, Object obj, boolean removeFoundKeys, String prefix) {
    StringBuffer notFound = new StringBuffer();
    Enumeration e = p.propertyNames();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        if (prefix != null) {
            if (key.startsWith(prefix)) {
                key = key.substring(prefix.length());
            } else { // Ignore
                key = null;
            }
        }
        if (key != null) {
            if (evokeWriteMethod(obj, key, p.getProperty(key)) && removeFoundKeys) {
                p.remove(key);
            }
        }
    }
}

From source file:com.evolveum.midpoint.tools.gui.PropertiesGenerator.java

private PropertiesStatistics mergeProperties(Properties baseProperties, Properties targetProperties) {
    PropertiesStatistics stats = new PropertiesStatistics();

    Set<Object> keySet = baseProperties.keySet();
    for (Object key : keySet) {
        if (targetProperties.containsKey(key)) {
            continue;
        }// w  w  w .j a va 2s.c  om

        targetProperties.setProperty((String) key, (String) baseProperties.get(key));
        stats.incrementAdded();
    }

    keySet = new HashSet<Object>();
    keySet.addAll(targetProperties.keySet());
    for (Object key : keySet) {
        if (baseProperties.containsKey(key)) {
            continue;
        }

        targetProperties.remove(key);
        stats.incrementDeleted();
    }

    return stats;
}

From source file:org.intermine.sql.Database.java

private void renameProperty(Properties props, String origName, String newName) {
    if (props.containsKey(origName)) {
        props.put(newName, props.get(origName));
        props.remove(origName);
    }/*from w ww  .ja v a2  s. co  m*/
}

From source file:at.spardat.xma.boot.BootRuntime.java

/**
 * Format des Registy-Eintrags ProxyServer:
 * wenn fr alle Protokolle der selbe proxy:
 * <host>[:port>] port ist optional z.b.: proxy-sd.s-mxs.net:8080
 *
 * sonst://from  w w w.ja va  2s  . c  o m
 * <protocol>=<host>[:<port>][;<protocoll>=<host>[:<port>][;...]]
 * z.b.: ftp=proxy-sd.s-mxs.net:8080;gopher=proxy-sd.s-mxs.net:8080;http=proxy-sd.s-mxs.net:8080;https=proxy-sd.s-mxs.net:8080
 * wenn nur http proxy ausgefllt ist und nicht fr alle Protokolle der selbe proxy: http=proxy-sd.s-mxs.net:8080
 */
private void getWindowsProxySettings(Properties props, Logger l) {
    String strkey = "HKEY_CURRENT_USER";
    String strSub = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
    String strProxyEnable = "ProxyEnable";
    String strProxyServer = "ProxyServer";
    String strProxyOverride = "ProxyOverride";
    String strProxyScript = "AutoConfigURL";

    props.remove(Statics.CFG_PROP_PROXYENABLE);
    props.remove(Statics.CFG_PROP_PROXYSERVER);
    props.remove(Statics.CFG_PROP_PROXYPORT);
    props.remove(Statics.CFG_PROP_SECUREPROXYSERVER);
    props.remove(Statics.CFG_PROP_SECUREPROXYPORT);
    props.remove(Statics.CFG_PROP_PROXYOVERRIDE);
    try {
        Natives natives = new Natives();
        String strProxyEnableValue = natives.getRegistryKey(strkey, strSub, strProxyEnable);
        if (strProxyEnableValue != null) {
            // String der Lnge 1 mit binrer 1 fr true
            // String der Lnge 0 fr false
            if (strProxyEnableValue.length() == 1) {
                int value = strProxyEnableValue.charAt(0);
                props.put(Statics.CFG_PROP_PROXYENABLE, Boolean.toString(value != 0));
            } else {
                props.put(Statics.CFG_PROP_PROXYENABLE, Boolean.toString(false));
            }
        }

        String strProxyValue = natives.getRegistryKey(strkey, strSub, strProxyServer);
        if (strProxyValue != null && strProxyValue.trim().length() > 0) {
            int pos = strProxyValue.indexOf("=");
            if (pos < 0) { // one entry for all protocols
                StringTokenizer tok = new StringTokenizer(strProxyValue, ":");
                String valProxy = tok.nextToken();
                props.put(Statics.CFG_PROP_PROXYSERVER, valProxy);
                props.put(Statics.CFG_PROP_SECUREPROXYSERVER, valProxy);
                if (tok.hasMoreTokens()) {
                    String valPort = tok.nextToken();
                    props.put(Statics.CFG_PROP_PROXYPORT, valPort);
                    props.put(Statics.CFG_PROP_SECUREPROXYPORT, valPort);
                } else { // default port is 80 for http and https proxies
                    props.put(Statics.CFG_PROP_PROXYPORT, "80");
                    props.put(Statics.CFG_PROP_SECUREPROXYPORT, "80");
                }
            } else { // different entrys per protocol
                for (StringTokenizer ptok = new StringTokenizer(strProxyValue, ";"); ptok.hasMoreTokens();) {
                    String strProtocolProxyValue = ptok.nextToken();
                    StringTokenizer tok = new StringTokenizer(strProtocolProxyValue, "=:");
                    String valProtocol = tok.nextToken();
                    if ("http".equals(valProtocol)) {
                        String valProxy = tok.nextToken();
                        props.put(Statics.CFG_PROP_PROXYSERVER, valProxy);
                        if (tok.hasMoreTokens()) {
                            String valPort = tok.nextToken();
                            props.put(Statics.CFG_PROP_PROXYPORT, valPort);
                        } else { // default port is 80 for http proxy
                            props.put(Statics.CFG_PROP_PROXYPORT, "80");
                        }
                    } else if ("https".equals(valProtocol)) {
                        String valProxy = tok.nextToken();
                        props.put(Statics.CFG_PROP_SECUREPROXYSERVER, valProxy);
                        if (tok.hasMoreTokens()) {
                            String valPort = tok.nextToken();
                            props.put(Statics.CFG_PROP_SECUREPROXYPORT, valPort);
                        } else { // default port is 80 for https proxy
                            props.put(Statics.CFG_PROP_SECUREPROXYPORT, "80");
                        }
                    }
                }
            }
        }
        String strProxyOverrideValue = natives.getRegistryKey(strkey, strSub, strProxyOverride);
        if (strProxyOverrideValue != null) {
            props.put(Statics.CFG_PROP_PROXYOVERRIDE, strProxyOverrideValue);
        }
        String strProxyScriptValue = natives.getRegistryKey(strkey, strSub, strProxyScript);
        if (strProxyScriptValue != null && strProxyScriptValue.length() > 0) {
            l.log(LogLevel.WARNING, "automatic proxy script '" + strProxyScriptValue + "' not supported");
        }
    } catch (Exception e) {
        l.log(LogLevel.WARNING, "error loading proxy values: ", e);
    } catch (UnsatisfiedLinkError err) {
        l.log(LogLevel.WARNING, "error loading proxy values: ", err);
    }
}

From source file:com.googlecode.fascinator.HarvestClient.java

public void reharvest(String oid, DigitalObject configObj, boolean userPriority)
        throws IOException, PluginException, MessagingException {
    log.info("Reharvest '{}'...", oid);

    // get the object from storage
    DigitalObject object = storage.getObject(oid);

    // Get/set properties
    Properties props = object.getMetadata();
    props.setProperty("render-pending", "true");
    String configOid = props.getProperty("jsonConfigOid");
    if (userPriority) {
        props.setProperty("userPriority", "true");
    } else {//from   w w  w .  ja  v  a  2  s.co m
        props.remove("userPriority");
    }
    object.close();

    // get its harvest config

    log.info("Using config from '{}'", configOid);

    Payload payload = configObj.getPayload(configObj.getSourceId());
    configFile = File.createTempFile("reharvest", ".json");
    OutputStream out = new FileOutputStream(configFile);
    IOUtils.copy(payload.open(), out);
    out.close();
    payload.close();
    configObj.close();

    // queue for rendering
    queueHarvest(oid, configFile, true, toolChainEntry);
    log.info("Object '{}' now queued for reindexing...", oid);

    // cleanup
    configFile.delete();

}

From source file:org.limewire.setting.SettingsFactory.java

/**
 * Save setting information to property file
 * We want to NOT save any properties which are the default value,
 * as well as any older properties that are no longer in use.
 * To avoid having to manually encode the file, we clone
 * the existing properties and manually remove the ones
 * which are default and aren't required to be saved.
 * It is important to do it this way (as opposed to creating a new
 * properties object and adding only those that should be saved
 * or aren't default) because 'adding' properties may fail if
 * certain settings classes haven't been statically loaded yet.
 * (Note that we cannot use 'store' since it's only available in 1.2)
 *///from   w w w . ja  v a 2 s.  co m
public synchronized void save() {
    Properties toSave = (Properties) PROPS.clone();

    //Add any settings which require saving or aren't default
    for (Setting set : settings) {
        if (!set.shouldAlwaysSave() && set.isDefault())
            toSave.remove(set.getKey());
    }

    OutputStream out = null;
    try {
        // some bugs were reported where the settings file was a directory.
        if (SETTINGS_FILE.isDirectory())
            SETTINGS_FILE.delete();

        // some bugs were reported where the settings file's parent
        // directory was deleted.
        File parent = SETTINGS_FILE.getParentFile();
        if (parent != null) {
            parent.mkdirs();
        }

        FileUtils.setWriteable(SETTINGS_FILE);

        if (SETTINGS_FILE.exists() && !SETTINGS_FILE.canRead()) {
            SETTINGS_FILE.delete();
        }

        try {
            out = new BufferedOutputStream(new FileOutputStream(SETTINGS_FILE));
        } catch (IOException ioe) {
            // Try again.
            if (SETTINGS_FILE.exists()) {
                SETTINGS_FILE.delete();
                out = new BufferedOutputStream(new FileOutputStream(SETTINGS_FILE));
            }
        }

        if (out != null) {
            // save the properties to disk.
            toSave.store(out, HEADING);
        } else {
            markFailure();
        }

    } catch (IOException e) {
        markFailure();
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:com.googlecode.fascinator.HarvestClient.java

/**
 * Reharvest Digital Object when there's a request to reharvest from the
 * portal. The portal can flag items for priority rendering.
 *
 * @param oid Object Id// w w w  .j  a  v a 2 s .c om
 * @param userPriority Set flag to have high priority render
 * @throws IOException If necessary files not found
 * @throws PluginException If the harvester plugin not found
 * @throws MessagingException If the object could not be queue'd
 */
public void reharvest(String oid, boolean userPriority)
        throws IOException, PluginException, MessagingException {
    log.info("Reharvest '{}'...", oid);

    // get the object from storage
    DigitalObject object = storage.getObject(oid);

    // Get/set properties
    Properties props = object.getMetadata();
    props.setProperty("render-pending", "true");
    String configOid = props.getProperty("jsonConfigOid");
    if (userPriority) {
        props.setProperty("userPriority", "true");
    } else {
        props.remove("userPriority");
    }
    object.close();

    // get its harvest config
    boolean usingTempFile = false;
    JsonSimple jsonSimple = null;

    if (configOid == null) {
        log.warn("No harvest config for '{}', using defaults...");
        configFile = JsonSimpleConfig.getSystemFile();
    } else {
        log.info("Using config from '{}'", configOid);
        DigitalObject configObj = storage.getObject(configOid);
        Payload payload = configObj.getPayload(configObj.getSourceId());
        jsonSimple = new JsonSimple(payload.open());
        usingTempFile = true;
    }

    if (usingTempFile) {
        queueHarvest(oid, jsonSimple, true, toolChainEntry);
    } else {
        // queue for rendering
        queueHarvest(oid, configFile, true, toolChainEntry);
    }
    log.info("Object '{}' now queued for reindexing...", oid);

    // cleanup

}

From source file:org.mule.impl.endpoint.MuleEndpointURI.java

public MuleEndpointURI(String address, String endpointName, String connectorName, String transformers,
        String responseTransformers, int createConnector, Properties properties, URI uri) {
    this.address = address;
    this.endpointName = endpointName;
    this.connectorName = connectorName;
    this.transformers = transformers;
    this.responseTransformers = responseTransformers;
    this.createConnector = createConnector;
    this.params = properties;
    this.uri = uri;
    this.userInfo = uri.getUserInfo();
    if (properties != null) {
        resourceInfo = (String) properties.remove("resourceInfo");
    }//from ww  w. j a  v a 2s.  c o m
}