Example usage for java.util Properties setProperty

List of usage examples for java.util Properties setProperty

Introduction

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

Prototype

public synchronized Object setProperty(String key, String value) 

Source Link

Document

Calls the Hashtable method put .

Usage

From source file:fedora.utilities.Log4J.java

/**
 * Initializes Log4J from a properties file.
 * /*from w w w.j a va  2 s .  c  o m*/
 * @param propFile the Log4J properties file.
 * @param options a set of name-value pairs to use while expanding any
 *                replacement variables (e.g. ${some.name}) in the 
 *                properties file.  These may also be specified in
 *                the properties file itself.  If found, the value
 *                in the properties file will take precendence.
 * @throws IOException if configuration fails due to problems with the file.
 */
public static void initFromPropFile(File propFile, Map<String, String> options) throws IOException {
    Properties props = new Properties();
    props.load(new FileInputStream(propFile));
    if (options != null) {
        for (String name : options.keySet()) {
            String value = options.get(name);
            if (!props.containsKey(name)) {
                props.setProperty(name, value);
            }
        }
    }
    PropertyConfigurator.configure(props);
}

From source file:gobblin.source.extractor.extract.kafka.KafkaDeserializerExtractor.java

/**
 * Gets {@link Properties} from a {@link WorkUnitState} and sets the config <code>schema.registry.url</code> to value
 * of {@link KafkaSchemaRegistry#KAFKA_SCHEMA_REGISTRY_URL} if set. This way users don't need to specify both
 * properties as <code>schema.registry.url</code> is required by the {@link ConfluentKafkaSchemaRegistry}.
 *//*from w  ww.j  av  a  2  s. c o  m*/
private static Properties getProps(WorkUnitState workUnitState) {
    Properties properties = workUnitState.getProperties();
    if (properties.containsKey(KafkaSchemaRegistry.KAFKA_SCHEMA_REGISTRY_URL)) {
        properties.setProperty(CONFLUENT_SCHEMA_REGISTRY_URL,
                properties.getProperty(KafkaSchemaRegistry.KAFKA_SCHEMA_REGISTRY_URL));
    }
    return properties;
}

From source file:com.adaptris.core.util.JdbcUtil.java

public static Properties mergeConnectionProperties(Properties p, String username, String password)
        throws PasswordException {
    if (!isEmpty(username)) {
        p.setProperty("user", username);
    }//from   ww  w  . ja  v  a2 s .  c  o m
    if (!isEmpty(password)) {
        p.setProperty("password", Password.decode(password));
    }
    return p;
}

From source file:com.cognifide.qa.bb.utils.PropertyUtils.java

private static void overrideFromSystemProperties(Properties properties) {
    properties.stringPropertyNames().stream().forEach((key) -> {
        String systemProperty = System.getProperty(key);
        if (StringUtils.isNotBlank(systemProperty)) {
            properties.setProperty(key, systemProperty);
        }//from   w ww  .  ja  va2 s .  c  o m
    });
}

From source file:ca.nrc.cadc.db.DBUtil.java

/**
 * Create a DataSource with a single connection to the server.  All failures
 * are thrown as RuntimeException with a Throwable (cause).
 *
 * @param config/* www.j av  a  2  s  . co m*/
 * @param suppressClose suppress close calls on the underlying Connection
 * @param test test the datasource before return (might throw)
 * @return a connected single connection DataSource
 * @throws DBConfigException
 */
public static DataSource getDataSource(ConnectionConfig config, boolean suppressClose, boolean test)
        throws DBConfigException {
    try {
        log.debug("server: " + config.getServer());
        log.debug("driver: " + config.getDriver());
        log.debug("url: " + config.getURL());
        log.debug("database: " + config.getDatabase());

        // load JDBC driver
        Class.forName(config.getDriver());

        SingleConnectionDataSource ds = new SingleConnectionDataSource(config.getURL(), config.getUsername(),
                config.getPassword(), suppressClose);

        Properties props = new Properties();
        props.setProperty("APPLICATIONNAME", getMainClass());
        ds.setConnectionProperties(props);

        if (test)
            testDS(ds, true);

        return ds;
    } catch (ClassNotFoundException ex) {
        throw new DBConfigException("failed to load JDBC driver: " + config.getDriver(), ex);
    } catch (SQLException ex) {
        throw new DBConfigException("failed to open connection: " + config.getURL(), ex);
    }

}

From source file:org.aliuge.crawler.fetcher.Fetcher.java

