Example usage for java.util Properties put

List of usage examples for java.util Properties put

Introduction

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

Prototype

@Override
    public synchronized Object put(Object key, Object value) 

Source Link

Usage

From source file:com.basp.trabajo_al_minuto.model.business.BusinessUtils.java

/**
 * Se encarga de enviar el mensaje de correo electronico *
 *///from ww  w  .  j a  v  a 2s .  co m
public static Boolean sendEmail(final EmailMessage emdto) throws BusinessException {
    try {
        Session session;
        Properties properties = System.getProperties();
        properties.put("mail.host", emdto.getHost());
        properties.put("mail.transport.protocol", "smtp");
        properties.put("mail.smtp.port", emdto.getPort());
        properties.put("mail.smtp.starttls.enable", emdto.getStarttls());
        if (emdto.getUser() != null && emdto.getPassword() != null) {
            properties.put("mail.smtp.auth", "true");
            session = Session.getDefaultInstance(properties, new Authenticator() {
                @Override
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(emdto.getUser(), emdto.getPassword());
                }
            });
        } else {
            properties.put("mail.smtp.auth", "false");
            session = Session.getDefaultInstance(properties);
        }

        message = new MimeMessage(session);
        message.setFrom(new InternetAddress(emdto.getFrom(), emdto.getMask()));
        message.setSubject(emdto.getSubject());

        for (String to : emdto.getToList()) {
            message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
        }
        if (emdto.getCcList() != null) {
            for (String cc : emdto.getCcList()) {
                message.addRecipient(Message.RecipientType.CC, new InternetAddress(cc));
            }
        }
        if (emdto.getCcoList() != null) {
            for (String cco : emdto.getCcoList()) {
                message.addRecipient(Message.RecipientType.BCC, new InternetAddress(cco));
            }
        }

        bodyPart = new MimeBodyPart();
        bodyPart.setContent(emdto.getBodyMessage(), emdto.getMimeTypeMessage());
        multipart = new MimeMultipart();
        multipart.addBodyPart(bodyPart);

        if (emdto.getFilePaths() != null) {
            for (String filePath : emdto.getFilePaths()) {
                File file = new File(filePath);
                if (file.exists()) {
                    dataSource = new FileDataSource(file);
                    bodyPart = new MimeBodyPart();
                    bodyPart.setDataHandler(new DataHandler(dataSource));
                    bodyPart.setFileName(file.getName());
                    multipart.addBodyPart(bodyPart);
                }
            }
        }

        message.setContent(multipart);
        Transport.send(message);
    } catch (MessagingException | UnsupportedEncodingException ex) {
        Logger.getLogger(BusinessUtils.class.getName()).log(Level.SEVERE, "BusinessUtils.sendEmail Exception",
                ex);
        throw new BusinessException(ex);
    }
    return Boolean.TRUE;
}

From source file:PropertyLoader.java

public static Properties loadProperties(String name, ClassLoader loader) throws Exception {
    if (name.startsWith("/"))
        name = name.substring(1);/*from www  .  j  av a 2s.  co  m*/
    if (name.endsWith(SUFFIX))
        name = name.substring(0, name.length() - SUFFIX.length());
    Properties result = new Properties();
    InputStream in = null;
    if (loader == null)
        loader = ClassLoader.getSystemClassLoader();
    if (LOAD_AS_RESOURCE_BUNDLE) {
        name = name.replace('/', '.');
        ResourceBundle rb = ResourceBundle.getBundle(name, Locale.getDefault(), loader);
        for (Enumeration keys = rb.getKeys(); keys.hasMoreElements();) {
            result.put((String) keys.nextElement(), rb.getString((String) keys.nextElement()));
        }
    } else {
        name = name.replace('.', '/');
        if (!name.endsWith(SUFFIX))
            name = name.concat(SUFFIX);
        in = loader.getResourceAsStream(name);
        if (in != null) {
            result = new Properties();
            result.load(in); // can throw IOException
        }
    }
    in.close();
    return result;
}

From source file:com.googlecode.flyway.commandline.Main.java

/**
 * Overrides the configuration from the config file with the properties passed in directly from the command-line.
 *
 * @param properties The properties to override.
 * @param args       The command-line arguments that were passed in.
 *//*from w w w  .ja v a2  s . com*/
