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.apache.juddi.subscription.notify.USERFRIENDLYSMTPNotifier.java

public static void notifyAccountDeleted(TemporaryMailContainer container) {
    try {// w ww  .j a  v a2 s  .  c  om
        Publisher publisher = container.getPublisher();
        Publisher deletedBy = container.getDeletedBy();
        String emailaddress = publisher.getEmailAddress();
        if (emailaddress == null || emailaddress.trim().equals(""))
            return;
        Properties properties = new Properties();
        Session session = null;
        String mailPrefix = AppConfig.getConfiguration().getString(Property.JUDDI_EMAIL_PREFIX,
                Property.DEFAULT_JUDDI_EMAIL_PREFIX);
        if (!mailPrefix.endsWith(".")) {
            mailPrefix = mailPrefix + ".";
        }
        for (String key : mailProps) {
            if (AppConfig.getConfiguration().containsKey(mailPrefix + key)) {
                properties.put(key, AppConfig.getConfiguration().getProperty(mailPrefix + key));
            } else if (System.getProperty(mailPrefix + key) != null) {
                properties.put(key, System.getProperty(mailPrefix + key));
            }
        }

        boolean auth = (properties.getProperty("mail.smtp.auth", "false")).equalsIgnoreCase("true");
        if (auth) {
            final String username = properties.getProperty("mail.smtp.user");
            String pwd = properties.getProperty("mail.smtp.password");
            //decrypt if possible
            if (properties.getProperty("mail.smtp.password" + Property.ENCRYPTED_ATTRIBUTE, "false")
                    .equalsIgnoreCase("true")) {
                try {
                    pwd = CryptorFactory.getCryptor().decrypt(pwd);
                } catch (NoSuchPaddingException ex) {
                    log.error("Unable to decrypt settings", ex);
                } catch (NoSuchAlgorithmException ex) {
                    log.error("Unable to decrypt settings", ex);
                } catch (InvalidAlgorithmParameterException ex) {
                    log.error("Unable to decrypt settings", ex);
                } catch (InvalidKeyException ex) {
                    log.error("Unable to decrypt settings", ex);
                } catch (IllegalBlockSizeException ex) {
                    log.error("Unable to decrypt settings", ex);
                } catch (BadPaddingException ex) {
                    log.error("Unable to decrypt settings", ex);
                }
            }
            final String password = pwd;
            log.debug("SMTP username = " + username + " from address = " + emailaddress);
            Properties eMailProperties = properties;
            eMailProperties.remove("mail.smtp.user");
            eMailProperties.remove("mail.smtp.password");
            session = Session.getInstance(properties, new javax.mail.Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(username, password);
                }
            });
        } else {
            Properties eMailProperties = properties;
            eMailProperties.remove("mail.smtp.user");
            eMailProperties.remove("mail.smtp.password");
            session = Session.getInstance(eMailProperties);
        }

        MimeMessage message = new MimeMessage(session);
        InternetAddress address = new InternetAddress(emailaddress);
        Address[] to = { address };
        message.setRecipients(RecipientType.TO, to);
        message.setFrom(new InternetAddress(properties.getProperty("mail.smtp.from", "jUDDI")));
        //Hello %s,<br><br>Your subscription UDDI subscription was deleted. Attached is what the subscription was. It was deleted by %s, %s at %s. This node is %s

        Multipart mp = new MimeMultipart();

        MimeBodyPart content = new MimeBodyPart();
        String msg_content = ResourceConfig.getGlobalMessage("notifications.smtp.accountDeleted");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd kk:mm:ssZ");
        //Hello %s, %s,<br><br>Your account has been deleted by %s, %s at %s. This node is %s.
        msg_content = String.format(msg_content, StringEscapeUtils.escapeHtml(publisher.getPublisherName()),
                StringEscapeUtils.escapeHtml(publisher.getAuthorizedName()),
                StringEscapeUtils.escapeHtml(deletedBy.getPublisherName()),
                StringEscapeUtils.escapeHtml(deletedBy.getAuthorizedName()),
                StringEscapeUtils.escapeHtml(sdf.format(new Date())),
                StringEscapeUtils.escapeHtml(
                        AppConfig.getConfiguration().getString(Property.JUDDI_NODE_ID, "(unknown node id!)")),
                AppConfig.getConfiguration().getString(Property.JUDDI_BASE_URL, "(unknown url)"),
                AppConfig.getConfiguration().getString(Property.JUDDI_BASE_URL_SECURE, "(unknown url)"));

        content.setContent(msg_content, "text/html; charset=UTF-8;");
        mp.addBodyPart(content);

        message.setContent(mp);
        message.setSubject(ResourceConfig.getGlobalMessage("notifications.smtp.accountDeleted.subject"));
        Transport.send(message);

    } catch (Throwable t) {
        log.warn("Error sending email!" + t.getMessage());
        log.debug("Error sending email!" + t.getMessage(), t);
    }
}

