List of usage examples for java.util Properties setProperty
public synchronized Object setProperty(String key, String value)
From source file:edu.illinois.cs.cogcomp.nlp.corpusreaders.ereReader.EREDocumentReader.java
/** * This method sets a range of configuration parameters based on which ERE release user specifies * * @param ereCorpusVal a value corresponding to enum EreCorpus ('ENR1', 'ENR2', or 'ENR3') * @param corpusRoot the root directory of the corpus on your file system * @return a ResourceManager with the appropriate configuration, * @throws Exception// w ww. j a va 2s. c o m */ public static ResourceManager buildEreConfig(String ereCorpusVal, String corpusRoot) throws Exception { // defaults: ENR3 String sourceDir = "source/"; String annotationDir = "ere/"; String sourceExtension = ".xml"; String annotationExtension = ".xml"; String corpusNameVal = "ERE_" + ereCorpusVal; switch (EreCorpus.valueOf(ereCorpusVal)) { case ENR1: sourceDir = "source/mpdfxml/"; annotationDir = "ere/mpdfxml/"; break; case ENR2: case ESR1: case ZHR1: sourceExtension = ".cmp.txt"; break; case ENR3: case ESR2: case ZHR2: break; case KBP17: sourceExtension = ""; break; default: String errMsg = "Illegal value for ereCorpus: " + ereCorpusVal; logger.error(errMsg); throw new IllegalArgumentException(ereCorpusVal); } Properties props = new Properties(); //set source, annotation directories relative to specified corpus root dir props.setProperty(CorpusReaderConfigurator.SOURCE_DIRECTORY.key, corpusRoot + "/" + sourceDir); props.setProperty(CorpusReaderConfigurator.ANNOTATION_DIRECTORY.key, corpusRoot + "/" + annotationDir); props.setProperty(CorpusReaderConfigurator.SOURCE_EXTENSION.key, sourceExtension); props.setProperty(CorpusReaderConfigurator.ANNOTATION_EXTENSION.key, annotationExtension); props.setProperty(CorpusReaderConfigurator.CORPUS_NAME.key, corpusNameVal); return new ResourceManager(props); }
From source file:com.blazemeter.bamboo.plugin.ServiceManager.java
public static String getVersion() { Properties props = new Properties(); try {/*from ww w .ja v a 2 s . c o m*/ props.load(ServiceManager.class.getResourceAsStream("version.properties")); } catch (IOException ex) { props.setProperty("version", "N/A"); } return props.getProperty("version"); }
From source file:SftpClientFactory.java
/** * Creates a new connection to the server. * @param hostname The name of the host to connect to. * @param port The port to use.// w w w. j a va2s. c o m * @param username The user's id. * @param password The user's password. * @param fileSystemOptions The FileSystem options. * @return A Session. * @throws FileSystemException if an error occurs. */ public static Session createConnection(String hostname, int port, char[] username, char[] password, FileSystemOptions fileSystemOptions) throws FileSystemException { JSch jsch = new JSch(); File sshDir = null; // new style - user passed File knownHostsFile = SftpFileSystemConfigBuilder.getInstance().getKnownHosts(fileSystemOptions); File[] identities = SftpFileSystemConfigBuilder.getInstance().getIdentities(fileSystemOptions); if (knownHostsFile != null) { try { jsch.setKnownHosts(knownHostsFile.getAbsolutePath()); } catch (JSchException e) { throw new FileSystemException("vfs.provider.sftp/known-hosts.error", knownHostsFile.getAbsolutePath(), e); } } else { sshDir = findSshDir(); // Load the known hosts file knownHostsFile = new File(sshDir, "known_hosts"); if (knownHostsFile.isFile() && knownHostsFile.canRead()) { try { jsch.setKnownHosts(knownHostsFile.getAbsolutePath()); } catch (JSchException e) { throw new FileSystemException("vfs.provider.sftp/known-hosts.error", knownHostsFile.getAbsolutePath(), e); } } } if (identities != null) { for (int iterIdentities = 0; iterIdentities < identities.length; iterIdentities++) { final File privateKeyFile = identities[iterIdentities]; try { jsch.addIdentity(privateKeyFile.getAbsolutePath()); } catch (final JSchException e) { throw new FileSystemException("vfs.provider.sftp/load-private-key.error", privateKeyFile, e); } } } else { if (sshDir == null) { sshDir = findSshDir(); } // Load the private key (rsa-key only) final File privateKeyFile = new File(sshDir, "id_rsa"); if (privateKeyFile.isFile() && privateKeyFile.canRead()) { try { jsch.addIdentity(privateKeyFile.getAbsolutePath()); } catch (final JSchException e) { throw new FileSystemException("vfs.provider.sftp/load-private-key.error", privateKeyFile, e); } } } Session session; try { session = jsch.getSession(new String(username), hostname, port); if (password != null) { session.setPassword(new String(password)); } Integer timeout = SftpFileSystemConfigBuilder.getInstance().getTimeout(fileSystemOptions); if (timeout != null) { session.setTimeout(timeout.intValue()); } UserInfo userInfo = SftpFileSystemConfigBuilder.getInstance().getUserInfo(fileSystemOptions); if (userInfo != null) { session.setUserInfo(userInfo); } Properties config = new Properties(); //set StrictHostKeyChecking property String strictHostKeyChecking = SftpFileSystemConfigBuilder.getInstance() .getStrictHostKeyChecking(fileSystemOptions); if (strictHostKeyChecking != null) { config.setProperty("StrictHostKeyChecking", strictHostKeyChecking); } //set PreferredAuthentications property String preferredAuthentications = SftpFileSystemConfigBuilder.getInstance() .getPreferredAuthentications(fileSystemOptions); if (preferredAuthentications != null) { config.setProperty("PreferredAuthentications", preferredAuthentications); } //set compression property String compression = SftpFileSystemConfigBuilder.getInstance().getCompression(fileSystemOptions); if (compression != null) { config.setProperty("compression.s2c", compression); config.setProperty("compression.c2s", compression); } String proxyHost = SftpFileSystemConfigBuilder.getInstance().getProxyHost(fileSystemOptions); if (proxyHost != null) { int proxyPort = SftpFileSystemConfigBuilder.getInstance().getProxyPort(fileSystemOptions); SftpFileSystemConfigBuilder.ProxyType proxyType = SftpFileSystemConfigBuilder.getInstance() .getProxyType(fileSystemOptions); Proxy proxy = null; if (SftpFileSystemConfigBuilder.PROXY_HTTP.equals(proxyType)) { if (proxyPort != 0) { proxy = new ProxyHTTP(proxyHost, proxyPort); } else { proxy = new ProxyHTTP(proxyHost); } } else if (SftpFileSystemConfigBuilder.PROXY_SOCKS5.equals(proxyType)) { if (proxyPort != 0) { proxy = new ProxySOCKS5(proxyHost, proxyPort); } else { proxy = new ProxySOCKS5(proxyHost); } } if (proxy != null) { session.setProxy(proxy); } } //set properties for the session if (config.size() > 0) { session.setConfig(config); } session.setDaemonThread(true); session.connect(); } catch (final Exception exc) { throw new FileSystemException("vfs.provider.sftp/connect.error", new Object[] { hostname }, exc); } return session; }
From source file:com.pieframework.runtime.core.Installer.java
public static Properties generateProps(String inputs) { Properties prop = new Properties(); String os = Configuration.getOs(); String home = Request.findAttribute(inputs, "home"); if (os.contains("indow")) { if (StringUtils.empty(home)) { home = WINHOME;//from w ww . j av a 2s. c o m } home += "\\"; prop.setProperty("pie.javabin", "\"" + getWindowsPath( System.getProperty("java.home") + File.separator + "bin" + File.separator + "java.exe") + "\""); prop.setProperty("pie.data", home + "data" + File.separator); prop.setProperty("pie.tmp", home + "tmp" + File.separator); prop.setProperty("pie.lib", home + "lib" + File.separator); prop.setProperty("pie.ext", home + "ext" + File.separator); prop.setProperty("pie.log", "c:\\logs\\pie\\pie.log"); prop.setProperty("pie.bootstrap", home + "conf" + File.separator + "bootstrap.properties"); prop.setProperty("pie.pathseparator", File.separator); prop.setProperty("pie.jar", home + "pie.jar"); prop.setProperty("pie.home", home); prop.setProperty("pie.config", getPieConf(os, home).getPath()); prop.setProperty("pie.shell", "cmd.exe"); prop.setProperty("pie.shellparam", "/c"); prop.setProperty("pie.shellquote", "\""); } else if (os.contains("inux")) { if (StringUtils.empty(home)) { home = LINHOME; } home += "/"; prop.setProperty("pie.javabin", System.getProperty("java.home") + "/" + "bin" + "/" + "java"); prop.setProperty("pie.data", home + "data" + "/"); prop.setProperty("pie.tmp", home + "tmp" + "/"); prop.setProperty("pie.lib", home + "lib" + "/"); prop.setProperty("pie.ext", home + "ext" + "/"); prop.setProperty("pie.log", "/opt/apps/logs/pie/pie.log"); prop.setProperty("pie.bootstrap", home + "conf" + "/" + "bootstrap.properties"); prop.setProperty("pie.pathseparator", "/"); prop.setProperty("pie.jar", home + "pie.jar"); prop.setProperty("pie.home", home); prop.setProperty("pie.config", getPieConf(os, home).getPath()); prop.setProperty("pie.shell", "bash"); prop.setProperty("pie.shellparam", "-lc"); prop.setProperty("pie.shellquote", "\""); } else if (os.equalsIgnoreCase("cygwin")) { if (StringUtils.empty(home)) { home = CYGHOME; } home += "\\\\\\\\"; prop.setProperty("pie.javabin", "java"); prop.setProperty("pie.data", home + "data" + "\\\\\\\\"); prop.setProperty("pie.tmp", home + "tmp" + "\\\\\\\\"); prop.setProperty("pie.lib", home + "lib" + "\\\\\\\\"); prop.setProperty("pie.ext", home + "ext" + "\\\\\\\\"); prop.setProperty("pie.log", "c:\\\\\\\\logs\\\\\\\\pie\\\\\\\\pie.log"); prop.setProperty("pie.bootstrap", home + "conf" + "\\\\\\\\" + "bootstrap.properties"); prop.setProperty("pie.pathseparator", "\\\\\\\\"); prop.setProperty("pie.jar", home + "pie.jar"); prop.setProperty("pie.home", home); prop.setProperty("pie.config", getPieConf(os, home).getPath()); prop.setProperty("pie.shell", "bash"); prop.setProperty("pie.shellparam", "-lc"); prop.setProperty("pie.shellquote", "\""); } else { throw new RuntimeException("Installer failed. environment " + os + " is not supported."); } prop.setProperty("pie.username", "pieadmin"); prop.setProperty("pie.password", "LVd0tc0m"); prop.setProperty("pie.p4user", "<username>"); prop.setProperty("pie.p4serverURI", "p4java://<server>:<port>"); prop.setProperty("pie.p4client", "<p4_local_client>"); prop.setProperty("pie.sshstore", "<keystore>"); prop.setProperty("pie.cli", os); prop.setProperty("pie.puttyexe", "<path_to_putty>"); prop.setProperty("pie.verbosity", "*:!compile:!handler:!delegator:!debug:!ssh"); prop.setProperty("pie.acton[0]", "*:print"); prop.setProperty("pie.defaultTimeout", "180"); prop.setProperty("pie.currentModels", "<systemId>:<modelVersion>"); return prop; }
From source file:com.tvh.gmaildrafter.Drafter.java
private static void composeMail(Credentials credentials, String subjectText, String bodyText, String[] attachments, String[] attachmentnames, String[] destinations, String[] cc, String[] bcc, Boolean sendImmediately) throws IOException, AuthenticationFailedException { if (subjectText == null) { subjectText = ""; }// w ww. j av a 2 s . c om if (bodyText == null) { bodyText = ""; } try { Properties props = null; Session session = null; if (!sendImmediately) { props = System.getProperties(); props.setProperty("mail.store.protocol", "imaps"); session = Session.getDefaultInstance(props, null); } else { props = new Properties(); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.socketFactory.port", "465"); props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.port", "465"); final String username = credentials.getUsername(); final String password = credentials.getPassword(); session = Session.getInstance(props, new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } }); } String signature = Signature.getSignature(credentials); if (signature == null) signature = ""; // Create the message Message draftMail = new MimeMessage(session); draftMail.setSubject(subjectText); Multipart parts = new MimeMultipart(); BodyPart body = new MimeBodyPart(); if (bodyText.toLowerCase().indexOf("<body") < 0) // rough guess to see if the body is html { bodyText = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head><body>" + StringEscapeUtils.escapeHtml(bodyText).replace("\n", "<br />" + "\n") + "<br>" + "</body></html>"; } if (signature != null && signature != "") { StringBuilder b = new StringBuilder(bodyText); if (signature.indexOf("</") < 0) // assume it's html if there's no </, rough guess { signature = StringEscapeUtils.escapeHtml(signature); } b.replace(bodyText.lastIndexOf("</body>"), bodyText.lastIndexOf("</body>") + 7, "<br>" + signature + "</body>"); bodyText = b.toString(); } body.setContent(bodyText, "text/html; charset=utf-8"); body.setDisposition("inline"); parts.addBodyPart(body); if (attachments != null) { for (int i = 0; i < attachments.length; i++) { BodyPart attachment = new MimeBodyPart(); DataSource source = new FileDataSource(attachments[i]); attachment.setDataHandler(new DataHandler(source)); if (attachmentnames != null && attachmentnames.length > i) { attachment.setFileName(attachmentnames[i]); } else { File file = new File(attachments[i]); attachment.setFileName(file.getName()); } parts.addBodyPart(attachment); } } draftMail.setContent(parts); if (destinations != null && destinations.length > 0) draftMail.setRecipients(Message.RecipientType.TO, stringToInternetAddress(destinations)); if (cc != null && cc.length > 0) draftMail.setRecipients(Message.RecipientType.CC, stringToInternetAddress(cc)); if (bcc != null && bcc.length > 0) draftMail.setRecipients(Message.RecipientType.BCC, stringToInternetAddress(bcc)); draftMail.setFlag(Flags.Flag.SEEN, true); if (sendImmediately) { Transport.send(draftMail); } else { URLName url = new URLName("imaps://imap.gmail.com"); IMAPSSLStore store = new IMAPSSLStore(session, url); store.connect(credentials.getUsername(), credentials.getPassword()); Folder[] f = store.getDefaultFolder().xlist("*"); long threadId = 0; for (Folder fd : f) { IMAPFolder folder = (IMAPFolder) fd; boolean thisIsDrafts = false; String atts[] = folder.getAttributes(); for (String a : atts) { if (a.equalsIgnoreCase("\\Drafts")) { thisIsDrafts = true; break; } } if (thisIsDrafts) { folder.open(Folder.READ_WRITE); Message[] messages = new Message[1]; messages[0] = draftMail; folder.appendMessages(messages); /* * Determine the Google Message Id, needed to open it in the * browser. Because we just created the message it is * reasonable to assume it is the last message in the draft * folder. If this turns out not to be the case we could * start creating the message with a random unique dummy * subject, find it using that subject and then modify the * subject to what it was supposed to be. */ messages[0] = folder.getMessage(folder.getMessageCount()); FetchProfile fp = new FetchProfile(); fp.add(IMAPFolder.FetchProfileItem.X_GM_THRID); folder.fetch(messages, fp); IMAPMessage googleMessage = (IMAPMessage) messages[0]; threadId = googleMessage.getGoogleMessageThreadId(); folder.close(false); } } if (threadId == 0) { System.exit(6); } store.close(); // Open the message in the default browser Runtime rt = Runtime.getRuntime(); String drafturl = "https://mail.google.com/mail/#drafts/" + Long.toHexString(threadId); File chrome = new File("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"); if (!chrome.exists()) chrome = new File("C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"); if (!chrome.exists()) { // Chrome not found, using default browser rt.exec("rundll32 url.dll,FileProtocolHandler " + drafturl); } else { String[] commandLine = new String[2]; commandLine[0] = chrome.getPath(); commandLine[1] = drafturl; rt.exec(commandLine); } } // else branch for sendImmediately } catch (NoSuchProviderException e) { e.printStackTrace(); System.exit(4); } catch (AuthenticationFailedException e) { throw (e); } catch (MessagingException e) { e.printStackTrace(); System.exit(5); } }
From source file:com.datos.vfs.provider.sftp.SftpClientFactory.java
/** * Creates a new connection to the server. * * @param hostname The name of the host to connect to. * @param port The port to use.//from w w w. j a v a 2s . com * @param username The user's id. * @param password The user's password. * @param fileSystemOptions The FileSystem options. * @return A Session. * @throws FileSystemException if an error occurs. */ public static Session createConnection(final String hostname, final int port, final char[] username, final char[] password, final FileSystemOptions fileSystemOptions) throws FileSystemException { final JSch jsch = new JSch(); File sshDir = null; // new style - user passed final SftpFileSystemConfigBuilder builder = SftpFileSystemConfigBuilder.getInstance(); final File knownHostsFile = builder.getKnownHosts(fileSystemOptions); final IdentityInfo[] identities = builder.getIdentityInfo(fileSystemOptions); final IdentityRepositoryFactory repositoryFactory = builder.getIdentityRepositoryFactory(fileSystemOptions); sshDir = findSshDir(); setKnownHosts(jsch, sshDir, knownHostsFile); if (repositoryFactory != null) { jsch.setIdentityRepository(repositoryFactory.create(jsch)); } addIdentities(jsch, sshDir, identities); Session session; try { session = jsch.getSession(new String(username), hostname, port); if (password != null) { session.setPassword(new String(password)); } final Integer timeout = builder.getTimeout(fileSystemOptions); if (timeout != null) { session.setTimeout(timeout.intValue()); } final UserInfo userInfo = builder.getUserInfo(fileSystemOptions); if (userInfo != null) { session.setUserInfo(userInfo); } final Properties config = new Properties(); // set StrictHostKeyChecking property final String strictHostKeyChecking = builder.getStrictHostKeyChecking(fileSystemOptions); if (strictHostKeyChecking != null) { config.setProperty("StrictHostKeyChecking", strictHostKeyChecking); } // set PreferredAuthentications property final String preferredAuthentications = builder.getPreferredAuthentications(fileSystemOptions); if (preferredAuthentications != null) { config.setProperty("PreferredAuthentications", preferredAuthentications); } // set compression property final String compression = builder.getCompression(fileSystemOptions); if (compression != null) { config.setProperty("compression.s2c", compression); config.setProperty("compression.c2s", compression); } final String proxyHost = builder.getProxyHost(fileSystemOptions); if (proxyHost != null) { final int proxyPort = builder.getProxyPort(fileSystemOptions); final SftpFileSystemConfigBuilder.ProxyType proxyType = builder.getProxyType(fileSystemOptions); Proxy proxy = null; if (SftpFileSystemConfigBuilder.PROXY_HTTP.equals(proxyType)) { proxy = createProxyHTTP(proxyHost, proxyPort); } else if (SftpFileSystemConfigBuilder.PROXY_SOCKS5.equals(proxyType)) { proxy = createProxySOCKS5(proxyHost, proxyPort); } else if (SftpFileSystemConfigBuilder.PROXY_STREAM.equals(proxyType)) { proxy = createStreamProxy(proxyHost, proxyPort, fileSystemOptions, builder); } if (proxy != null) { session.setProxy(proxy); } } // set properties for the session if (config.size() > 0) { session.setConfig(config); } session.setDaemonThread(true); session.connect(); } catch (final Exception exc) { throw new FileSystemException("vfs.provider.sftp/connect.error", exc, hostname); } return session; }
From source file:dk.hippogrif.prettyxml.PrettyPrint.java
static void checkBoolean(String key, Properties prop) throws Exception { String s = prop.getProperty(key); if (s != null) { if ("false".equalsIgnoreCase(s)) { prop.setProperty(key, "false"); } else if ("true".equalsIgnoreCase(s)) { prop.setProperty(key, "true"); } else {//from w w w . j av a2 s .c o m throw new Exception("value of property " + key + " must be true or false, was: " + s); } } }
From source file:Main.java
public static boolean setProperty(String filePath, String fileName, String propertyName, List<String> propertyValueList) { try {// w w w. ja v a2s.c o m Properties p = loadPropertyInstance(filePath, fileName); StringBuilder propertyValue = new StringBuilder(); if (propertyValueList != null && propertyValueList.size() > 0) { for (String value : propertyValueList) { propertyValue.append( value.replaceAll("(\\\\)+$", "").replaceAll("\\\\", "\\\\\\\\").replaceAll(";", "\\\\;") + ";"); } } p.setProperty(propertyName, propertyValue.toString()); String comment = "Update '" + propertyName + "' value"; return storePropertyInstance(filePath, fileName, p, comment); } catch (Exception e) { e.printStackTrace(); return false; } }
From source file:com.adaptris.core.management.BootstrapProperties.java
private static Properties overrideWithSystemProperties(Properties p) { for (Map.Entry<String, String> kv : BOOTSTRAP_OVERRIDES.entrySet()) { String override = System.getProperty(kv.getKey()); if (!StringUtils.isBlank(override)) { log.trace("Overriding [{}] with [{}]", kv.getValue(), override); p.setProperty(kv.getValue(), override); }/*from ww w .j a va2 s . co m*/ } return p; }
From source file:com.piusvelte.taplock.server.TapLockServer.java
protected static void setTrayIconDisplay(boolean display) { sDisplaySystemTray = display;/* w ww . ja va 2 s . c om*/ Properties prop = new Properties(); try { prop.load(new FileInputStream(sProperties)); prop.setProperty(sDisplaySystemTrayKey, Boolean.toString(sDisplaySystemTray)); prop.store(new FileOutputStream(sProperties), null); } catch (FileNotFoundException e) { writeLog("prop load: " + e.getMessage()); } catch (IOException e) { writeLog("prop load: " + e.getMessage()); } }