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:TransformThread.java

/** Sets the appropriate system properties if XSLTC is
 * to be used (according to USE_XSLTC)/* w ww  . j  a v a 2  s  .c om*/
 */
private static void initSystemProperties() {
    if (USE_XSLTC) {
        // Set the TransformerFactory system property if XSLTC is required
        // Note: To make this sample more flexible, load properties from a properties file.
        // The setting for the Xalan Transformer is "org.apache.xalan.processor.TransformerFactoryImpl"
        String key = "javax.xml.transform.TransformerFactory";
        String value = "org.apache.xalan.xsltc.trax.TransformerFactoryImpl";
        Properties props = System.getProperties();
        props.put(key, value);
        System.setProperties(props);
    }
}

From source file:com.opengamma.examples.simulated.DBTestUtils.java

public static Properties loadProperties(String configResourceLocation) throws IOException {
    Resource resource = ResourceUtils.createResource(configResourceLocation);
    Properties props = new Properties();
    props.load(resource.getInputStream());

    String nextConfiguration = props.getProperty("MANAGER.NEXT.FILE");
    if (nextConfiguration != null) {
        resource = ResourceUtils.createResource(nextConfiguration);
        Properties parentProps = new Properties();
        parentProps.load(resource.getInputStream());
        for (String key : props.stringPropertyNames()) {
            parentProps.put(key, props.getProperty(key));
        }/*from  www  . ja  v  a 2  s . c  om*/
        props = parentProps;
    }

    for (String key : props.stringPropertyNames()) {
        s_logger.debug("\t{}={}", key, props.getProperty(key));
    }

    return props;
}

From source file:com.concursive.connect.cache.utils.CacheUtils.java

public static Ehcache createInMemoryCache(String cacheName, CacheEntryFactory entryFactory, int maxElements) {
    CacheManager manager = CacheManager.getInstance();
    Ehcache cache = getCache(cacheName);
    if (cache == null) {
        // Create the cache
        cache = new Cache(cacheName, maxElements, memoryStoreEvictionPolicy, overflowToDisk, diskStorePath,
                eternal, timeToLive, timeToIdle, diskPersistent, diskExpiryThreadIntervalSeconds, null);
        // Associate the cacheEntryFactory with the cache
        SelfPopulatingCache selfPopulatingCache = new SelfPopulatingCache(cache, entryFactory);
        // Add any additional listener properties
        if (manager.getCachePeerListener("RMI") != null) {
            LOG.info("Setting RMI properties");
            Properties properties = new Properties();
            properties.put("replicateAsynchronously", "true");
            properties.put("replicatePuts", "false");
            properties.put("replicateUpdates", "true");
            properties.put("replicateRemovals", "true");
            properties.put("replicateUpdatesViaCopy", "false");
            properties.put("asynchronousReplicationIntervalMillis", "1000");
            RMICacheReplicatorFactory factory = new RMICacheReplicatorFactory();
            CacheEventListener listener = factory.createCacheEventListener(properties);
            selfPopulatingCache.getCacheEventNotificationService().registerListener(listener);
            RMIBootstrapCacheLoaderFactory bootstrapFactory = new RMIBootstrapCacheLoaderFactory();
            BootstrapCacheLoader bootstrapCacheLoader = bootstrapFactory
                    .createBootstrapCacheLoader(new Properties());
            selfPopulatingCache.setBootstrapCacheLoader(bootstrapCacheLoader);
            LOG.debug("RMI enabled");
        }//  w  ww.  j a  v a  2 s . c  om
        // Make the cache available
        manager.addCache(selfPopulatingCache);
        LOG.info("cache created: " + cache.getName());
    }
    return cache;
}

From source file:gobblin.util.JobConfigurationUtils.java

/**
 * Put all configuration properties in a given {@link Configuration} object into a given
 * {@link Properties} object./*  w w  w .j  a v a 2  s  .co m*/
 *
 * @param configuration the given {@link Configuration} object
 * @param properties the given {@link Properties} object
 */
public static void putConfigurationIntoProperties(Configuration configuration, Properties properties) {
    for (Iterator<Entry<String, String>> it = configuration.iterator(); it.hasNext();) {
        Entry<String, String> entry = it.next();
        properties.put(entry.getKey(), entry.getValue());
    }
}

From source file:simplehttpserver.SimpleHttpServer.java

static public Connection getConnection() throws SQLException {

    Connection conn = null;//from  ww  w  . j  av a  2 s. co  m
    Properties connectionProps = new Properties();
    connectionProps.put("user", userName);
    //connectionProps.put("password", password);

    conn = DriverManager.getConnection("jdbc:" + "mysql" + "://" + serverName + ":" + portNumber + "/",
            connectionProps);

    System.out.println("Connected to database");
    return conn;
}