/* private -> for testing*/
static void overrideConfiguration(Properties properties, String[] args) {
    for (String arg : args) {
        if (isPropertyArgument(arg)) {
            properties.put("flyway." + getArgumentProperty(arg), getArgumentValue(arg));
        }
    }
}

From source file:info.magnolia.importexport.PropertiesImportExport.java

private static void addStringProperty(Properties out, String path, String stringProperty) {
    if (StringUtils.isNotEmpty(stringProperty)) {
        out.put(path, stringProperty);
    }/*  w w w . j  a v a  2s. co  m*/
}

From source file:scalespace.filter.BoG_Filter_.java

public static void savePreferences(Properties prefs) {
    prefs.put(LEN, Integer.toString(sz));
    prefs.put(ISO, Boolean.toString(isiso));
    prefs.put(ISSEP, Boolean.toString(sep));
    // prefs.put(SIGMA, Float.toString(sigma));

}

From source file:com.flexive.core.timer.FxQuartz.java

/**
 * Start the Quartz scheduler//from w w  w  . j a v  a  2 s . c om
 *
 * @throws SchedulerException on errors
 */
public static void startup() throws SchedulerException {

    FxContext currCtx = FxContext.get();
    if (currCtx.isTestDivision()) {
        //disable scheduler for embedded containers
        LOG.info("Quartz scheduler disabled for embedded (test) container.");
        return;
    }
    if (System.getProperty(PROP_DISABLE) != null) {
        LOG.info("Quartz scheduler disabled because system property " + PROP_DISABLE + " is set.");
        return;
    }

    // Grab the Scheduler instance from the Factory
    // see http://wiki.opensymphony.com/display/QRTZ1/ConfigJobStoreCMT for more options
    Properties props = new Properties();
    props.put("org.quartz.scheduler.skipUpdateCheck", "true");
    props.put(StdSchedulerFactory.PROP_DATASOURCE_PREFIX, "fxQuartzDS");
    props.put("org.quartz.jobStore.dataSource", "fxQuartzDS");
    props.put("org.quartz.dataSource.fxQuartzDS." + StdSchedulerFactory.PROP_CONNECTION_PROVIDER_CLASS,
            FxQuartzConnectionProviderNonTX.class.getCanonicalName());
    props.put("org.quartz.dataSource.fxQuartzDS.divisionId", String.valueOf(currCtx.getDivisionId()));
    props.put(StdSchedulerFactory.PROP_JOB_STORE_CLASS, JobStoreCMT.class.getCanonicalName());

    final String driverDelegateClass;
    if ("PostgreSQL".equalsIgnoreCase(FxContext.get().getDivisionData().getDbVendor())) {
        driverDelegateClass = PostgreSQLDelegate.class.getCanonicalName();
    } else {
        driverDelegateClass = StdJDBCDelegate.class.getCanonicalName();
    }
    props.put("org.quartz.jobStore.driverDelegateClass", driverDelegateClass);

    /*props.put("org.quartz.jobStore.dataSource", "fxQuartzDS");
    try {
    props.put("org.quartz.dataSource.fxQuartzDS.jndiURL", Database.getDivisionData().getDataSource());
    } catch (SQLException e) {
    LOG.error("Quartz scheduler disabled! Failed to lookup DataSource for org.quartz.dataSource.fxQuartzDS.jndiURL: " + e.getMessage());
    return;
    }
            
    System.out.println("==> QUARTZ DS: "+props.get("org.quartz.dataSource.fxQuartzDS.jndiURL"));
    */
    props.put(StdSchedulerFactory.PROP_JOB_STORE_PREFIX, "QRTZ_");
    props.put("org.quartz.scheduler.instanceId", StdSchedulerFactory.AUTO_GENERATE_INSTANCE_ID);
    //        props.put("org.quartz.scheduler.xaTransacted", "false");
    props.put(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, SimpleThreadPool.class.getCanonicalName());
    props.put("org.quartz.threadPool.threadCount", String.valueOf(1));
    props.put("org.quartz.jobStore.nonManagedTXDataSource", "fxQuartzNoTXDS");

    props.put(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME,
            "FxQuartzScheduler_Division_" + FxContext.get().getDivisionId());
    props.put("org.quartz.jobStore.isClustered", "true");
    //        props.put("org.quartz.jobStore.txIsolationLevelSerializable", "false");
    props.put("org.quartz.jobStore.txIsolationLevelReadCommitted", "true");
    // lower db load
    props.put("org.quartz.jobStore.clusterCheckinInterval", "60000");

    props.put("org.quartz.dataSource.fxQuartzNoTXDS." + StdSchedulerFactory.PROP_CONNECTION_PROVIDER_CLASS,
            FxQuartzConnectionProviderNonTX.class.getCanonicalName());
    props.put("org.quartz.dataSource.fxQuartzNoTXDS.divisionId", String.valueOf(currCtx.getDivisionId()));

    /*props.put("org.quartz.dataSource.fxQuartzNoTXDS.driver","com.mysql.jdbc.Driver");
    props.put("org.quartz.dataSource.fxQuartzNoTXDS.URL", "jdbc:mysql://localhost:3306/flexive?useUnicode=true&characterEncoding=utf8&characterResultSets=utf8");
    props.put("org.quartz.dataSource.fxQuartzNoTXDS.user", "root");
    props.put("org.quartz.dataSource.fxQuartzNoTXDS.password", "a");*/

    Scheduler scheduler = new StdSchedulerFactory(props).getScheduler();
    FxContext ctx = FxContext._getEJBContext(currCtx);
    ctx.overrideTicket(UserTicketImpl.getGuestTicket().cloneAsGlobalSupervisor());
    ctx.clearCachedAttributes();
    scheduler.getContext().put(SCHEDCONTEXT_FX_CONTEXT, ctx);
    // and start it off
    scheduler.start();

    boolean found = false;
    for (String existingJob : scheduler.getJobNames(GROUP_INTERNAL))
        if (JOB_MAINTENANCE.equals(existingJob)) {
            found = true;
            break;
        }

    if (found) {
        //            System.out.println("Maintenance job already exists - done.");
        LOG.info("Quartz started. The scheduler can be disabled by with the command line option -D"
                + PROP_DISABLE);
        return;
    }

    JobDetail job = new JobDetail(JOB_MAINTENANCE, GROUP_INTERNAL, MaintenanceJob.class);
    job.setVolatility(false);
    //trigger every 30 minutes
    SimpleTrigger tr = new SimpleTrigger(JOB_MAINTENANCE, GROUP_INTERNAL);
    tr.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);
    tr.setRepeatInterval(1800000L); //30 minutes
    //        tr.setRepeatInterval(10000L); //10 seconds for testing purposes
    tr.setVolatility(false);
    scheduler.scheduleJob(job, tr);
    LOG.info("Quartz started and maintenance job is scheduled.");
}

