List of usage examples for java.util Properties setProperty
public synchronized Object setProperty(String key, String value)
From source file:com.piusvelte.taplock.server.TapLockServer.java
protected static void setDebugging(boolean debugging) { if (sDebugging) writeLog("debugging stopped"); sDebugging = debugging;//from w ww. j a va 2s .c o m if (sDebugging) writeLog("debugging started"); Properties prop = new Properties(); try { prop.load(new FileInputStream(sProperties)); prop.setProperty(sDebuggingKey, Boolean.toString(sDebugging)); prop.store(new FileOutputStream(sProperties), null); } catch (FileNotFoundException e) { writeLog("prop load: " + e.getMessage()); } catch (IOException e) { writeLog("prop load: " + e.getMessage()); } }
From source file:com.puppycrawl.tools.checkstyle.XDocsPagesTest.java
private static void testCheckstyleXml(String fileName, String code, String unserializedSource) throws IOException { // can't process non-existent examples, or out of context snippets if (code.contains("com.mycompany") || code.contains("checkstyle-packages") || code.contains("MethodLimit") || code.contains("<suppress ") || code.contains("<import-control ") || unserializedSource.startsWith("<property ") || unserializedSource.startsWith("<taskdef ")) { return;//from w ww . jav a2 s. c o m } // validate checkstyle structure and contents try { final Properties properties = new Properties(); properties.setProperty("checkstyle.header.file", new File("config/java.header").getCanonicalPath()); final PropertiesExpander expander = new PropertiesExpander(properties); final Configuration config = ConfigurationLoader .loadConfiguration(new InputSource(new StringReader(code)), expander, false); final Checker checker = new Checker(); try { final ClassLoader moduleClassLoader = Checker.class.getClassLoader(); checker.setModuleClassLoader(moduleClassLoader); checker.configure(config); } finally { checker.destroy(); } } catch (CheckstyleException e) { Assert.fail(fileName + " has invalid Checkstyle xml (" + e.getMessage() + "): " + unserializedSource); } }
From source file:com.tesora.dve.common.PEUrl.java
/** * Initialize with the information contained in <code>connectString</code> * /* www . jav a 2 s . c om*/ * @param connectString * - a String representing parameters for a URL in * "connect string" format. e.g. * "host=localhost;port=3306;dbname=dve_catalog" * @throws PEException * - if <code>connectString</code> is malformed - connectString * must contain at least a "host" token * */ public static PEUrl fromConnectString(String connectString) throws PEException { PEUrl url = new PEUrl(); // TODO this "parser" will not handle embedded delimeters String delims = "[=;]"; String[] tokens = connectString.split(delims); if (tokens.length % 2 != 0) throw new PEException("Connect String does not contain the correct number of elements"); Properties props = new Properties(); for (int i = 0; i < tokens.length; i = i + 2) { props.setProperty(tokens[i], tokens[i + 1]); } url.initializeFromProps(props, null /* prefix */, false /* useDefaults */); if (!url.isInitialized()) throw new PEException("Error creating URL object from connect string: " + connectString); return url; }
From source file:com.piusvelte.taplock.server.TapLockServer.java
protected static void setPassphrase(String passphrase) { Properties prop = new Properties(); try {//from w w w .j a v a2 s . c o m prop.load(new FileInputStream(sProperties)); prop.setProperty(sPassphraseKey, passphrase); prop.store(new FileOutputStream(sProperties), null); } catch (FileNotFoundException e) { writeLog("prop load: " + e.getMessage()); } catch (IOException e) { writeLog("prop load: " + e.getMessage()); } if (OS == OS_WIN) { KeyStore ks = getKeyStore(); if (ks != null) { SecretKey sk = getSecretKey(ks); if (ks != null) { try { ks.setKeyEntry(TAP_LOCK, sk, sPassphrase.toCharArray(), null); ks.store(new FileOutputStream(sKeystore), sPassphrase.toCharArray()); } catch (KeyStoreException e) { writeLog("change key password: " + e.getMessage()); } catch (NoSuchAlgorithmException e) { writeLog("change key password: " + e.getMessage()); } catch (CertificateException e) { writeLog("change key password: " + e.getMessage()); } catch (FileNotFoundException e) { writeLog("change key password: " + e.getMessage()); } catch (IOException e) { writeLog("change key password: " + e.getMessage()); } } } } sPassphrase = passphrase; }
From source file:com.sun.socialsite.business.EmfProvider.java
/** * Called once (and only once) to find and initialize our EMF. */// w w w .j a v a 2s . c o m private static EntityManagerFactory initEmf() throws SocialSiteException { String jpaConfigurationType = Config.getProperty("jpa.configurationType"); log.info("jpaConfigurationType=" + jpaConfigurationType); if ("jndi".equals(jpaConfigurationType)) { String emfJndiName = "java:comp/env/" + Config.getProperty("jpa.emf.jndi.name"); log.info("emfJndiName=" + emfJndiName); try { return (EntityManagerFactory) new InitialContext().lookup(emfJndiName); } catch (NamingException e) { throw new SocialSiteException("Could not look up EntityManagerFactory in jndi at " + emfJndiName, e); } } else { DatabaseProvider dbProvider = Startup.getDatabaseProvider(); // Pull in any settings defined in our EMF properties file Properties emfProps = loadPropertiesFromResourceName(EMF_PROPS, getContextClassLoader()); // Add all OpenJPA and Toplinks properties found in Config for (String key : Config.keySet()) { if (key.startsWith("openjpa.") || key.startsWith("toplink.")) { String value = Config.getProperty(key); log.info(key + ": " + value); emfProps.setProperty(key, value); } } if (dbProvider.getType() == DatabaseProvider.ConfigurationType.JNDI_NAME) { // We're doing JNDI, so set OpenJPA JNDI name property String jndiName = "java:comp/env/" + dbProvider.getJndiName(); emfProps.setProperty("openjpa.ConnectionFactoryName", jndiName); } else { // So set JDBC properties for OpenJPA emfProps.setProperty("openjpa.ConnectionDriverName", dbProvider.getJdbcDriverClass()); emfProps.setProperty("openjpa.ConnectionURL", dbProvider.getJdbcConnectionURL()); emfProps.setProperty("openjpa.ConnectionUserName", dbProvider.getJdbcUsername()); emfProps.setProperty("openjpa.ConnectionPassword", dbProvider.getJdbcPassword()); // And Toplink JPA emfProps.setProperty("eclipselink.jdbc.driver", dbProvider.getJdbcDriverClass()); emfProps.setProperty("eclipselink.jdbc.url", dbProvider.getJdbcConnectionURL()); emfProps.setProperty("eclipselink.jdbc.user", dbProvider.getJdbcUsername()); emfProps.setProperty("eclipselink.jdbc.password", dbProvider.getJdbcPassword()); // And Toplink JPA emfProps.setProperty("toplink.jdbc.driver", dbProvider.getJdbcDriverClass()); emfProps.setProperty("toplink.jdbc.url", dbProvider.getJdbcConnectionURL()); emfProps.setProperty("toplink.jdbc.user", dbProvider.getJdbcUsername()); emfProps.setProperty("toplink.jdbc.password", dbProvider.getJdbcPassword()); // And Hibernate JPA emfProps.setProperty("hibernate.connection.driver_class", dbProvider.getJdbcDriverClass()); emfProps.setProperty("hibernate.connection.url", dbProvider.getJdbcConnectionURL()); emfProps.setProperty("hibernate.connection.username", dbProvider.getJdbcUsername()); emfProps.setProperty("hibernate.connection.password", dbProvider.getJdbcPassword()); } try { String puName = Config.getProperty("socialsite.puname", "SocialSite_PU"); return Persistence.createEntityManagerFactory(puName, emfProps); } catch (PersistenceException pe) { log.error("Failed to create entity manager", pe); throw new SocialSiteException(pe); } } }
From source file:mas.MAS_TOP_PAPERS.java
/** * @param args the command line arguments *//* w ww . j a v a 2 s . co m*/ // for old version public static void getData(int startIdx, int endIdx) { try { Properties prop = new Properties(); prop.setProperty("AppId", "1df63064-efad-4bbd-a797-1131499b7728"); prop.setProperty("ResultObjects", "publication"); prop.setProperty("DomainID", "22"); prop.setProperty("SubDomainID", "2"); prop.setProperty("YearStart", "2001"); prop.setProperty("YearEnd", "2010"); prop.setProperty("StartIdx", startIdx + ""); prop.setProperty("EndIdx", endIdx + ""); String url_org = "http://academic.research.microsoft.com/json.svc/search"; String url_str = generateURL(url_org, prop); URL url = new URL(url_str); URLConnection yc = url.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) { System.out.println(inputLine); } in.close(); } catch (MalformedURLException ex) { Logger.getLogger(MAS_TOP_PAPERS.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(MAS_TOP_PAPERS.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:emp.cloud.pigutils.EmbeddedPigRunner.java
static int executeScript(Configuration hadoopConfig, PigProgressNotificationListener listener, String taskName, String script) throws Throwable { boolean verbose = false; boolean gruntCalled = false; String logFileName = null;/*from www . ja va 2s . c o m*/ try { Properties properties = new Properties(); PropertiesUtil.loadDefaultProperties(properties); properties.putAll(ConfigurationUtil.toProperties(hadoopConfig)); HashSet<String> optimizerRules = new HashSet<String>(); ExecType execType = ExecType.MAPREDUCE; if (properties.getProperty("aggregate.warning") == null) { // by default warning aggregation is on properties.setProperty("aggregate.warning", "" + true); } if (properties.getProperty("opt.multiquery") == null) { // by default multiquery optimization is on properties.setProperty("opt.multiquery", "" + true); } if (properties.getProperty("stop.on.failure") == null) { // by default we keep going on error on the backend properties.setProperty("stop.on.failure", "" + false); } // set up client side system properties in UDF context UDFContext.getUDFContext().setClientSystemProps(properties); // create the context with the parameter PigContext pigContext = new PigContext(execType, properties); // create the static script state object ScriptState scriptState = ScriptState.start("", pigContext); if (listener != null) { scriptState.registerListener(listener); } if (!Boolean.valueOf(properties.getProperty(PROP_FILT_SIMPL_OPT, "false"))) { // turn off if the user has not explicitly turned on this // optimization optimizerRules.add("FilterLogicExpressionSimplifier"); } if (optimizerRules.size() > 0) { pigContext.getProperties().setProperty("pig.optimizer.rules", ObjectSerializer.serialize(optimizerRules)); } if (properties.get("udf.import.list") != null) PigContext.initializeImportList((String) properties.get("udf.import.list")); PigContext.setClassLoader(pigContext.createCl(null)); pigContext.getProperties().setProperty(PigContext.JOB_NAME, taskName); Grunt grunt = null; BufferedReader in; scriptState.setScript(script); in = new BufferedReader(new StringReader(script)); grunt = new Grunt(in, pigContext); gruntCalled = true; int results[] = grunt.exec(); return getReturnCodeForStats(results); // } catch (Exception e) { // if (e instanceof PigException) { // PigException pe = (PigException) e; // int rc = (pe.retriable()) ? ReturnCode.RETRIABLE_EXCEPTION // : ReturnCode.PIG_EXCEPTION; // PigStatsUtil.setErrorCode(pe.getErrorCode()); // } // PigStatsUtil.setErrorMessage(e.getMessage()); // // if (!gruntCalled) { // LogUtils.writeLog(e, logFileName, log, verbose, // "Error before Pig is launched"); // } // FileLocalizer.deleteTempFiles(); // // if (!gruntCalled) { // LogUtils.writeLog(e, logFileName, log, verbose, // "Error before Pig is launched"); // } // throw e; // } catch (Throwable e) { // PigStatsUtil.setErrorMessage(e.getMessage()); // throw new IllegalStateException(e); } finally { // clear temp files FileLocalizer.deleteTempFiles(); } }
From source file:info.magnolia.importexport.PropertiesImportExport.java
public static void appendNodeProperties(Content node, Properties out) { final Collection<NodeData> props = node.getNodeDataCollection(); for (NodeData prop : props) { final String path = getExportPath(node) + "." + prop.getName(); String propertyValue = getPropertyString(prop); if (propertyValue != null) { out.setProperty(path, propertyValue); }/*from w w w.ja va 2s . c o m*/ } }
From source file:com.xemantic.tadedon.configuration.Configurations.java
public static Properties toProperties(Configuration configuraton) { Properties properties = new Properties(); for (@SuppressWarnings("unchecked") Iterator<String> iterator = configuraton.getKeys(); iterator.hasNext();) { String key = iterator.next(); Object objValue = configuraton.getProperty(key); String value;// w ww . j a va 2 s . c o m if (objValue instanceof String) { value = (String) objValue; } else { value = objValue.toString(); } properties.setProperty(key, value); } return properties; }
From source file:com.emc.kibana.emailer.KibanaEmailer.java
private static void sendFileEmail(String security) { final String username = smtpUsername; final String password = smtpPassword; // Get system properties Properties properties = System.getProperties(); // Setup mail server properties.setProperty("mail.smtp.host", smtpHost); if (security.equals(SMTP_SECURITY_TLS)) { properties.put("mail.smtp.auth", "true"); properties.put("mail.smtp.starttls.enable", "true"); properties.put("mail.smtp.host", smtpHost); properties.put("mail.smtp.port", smtpPort); } else if (security.equals(SMTP_SECURITY_SSL)) { properties.put("mail.smtp.socketFactory.port", smtpPort); properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); properties.put("mail.smtp.auth", "true"); properties.put("mail.smtp.port", smtpPort); }/* w w w . j a va2 s. c o m*/ Session session = Session.getInstance(properties, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } }); try { // Create a default MimeMessage object. MimeMessage message = new MimeMessage(session); // Set From: header field of the header. message.setFrom(new InternetAddress(sourceAddress)); // Set To: header field of the header. for (String destinationAddress : destinationAddressList) { message.addRecipient(Message.RecipientType.TO, new InternetAddress(destinationAddress)); } // Set Subject: header field message.setSubject(mailTitle); // Create the message part BodyPart messageBodyPart = new MimeBodyPart(); StringBuffer bodyBuffer = new StringBuffer(mailBody); if (!kibanaUrls.isEmpty()) { bodyBuffer.append("\n\n"); } // Add urls info to e-mail for (Map<String, String> kibanaUrl : kibanaUrls) { // Add urls to e-mail String urlName = kibanaUrl.get(NAME_KEY); String reportUrl = kibanaUrl.get(URL_KEY); if (urlName != null && reportUrl != null) { bodyBuffer.append("- ").append(urlName).append(": ").append(reportUrl).append("\n\n\n"); } } // Fill the message messageBodyPart.setText(bodyBuffer.toString()); // Create a multipart message Multipart multipart = new MimeMultipart(); // Set text message part multipart.addBodyPart(messageBodyPart); // Part two is attachments for (Map<String, String> kibanaScreenCapture : kibanaScreenCaptures) { messageBodyPart = new MimeBodyPart(); String absoluteFilename = kibanaScreenCapture.get(ABSOLUE_FILE_NAME_KEY); String filename = kibanaScreenCapture.get(FILE_NAME_KEY); DataSource source = new FileDataSource(absoluteFilename); messageBodyPart.setDataHandler(new DataHandler(source)); messageBodyPart.setFileName(filename); multipart.addBodyPart(messageBodyPart); } // Send the complete message parts message.setContent(multipart); // Send message Transport.send(message); logger.info("Sent mail message successfully"); } catch (MessagingException mex) { throw new RuntimeException(mex); } }