From source file:control.LoadControler.java

public static List<Carte> loadCartes(String filePath) {

    File folder = new File(userPath(filePath));
    Set<File> fileSet = listFilesForFolder(folder);

    List<Carte> list = new ArrayList<>();

    for (File file : fileSet) {

        try {//from   ww  w.j  a  va2s  . com
            PropertiesReader ppr = new PropertiesReader(file.getCanonicalPath());
            Properties properties = ppr.readProperties();

            Carte carte = new Carte();

            try {
                carte.setNom(properties.getProperty("nom"));
                carte.setDx(Integer.parseInt(properties.getProperty("dx")));
                carte.setDy(Integer.parseInt(properties.getProperty("dy")));

                Properties ppts = new Properties();
                ppts.putAll(properties);
                ppts.remove("nom");
                ppts.remove("dx");
                ppts.remove("dy");
                carte.setProperties(ppts);

                System.out.println(carte.toString()); //DEBUG
                list.add(carte);

            } catch (NumberFormatException e) {
                e.printStackTrace();
                System.out.println("##### Erreur lors de la cration de la carte #####");
                JOptionPane.showMessageDialog(null, e);
            }
        } catch (IOException ex) {
            Logger.getLogger(LoadControler.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(null, ex);
        }

    }

    return list;
}

From source file:org.apache.juddi.subscription.notify.USERFRIENDLYSMTPNotifier.java

public static void notifySubscriptionDeleted(TemporaryMailContainer container) {
    try {/*from   w w  w  .  j a  va2 s.  c  om*/
        Publisher publisher = container.getPublisher();
        Publisher deletedBy = container.getDeletedBy();
        Subscription obj = container.getObj();
        String emailaddress = publisher.getEmailAddress();
        if (emailaddress == null || emailaddress.trim().equals(""))
            return;
        Properties properties = new Properties();
        Session session = null;
        String mailPrefix = AppConfig.getConfiguration().getString(Property.JUDDI_EMAIL_PREFIX,
                Property.DEFAULT_JUDDI_EMAIL_PREFIX);
        if (!mailPrefix.endsWith(".")) {
            mailPrefix = mailPrefix + ".";
        }
        for (String key : mailProps) {
            if (AppConfig.getConfiguration().containsKey(mailPrefix + key)) {
                properties.put(key, AppConfig.getConfiguration().getProperty(mailPrefix + key));
            } else if (System.getProperty(mailPrefix + key) != null) {
                properties.put(key, System.getProperty(mailPrefix + key));
            }
        }

        boolean auth = (properties.getProperty("mail.smtp.auth", "false")).equalsIgnoreCase("true");
        if (auth) {
            final String username = properties.getProperty("mail.smtp.user");
            String pwd = properties.getProperty("mail.smtp.password");
            //decrypt if possible
            if (properties.getProperty("mail.smtp.password" + Property.ENCRYPTED_ATTRIBUTE, "false")
                    .equalsIgnoreCase("true")) {
                try {
                    pwd = CryptorFactory.getCryptor().decrypt(pwd);
                } catch (NoSuchPaddingException ex) {
                    log.error("Unable to decrypt settings", ex);
                } catch (NoSuchAlgorithmException ex) {
                    log.error("Unable to decrypt settings", ex);
                } catch (InvalidAlgorithmParameterException ex) {
                    log.error("Unable to decrypt settings", ex);
                } catch (InvalidKeyException ex) {
                    log.error("Unable to decrypt settings", ex);
                } catch (IllegalBlockSizeException ex) {
                    log.error("Unable to decrypt settings", ex);
                } catch (BadPaddingException ex) {
                    log.error("Unable to decrypt settings", ex);
                }
            }
            final String password = pwd;
            log.debug("SMTP username = " + username + " from address = " + emailaddress);
            Properties eMailProperties = properties;
            eMailProperties.remove("mail.smtp.user");
            eMailProperties.remove("mail.smtp.password");
            session = Session.getInstance(properties, new javax.mail.Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(username, password);
                }
            });
        } else {
            Properties eMailProperties = properties;
            eMailProperties.remove("mail.smtp.user");
            eMailProperties.remove("mail.smtp.password");
            session = Session.getInstance(eMailProperties);
        }

        MimeMessage message = new MimeMessage(session);
        InternetAddress address = new InternetAddress(emailaddress);
        Address[] to = { address };
        message.setRecipients(RecipientType.TO, to);
        message.setFrom(new InternetAddress(properties.getProperty("mail.smtp.from", "jUDDI")));
        //Hello %s,<br><br>Your subscription UDDI subscription was deleted. Attached is what the subscription was. It was deleted by %s, %s at %s. This node is %s
        //maybe nice to use a template rather then sending raw xml.
        org.uddi.sub_v3.Subscription api = new org.uddi.sub_v3.Subscription();
        MappingModelToApi.mapSubscription(obj, api);
        String subscriptionResultXML = JAXBMarshaller.marshallToString(api, JAXBMarshaller.PACKAGE_SUBSCR_RES);
        Multipart mp = new MimeMultipart();

        MimeBodyPart content = new MimeBodyPart();
        String msg_content = ResourceConfig.getGlobalMessage("notifications.smtp.subscriptionDeleted");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd kk:mm:ssZ");
        //Hello %s, %s<br><br>Your subscription UDDI subscription was deleted. Attached is what the subscription was. It was deleted by %s, %s at %s. This node is %s.
        msg_content = String.format(msg_content, StringEscapeUtils.escapeHtml(publisher.getPublisherName()),
                StringEscapeUtils.escapeHtml(publisher.getAuthorizedName()),
                StringEscapeUtils.escapeHtml(deletedBy.getPublisherName()),
                StringEscapeUtils.escapeHtml(deletedBy.getAuthorizedName()),
                StringEscapeUtils.escapeHtml(sdf.format(new Date())),
                StringEscapeUtils.escapeHtml(
                        AppConfig.getConfiguration().getString(Property.JUDDI_NODE_ID, "(unknown node id!)")),
                AppConfig.getConfiguration().getString(Property.JUDDI_BASE_URL, "(unknown url)"),
                AppConfig.getConfiguration().getString(Property.JUDDI_BASE_URL_SECURE, "(unknown url)"));

        content.setContent(msg_content, "text/html; charset=UTF-8;");
        mp.addBodyPart(content);

        MimeBodyPart attachment = new MimeBodyPart();
        attachment.setContent(subscriptionResultXML, "text/xml; charset=UTF-8;");
        attachment.setFileName("uddiNotification.xml");
        mp.addBodyPart(attachment);

        message.setContent(mp);
        message.setSubject(ResourceConfig.getGlobalMessage("notifications.smtp.userfriendly.subject") + " "
                + StringEscapeUtils.escapeHtml(obj.getSubscriptionKey()));
        Transport.send(message);

    } catch (Throwable t) {
        log.warn("Error sending email!" + t.getMessage());
        log.debug("Error sending email!" + t.getMessage(), t);
    }
}