From source file:scalespace.filter.ALoG_Filter_.java

public static void savePreferences(Properties prefs) {
    prefs.put(LEN, Integer.toString(sz));
    // prefs.put(SIGMA, Float.toString(sigma));

}

From source file:io.fabric8.profiles.ProfilesHelpers.java

public static void merge(Properties target, Properties source) {
    if (source.contains(DELETED)) {
        target.clear();// w ww  . j  av a 2 s  .  co  m
    } else {
        for (Map.Entry<Object, Object> entry : source.entrySet()) {
            if (DELETED.equals(entry.getValue())) {
                target.remove(entry.getKey());
            } else {
                target.put(entry.getKey(), entry.getValue());
            }
        }
    }
}

From source file:org.soitoolkit.commons.mule.util.MiscUtil.java

/**
 * Convert ResourceBundle into a Properties object.
 *
 * @param resource a resource bundle to convert.
 * @return Properties a properties version of the resource bundle.
 *//*  w ww  .j a va  2  s  .  co m*/
static Properties convertResourceBundleToProperties(ResourceBundle resource) {
    Properties properties = new Properties();

    Enumeration<String> keys = resource.getKeys();
    while (keys.hasMoreElements()) {
        String key = keys.nextElement();
        properties.put(key, resource.getString(key));
    }

    return properties;
}

From source file:com.haulmont.cuba.core.entity.LocaleHelper.java

public static String convertToSimpleKeyLocales(String localeBundle) {
    Properties result = new Properties();
    Properties properties = loadProperties(localeBundle);
    if (properties != null) {
        for (Map.Entry<Object, Object> entry : properties.entrySet()) {
            String key = (String) entry.getKey();
            key = key.substring(0, key.indexOf("/"));
            result.put(key, entry.getValue());
        }// w w  w  . j  a  v a  2  s  .c om
    }
    return convertPropertiesToString(result);
}