Example usage for java.util Hashtable remove

List of usage examples for java.util Hashtable remove

Introduction

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

Prototype

public synchronized V remove(Object key) 

Source Link

Document

Removes the key (and its corresponding value) from this hashtable.

Usage

From source file:org.openflexo.view.controller.FlexoInspectorController.java

/**
 * @param parameters/*  www. jav a  2  s  .  c  o  m*/
 */
private static void cleanParameters(Hashtable<String, ParamModel> parameters, ParamModel paramModel) {
    Hashtable<String, ParamModel> clone = new Hashtable<String, ParamModel>(paramModel.parameters);
    Enumeration<String> en = clone.keys();
    while (en.hasMoreElements()) {
        ParamModel p = paramModel.parameters.get(en.nextElement());
        if (p == null) {
            continue;
        }
        if (p.parameters.size() > 0) {
            cleanParameters(paramModel.parameters, p);
        }
        if (parametersContainerIsDisplayable(paramModel, UserType.getCurrentUserType())) {
            // Let's keep it
        } else {
            parameters.remove(paramModel.name);
        }
    }
}

From source file:com.jaspersoft.jasperserver.api.security.externalAuth.ldap.JSLdapContextSource.java

public DirContext getReadWriteContext(String userDn, Object credentials) {
    Hashtable env = new Hashtable(getAnonymousEnv());

    env.put(Context.SECURITY_PRINCIPAL, userDn);
    env.put(Context.SECURITY_CREDENTIALS, credentials);
    env.remove(SUN_LDAP_POOLING_FLAG);

    if (logger.isDebugEnabled()) {
        logger.debug("Creating context with principal: '" + userDn + "'");
    }//  www.j a  v a 2 s  .  c  om

    return createContext(env);
}

From source file:org.jasig.cas.adaptors.ldap.util.AuthenticatedLdapContextSource.java

public DirContext getDirContext(final String principal, final String credentials) {
    final Hashtable<String, String> environment = (Hashtable) getAnonymousEnv().clone();

    environment.put(Context.SECURITY_PRINCIPAL, principal);
    environment.put(Context.SECURITY_CREDENTIALS, credentials);

    environment.remove("com.sun.jndi.ldap.connect.pool"); // remove this since we're modifying principal

    try {/*  www.j a va  2s  .  c  o  m*/
        return getDirContextInstance(environment);
    } catch (final NamingException e) {
        throw new DataAccessResourceFailureException("Unable to create DirContext");
    }
}

From source file:com.apatar.flickr.function.UploadPhotoFlickrTable.java