From source file:org.eclipse.gyrex.jobs.internal.worker.JobInfo.java

public static JobInfo parse(final IMessage message) throws IOException {
    final Properties properties = new Properties();
    try (InflaterInputStream in = new InflaterInputStream(new ByteArrayInputStream(message.getBody()))) {
        properties.load(in);//  ww  w.j  av a  2s .c om
    }

    // check version (remove key from properties)
    final Object versionValue = properties.remove(VERSION);
    if (!VERSION_VALUE.equals(versionValue))
        throw new IOException(String.format("invalid record data: version mismatch (expected %s, found %s)",
                VERSION_VALUE, String.valueOf(versionValue)));

    // get id (remove key from properties as well)
    final Object jobIdValue = properties.remove(ID);
    if ((null == jobIdValue) || !(jobIdValue instanceof String) || !IdHelper.isValidId(((String) jobIdValue)))
        throw new IOException(
                String.format("invalid record data: missing/invalid job id %s", String.valueOf(jobIdValue)));

    // get type (remove key from properties as well)
    final Object jobTypeValue = properties.remove(TYPE_ID);
    if ((null == jobTypeValue) || !(jobTypeValue instanceof String)
            || !IdHelper.isValidId(((String) jobTypeValue)))
        throw new IOException(
                String.format("invalid record data: missing/invalid job id %s", String.valueOf(jobTypeValue)));

    // get path (remove key from properties as well)
    final Object contextPathValue = properties.remove(CONTEXT_PATH);
    if ((null == contextPathValue) || !(contextPathValue instanceof String)
            || !Path.EMPTY.isValidPath(((String) contextPathValue)))
        throw new IOException(String.format("invalid record data: missing/invalid context path %s",
                String.valueOf(contextPathValue)));

    // get queue trigger (remove key from properties as well)
    final Object queueTrigger = properties.remove(QUEUE_TRIGGER);
    if ((null != queueTrigger) && !(queueTrigger instanceof String))
        throw new IOException(
                String.format("invalid record data: invalid queue trigger %s", String.valueOf(queueTrigger)));

    // get queue timestamp (remove key from properties as well)
    final Object queueTimestamp = properties.remove(QUEUE_TIMESTAMP);
    if ((null == queueTimestamp) || !(queueTimestamp instanceof String))
        throw new IOException(String.format("invalid record data: missing/invalid queue timestamp %s",
                String.valueOf(queueTimestamp)));

    // get schedule info (remove key from properties as well)
    final Object scheduleInfo = properties.remove(SCHEDULE_INFO);
    if ((null != scheduleInfo) && !(scheduleInfo instanceof String))
        throw new IOException(
                String.format("invalid record data: invalid schedule info %s", String.valueOf(scheduleInfo)));

    // get last successful finish timestamp (remove key from properties as well)
    final Object lastSuccessfulStart = properties.remove(LAST_SUCCESSFUL_START);
    if ((null == lastSuccessfulStart) || !(lastSuccessfulStart instanceof String))
        throw new IOException(
                String.format("invalid record data: missing/invalid last successful finish timestamp %s",
                        String.valueOf(lastSuccessfulStart)));

    // collect properties
    final Map<String, String> jobProperties = new HashMap<String, String>();
    for (final Iterator<?> stream = properties.keySet().iterator(); stream.hasNext();) {
        final String key = (String) stream.next();
        if (!key.startsWith(PREFIX)) {
            jobProperties.put(key, properties.getProperty(key));
        }
    }

    // create job info
    return new JobInfo((String) jobTypeValue, (String) jobIdValue, new Path((String) contextPathValue),
            jobProperties, (String) queueTrigger, NumberUtils.toLong((String) queueTimestamp),
            (String) scheduleInfo, NumberUtils.toLong((String) lastSuccessfulStart));
}

