List of usage examples for java.text MessageFormat format
public static String format(String pattern, Object... arguments)
From source file:com.artistech.tuio.mouse.MouseDriver.java
/** * Main: can take a port value as an argument. * * @param args/* w w w. ja v a2 s. c o m*/ */ public static void main(String args[]) { int tuio_port = 3333; Options options = new Options(); options.addOption("t", "tuio-port", true, "TUIO Port to listen on. (Default = 3333)"); options.addOption("h", "help", false, "Show this message."); HelpFormatter formatter = new HelpFormatter(); try { CommandLineParser parser = new org.apache.commons.cli.BasicParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("help")) { formatter.printHelp("tuio-mouse-driver", options); return; } else { if (cmd.hasOption("t") || cmd.hasOption("tuio-port")) { tuio_port = Integer.parseInt(cmd.getOptionValue("t")); } } } catch (ParseException | NumberFormatException ex) { System.err.println("Error Processing Command Options:"); formatter.printHelp("tuio-mouse-driver", options); return; } try { MouseDriver mouse = new MouseDriver(); TuioClient client = new TuioClient(tuio_port); logger.info( MessageFormat.format("Listening to TUIO message at port: {0}", Integer.toString(tuio_port))); client.addTuioListener(mouse); client.connect(); } catch (AWTException e) { logger.fatal(null, e); } }
From source file:com.asakusafw.compiler.bootstrap.OperatorCompilerDriver.java
/** * //from w ww . java 2 s. c om * @param args */ public static void main(String... args) { try { start(args); } catch (Exception e) { HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(Integer.MAX_VALUE); formatter.printHelp(MessageFormat.format("java -classpath ... {0}", //$NON-NLS-1$ OperatorCompilerDriver.class.getName()), OPTIONS, true); e.printStackTrace(System.out); System.exit(1); } }
From source file:com.continuent.tungsten.common.security.KeystoreManagerCtrl.java
/** * Password Manager entry point/*from ww w . ja v a2 s . c o m*/ * * @param argv * @throws Exception */ public static void main(String argv[]) throws Exception { keystoreManager = new KeystoreManagerCtrl(); // --- Options --- CommandLine line = null; try { CommandLineParser parser = new GnuParser(); // --- Parse the command line arguments --- // --- Help line = parser.parse(keystoreManager.helpOptions, argv, true); if (line.hasOption(_HELP)) { DisplayHelpAndExit(EXIT_CODE.EXIT_OK); } // --- Program command line options line = parser.parse(keystoreManager.options, argv); // --- Compulsory arguments : Get options --- if (line.hasOption(_KEYSTORE_LOCATION)) keystoreManager.keystoreLocation = line.getOptionValue(_KEYSTORE_LOCATION); if (line.hasOption(_KEY_ALIAS)) keystoreManager.keyAlias = line.getOptionValue(_KEY_ALIAS); if (line.hasOption(_KEY_TYPE)) { String keyType = line.getOptionValue(_KEY_TYPE); // This will throw an exception if the type is not recognised KEYSTORE_TYPE certificateTYpe = KEYSTORE_TYPE.fromString(keyType); keystoreManager.keyType = certificateTYpe; } if (line.hasOption(_KEYSTORE_PASSWORD)) keystoreManager.keystorePassword = line.getOptionValue(_KEYSTORE_PASSWORD); if (line.hasOption(_KEY_PASSWORD)) keystoreManager.keyPassword = line.getOptionValue(_KEY_PASSWORD); } catch (ParseException exp) { logger.error(exp.getMessage()); DisplayHelpAndExit(EXIT_CODE.EXIT_ERROR); } catch (Exception e) { // Workaround for Junit test if (e.toString().contains("CheckExitCalled")) { throw e; } else // Normal behaviour { logger.error(e.getMessage()); Exit(EXIT_CODE.EXIT_ERROR); } } // --- Perform commands --- // ######### Check password ########## if (line.hasOption(_CHECK)) { try { if (keystoreManager.keystorePassword == null || keystoreManager.keyPassword == null) { // --- Get passwords from stdin if not given on command line List<String> listPrompts = Arrays.asList("Keystore password:", MessageFormat.format("Password for key {0}:", keystoreManager.keyAlias)); List<String> listUserInput = keystoreManager.getUserInputFromStdin(listPrompts); if (listUserInput.size() == listPrompts.size()) { keystoreManager.keystorePassword = listUserInput.get(0); keystoreManager.keyPassword = listUserInput.get(1); } else { throw new NoSuchElementException(); } } try { // --- Check that all keys in keystore use the keystore // password logger.info(MessageFormat.format("Using keystore:{0}", keystoreManager.keystoreLocation)); SecurityHelper.checkKeyStorePasswords(keystoreManager.keystoreLocation, keystoreManager.keyType, keystoreManager.keystorePassword, keystoreManager.keyAlias, keystoreManager.keyPassword); logger.info(MessageFormat.format("OK : Identical password for Keystore and key={0}", keystoreManager.keyAlias)); } catch (UnrecoverableKeyException uke) { logger.error(MessageFormat.format("At least 1 key has a wrong password.{0}", uke.getMessage())); Exit(EXIT_CODE.EXIT_ERROR); } catch (Exception e) { logger.error(MessageFormat.format("{0}", e.getMessage())); Exit(EXIT_CODE.EXIT_ERROR); } } catch (NoSuchElementException nse) { logger.error(nse.getMessage()); Exit(EXIT_CODE.EXIT_ERROR); } catch (Exception e) { logger.error(MessageFormat.format("Error while running the program: {0}", e.getMessage())); Exit(EXIT_CODE.EXIT_ERROR); } } Exit(EXIT_CODE.EXIT_OK); }
From source file:Main.java
public static String transDistanceToStandardFormat(double distance) { if (distance < 1000) { return MessageFormat.format("{0} m", String.format("%.2f", distance)); }/*from w ww .j a v a2 s . com*/ return MessageFormat.format("{0} km", String.format("%.2f", distance / 1000)); }
From source file:Main.java
public static String toHref(String title) { StringBuffer sb = new StringBuffer(title); Pattern pat = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); Matcher mat = pat.matcher(title); int index = 0; int index1 = 0; while (mat.find()) { String url = mat.group(); //System.out.println(url); if (url.indexOf("http://") != 0) url = "http://" + url; Object obj[] = { "'" + url + "'" }; String a = MessageFormat.format(A1, obj); int l = a.length(); index += index1;/* ww w .ja v a2s .c o m*/ sb.insert(mat.start() + index, a); index += l; sb.insert((mat.end()) + index, A2); index1 = A2.length(); } return sb.toString(); }
From source file:Main.java
public static String format(String template, Object... arguments) { return MessageFormat.format(template, arguments); }
From source file:Main.java
public static String format(final String template, final Object... arguments) { return MessageFormat.format(template, arguments); }
From source file:Main.java
public static String getDropSql() { return MessageFormat.format("drop table if exists {0};", TABLE_NAME); //$NON-NLS-1$ }
From source file:com.alifi.jgenerator.utils.StringFormatUtils.java
public static String formats(String pattern, Object... args) { return MessageFormat.format(pattern, args); }
From source file:com.microsoft.tfs.core.clients.workitem.query.QueryUtils.java
public static String getExtendedDescription(final StoredQuery query) { final QueryItem queryItem = query.getProject().getQueryHierarchy().find(query.getQueryGUID()); String name, hierarchy;/* w w w. j a v a2 s .c o m*/ if (queryItem == null) { /* Should not happen, but fall back to the data within the query. */ log.warn(MessageFormat.format("Could not locate query {0} in query hierarchy", query.getQueryGUID())); //$NON-NLS-1$ name = query.getName(); hierarchy = query.getProject().getName(); } else { name = queryItem.getName(); QueryItem parent = queryItem.getParent(); if (parent == null) { /* Should never happen */ return name; } else { /* Add our parent to the hierarchy stack */ hierarchy = parent.getName(); /* * Now start with our grandparent, walking back up the tree to * the root */ while (parent.getParent() != null) { hierarchy = MessageFormat.format("{0} / {1}", parent.getParent().getName(), hierarchy); //$NON-NLS-1$ parent = parent.getParent(); } } } return MessageFormat.format("{0} ({1})", name, hierarchy); //$NON-NLS-1$ }