List of usage examples for java.lang String toString
public String toString()
From source file:DDTTestRunner.java
public static void addVariable(String key, String value) { String result = ""; try {//from w w w .j ava 2 s . c o m if ((getVarsMap().get(key) != null)) getVarsMap().remove(key); // Consider the special case of date variables used for resetting date-specific system variables if (value.toString().toLowerCase().startsWith("%date") && (value.toString().toLowerCase().endsWith("%"))) { try { DDTDate referenceDate = new DDTDate(); referenceDate.resetDateProperties(value.toString(), getVarsMap()); if (referenceDate.hasException()) result = referenceDate.getException().getMessage().toString(); else result = referenceDate.getComments(); } catch (Exception e) { result = "Error encountered in setting date variables: " + e.getCause().toString(); } } else { getVarsMap().put(key.toLowerCase(), value); result = "Variable " + Util.sq(key.toLowerCase()) + " (re)set in the variables map to " + Util.sq((value instanceof String) ? value : value.toString()); } } catch (Exception e) { result = e.getCause().toString(); } finally { System.out.println(result); } }
From source file:com.opendoorlogistics.core.tables.io.PoiIO.java
private static SaveElementResult saveElementToCell(ODLTableReadOnly table, int row, int col, Cell cell) { boolean oversized = false; switch (table.getColumnType(col)) { case LONG:// w w w . j a v a 2 s . c om case DOUBLE: Number dVal = (Number) table.getValueAt(row, col); if (dVal != null) { cell.setCellValue(dVal.doubleValue()); cell.setCellType(Cell.CELL_TYPE_NUMERIC); } else { cell.setCellValue((String) null); cell.setCellType(Cell.CELL_TYPE_BLANK); } break; default: String sval = TableUtils.getValueAsString(table, row, col); if (sval != null) { if (sval.length() >= MAX_CHAR_COUNT_IN_EXCEL_CELL) { oversized = true; } cell.setCellValue(sval.toString()); } else { cell.setCellValue((String) null); } cell.setCellType(Cell.CELL_TYPE_STRING); break; } return oversized ? SaveElementResult.OVERSIZED : SaveElementResult.OK; }
From source file:dk.netarkivet.archive.arcrepositoryadmin.ArchiveDBConnection.java
/** * Initializes the connection pool./*from ww w. j av a 2 s . c om*/ * @param dbSpec the object representing the chosen DB target system. * @param jdbcUrl the JDBC URL to connect to. * @throws SQLException */ private static void initDataSource(DBSpecifics dbSpec, String jdbcUrl) throws SQLException { dataSource = new ComboPooledDataSource(); String username = Settings.get(ArchiveSettings.DB_USERNAME); if (!username.isEmpty()) { dataSource.setUser(username); } String password = Settings.get(ArchiveSettings.DB_PASSWORD); if (!password.isEmpty()) { dataSource.setPassword(password); } try { dataSource.setDriverClass(dbSpec.getDriverClassName()); } catch (PropertyVetoException e) { final String message = "Failed to set datasource JDBC driver class '" + dbSpec.getDriverClassName() + "'" + "\n"; throw new IOFailure(message, e); } dataSource.setJdbcUrl(jdbcUrl); // Configure pool size dataSource.setMinPoolSize(Settings.getInt(ArchiveSettings.DB_POOL_MIN_SIZE)); dataSource.setMaxPoolSize(Settings.getInt(ArchiveSettings.DB_POOL_MAX_SIZE)); dataSource.setAcquireIncrement(Settings.getInt(ArchiveSettings.DB_POOL_ACQ_INC)); // Configure idle connection testing int testPeriod = Settings.getInt(ArchiveSettings.DB_POOL_IDLE_CONN_TEST_PERIOD); if (testPeriod > 0) { dataSource.setIdleConnectionTestPeriod(testPeriod); dataSource.setTestConnectionOnCheckin( Settings.getBoolean(ArchiveSettings.DB_POOL_IDLE_CONN_TEST_ON_CHECKIN)); String testQuery = Settings.get(ArchiveSettings.DB_POOL_IDLE_CONN_TEST_QUERY); if (!testQuery.isEmpty()) { dataSource.setPreferredTestQuery(testQuery); } } // Configure statement pooling dataSource.setMaxStatements(Settings.getInt(ArchiveSettings.DB_POOL_MAX_STM)); dataSource.setMaxStatementsPerConnection(Settings.getInt(ArchiveSettings.DB_POOL_MAX_STM_PER_CONN)); if (log.isInfoEnabled()) { String msg = "Connection pool initialized with the following values:"; msg += "\n- minPoolSize=" + dataSource.getMinPoolSize(); msg += "\n- maxPoolSize=" + dataSource.getMaxPoolSize(); msg += "\n- acquireIncrement=" + dataSource.getAcquireIncrement(); msg += "\n- maxStatements=" + dataSource.getMaxStatements(); msg += "\n- maxStatementsPerConnection=" + dataSource.getMaxStatementsPerConnection(); msg += "\n- idleConnTestPeriod=" + dataSource.getIdleConnectionTestPeriod(); msg += "\n- idleConnTestQuery='" + dataSource.getPreferredTestQuery() + "'"; msg += "\n- idleConnTestOnCheckin=" + dataSource.isTestConnectionOnCheckin(); log.info(msg.toString()); } }
From source file:test.Http.java
/** * post url :??jsonString???json,?json// www.ja v a2 s . com * * @date * @param url * @param jsonString * @return * @throws Exception */ public static String httpPostWithJsons(String url, String jsonString) throws Exception { System.out.println("==url++" + url + "==jsonString" + jsonString); String responseBodyData = null; HttpClient httpClient = new DefaultHttpClient(); // httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 6000); // ? httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 6000); HttpPost httpPost = new HttpPost(url); httpPost.addHeader("Content-Type", "text/html"); // byte[] requestStrings = jsonString.toString().getBytes("UTF-8"); ByteArrayEntity byteArrayEntity = new ByteArrayEntity(requestStrings); httpPost.setEntity(byteArrayEntity); try { HttpResponse response = httpClient.execute(httpPost);// post if (response.getStatusLine().getStatusCode() == 200) { responseBodyData = EntityUtils.toString(response.getEntity()); } else { responseBodyData = null; } } catch (Exception e) { } finally { httpPost.abort(); httpClient = null; } return responseBodyData; }
From source file:hu.unideb.studentSupportInterface.converters.RoleConverter.java
@Override public Object getAsObject(FacesContext context, UIComponent component, String value) { if (value.toString().equals("UPLOADER")) return Role.UPLOADER; if (value.toString().equals("ASSESSOR")) return Role.ASSESSOR; if (value.toString().equals("TUTOR")) return Role.TUTOR; if (value.toString().equals("ADMIN")) return Role.ADMIN; return null;// w w w . j a v a 2 s .com }
From source file:com.ling.spring.task.FixedRateTask.java
/** * fixedRate ?// ww w. j a va 2 s. c om * fixedDelay ?? */ @Async @Scheduled(fixedRate = 5000) public void runTask() { System.out.println("fixedRate run..." + format.format(new Date())); try { Thread.currentThread().sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } String s = null; System.out.println(s.toString()); }
From source file:com.jsfsample.util.StringUtil.java
/** * This method is used to encrypt user input password or challenge question * answers and save them into database. Since Oracle encryption will return * a string of all upper case letters, this method will convert the * encrypted string to upper case./*from w w w. j av a2 s .c o m*/ */ @Deprecated public static String getEncryptedString(String originalString) throws Exception { SecretKeySpec keySpec = new SecretKeySpec("1234567890".getBytes(), "RC4"); Cipher cipher = Cipher.getInstance("RC4"); cipher.init(Cipher.ENCRYPT_MODE, keySpec); byte[] encryptedCode = cipher.doFinal(originalString.toString().getBytes()); String encryptedString = "";//asHex(encryptedCode).toUpperCase(); // if (log.isDebugEnabled()) // log.debug("--------->original string: " + originalString); // if (log.isDebugEnabled()) // log.debug("--------->encrypted string: " + encryptedString); return encryptedString; }
From source file:com.wbtech.common.CommonUtil.java
/** * ?APPKEY//from w ww. j av a 2 s . c o m * * @param context * @return appkey */ public static String getAppKey(Context paramContext) { String umsAppkey; try { PackageManager localPackageManager = paramContext.getPackageManager(); ApplicationInfo localApplicationInfo = localPackageManager .getApplicationInfo(paramContext.getPackageName(), 128); if (localApplicationInfo != null) { String str = localApplicationInfo.metaData.getString("UMS_APPKEY"); if (str != null) { umsAppkey = str; return umsAppkey.toString(); } if (UmsConstants.DebugMode) Log.e("UmsAgent", "Could not read UMS_APPKEY meta-data from AndroidManifest.xml."); } } catch (Exception localException) { if (UmsConstants.DebugMode) { Log.e("UmsAgent", "Could not read UMENG_APPKEY meta-data from AndroidManifest.xml."); localException.printStackTrace(); } } return null; }
From source file:by.zatta.pilight.model.Config.java
public static void parse(JSONObject jloc) { Iterator<?> lit = jloc.keys(); /* Iterate through all locations */ while (lit.hasNext()) { String locationID = (String) lit.next(); String locationName = ""; try {/*from ww w. j a v a 2 s .co m*/ JSONObject jdev = jloc.getJSONObject(locationID); if (jdev.has("name")) locationName = jdev.getString("name"); // Log.v(TAG, locationID + " = " +locationName); Iterator<?> dit = jdev.keys(); /* Iterate through all devices of this location */ while (dit.hasNext()) { String dkey = (String) dit.next(); // Log.v("dkey", dkey); if (!dkey.equals("name")) { try { /* Create new device object for this location */ DeviceEntry device = new DeviceEntry(); device.setNameID(dkey); device.setLocationID(locationID); List<SettingEntry> settings = new ArrayList<SettingEntry>(); SettingEntry sentry = new SettingEntry(); sentry.setKey("locationName"); sentry.setValue(locationName); settings.add(sentry); JSONObject jset = jdev.getJSONObject(dkey); Iterator<?> sit = jset.keys(); /* Iterate through all settings of this device */ while (sit.hasNext()) { String skey = (String) sit.next(); if (skey.equals("type")) { device.setType(Integer.valueOf(jset.getString(skey))); } /* OBSOLETE LOOP SINCE PILIGHT 4.0 */ // } else if (skey.equals("settings")) { // // iterate over all specific settings // JSONObject jthi = jset.getJSONObject(skey); // Iterator<?> thit = jthi.keys(); // while (thit.hasNext()) { // String thkey = (String) thit.next(); // sentry = new SettingEntry(); // sentry.setKey("sett_" + thkey); // // JSONArray jvalarr = jthi.optJSONArray(thkey); // String jvalstr = jthi.optString(thkey); // Double jvaldbl = jthi.optDouble(thkey); // Long jvallng = jthi.optLong(thkey); // // if (jvalarr != null) { // for (Short i = 0; i < jvalarr.length(); i++) { // sentry.setKey(thkey); // sentry.setValue(jvalarr.get(i).toString()); // } // } else if (jvalstr != null) { // sentry.setValue(jvalstr.toString()); // } else if (jvaldbl != null) { // Log.e(TAG, skey + "double : " + jvaldbl.toString()); // sentry.setValue(jvaldbl.toString()); // } else if (jvallng != null) { // Log.e(TAG, skey + "long : " + jvallng.toString()); // sentry.setValue(jvallng.toString()); // } // if (sentry != null) settings.add(sentry); // } // } else if (skey.equals("id") || skey.equals("protocol") || skey.equals("order")) { } else { try { sentry = new SettingEntry(); sentry.setKey(skey); JSONArray jvalarr = jset.optJSONArray(skey); String jvalstr = jset.optString(skey); Double jvaldbl = jset.optDouble(skey); Long jvallng = jset.optLong(skey); if (jvalarr != null) { for (Short i = 0; i < jvalarr.length(); i++) { sentry.setKey(skey); sentry.setValue(jvalarr.get(i).toString()); } } else if (jvalstr != null) { sentry.setValue(jvalstr.toString()); } else if (jvaldbl != null) { Log.e(TAG, skey + "double : " + jvaldbl.toString()); sentry.setValue(jvaldbl.toString()); } else if (jvallng != null) { Log.e(TAG, skey + "long : " + jvallng.toString()); sentry.setValue(jvallng.toString()); } if (sentry != null) settings.add(sentry); } catch (JSONException e) { Log.w(TAG, "The received SETTING is of an incorrent format"); } } } device.setSettings(settings); mDevices.add(device); } catch (JSONException e) { Log.w(TAG, "The received DEVICE is of an incorrent format"); } } } } catch (JSONException e) { Log.w(TAG, "The received LOCATION is of an incorrent format"); } } try { print(); } catch (Exception e) { Log.w(TAG, "4) couldnt print"); } }
From source file:com.thinkbiganalytics.policy.standardization.TrimStandardizer.java
@Override public String convertValue(String value) { return StringUtils.trim(value.toString()); }