List of usage examples for java.text MessageFormat format
public static String format(String pattern, Object... arguments)
From source file:com.nearinfinity.blur.log.LogImpl.java
public void info(Object message, Throwable t, Object... args) { if (isInfoEnabled()) { log.info(MessageFormat.format(message.toString(), args), t); }/*from w w w. j av a 2 s . co m*/ }
From source file:com.eu.evaluation.server.service.impl.eva.UniqueEvaluate.java
public boolean evaluate(String evaluateItemHistoryID, AccessSystem accessSystem, String instanceClass, int instanceType, String instanceID) throws Exception { String debugInfo = "{0} = {1} , = {2} , = {3} , ID = {4}"; EvaluateItemHistory ev = evaluateItemHistoryDAO.get(evaluateItemHistoryID);// logger.debug(MessageFormat.format(debugInfo, new Object[] { "", accessSystem.getName(), ev.getObjectDictionary().getDisplayname(), ev.getFieldDictionary().getDisplayname(), instanceID })); Object entity = defaultDAO.findEvaluateData(instanceClass, instanceID, ev.getEvaluateVersion().getId(), accessSystem);//?? if (entity == null) { notPassMessage = "{0} {1} ? {2} ? {3} , ID {4} {5}"; notPassMessage = MessageFormat.format(notPassMessage, new Object[] { ev.getObjectDictionary().getDisplayname(), ev.getFieldDictionary().getDisplayname(), accessSystem.getName(), ev.getEvaluateVersion().getName(), instanceID, ev.getObjectDictionary().getDisplayname() }); return false; }//from w w w.j a v a 2 s. com //??? String field = ev.getFieldDictionary().getPropertyName(); Object fieldValue = BeanUtils.getProperty(entity, field); //sql?? String jpql = "select count(*) from {0} t where t.{1} = :value and t.evaluateVersion.id = :evID and t.position = :position"; jpql = MessageFormat.format(jpql, new Object[] { instanceClass, field }); MapSqlParameterSource params = new MapSqlParameterSource("value", fieldValue); params.addValue("evID", ev.getEvaluateVersion().getId()); params.addValue("position", accessSystem.getCode()); long count = defaultDAO.executeCount(jpql, params); if (count > 1) {//1? notPassMessage = getErrorMsg(ev, entity, accessSystem); } logger.debug(MessageFormat.format(debugInfo, new Object[] { "?", accessSystem.getName(), ev.getObjectDictionary().getDisplayname(), ev.getFieldDictionary().getDisplayname(), instanceID })); return count <= 1; }
From source file:hadoopInstaller.logging.MessageFormattingLog.java
public void error(String format, Object... arguments) { this.log.error(MessageFormat.format(Messages.getString(format), arguments)); }
From source file:net.sourceforge.fenixedu.presentationTier.jsf.validators.DateValidator.java
@Override public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { if (value != null) { String val = value.toString(); if (org.apache.commons.validator.DateValidator.getInstance().isValid(val, this.getFormat(), this.getStrict()) == false) { String errorMessage = MessageFormat.format(BundleUtil.getString(Bundle.APPLICATION, INVALID_DATE), new Object[] { this.getFormat() }); throw new ValidatorException(new FacesMessage(errorMessage)); }//w w w . ja v a 2 s . c om } }
From source file:com.nextep.designer.sqlgen.sqlite.impl.SQLLiteDatabaseConnector.java
@Override public Connection getConnection(IConnection conn) throws SQLException { final String connURL = getConnectionURL(conn); LOGGER.info(MessageFormat.format(SQLiteMessages.getString("connector.sqlite.connecting"), //$NON-NLS-1$ connURL));/*from w w w. j a v a 2 s . com*/ Connection connection = null; try { DriverManager.setLoginTimeout(15); connection = DriverManager.getConnection(connURL, conn.getLogin(), conn.getPassword()); } catch (SQLException sqle) { LOGGER.error("Unable to connect to SQLite database: " + sqle.getMessage(), sqle); throw sqle; } LOGGER.info("SQLite connection established"); return connection; }
From source file:com.newrelic.agent.Deployments.java
static int recordDeployment(CommandLine cmd, AgentConfig config)/* 37: */ throws Exception /* 38: */ {/*from ww w .j av a 2 s .co m*/ /* 39: 35 */ String appName = config.getApplicationName(); /* 40: 36 */ if (cmd.hasOption("appname")) { /* 41: 37 */ appName = cmd.getOptionValue("appname"); /* 42: */ } /* 43: 39 */ if (appName == null) { /* 44: 40 */ throw new IllegalArgumentException( "A deployment must be associated with an application. Set app_name in newrelic.yml or specify the application name with the -appname switch."); /* 45: */ } /* 46: 43 */ System.out.println("Recording a deployment for application " + appName); /* 47: */ /* 48: 45 */ String uri = "/deployments.xml"; /* 49: 46 */ String payload = getDeploymentPayload(appName, cmd); /* 50: 47 */ String protocol = "http" + (config.isSSL() ? "s" : ""); /* 51: 48 */ URL url = new URL(protocol, config.getApiHost(), config.getApiPort(), uri); /* 52: */ /* 53: 50 */ System.out.println(MessageFormat.format("Opening connection to {0}:{1}", new Object[] { config.getApiHost(), Integer.toString(config.getApiPort()) })); /* 54: */ /* 55: */ /* 56: 53 */ HttpURLConnection conn = (HttpURLConnection) url.openConnection(); /* 57: 54 */ conn.setRequestProperty("x-license-key", config.getLicenseKey()); /* 58: */ /* 59: 56 */ conn.setRequestMethod("POST"); /* 60: 57 */ conn.setConnectTimeout(10000); /* 61: 58 */ conn.setReadTimeout(10000); /* 62: 59 */ conn.setDoOutput(true); /* 63: 60 */ conn.setDoInput(true); /* 64: */ /* 65: 62 */ conn.setRequestProperty("Content-Length", Integer.toString(payload.length())); /* 66: 63 */ conn.setFixedLengthStreamingMode(payload.length()); /* 67: 64 */ conn.getOutputStream().write(payload.getBytes()); /* 68: */ /* 69: 66 */ int responseCode = conn.getResponseCode(); /* 70: 67 */ if (responseCode < 300) /* 71: */ { /* 72: 68 */ System.out.println("Deployment successfully recorded"); /* 73: */ } /* 74: 69 */ else if (responseCode == 401) /* 75: */ { /* 76: 70 */ System.out.println( "Unable to notify New Relic of the deployment because of an authorization error. Check your license key."); /* 77: 71 */ System.out.println("Response message: " + conn.getResponseMessage()); /* 78: */ } /* 79: */ else /* 80: */ { /* 81: 73 */ System.out.println("Unable to notify New Relic of the deployment"); /* 82: 74 */ System.out.println("Response message: " + conn.getResponseMessage()); /* 83: */ } /* 84: 76 */ boolean isError = responseCode >= 300; /* 85: 77 */ if ((isError) || (config.isDebugEnabled())) /* 86: */ { /* 87: 78 */ System.out.println("Response code: " + responseCode); /* 88: 79 */ InputStream inStream = isError ? conn.getErrorStream() : conn.getInputStream(); /* 89: 81 */ if (inStream != null) /* 90: */ { /* 91: 82 */ ByteArrayOutputStream output = new ByteArrayOutputStream(); /* 92: 83 */ Streams.copy(inStream, output); /* 93: */ /* 94: 85 */ PrintStream out = isError ? System.err : System.out; /* 95: */ /* 96: 87 */ out.println(output); /* 97: */ } /* 98: */ } /* 99: 90 */ return responseCode; /* 100: */ }
From source file:com.continuent.tungsten.common.security.PasswordManagerCtrl.java
/** * Password Manager entry point/* w w w . j a v a 2 s. c om*/ * * @param argv * @throws Exception */ public static void main(String argv[]) throws Exception { pwd = new PasswordManagerCtrl(); // --- Options --- ClientApplicationType clientApplicationType = null; String securityPropertiesFileLocation = null; String username = null; String password = null; CommandLine line = null; try { CommandLineParser parser = new GnuParser(); // --- Parse the command line arguments --- // --- Help line = parser.parse(pwd.helpOptions, argv, true); if (line.hasOption(_HELP)) { DisplayHelpAndExit(EXIT_CODE.EXIT_OK); } // --- Program command line options line = parser.parse(pwd.options, argv); // --- Handle options --- // --- Optional arguments : Get options --- if (line.hasOption(_HELP)) { DisplayHelpAndExit(EXIT_CODE.EXIT_OK); } if (line.hasOption(_TARGET_APPLICATION)) // Target Application { String target = line.getOptionValue(TARGET_APPLICATION); clientApplicationType = PasswordManagerCtrl.getClientApplicationType(target); } if (line.hasOption(_FILE)) // security.properties file location { securityPropertiesFileLocation = line.getOptionValue(_FILE); } if (line.hasOption(_AUTHENTICATE)) { // Make sure username + password are provided String[] authenticateArgs = line.getOptionValues(_AUTHENTICATE); if (authenticateArgs.length < 2) throw new MissingArgumentException(authenticate); username = authenticateArgs[0]; password = authenticateArgs[1]; } if (line.hasOption(_CREATE)) { // Make sure username + password are provided String[] createArgs = line.getOptionValues(_CREATE); if (createArgs.length < 2) throw new MissingArgumentException(create); username = createArgs[0]; password = createArgs[1]; } // --- Options to replace values in security.properties file --- if (line.hasOption(_ENCRYPTED_PASSWORD)) pwd.useEncryptedPassword = true; if (line.hasOption(_TRUSTSTORE_LOCATION)) pwd.truststoreLocation = line.getOptionValue(_TRUSTSTORE_LOCATION); if (line.hasOption(_TRUSTSTORE_PASSWORD)) pwd.truststorePassword = line.getOptionValue(_TRUSTSTORE_PASSWORD); if (line.hasOption(_KEYSTORE_LOCATION)) pwd.keystoreLocation = line.getOptionValue(_KEYSTORE_LOCATION); if (line.hasOption(_KEYSTORE_PASSWORD)) pwd.keystorePassword = line.getOptionValue(_KEYSTORE_PASSWORD); if (line.hasOption(_PASSWORD_FILE_LOCATION)) pwd.passwordFileLocation = (String) line.getOptionValue(_PASSWORD_FILE_LOCATION); try { pwd.passwordManager = new PasswordManager(securityPropertiesFileLocation, clientApplicationType); AuthenticationInfo authenticationInfo = pwd.passwordManager.getAuthenticationInfo(); // --- Substitute with user provided options if (pwd.useEncryptedPassword != null) authenticationInfo.setUseEncryptedPasswords(pwd.useEncryptedPassword); if (pwd.truststoreLocation != null) authenticationInfo.setTruststoreLocation(pwd.truststoreLocation); if (pwd.truststorePassword != null) authenticationInfo.setTruststorePassword(pwd.truststorePassword); if (pwd.keystoreLocation != null) authenticationInfo.setKeystoreLocation(pwd.keystoreLocation); if (pwd.keystorePassword != null) authenticationInfo.setKeystorePassword(pwd.keystorePassword); if (pwd.passwordFileLocation != null) authenticationInfo.setPasswordFileLocation(pwd.passwordFileLocation); // --- Display summary of used parameters --- logger.info("Using parameters: "); logger.info("-----------------"); if (authenticationInfo.getParentPropertiesFileLocation() != null) logger.info(MessageFormat.format("security.properties \t = {0}", authenticationInfo.getParentPropertiesFileLocation())); logger.info(MessageFormat.format("password_file.location \t = {0}", authenticationInfo.getPasswordFileLocation())); logger.info(MessageFormat.format("encrypted.password \t = {0}", authenticationInfo.isUseEncryptedPasswords())); // --- Keystore if (line.hasOption(_AUTHENTICATE)) { logger.info(MessageFormat.format("keystore.location \t = {0}", authenticationInfo.getKeystoreLocation())); logger.info(MessageFormat.format("keystore.password \t = {0}", authenticationInfo.getKeystorePassword())); } // --- Truststore if (authenticationInfo.isUseEncryptedPasswords()) { logger.info(MessageFormat.format("truststore.location \t = {0}", authenticationInfo.getTruststoreLocation())); logger.info(MessageFormat.format("truststore.password \t = {0}", authenticationInfo.getTruststorePassword())); } logger.info("-----------------"); // --- AuthenticationInfo consistency check // Try to create files if possible pwd.passwordManager.try_createAuthenticationInfoFiles(); authenticationInfo.checkAndCleanAuthenticationInfo(); } catch (ConfigurationException ce) { logger.error(MessageFormat.format( "Could not retrieve configuration information: {0}\nTry to specify a security.properties file location, provide options on the command line, or have the cluster.home variable set.", ce.getMessage())); System.exit(EXIT_CODE.EXIT_ERROR.value); } catch (ServerRuntimeException sre) { logger.error(sre.getLocalizedMessage()); // AuthenticationInfo consistency check : failed DisplayHelpAndExit(EXIT_CODE.EXIT_ERROR); } // --- Perform commands --- // ######### Authenticate ########## if (line.hasOption(_AUTHENTICATE)) { try { boolean authOK = pwd.passwordManager.authenticateUser(username, password); String msgAuthOK = (authOK) ? "SUCCESS" : "FAILED"; logger.info( MessageFormat.format("Authenticating {0}:{1} = {2}", username, password, msgAuthOK)); } catch (Exception e) { logger.error(MessageFormat.format("Error while authenticating user: {0}", e.getMessage())); } } // ######### Create ########## if (line.hasOption(_CREATE)) { try { pwd.passwordManager.setPasswordForUser(username, password); logger.info(MessageFormat.format("User created successfuly: {0}", username)); } catch (Exception e) { logger.error(MessageFormat.format("Error while creating user: {0}", e.getMessage())); } } // ########## DELETE ########## else if (line.hasOption(_DELETE)) { username = line.getOptionValue(_DELETE); try { pwd.passwordManager.deleteUser(username); logger.info(MessageFormat.format("User deleted successfuly: {0}", username)); } catch (Exception e) { logger.error(MessageFormat.format("Error while deleting user: {0}", e.getMessage())); } } } catch (ParseException exp) { logger.error(exp.getMessage()); DisplayHelpAndExit(EXIT_CODE.EXIT_ERROR); } }
From source file:org.remus.cmdlinehero.base.Executor.java
final void notifySchedule(final ExecutionInstruction instruction) { LOGGER.info(MessageFormat.format("Scheduled job {0}", instruction.getClass().getSimpleName())); for (final TaskListener listener : listeners) { try {//from w ww . ja va2 s . c o m listener.taskScheduled(new TaskChangeEvent(instruction, new Date())); } catch (final Throwable t) { // do nothing } } }
From source file:com.sazneo.export.formatter.html.HtmlFormatter.java
public HtmlFormatter(File styleSheet, File dataFile, OutputStream outputStream) { logger.debug(MessageFormat.format("Using stylesheet: {0}", styleSheet.getAbsolutePath())); this.styleSheet = styleSheet; logger.debug(MessageFormat.format("Using export XML from: {0}", dataFile.getAbsolutePath())); this.dataFile = dataFile; this.outputStream = outputStream; }
From source file:com.ibm.watson.developer_cloud.professor_languo.configuration.IndexerAndSearcherFactory.java
/** * get the indexer. This function picks the indexer type based on the input properties * //from w ww . j a va 2 s . com * @param properties - the properties for initialization * @return - the lucene or RnR indexer * @throws IngestionException */ public static Indexer getIndexer(Properties properties) throws IngestionException { Indexer indexer; String provider = properties.getProperty(RetrieveAndRankConstants.PROVIDER); switch (provider) { case RetrieveAndRankConstants.LUCENE: indexer = new LuceneIndexer(); break; case RetrieveAndRankConstants.SOLR: indexer = new RetrieveAndRankIndexer(); break; default: String errorMsg = MessageFormat.format(Messages.getString("RetrieveAndRank.PROVIDER_NOT_FOUND"), //$NON-NLS-1$ provider); throw new IllegalArgumentException(errorMsg); } try { loadStaticBluemixProperties(properties); indexer.initialize(properties); } catch (IllegalArgumentException | IOException e) { throw new IngestionException(e); } return indexer; }