private static void storeProxyIp() {
    // ? ???ip/*from ww w  .  j a  v a 2 s .c  o m*/
    Properties pro = new Properties();
    for (int i = 0; i < proxyIps.size(); i++) {
        pro.setProperty("proxy" + i, proxyIps.get(i));
    }
    OutputStream out = null;
    try {
        out = new FileOutputStream(new File(config.getProxyPath()));
        pro.store(out, "?Ip,[" + DateTimeUtil.getDateTime() + "]");
    } catch (FileNotFoundException e) {
        slog.error("?IP????:" + new File(config.getProxyPath()).toString(),
                e);
        e.printStackTrace();
    } catch (IOException e) {
        slog.error("?Ip:", e);
        e.printStackTrace();
    } finally {
        try {
            out.close();
        } catch (IOException e) {
        }
    }
}

From source file:at.gv.egovernment.moa.id.configuration.helper.MailHelper.java

private static void sendMail(ConfigurationProvider config, String subject, String recipient, String content)
        throws ConfigurationException {
    try {//w w w.  ja v a  2  s  . c o m
        log.debug("Sending mail.");
        MiscUtil.assertNotNull(subject, "subject");
        MiscUtil.assertNotNull(recipient, "recipient");
        MiscUtil.assertNotNull(content, "content");

        Properties props = new Properties();
        props.setProperty("mail.transport.protocol", "smtp");
        props.setProperty("mail.host", config.getSMTPMailHost());
        log.trace("Mail host: " + config.getSMTPMailHost());
        if (config.getSMTPMailPort() != null) {
            log.trace("Mail port: " + config.getSMTPMailPort());
            props.setProperty("mail.port", config.getSMTPMailPort());
        }
        if (config.getSMTPMailUsername() != null) {
            log.trace("Mail user: " + config.getSMTPMailUsername());
            props.setProperty("mail.user", config.getSMTPMailUsername());
        }
        if (config.getSMTPMailPassword() != null) {
            log.trace("Mail password: " + config.getSMTPMailPassword());
            props.setProperty("mail.password", config.getSMTPMailPassword());
        }

        Session mailSession = Session.getDefaultInstance(props, null);
        Transport transport = mailSession.getTransport();

        MimeMessage message = new MimeMessage(mailSession);
        message.setSubject(subject);
        log.trace("Mail from: " + config.getMailFromName() + "/" + config.getMailFromAddress());
        message.setFrom(new InternetAddress(config.getMailFromAddress(), config.getMailFromName()));
        log.trace("Recipient: " + recipient);
        message.addRecipient(Message.RecipientType.TO, new InternetAddress(recipient));

        log.trace("Creating multipart content of mail.");
        MimeMultipart multipart = new MimeMultipart("related");

        log.trace("Adding first part (html)");
        BodyPart messageBodyPart = new MimeBodyPart();
        messageBodyPart.setContent(content, "text/html; charset=ISO-8859-15");
        multipart.addBodyPart(messageBodyPart);

        //         log.trace("Adding mail images");
        //         messageBodyPart = new MimeBodyPart();
        //         for (Image image : images) {
        //            messageBodyPart.setDataHandler(new DataHandler(image));
        //            messageBodyPart.setHeader("Content-ID", "<" + image.getContentId() + ">");
        //            multipart.addBodyPart(messageBodyPart);
        //         }

        message.setContent(multipart);
        transport.connect();
        log.trace("Sending mail message.");
        transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
        log.trace("Successfully sent.");
        transport.close();

    } catch (MessagingException e) {
        throw new ConfigurationException(e);

    } catch (UnsupportedEncodingException e) {
        throw new ConfigurationException(e);

    }
}

From source file:com.adaptris.jdbc.connection.FailoverConnection.java

private static Properties mergeConnectionProperties(Properties p, String username, String password)
        throws PasswordException {
    if (!isEmpty(username)) {
        p.setProperty("user", username);
    }/*from  www. j  a  va 2s .  c o  m*/
    if (!isEmpty(password)) {
        p.setProperty("password", Password.decode(password));
    }
    return p;
}

From source file:Main.java

public static void loadAttributesFromNode(Node node, Properties attrs) {
    attrs.clear();/*from w  w  w  .  j  a v a  2s.  c  o  m*/
    Element elem = (Element) node;
    NodeList list = elem.getElementsByTagName(TAG_ATTR);
    for (int i = 0; i < list.getLength(); i++) {
        String text = getTextTag(list.item(i));
        String[] s = text.split("=");
        if (s.length >= 2) {
            attrs.setProperty(s[0], s[1]);
        }
    }
}