From source file:de.unigoettingen.sub.commons.util.stream.StreamUtils.java

/************************************************************************************
 * get {@link InputStream} from given URL using a basis path and proxy informations
 * //from   w w w .j  av a  2  s.c  o  m
 * @param url the url from where to get the {@link InputStream}
 * @param basepath the basispath
 * @param httpproxyhost the host for proxy
 * @param httpproxyport the port for proxy
 * @param httpproxyusername the username for the proxy
 * @param httpproxypassword the password for the proxy
 * @return {@link InputStream} for url
 * @throws IOException
 ************************************************************************************/
public static InputStream getInputStreamFromUrl(URL url, String basepath, String httpproxyhost,
        String httpproxyport, String httpproxyusername, String httpproxypassword) throws IOException {
    InputStream inStream = null;

    if (url.getProtocol().equalsIgnoreCase("http")) {
        if (httpproxyhost != null) {
            Properties properties = System.getProperties();
            properties.put("http.proxyHost", httpproxyhost);
            if (httpproxyport != null) {
                properties.put("http.proxyPort", httpproxyport);
            } else {
                properties.put("http.proxyPort", "80");
            }
        }
        URLConnection con = url.openConnection();
        if (httpproxyusername != null) {
            String login = httpproxyusername + ":" + httpproxypassword;
            String encodedLogin = new String(Base64.encodeBase64(login.getBytes()));
            con.setRequestProperty("Proxy-Authorization", "Basic " + encodedLogin);
        }
        inStream = con.getInputStream();
    } else if (url.getProtocol().equalsIgnoreCase("file")) {
        int size = url.openConnection().getContentLength();
        Integer maxFileLength = ContentServerConfiguration.getInstance().getMaxFileLength();

        if (maxFileLength != 0 && size > maxFileLength) {
            // System.out.println("File " + url.getFile() + " is too large (" + size + "/" + maxFileLength + ")");
            return getInputStreamFromUrl(new URL(ContentServerConfiguration.getInstance().getErrorFile()));
        }
        String filepath = url.getFile();

        filepath = URLDecoder.decode(filepath, System.getProperty("file.encoding"));

        File f = new File(filepath);
        if (!f.isFile()) {
            // try for a file with different suffix case
            int suffixIndex = filepath.lastIndexOf('.');
            f = new File(filepath.substring(0, suffixIndex) + filepath.substring(suffixIndex).toLowerCase());
            if (!f.isFile()) {
                f = new File(
                        filepath.substring(0, suffixIndex) + filepath.substring(suffixIndex).toUpperCase());
            }
            // search all files in this directory for this case-insensitive name
            if (!f.isFile()) {
                File[] files = f.getParentFile().listFiles();
                if (files != null) {
                    for (File file : files) {
                        if (file.getName().compareToIgnoreCase(f.getName()) == 0) {
                            f = file;
                            break;
                        }
                    }
                }
            }
        }
        inStream = new FileInputStream(f);

    } else if (url.getProtocol().length() == 0) {
        String filepath = url.getFile();
        // we just have the relative path, need to find the absolute path
        String path = basepath + filepath;

        // call this method again
        URL completeurl = new URL(path);
        inStream = getInputStreamFromUrl(completeurl);
    }

    return inStream;
}

From source file:com.qubole.quark.planner.test.LatticeWithFilterTest.java

@BeforeClass
public static void setUpClass() throws Exception {
    Properties info = new Properties();
    info.put("unitTestMode", "true");
    info.put("schemaFactory", "com.qubole.quark.planner.test.LatticeWithFilterTest$SchemaFactory");

    ImmutableList<String> defaultSchema = ImmutableList.of("FOODMART");
    final ObjectMapper mapper = new ObjectMapper();

    info.put("defaultSchema", mapper.writeValueAsString(defaultSchema));

    parser = new SqlQueryParser(info);

}

From source file:com.rxx.common.util.MailUtil.java

/**
 * /*from  www  .ja v a2s.c  o  m*/
 *
 * @param host 
 * @param port
 * @param userName
 * @param password
 * @param title
 * @param content
 * @param toUser
 */
public static void sendText(String host, int port, String userName, String password, String title,
        String content, String[] toUser) {
    JavaMailSenderImpl senderImpl = new JavaMailSenderImpl();
    // mail server
    senderImpl.setHost(host);
    senderImpl.setPort(port);
    // 
    SimpleMailMessage mailMessage = new SimpleMailMessage();
    //  
    // String[] array = new String[] {"sun111@163.com","sun222@sohu.com"};
    // mailMessage.setTo(array);
    mailMessage.setTo(toUser);
    mailMessage.setFrom(userName);
    mailMessage.setSubject(title);
    mailMessage.setText(content);

    senderImpl.setUsername(userName); // ,username
    senderImpl.setPassword(password); // , password

    Properties prop = new Properties();
    prop.put(" mail.smtp.auth ", " true "); // true,
    prop.put(" mail.smtp.timeout ", " 25000 ");
    senderImpl.setJavaMailProperties(prop);
    // 
    senderImpl.send(mailMessage);
}

