List of usage examples for java.util Properties isEmpty
@Override public boolean isEmpty()
From source file:org.apache.tomcat.maven.runner.Tomcat7RunnerCli.java
public static void main(String[] args) throws Exception { CommandLineParser parser = new GnuParser(); CommandLine line = null;//from ww w. j a va 2s. c o m try { line = parser.parse(Tomcat7RunnerCli.options, args); } catch (ParseException e) { System.err.println("Parsing failed. Reason: " + e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(getCmdLineSyntax(), Tomcat7RunnerCli.options); System.exit(1); } if (line.hasOption(help.getOpt())) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(getCmdLineSyntax(), Tomcat7RunnerCli.options); System.exit(0); } if (line.hasOption(obfuscate.getOpt())) { System.out.println(PasswordUtil.obfuscate(line.getOptionValue(obfuscate.getOpt()))); System.exit(0); } Tomcat7Runner tomcat7Runner = new Tomcat7Runner(); tomcat7Runner.runtimeProperties = buildStandaloneProperties(); if (line.hasOption(serverXmlPath.getOpt())) { tomcat7Runner.serverXmlPath = line.getOptionValue(serverXmlPath.getOpt()); } String port = tomcat7Runner.runtimeProperties.getProperty(Tomcat7Runner.HTTP_PORT_KEY); if (port != null) { tomcat7Runner.httpPort = Integer.parseInt(port); } // cli win for the port if (line.hasOption(httpPort.getOpt())) { tomcat7Runner.httpPort = Integer.parseInt(line.getOptionValue(httpPort.getOpt())); } if (line.hasOption(maxPostSize.getOpt())) { tomcat7Runner.maxPostSize = Integer.parseInt(line.getOptionValue(maxPostSize.getOpt())); } if (line.hasOption(httpsPort.getOpt())) { tomcat7Runner.httpsPort = Integer.parseInt(line.getOptionValue(httpsPort.getOpt())); } if (line.hasOption(ajpPort.getOpt())) { tomcat7Runner.ajpPort = Integer.parseInt(line.getOptionValue(ajpPort.getOpt())); } if (line.hasOption(resetExtract.getOpt())) { tomcat7Runner.resetExtract = true; } if (line.hasOption(debug.getOpt())) { tomcat7Runner.debug = true; } if (line.hasOption(httpProtocol.getOpt())) { tomcat7Runner.httpProtocol = line.getOptionValue(httpProtocol.getOpt()); } if (line.hasOption(sysProps.getOpt())) { Properties systemProperties = line.getOptionProperties(sysProps.getOpt()); if (systemProperties != null && !systemProperties.isEmpty()) { for (Map.Entry<Object, Object> sysProp : systemProperties.entrySet()) { System.setProperty((String) sysProp.getKey(), (String) sysProp.getValue()); } } } if (line.hasOption(clientAuth.getOpt())) { tomcat7Runner.clientAuth = clientAuth.getOpt(); } if (line.hasOption(keyAlias.getOpt())) { tomcat7Runner.keyAlias = line.getOptionValue(keyAlias.getOpt()); } if (line.hasOption(extractDirectory.getOpt())) { tomcat7Runner.extractDirectory = line.getOptionValue(extractDirectory.getOpt()); } if (line.hasOption(loggerName.getOpt())) { tomcat7Runner.loggerName = line.getOptionValue(loggerName.getOpt()); } if (line.hasOption(uriEncoding.getOpt())) { tomcat7Runner.uriEncoding = line.getOptionValue(uriEncoding.getOpt()); } // here we go tomcat7Runner.run(); }
From source file:org.apache.tomcat.maven.runner.Tomcat8RunnerCli.java
public static void main(String[] args) throws Exception { CommandLineParser parser = new GnuParser(); CommandLine line = null;//www . j a v a 2 s . com try { line = parser.parse(Tomcat8RunnerCli.options, args); } catch (ParseException e) { System.err.println("Parsing failed. Reason: " + e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(getCmdLineSyntax(), Tomcat8RunnerCli.options); System.exit(1); } if (line.hasOption(help.getOpt())) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(getCmdLineSyntax(), Tomcat8RunnerCli.options); System.exit(0); } if (line.hasOption(obfuscate.getOpt())) { System.out.println(PasswordUtil.obfuscate(line.getOptionValue(obfuscate.getOpt()))); System.exit(0); } Tomcat8Runner tomcat8Runner = new Tomcat8Runner(); tomcat8Runner.runtimeProperties = buildStandaloneProperties(); if (line.hasOption(serverXmlPath.getOpt())) { tomcat8Runner.serverXmlPath = line.getOptionValue(serverXmlPath.getOpt()); } String port = tomcat8Runner.runtimeProperties.getProperty(Tomcat8Runner.HTTP_PORT_KEY); if (port != null) { tomcat8Runner.httpPort = Integer.parseInt(port); } // cli win for the port if (line.hasOption(httpPort.getOpt())) { tomcat8Runner.httpPort = Integer.parseInt(line.getOptionValue(httpPort.getOpt())); } if (line.hasOption(maxPostSize.getOpt())) { tomcat8Runner.maxPostSize = Integer.parseInt(line.getOptionValue(maxPostSize.getOpt())); } if (line.hasOption(httpsPort.getOpt())) { tomcat8Runner.httpsPort = Integer.parseInt(line.getOptionValue(httpsPort.getOpt())); } if (line.hasOption(ajpPort.getOpt())) { tomcat8Runner.ajpPort = Integer.parseInt(line.getOptionValue(ajpPort.getOpt())); } if (line.hasOption(resetExtract.getOpt())) { tomcat8Runner.resetExtract = true; } if (line.hasOption(debug.getOpt())) { tomcat8Runner.debug = true; } if (line.hasOption(httpProtocol.getOpt())) { tomcat8Runner.httpProtocol = line.getOptionValue(httpProtocol.getOpt()); } if (line.hasOption(sysProps.getOpt())) { Properties systemProperties = line.getOptionProperties(sysProps.getOpt()); if (systemProperties != null && !systemProperties.isEmpty()) { for (Map.Entry<Object, Object> sysProp : systemProperties.entrySet()) { System.setProperty((String) sysProp.getKey(), (String) sysProp.getValue()); } } } if (line.hasOption(clientAuth.getOpt())) { tomcat8Runner.clientAuth = clientAuth.getOpt(); } if (line.hasOption(keyAlias.getOpt())) { tomcat8Runner.keyAlias = line.getOptionValue(keyAlias.getOpt()); } if (line.hasOption(extractDirectory.getOpt())) { tomcat8Runner.extractDirectory = line.getOptionValue(extractDirectory.getOpt()); } if (line.hasOption(loggerName.getOpt())) { tomcat8Runner.loggerName = line.getOptionValue(loggerName.getOpt()); } if (line.hasOption(uriEncoding.getOpt())) { tomcat8Runner.uriEncoding = line.getOptionValue(uriEncoding.getOpt()); } // here we go tomcat8Runner.run(); }
From source file:com.openx.oauthdemo.Demo.java
/** * Main class. OX3 with OAuth demo//from w ww.j a v a 2 s. com * @param args */ public static void main(String[] args) { String apiKey, apiSecret, loginUrl, username, password, domain, path, requestTokenUrl, accessTokenUrl, realm, authorizeUrl; String propertiesFile = "default.properties"; // load params from the properties file Properties defaultProps = new Properties(); InputStream in = null; try { ClassLoader cl = ClassLoader.getSystemClassLoader(); in = cl.getResourceAsStream(propertiesFile); if (in != null) { defaultProps.load(in); } } catch (IOException ex) { System.out.println("The properties file was not found!"); return; } finally { if (in != null) { try { in.close(); } catch (IOException ex) { System.out.println("IO Error closing the properties file"); return; } } } if (defaultProps.isEmpty()) { System.out.println("The properties file was not loaded!"); return; } apiKey = defaultProps.getProperty("apiKey"); apiSecret = defaultProps.getProperty("apiSecret"); loginUrl = defaultProps.getProperty("loginUrl"); username = defaultProps.getProperty("username"); password = defaultProps.getProperty("password"); domain = defaultProps.getProperty("domain"); path = defaultProps.getProperty("path"); requestTokenUrl = defaultProps.getProperty("requestTokenUrl"); accessTokenUrl = defaultProps.getProperty("accessTokenUrl"); realm = defaultProps.getProperty("realm"); authorizeUrl = defaultProps.getProperty("authorizeUrl"); // log in to the server Client cl = new Client(apiKey, apiSecret, loginUrl, username, password, domain, path, requestTokenUrl, accessTokenUrl, realm, authorizeUrl); try { // connect to the server cl.OX3OAuth(); } catch (UnsupportedEncodingException ex) { Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, "UTF-8 support needed for OAuth", ex); } catch (IOException ex) { Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, "IO file reading error", ex); } catch (Exception ex) { Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, "API issue", ex); } // now lets make a call to the api to check String json; try { json = cl.getHelper().callOX3Api(domain, path, "account"); } catch (IOException ex) { System.out.println("There was an error calling the API"); return; } System.out.println("JSON response: " + json); Gson gson = new Gson(); int[] accounts = gson.fromJson(json, int[].class); if (accounts.length > 0) { // let's get a single account try { json = cl.getHelper().callOX3Api(domain, path, "account", accounts[0]); } catch (IOException ex) { System.out.println("There was an error calling the API"); return; } System.out.println("JSON response: " + json); OX3Account account = gson.fromJson(json, OX3Account.class); System.out.println("Account id: " + account.getId() + " name: " + account.getName()); } }
From source file:pt.ua.tm.neji.web.cli.WebMain.java
public static void main(String[] args) { // Set JSP to use Standard JavaC always System.setProperty("org.apache.jasper.compiler.disablejsr199", "false"); CommandLineParser parser = new GnuParser(); Options options = new Options(); options.addOption("h", "help", false, "Print this usage information."); options.addOption("v", "verbose", false, "Verbose mode."); options.addOption("d", "dictionaires", true, "Folder that contains the dictionaries."); options.addOption("m", "models", true, "Folder that contains the ML models."); options.addOption("port", "port", true, "Server port."); options.addOption("c", "configuration", true, "Configuration properties file."); options.addOption("t", "threads", true, "Number of threads. By default, if more than one core is available, it is the number of cores minus 1."); CommandLine commandLine;//from w ww.j av a 2s . c o m try { // Parse the program arguments commandLine = parser.parse(options, args); } catch (ParseException ex) { logger.error("There was a problem processing the input arguments.", ex); return; } // Show help text if (commandLine.hasOption('h')) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(150, "./nejiWeb.sh " + USAGE, HEADER, options, FOOTER); return; } // Get threads int numThreads = Runtime.getRuntime().availableProcessors() - 1; numThreads = numThreads > 0 ? numThreads : 1; if (commandLine.hasOption('t')) { String threadsText = commandLine.getOptionValue('t'); numThreads = Integer.parseInt(threadsText); if (numThreads <= 0 || numThreads > 32) { logger.error("Illegal number of threads. Must be between 1 and 32."); return; } } // Get port int port = 8010; if (commandLine.hasOption("port")) { String portString = commandLine.getOptionValue("port"); port = Integer.parseInt(portString); } // Get configuration String configurationFile = null; Properties configurationProperties = null; if (commandLine.hasOption("configuration")) { configurationFile = commandLine.getOptionValue("configuration"); try { configurationProperties = new Properties(); configurationProperties.load(new FileInputStream(configurationFile)); } catch (IOException e) { configurationProperties = null; } } if (configurationProperties != null && !configurationProperties.isEmpty()) { ServerConfiguration.initialize(configurationProperties); } else { ServerConfiguration.initialize(); } // Set system proxy if (!ServerConfiguration.getInstance().getProxyURL().isEmpty() && !ServerConfiguration.getInstance().getProxyPort().isEmpty()) { System.setProperty("https.proxyHost", ServerConfiguration.getInstance().getProxyURL()); System.setProperty("https.proxyPort", ServerConfiguration.getInstance().getProxyPort()); System.setProperty("http.proxyHost", ServerConfiguration.getInstance().getProxyURL()); System.setProperty("http.proxyPort", ServerConfiguration.getInstance().getProxyPort()); if (!ServerConfiguration.getInstance().getProxyUsername().isEmpty()) { final String proxyUser = ServerConfiguration.getInstance().getProxyUsername(); final String proxyPassword = ServerConfiguration.getInstance().getProxyPassword(); System.setProperty("https.proxyUser", proxyUser); System.setProperty("https.proxyPassword", proxyPassword); System.setProperty("http.proxyUser", proxyUser); System.setProperty("http.proxyPassword", proxyPassword); Authenticator.setDefault(new Authenticator() { @Override public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(proxyUser, proxyPassword.toCharArray()); } }); } } // Get verbose mode boolean verbose = commandLine.hasOption('v'); Constants.verbose = verbose; if (Constants.verbose) { MalletLogger.getGlobal().setLevel(Level.INFO); // Redirect sout LoggingOutputStream los = new LoggingOutputStream(LoggerFactory.getLogger("stdout"), false); System.setOut(new PrintStream(los, true)); // Redirect serr los = new LoggingOutputStream(LoggerFactory.getLogger("sterr"), true); System.setErr(new PrintStream(los, true)); } else { MalletLogger.getGlobal().setLevel(Level.OFF); } // Get dictionaries folder String dictionariesFolder = null; if (commandLine.hasOption('d')) { dictionariesFolder = commandLine.getOptionValue('d'); File test = new File(dictionariesFolder); if (!test.isDirectory() || !test.canRead()) { logger.error("The specified dictionaries path is not a folder or is not readable."); return; } dictionariesFolder = test.getAbsolutePath(); dictionariesFolder += File.separator; } // Get models folder String modelsFolder = null; if (commandLine.hasOption('m')) { modelsFolder = commandLine.getOptionValue('m'); File test = new File(modelsFolder); if (!test.isDirectory() || !test.canRead()) { logger.error("The specified models path is not a folder or is not readable."); return; } modelsFolder = test.getAbsolutePath(); modelsFolder += File.separator; } // Redirect JUL to SLF4 SLF4JBridgeHandler.removeHandlersForRootLogger(); SLF4JBridgeHandler.install(); // Output formats (All) List<OutputFormat> outputFormats = new ArrayList<>(); outputFormats.add(OutputFormat.A1); outputFormats.add(OutputFormat.B64); outputFormats.add(OutputFormat.BC2); outputFormats.add(OutputFormat.BIOC); outputFormats.add(OutputFormat.CONLL); outputFormats.add(OutputFormat.JSON); outputFormats.add(OutputFormat.NEJI); outputFormats.add(OutputFormat.PIPE); outputFormats.add(OutputFormat.PIPEXT); outputFormats.add(OutputFormat.XML); // Context is built through a descriptor first, so that the pipeline can be validated before any processing ContextConfiguration descriptor = null; try { descriptor = new ContextConfiguration.Builder().withInputFormat(InputFormat.RAW) // HARDCODED .withOutputFormats(outputFormats).withParserTool(ParserTool.GDEP) .withParserLanguage(ParserLanguage.ENGLISH).withParserLevel(ParserLevel.CHUNKING).build(); } catch (NejiException ex) { ex.printStackTrace(); System.exit(1); } // Create resources dirs if they don't exist try { File dictionariesDir = new File(DICTIONARIES_PATH); File modelsDir = new File(MODELS_PATH); if (!dictionariesDir.exists()) { dictionariesDir.mkdirs(); (new File(dictionariesDir, "_priority")).createNewFile(); } if (!modelsDir.exists()) { modelsDir.mkdirs(); (new File(modelsDir, "_priority")).createNewFile(); } } catch (IOException ex) { ex.printStackTrace(); System.exit(1); } // Contenxt Context context = new Context(descriptor, MODELS_PATH, DICTIONARIES_PATH); // Start server try { Server server = Server.getInstance(); server.initialize(context, port, numThreads); server.start(); logger.info("Server started at localhost:{}", port); logger.info("Press Cmd-C / Ctrl+C to shutdown the server..."); server.join(); } catch (Exception ex) { ex.printStackTrace(); logger.info("Shutting down the server..."); } }
From source file:Main.java
/** * Copies all elements from <code>properties</code> into a Map. The returned map might be unmodifiable * @param properties//from w ww . j a v a2 s . co m * @return The map containing all elements */ public static Map<String, String> toMap(Properties properties) { if (properties == null || properties.isEmpty()) return Collections.<String, String>emptyMap(); Map<String, String> props = new HashMap<String, String>(properties.size()); putAll(properties, props); return props; }
From source file:com.google.mr4c.config.ConfigUtils.java
public static void logProperties(String desc, Logger log, Properties props) { if (props.isEmpty()) { log.info("No {} properties", desc); return;/*from ww w . j a v a 2 s. c o m*/ } log.info("Begin dump of {} properties", desc); log.info(CollectionUtils.toFileContent(props)); log.info("End dump of {} properties", desc); }
From source file:org.ktc.soapui.maven.extension.AbstractSoapuiRunnerMojo.java
private static boolean isNullOrEmpty(Properties props) { return props == null || props.isEmpty(); }
From source file:adalid.util.google.Translator.java
public static Properties translate(Properties properties) { if (properties == null || properties.isEmpty()) { return properties; }/*w w w . java 2s . com*/ String arg, translation; URIBuilder builder = newURIBuilder(); try (CloseableHttpClient client = HttpClients.createDefault()) { Set<String> names = properties.stringPropertyNames(); for (String name : names) { arg = properties.getProperty(name); logger.info(arg); translation = translate(arg, builder, client); logger.info(translation); if (translation != null) { properties.setProperty(name, translation); } } } catch (IOException | URISyntaxException ex) { logger.fatal(ex); } return properties; }
From source file:io.servicecomb.foundation.common.utils.Log4jUtils.java
public static void init(List<String> locationPatterns) throws Exception { if (inited) { return;/*from w ww . j a va2s.c o m*/ } synchronized (LOCK) { if (inited) { return; } PropertiesLoader loader = new PropertiesLoader(locationPatterns); Properties properties = loader.load(); if (properties.isEmpty()) { throw new Exception("can not find resource " + locationPatterns); } PropertyConfigurator.configure(properties); inited = true; // ???merge? outputFile(loader.getFoundResList(), properties); } }
From source file:org.apache.servicecomb.foundation.common.utils.Log4jUtils.java
public static void init(List<String> locationPatterns) throws Exception { if (inited) { return;//from w w w . j a v a 2 s. c o m } synchronized (LOCK) { if (inited) { return; } PropertiesLoader loader = new PropertiesLoader(locationPatterns); Properties properties = loader.load(); if (properties.isEmpty()) { throw new Exception("can not find resource " + locationPatterns); } PropertyConfigurator.configure(properties); inited = true; if (OUTPUT_CONFIG_ENABLED_TRUE .equals(properties.getProperty(OUTPUT_CONFIG_ENABLED, OUTPUT_CONFIG_ENABLED_TRUE))) { // If the property file with the highest priority is on a hard disk(not in a jar package) // and we have write access, output the merged property file for the purpose of debugging outputFile(loader.getFoundResList(), properties); } } }