From source file:be.fedict.eid.dss.protocol.simple.client.SignatureRequestUtil.java

/**
 * Creates a Signature Request and posts it to the eID DSS Service. If a SP
 * identity is specified, a service signature will be added.
 * /* w w w.  ja  v  a2s .com*/
 * @param signatureRequest
 *            optional signature request containing the base64 encoded
 *            document to be siged. If <code>null</code> signatureRequestId
 *            becomes required.
 * @param signatureRequestId
 *            optional signature request ID, which is the ID returned by the
 *            eID DSS Web Service after a "store" operation. If
 *            <code>null</code> signatureRequest becomes required.
 * @param contentType
 *            optional content type of the document to be signed
 * @param dssDestination
 *            eID DSS Protocol Entry point which will handle the signature
 *            request.
 * @param spDestination
 *            SP destination that will handle the returned DSS Signature
 *            Response.
 * @param relayState
 *            optional relayState to be included (if not <code>null</code>)
 *            in the signature request.
 * @param spIdentity
 *            optional SP Identity, if present the signature request will be
 *            signed.
 * @param response
 *            HTTP Servlet Response used for posting the signature request.
 * @param language
 *            optional language indication which the eID DSS will use.
 * @throws SignatureException
 *             exception setting signature.
 * @throws InvalidKeyException
 *             SP Identity key is invalid
 * @throws NoSuchAlgorithmException
 *             Signature algorithm not available
 * @throws CertificateEncodingException
 *             failed to encode the certificate chain of the SP Identity
 * @throws IOException
 *             IO Exception
 */
public static void sendRequest(String signatureRequest, String signatureRequestId, String contentType,
        String dssDestination, String spDestination, String relayState, KeyStore.PrivateKeyEntry spIdentity,
        HttpServletResponse response, String language)

        throws SignatureException, InvalidKeyException, NoSuchAlgorithmException, CertificateEncodingException,
        IOException {

    // construct service signature
    ServiceSignatureDO serviceSignature = null;
    if (null != spIdentity) {
        serviceSignature = getServiceSignature(spIdentity, signatureRequest, signatureRequestId, spDestination,
                language, contentType, relayState);
    }

    Properties velocityProperties = new Properties();
    velocityProperties.setProperty("resource.loader", "class");
    velocityProperties.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, JdkLogChute.class.getName());
    velocityProperties.setProperty(JdkLogChute.RUNTIME_LOG_JDK_LOGGER, SignatureRequestUtil.class.getName());
    velocityProperties.setProperty("class.resource.loader.class",
            "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
    velocityProperties.setProperty("file.resource.loader.cache ", "false");
    VelocityEngine velocityEngine;
    try {
        velocityEngine = new VelocityEngine(velocityProperties);
        velocityEngine.init();
    } catch (Exception e) {
        throw new RuntimeException("could not initialize velocity engine", e);
    }
    VelocityContext velocityContext = new VelocityContext();
    velocityContext.put("action", dssDestination);
    if (null != signatureRequest) {
        velocityContext.put("SignatureRequest", signatureRequest);
    }
    if (null != signatureRequestId) {
        velocityContext.put("SignatureRequestId", signatureRequestId);
    }
    if (null != contentType) {
        velocityContext.put("ContentType", contentType);
    }
    if (null != relayState) {
        velocityContext.put("RelayState", relayState);
    }
    if (null != dssDestination) {
        velocityContext.put("Target", spDestination);
    }
    if (null != language) {
        velocityContext.put("Language", language);
    }
    if (null != serviceSignature) {
        velocityContext.put("ServiceSigned", serviceSignature.getServiceSigned());
        velocityContext.put("ServiceSignature", serviceSignature.getServiceSignature());
        velocityContext.put("ServiceCertificateChainSize", serviceSignature.getServiceCertificateChainSize());
        velocityContext.put("ServiceCertificates", serviceSignature.getServiceCertificates());
    }

    Template template;
    try {
        template = velocityEngine.getTemplate(POST_BINDING_TEMPLATE);
    } catch (Exception e) {
        throw new RuntimeException("Velocity template error: " + e.getMessage(), e);
    }

    response.setContentType("text/html; charset=UTF-8");
    template.merge(velocityContext, response.getWriter());
}