From source file:org.artifactory.common.property.ArtifactorySystemProperties.java

private static void validateConstants(Properties artProps) {
    String chrootPropertyName = ConstantValues.uiChroot.getPropertyName();
    String chroot = (String) artProps.get(chrootPropertyName);
    if (StringUtils.isNotBlank(chroot)) {
        if (!new File(chroot).exists()) {
            artProps.remove(chrootPropertyName);
            BootstrapLogger.error("Selected chroot '" + chroot + "' does not exist. Ignoring property value!");
        }/*from w ww . ja v a  2s  . c  om*/
    }
}

From source file:org.nuxeo.theme.themes.ThemeRepairer.java

private static void cleanupStyles(Element element) {
    Widget widget = (Widget) ElementFormatter.getFormatFor(element, "widget");
    Style style = (Style) ElementFormatter.getFormatFor(element, "style");
    String xpath = element.computeXPath();

    // Simplify styles by removing disallowed layout properties and by
    // cleaning up paths without properties
    if (style != null && widget != null) {
        String viewName = widget.getName();
        List<String> pathsToClear = new ArrayList<String>();

        for (String path : style.getPathsForView(viewName)) {
            Properties styleProperties = style.getPropertiesFor(viewName, path);
            if (styleProperties == null) {
                continue;
            }/*from   w  ww  .j av  a  2 s . c o m*/
            for (String key : LAYOUT_PROPERTIES) {
                if (styleProperties.containsKey(key)) {
                    styleProperties.remove(key);
                    log.debug("Removed property: '" + key + "' from <style> for element " + xpath);
                }
            }

            if (styleProperties.isEmpty()) {
                pathsToClear.add(path);
                continue;
            }

            List<String> stylePropertiesToRemove = new ArrayList<String>();
            for (Object key : styleProperties.keySet()) {
                String propertyName = (String) key;
                if ((widget instanceof PageElement && !Utils.contains(PAGE_STYLE_PROPERTIES, propertyName))
                        || (widget instanceof SectionElement
                                && !Utils.contains(SECTION_STYLE_PROPERTIES, propertyName))
                        || (widget instanceof CellElement
                                && !Utils.contains(CELL_STYLE_PROPERTIES, propertyName))) {
                    stylePropertiesToRemove.add(propertyName);
                }
            }

            for (String propertyName : stylePropertiesToRemove) {
                styleProperties.remove(propertyName);
                log.debug("Removed style property: '" + propertyName + " in path: " + path + "' for element "
                        + xpath);
            }
        }

        for (String path : pathsToClear) {
            style.clearPropertiesFor(viewName, path);
            log.debug("Removed empty style path: '" + path + "' for element " + xpath);
        }
    }
}