From source file:com.amazon.payments.paywithamazon.impl.Util.java

/**
 * This method uses PaymentsConfig to set proxy settings and uses
 * HttpURLConnection instance to make requests.
 *
 * @param method The HTTP method (GET,POST,PUT,etc.).
 * @param url The URL/*from  www  .  j av a2s .  c o m*/
 * @param urlParameters URL Parameters
 * @param config client configuration container
 * @return ResponseData
 * @throws IOException
 */
public static ResponseData httpSendRequest(String method, String url, String urlParameters,
        Map<String, String> headers, PaymentsConfig config) throws IOException {

    Map<String, String> headerMap = new HashMap<String, String>();
    if (config != null) {
        String userAgent = "Language=Java; ApplicationLibraryVersion="
                + ServiceConstants.APPLICATION_LIBRARY_VERSION + "; "
                + "Platform=JAVA_PLATFORM; MWSClientVersion=" + ServiceConstants.AMAZON_PAYMENTS_API_VERSION
                + ";" + " ApplicationName=" + config.getApplicationName() + ";" + "ApplicationVersion="
                + config.getApplicationName();
        headerMap.put("User-Agent", userAgent);

        if (config.getProxyHost() != null) {
            Properties systemSettings = System.getProperties();
            systemSettings.put("proxySet", "true");
            systemSettings.put("http.proxyHost", config.getProxyHost());
            systemSettings.put("http.proxyPort", config.getProxyPort());
            if (config.getProxyUsername() != null && config.getProxyPassword() != null) {
                String password = config.getProxyUsername() + ":" + config.getProxyPassword();
                byte[] encodedPassword = Base64.encodeBase64(password.getBytes());
                if (encodedPassword != null) {
                    headerMap.put("Proxy-Authorization", new String(encodedPassword));
                }
            }
        }
    }

    ResponseData response = Util.httpSendRequest(method, url, urlParameters, headerMap);
    return response;
}

From source file:org.alfresco.bm.file.FileDataServiceTest.java

@BeforeClass
public static void setUp() throws IOException {
    // Create a test file
    File tempDir = new File(System.getProperty("java.io.tmpdir"));
    File testFiles = new File(tempDir, "FileDataServiceTest");
    testFiles.mkdirs();/*from w ww  .j  a  v  a  2s  .  c  om*/
    File testFile = new File(testFiles, "test.txt");
    if (!testFile.exists()) {
        String text = "SOME TEXT";
        Files.write(text, testFile, Charsets.UTF_8);
    }

    File localDir = new File(System.getProperty("java.io.tmpdir") + "/" + "fileset-123");
    if (localDir.exists()) {
        localDir.delete();
    }

    Properties props = new Properties();
    props.put("test.mongoCollection", COLLECTION_BM_FILE_DATA_SERVICE);
    props.put("test.localDir", localDir.getCanonicalFile());
    props.put("test.ftpHost", "ftp.mirrorservice.org");
    props.put("test.ftpPort", "21");
    props.put("test.ftpUsername", "anonymous");
    props.put("test.ftpPassword", "");
    props.put("test.ftpPath", "/sites/www.linuxfromscratch.org/images");
    props.put("test.testFileDir", testFiles.getCanonicalPath());

    ctx = new ClassPathXmlApplicationContext(new String[] { "test-MongoFileDataTest-context.xml" }, false);
    ctx.getEnvironment().getPropertySources().addFirst(new PropertiesPropertySource("TestProps", props));
    ctx.refresh();
    ctx.start();

    // Get the new beans
    fileDataService = ctx.getBean(FileDataService.class);
    ftpTestFileService = ctx.getBean(FtpTestFileService.class);
    localTestFileService = ctx.getBean(LocalTestFileService.class);

    // Do a directory listing and use that as the dataset
    File randomDir = new File(System.getProperty("user.dir"));
    File[] localFiles = randomDir.listFiles(new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            return !pathname.isDirectory();
        }
    });
    fileDatas = new FileData[localFiles.length];
    for (int i = 0; i < localFiles.length; i++) {
        String remoteName = localFiles[i].getName();
        if (remoteName.length() == 0) {
            continue;
        }
        fileDatas[i] = FileDataServiceTest.createFileData(remoteName);
    }
}