List of usage examples for java.lang System getProperties
public static Properties getProperties()
From source file:jp.mamesoft.mailsocketchat.Mail.java
public void run() { while (true) { try {// w w w . ja va 2 s .c o m System.out.println("????"); Properties props = System.getProperties(); // Get a Session object Session session = Session.getInstance(props, null); // session.setDebug(true); // Get a Store object Store store = session.getStore("imaps"); // Connect store.connect("imap.gmail.com", 993, Mailsocketchat.mail_user, Mailsocketchat.mail_pass); System.out.println("??????"); // Open a Folder Folder folder = store.getFolder("INBOX"); if (folder == null || !folder.exists()) { System.out.println("IMAP??????"); System.exit(1); } folder.open(Folder.READ_WRITE); // Add messageCountListener to listen for new messages folder.addMessageCountListener(new MessageCountAdapter() { public void messagesAdded(MessageCountEvent ev) { Message[] msgs = ev.getMessages(); // Just dump out the new messages for (int i = 0; i < msgs.length; i++) { try { System.out.println("?????"); InternetAddress addrfrom = (InternetAddress) msgs[i].getFrom()[0]; String subject = msgs[i].getSubject(); if (subject == null) { subject = ""; } Pattern hashtag_p = Pattern.compile("#(.+)"); Matcher hashtag_m = hashtag_p.matcher(subject); if (subject.equals("#")) { hashtag = null; } else if (hashtag_m.find()) { hashtag = hashtag_m.group(1); } String comment = msgs[i].getContent().toString().replaceAll("\r\n", " "); comment = comment.replaceAll("\n", " "); comment = comment.replaceAll("\r", " "); JSONObject data = new JSONObject(); data.put("comment", comment); if (hashtag != null) { data.put("channel", hashtag); } if (!comment.equals("") && !comment.equals(" ") && !comment.equals(" ")) { Mailsocketchat.socket.emit("say", data); System.out.println("????"); } // if (subject.equals("push") || subject.equals("Push") || subject.equals("")) { Send(addrfrom.getAddress(), 2); Mailsocketchat.push = true; Mailsocketchat.repeat = false; Mailsocketchat.address = addrfrom.getAddress(); repeatthread.cancel(); repeatthread = null; System.out.println("?????"); } else if (subject.equals("fetch") || subject.equals("Fetch") || subject.equals("?")) { Send(addrfrom.getAddress(), 3); Mailsocketchat.push = false; Mailsocketchat.repeat = false; repeatthread.cancel(); repeatthread = null; System.out.println("??????"); } else if (subject.equals("repeat") || subject.equals("Repeat") || subject.equals("")) { Send(addrfrom.getAddress(), 7); Mailsocketchat.push = false; Mailsocketchat.repeat = true; Mailsocketchat.address = addrfrom.getAddress(); if (repeatthread == null) { repeatthread = new Repeat(); repeat = new Timer(); } repeat.schedule(repeatthread, 0, 30 * 1000); System.out.println("?????"); } else if (subject.equals("list") || subject.equals("List") || subject.equals("")) { Send(addrfrom.getAddress(), 4); } else if (subject.equals("help") || subject.equals("Help") || subject.equals("")) { Send(addrfrom.getAddress(), 5); } else { if (!Mailsocketchat.push && !Mailsocketchat.repeat) { Send(addrfrom.getAddress(), 0); } else if (comment.equals("") || comment.equals(" ") || comment.equals(" ")) { Send(addrfrom.getAddress(), 5); } } } catch (IOException ioex) { System.out.println( "??????????"); } catch (MessagingException mex) { System.out.println( "??????????"); } } } }); // Check mail once in "freq" MILLIseconds int freq = 1000; //?? boolean supportsIdle = false; try { if (folder instanceof IMAPFolder) { IMAPFolder f = (IMAPFolder) folder; f.idle(); supportsIdle = true; } } catch (FolderClosedException fex) { throw fex; } catch (MessagingException mex) { supportsIdle = false; } for (;;) { if (supportsIdle && folder instanceof IMAPFolder) { IMAPFolder f = (IMAPFolder) folder; f.idle(); } else { Thread.sleep(freq); // sleep for freq milliseconds // This is to force the IMAP server to send us // EXISTS notifications. folder.getMessageCount(); } } } catch (Exception ex) { System.out.println("??????????"); } } }
From source file:com.alibaba.citrus.service.form.impl.MessageContextFactory.java
/** * formcontext//www . jav a2s . c o m * <ol> * <li><code>System.getProperties()</code></li> * <li><code>stringUtil</code><code>stringEscapeUtil</code></li> * </ol> */ public static MessageContext newInstance(final Form form) { MessageContext formContext = new MessageContext() { private static final long serialVersionUID = 3833185835016140853L; @Override protected Object internalGet(String key) { return null; } @Override public ExpressionContext getParentContext() { return null; } @Override protected void buildToString(ToStringBuilder sb) { sb.append("FormMessageContext"); } @Override protected void buildToString(MapBuilder mb) { mb.append("form", form); } }; Map<String, Object> utils = Utils.getUtils(); formContext.putAll(System.getProperties()); formContext.putAll(utils); return formContext; }
From source file:EmailBean.java
public void sendMessage() throws Exception { Properties properties = System.getProperties(); //populate the 'Properties' object with the mail //server address, so that the default 'Session' //instance can use it. properties.put("mail.smtp.host", smtpHost); Session session = Session.getDefaultInstance(properties); Message mailMsg = new MimeMessage(session);//a new email message InternetAddress[] addresses = null;// w ww . j a v a 2s. c om try { if (to != null) { //throws 'AddressException' if the 'to' email address //violates RFC822 syntax addresses = InternetAddress.parse(to, false); mailMsg.setRecipients(Message.RecipientType.TO, addresses); } else { throw new MessagingException("The mail message requires a 'To' address."); } if (from != null) { mailMsg.setFrom(new InternetAddress(from)); } else { throw new MessagingException("The mail message requires a valid 'From' address."); } if (subject != null) mailMsg.setSubject(subject); if (content != null) mailMsg.setText(content); //Finally, send the mail message; throws a 'SendFailedException' //if any of the message's recipients have an invalid address Transport.send(mailMsg); } catch (Exception exc) { throw exc; } }
From source file:com.roche.iceboar.settings.GlobalSettingsFactory.java
/** * Reads system properties (incl. those specified in JNLP file). * * @param args// www. j a v a 2 s . c o m */ public static GlobalSettings getGlobalSettings(String[] args) { long jvmStartTime = ManagementFactory.getRuntimeMXBean().getStartTime(); String codeBase = getCodeBase(); Properties properties = System.getProperties(); boolean showDebug = getShowDebug(properties); String frameTitle = properties.getProperty(JNLP_FRAME_TITLE, DEFAULT_FRAME_TITLE); String currentJavaVersion = properties.getProperty(JAVA_VERSION); String targetJavaVersion = getTargetJavaVersion(currentJavaVersion, properties); String tempDirectory = properties.getProperty(TEMP_DIRECTORY); String mainClass = properties.getProperty(JNLP_MAIN_CLASS); String targetJavaURL = getTargetJavaUrl(codeBase, properties); List<String> jarURLs = getDependenciesJars(codeBase, properties); List<String> allPropertiesForTarget = getAllPropertiesForTarget(properties); String initialHeapSize = properties.getProperty(JNLP_INITIAL_HEAP_SIZE); String maxHeapSize = properties.getProperty(JNLP_MAX_HEAP_SIZE); String javaVmArgs = properties.getProperty(JNLP_JAVA_VM_ARGS); String operationSystemName = properties.getProperty(OS_NAME); String pathSeparator = properties.getProperty(PATH_SEPARATOR); boolean closeOnEnd = getCloseOnEnd(properties); String cachePath = tempDirectory + ".IceBoar.cache"; CacheStatus cacheStatus = getCacheStatus(cachePath); List<String> icons = getIcons(codeBase, properties); String splash = getSplashScreen(codeBase, properties); boolean hideFrameBorder = getHideFrameBorder(properties); GlobalSettings settings = GlobalSettings.builder().applicationArguments(args).jvmStartTime(jvmStartTime) .showDebug(showDebug).frameTitle(frameTitle).currentJavaVersion(currentJavaVersion) .targetJavaVersion(targetJavaVersion).tempDirectory(tempDirectory).mainClass(mainClass) .targetJavaURL(targetJavaURL).jarURLs(jarURLs).allPropertiesForTarget(allPropertiesForTarget) .operationSystemName(operationSystemName).pathSeparator(pathSeparator) .initialHeapSize(initialHeapSize).maxHeapSize(maxHeapSize).javaVmArgs(javaVmArgs) .closeOnEnd(closeOnEnd).cachePath(cachePath).cacheStatus(cacheStatus).icons(icons) .customSplashImage(splash).hideFrameBorder(hideFrameBorder).build(); return settings; }
From source file:com.streamsets.datacollector.main.TestLogConfigurator.java
@After public void cleanUp() throws Exception { System.getProperties().remove("log4j.configuration"); System.getProperties().remove("log4j.defaultInitOverride"); for (Thread thread : Thread.getAllStackTraces().keySet()) { if (thread instanceof FileWatchdog) { Field interrupted = ((Class) thread.getClass().getGenericSuperclass()) .getDeclaredField("interrupted"); interrupted.setAccessible(true); interrupted.set(thread, true); thread.interrupt();/*from w w w .j a v a2 s.c o m*/ } } }
From source file:ar.com.zauber.commons.spring.configurers.SystemPropertyPlaceholderConfigurer.java
/** constructor */ public SystemPropertyPlaceholderConfigurer() { setLocation(new AbstractResource() { public String getDescription() { return "system properties"; }//from ww w . j av a2 s .c o m public InputStream getInputStream() throws IOException { final ByteArrayOutputStream os = new ByteArrayOutputStream(); System.getProperties().store(os, null); return new ByteArrayInputStream(os.toByteArray()); } /** @see AbstractResource#getFilename() */ @Override public String getFilename() throws IllegalStateException { return "system.properties"; } }); }
From source file:org.hyperic.hq.hqapi1.tools.AbstractCommand.java
private static void configureLogging(String level) { Properties props = new Properties(); props.setProperty("log4j.rootLogger", level.toUpperCase() + ", R"); props.setProperty("log4j.logger.httpclient.wire", level.toUpperCase()); props.setProperty("log4j.logger.org.apache.commons.httpclient", level.toUpperCase()); for (String[] PROPS : LOG_PROPS) { props.setProperty(PROPS[0], PROPS[1]); }/*from w w w . j ava 2 s .c o m*/ props.putAll(System.getProperties()); PropertyConfigurator.configure(props); }
From source file:com.npower.dm.server.engine.EngineConfig.java
public synchronized static Properties getProperties() throws DMException { if (properties != null) { return properties; }/*from ww w.ja va 2 s. co m*/ properties = new Properties(System.getProperties()); try { InputStream propertiesIns = null; String home = System.getProperty(Constances.PROPERTY_HOME); log.info(Constances.PROPERTY_HOME + ": " + home); if (home != null) { File homeDir = new File(home); File propertiesFile = null; if (homeDir.exists()) { propertiesFile = new File(homeDir, PROPERTIES_FILE_LOCATION); } if (propertiesFile != null && propertiesFile.exists()) { propertiesIns = new FileInputStream(propertiesFile); log.info("Using DM properties file: " + propertiesFile.getAbsolutePath()); } } if (propertiesIns != null) { properties.load(propertiesIns); } return properties; } catch (FileNotFoundException e) { throw new DMException("Error to load management bean properties file.", e); } catch (IOException e) { throw new DMException("Error to load management bean properties file.", e); } }
From source file:com.vladsch.flexmark.page.generator.plugin.BetterAbstractMojoTestCase.java
protected MavenSession newMavenSession() { try {/*from w w w. ja va2 s .c o m*/ MavenExecutionRequest request = new DefaultMavenExecutionRequest(); MavenExecutionResult result = new DefaultMavenExecutionResult(); // populate sensible defaults, including repository basedir and remote repos MavenExecutionRequestPopulator populator; populator = getContainer().lookup(MavenExecutionRequestPopulator.class); populator.populateDefaults(request); // this is needed to allow java profiles to get resolved; i.e. avoid during project builds: // [ERROR] Failed to determine Java version for profile java-1.5-detected @ org.apache.commons:commons-parent:22, /Users/alex/.m2/repository/org/apache/commons/commons-parent/22/commons-parent-22.pom, line 909, column 14 request.setSystemProperties(System.getProperties()); // and this is needed so that the repo session in the maven session // has a repo manager, and it points at the local repo // (cf MavenRepositorySystemUtils.newSession() which is what is otherwise done) DefaultMaven maven = (DefaultMaven) getContainer().lookup(Maven.class); DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) maven .newRepositorySession(request); repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory().newInstance(repoSession, new LocalRepository(request.getLocalRepository().getBasedir()))); @SuppressWarnings("deprecation") MavenSession session = new MavenSession(getContainer(), repoSession, request, result); return session; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.ruleoftech.markdown.page.generator.plugin.BetterAbstractMojoTestCase.java
protected MavenSession newMavenSession() { try {/* w w w . ja v a 2 s.c o m*/ MavenExecutionRequest request = new DefaultMavenExecutionRequest(); MavenExecutionResult result = new DefaultMavenExecutionResult(); // populate sensible defaults, including repository basedir and remote repos MavenExecutionRequestPopulator populator; populator = getContainer().lookup(MavenExecutionRequestPopulator.class); populator.populateDefaults(request); // this is needed to allow java profiles to get resolved; i.e. avoid during project builds: // [ERROR] Failed to determine Java version for profile java-1.5-detected @ org.apache.commons:commons-parent:22, /Users/alex/.m2/repository/org/apache/commons/commons-parent/22/commons-parent-22.pom, line 909, column 14 request.setSystemProperties(System.getProperties()); // and this is needed so that the repo session in the maven session // has a repo manager, and it points at the local repo // (cf MavenRepositorySystemUtils.newSession() which is what is otherwise done) DefaultMaven maven = (DefaultMaven) getContainer().lookup(Maven.class); DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) maven .newRepositorySession(request); repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory().newInstance(repoSession, new LocalRepository(request.getLocalRepository().getBasedir()))); @SuppressWarnings("deprecation") MavenSession session = new MavenSession(getContainer(), repoSession, request, result); return session; } catch (Exception e) { throw new RuntimeException(e); } }