From source file:com.googlecode.fascinator.messaging.ConveyerBelt.java

/**
 * Find out what transformers are required to run for a particular render
 * step.// ww  w . jav  a 2 s  .  c  o  m
 * 
 * @param object The digital object to transform.
 * @param config The configuration for the particular harvester.
 * @param thisType The type of render chain (step).
 * @param routing Flag if query is for routing. Set this value will force a
 *            check for user priority, and then clear the flag if found.
 * @return List<String> A list of names for instantiated transformers.
 */
public static List<String> getTransformList(DigitalObject object, JsonSimpleConfig config, String thisType,
        boolean routing) throws StorageException {
    List<String> plugins = new ArrayList<String>();
    Properties props = object.getMetadata();

    // User initiated event
    if (routing) {
        String user = props.getProperty("userPriority");
        if (user != null && user.equals("true")) {
            log.info("User priority flag set: '{}'", object.getId());
            plugins.add(CRITICAL_USER_SELECTOR);
            props.remove("userPriority");
            object.close();
        }
    }

    // Property data, highest priority
    String pluginList = props.getProperty(thisType);
    if (pluginList != null) {
        // Turn the string into a real list
        for (String plugin : StringUtils.split(pluginList, ",")) {
            plugins.add(StringUtils.trim(plugin));
        }

    } else {
        // The harvester specified none, fallback to the
        // default list for this harvest source.
        List<String> transformerList = config.getStringList("transformer", thisType);
        if (transformerList != null) {
            for (String entry : transformerList) {
                plugins.add(StringUtils.trim(entry));
            }
        } else {
            log.info("No transformers configured!");
        }
    }
    return plugins;
}

From source file:org.apache.ranger.hadoop.client.config.HadoopConfigHolder.java

private static void addConfiguration(String dataSource, String resourceName, String propertyName,
        String value) {//  www.  j a v  a 2s  .c  om

    if (dataSource == null || dataSource.isEmpty()) {
        return;
    }

    if (propertyName == null || propertyName.isEmpty()) {
        return;
    }

    if (resourceName == null) {
        resourceName = DEFAULT_RESOURCE_NAME;
    }

    HashMap<String, Properties> resourceName2PropertiesMap = dataSource2ResourceListMap.get(dataSource);

    if (resourceName2PropertiesMap == null) {
        resourceName2PropertiesMap = new HashMap<String, Properties>();
        dataSource2ResourceListMap.put(dataSource, resourceName2PropertiesMap);
    }

    Properties prop = resourceName2PropertiesMap.get(resourceName);
    if (prop == null) {
        prop = new Properties();
        resourceName2PropertiesMap.put(resourceName, prop);
    }
    if (value == null) {
        prop.remove(propertyName);
    } else {
        prop.put(propertyName, value);
    }
}

From source file:gdt.data.grain.Locator.java

/**
   * Remove the name/value pair from the locator. 
   * @param locator$ the locator string/*from www .java2s . c o m*/
   * @param name$ the name. 
* @return  the locator string.   
   */
public static String remove(String locator$, String name$) {
    if (name$ == null)
        return locator$;
    Properties locator = toProperties(locator$);
    if (locator == null)
        return locator$;
    Enumeration<?> en = locator.keys();
    String key$;
    while (en.hasMoreElements()) {
        key$ = (String) en.nextElement();
        if (name$.equals(key$)) {
            locator.remove(key$);
            break;
        }
    }
    return toString(locator);
}

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

static void checkString(String key, Properties prop) {
    String s = prop.getProperty(key);
    if (s != null) {
        s = s.trim();/*  w ww .  ja  v a2  s  .c  o m*/
        if (s.length() == 0) {
            prop.remove(key);
        } else {
            prop.setProperty(key, s);
        }
    }
}