public List<KeyInsensitiveMap> execute(FlickrNode node, Hashtable<String, Object> values, String strApi,
        String strSecret) throws IOException, XmlRpcException {
    byte[] photo = (byte[]) values.get("photo");

    int size = values.size() + 2;

    values.remove("photo");

    File newFile = ApplicationData.createFile("flicr", photo);

    PostMethod post = new PostMethod("http://api.flickr.com/services/upload");
    Part[] parts = new Part[size];

    parts[0] = new FilePart("photo", newFile);
    parts[1] = new StringPart("api_key", strApi);
    int i = 2;// w  ww.j a  v  a 2  s . c  o  m
    for (String key : values.keySet())
        parts[i++] = new StringPart(key, values.get(key).toString());

    values.put("api_key", strApi);

    parts[i] = new StringPart("api_sig", FlickrUtils.Sign(values, strApi, strSecret));

    post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));

    HttpClient client = new HttpClient();
    client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
    int status = client.executeMethod(post);
    if (status != HttpStatus.SC_OK) {
        JOptionPane.showMessageDialog(ApatarUiMain.MAIN_FRAME,
                "Upload failed, response=" + HttpStatus.getStatusText(status));
        return null;
    } else {
        InputStream is = post.getResponseBodyAsStream();
        try {
            return createKeyInsensitiveMapFromElement(FlickrUtils.getRootElementFromInputStream(is));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return null;
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.vendors.VendorHelper.java

/**
 * Save the request parameters from the Custom Fields page
 *//*from   w  ww  . ja  v a  2  s  . c  o  m*/
public static void saveCustom(Vendor vendor, HttpServletRequest request, SessionManager sessionMgr) {
    FieldSecurity fs = (FieldSecurity) sessionMgr.getAttribute(VendorConstants.FIELD_SECURITY_CHECK_PROJS);
    if (fs != null) {
        String access = fs.get(VendorSecureFields.CUSTOM_FIELDS);
        if ("hidden".equals(access) || "locked".equals(access)) {
            return;
        }
    }
    Hashtable fields = vendor.getCustomFields();
    if (fields == null) {
        fields = new Hashtable();
    }
    ArrayList list = CustomPageHelper.getCustomFieldNames();
    for (int i = 0; i < list.size(); i++) {
        String key = (String) list.get(i);
        String value = (String) request.getParameter(key);
        if (value == null) {
            fields.remove(key);
        } else {
            // if already in the list
            CustomField cf = (CustomField) fields.get(key);
            if (cf != null) {
                cf.setValue(value);
            } else {
                cf = new CustomField(key, value);
            }
            fields.put(key, cf);

        }
    }
    vendor.setCustomFields(fields);
}

From source file:de.kaiserpfalzEdv.commons.jee.jndi.SimpleContextFactory.java

@Override
public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException {
    Hashtable<Object, Object> env = new Hashtable<>(environment.size());

    for (Object key : environment.keySet()) {
        env.put(key, environment.get(key));
    }/*from  ww w .j  a  v a2 s. c  om*/

    String configPath = System.getProperty(CONFIG_FILE_NAME_PROPERTY);
    if (isNotBlank(configPath)) {
        env.remove(org.osjava.sj.SimpleContext.SIMPLE_ROOT);
        env.put(org.osjava.sj.SimpleContext.SIMPLE_ROOT, configPath);
    } else {
        configPath = (String) env.get(org.osjava.sj.SimpleContext.SIMPLE_ROOT);
    }

    LOG.trace("***** Loading configuration from: {}", configPath);

    return new SimpleContext(env);
}

From source file:org.acegisecurity.ldap.DefaultInitialDirContextFactory.java

public DirContext newInitialDirContext(String username, String password) {
    Hashtable env = getEnvironment();

    // Don't pool connections for individual users
    if (!username.equals(managerDn)) {
        env.remove(CONNECTION_POOL_KEY);
    }/* ww w.  ja va2s. co  m*/

    env.put(Context.SECURITY_PRINCIPAL, username);
    env.put(Context.SECURITY_CREDENTIALS, password);

    return connect(env);
}

From source file:com.basistech.yca.FlatteningConfigFileManager.java

private void processAddOrUpdate(Path filename) {
    // create and modify look quite similar.
    Path child = configurationDirectory.resolve(filename);

    // The heck with content type probing, let's do this the simple way.
    int lastDot = filename.toString().lastIndexOf('.');
    if (lastDot == -1) {
        LOG.info("File has no suffix; ignoring: " + child);
        return;/*from   w  ww.  j  a va  2 s . c  o  m*/
    }

    ObjectMapper mapper;
    String suffix = filename.toString().substring(lastDot + 1);
    if ("json".equals(suffix) || "js".equals(suffix)) {
        mapper = new ObjectMapper();
    } else if ("yaml".equals(suffix) || "yml".equals(suffix)) {
        mapper = new ObjectMapper(new YAMLFactory());
    } else {
        LOG.error("Unsupported file name " + filename.toString());
        return;
    }

    JsonNode content;
    try {
        content = mapper.readTree(child.toFile());
    } catch (IOException e) {
        LOG.error("Failed to read contents of " + child, e);
        return;
    }

    @SuppressWarnings("unchecked")
    Dictionary<String, Object> dict = (Dictionary<String, Object>) JsonNodeFlattener.flatten(content);

    String pid[] = parsePid(filename);
    Configuration config;
    try {
        config = getConfiguration(toConfigKey(filename), pid[0], pid[1]);
    } catch (IOException e) {
        LOG.error("Failed to get configuration for " + formatPid(pid));
        return;
    }

    Dictionary<String, Object> props = config.getProperties();
    Hashtable<String, Object> old = null;
    if (props != null) {
        old = new Hashtable<>(new DictionaryAsMap<>(props));
    }
    if (old != null) {
        old.remove(FILENAME_PROPERTY_KEY);
        old.remove(Constants.SERVICE_PID);
        old.remove(ConfigurationAdmin.SERVICE_FACTORYPID);
    }

    if (!dict.equals(old)) {
        dict.put(FILENAME_PROPERTY_KEY, toConfigKey(filename));
        if (old == null) {
            LOG.info("Creating configuration from " + filename);
        } else {
            LOG.info("Updating configuration from " + filename);
        }
        try {
            config.update(dict);
        } catch (IOException e) {
            LOG.error("Failed to update configuration for " + formatPid(pid));
        }
    }
}

From source file:org.springframework.security.ldap.DefaultSpringSecurityContextSource.java

/**
 * Create and initialize an instance which will connect to the supplied LDAP URL. If
 * you want to use more than one server for fail-over, rather use the
 * {@link #DefaultSpringSecurityContextSource(List, String)} constructor.
 *
 * @param providerUrl an LDAP URL of the form
 * <code>ldap://localhost:389/base_dn</code>
 *//*w  w  w  .j av a2s  .c  om*/
public DefaultSpringSecurityContextSource(String providerUrl) {
    Assert.hasLength(providerUrl, "An LDAP connection URL must be supplied.");

    StringTokenizer st = new StringTokenizer(providerUrl);

    ArrayList<String> urls = new ArrayList<>();

    // Work out rootDn from the first URL and check that the other URLs (if any) match
    while (st.hasMoreTokens()) {
        String url = st.nextToken();
        String urlRootDn = LdapUtils.parseRootDnFromUrl(url);

        urls.add(url.substring(0, url.lastIndexOf(urlRootDn)));

        this.logger.info(" URL '" + url + "', root DN is '" + urlRootDn + "'");

        if (this.rootDn == null) {
            this.rootDn = urlRootDn;
        } else if (!this.rootDn.equals(urlRootDn)) {
            throw new IllegalArgumentException("Root DNs must be the same when using multiple URLs");
        }
    }

    setUrls(urls.toArray(new String[urls.size()]));
    setBase(this.rootDn);
    setPooled(true);
    setAuthenticationStrategy(new SimpleDirContextAuthenticationStrategy() {
        @Override
        @SuppressWarnings("rawtypes")
        public void setupEnvironment(Hashtable env, String dn, String password) {
            super.setupEnvironment(env, dn, password);
            // Remove the pooling flag unless we are authenticating as the 'manager'
            // user.
            if (!DefaultSpringSecurityContextSource.this.userDn.equals(dn)
                    && env.containsKey(SUN_LDAP_POOLING_FLAG)) {
                DefaultSpringSecurityContextSource.this.logger.debug("Removing pooling flag for user " + dn);
                env.remove(SUN_LDAP_POOLING_FLAG);
            }
        }
    });
}

From source file:org.ops4j.pax.web.service.internal.Activator.java

private void setProperty(final Hashtable<String, Object> properties, final String name, final Object value) {
    if (value != null) {
        if (value instanceof File) {
            properties.put(name, ((File) value).getAbsolutePath());
        } else if (value instanceof Object[]) {
            properties.put(name, join(",", (Object[]) value));
        } else {/*from   w  ww.  ja v  a 2  s . com*/
            properties.put(name, value.toString());
        }
    } else {
        properties.remove(name);
    }
}