List of usage examples for java.lang StringBuffer deleteCharAt
@Override public synchronized StringBuffer deleteCharAt(int index)
From source file:com.wabacus.system.fileupload.AbsFileUpload.java
protected String showDataImportFileUpload(List<String> lstDataImportFileNames) { if (lstDataImportFileNames == null || lstDataImportFileNames.size() == 0) return ""; StringBuffer resultBuf = new StringBuffer(); resultBuf.append(/*w w w . j av a 2 s . c o m*/ "<table border=0 cellspacing=1 cellpadding=2 style=\"margin:0px\" width=\"98%\" ID=\"Table1\" align=\"center\">"); resultBuf.append("<tr class=filetitle><td style='font-size:13px;'>?</td></tr>"); StringBuffer fileNameBuf = new StringBuffer(); int idx = 0; for (String filenameTmp : lstDataImportFileNames) { fileNameBuf.append(filenameTmp).append("; "); resultBuf.append( "<tr><td style='font-size:13px;'><input type=\"file\" contentEditable=\"false\" name=\"uploadfile" + (idx++) + "\"></td></tr>"); } if (fileNameBuf.length() > 2 && fileNameBuf.charAt(fileNameBuf.length() - 2) == ';') { fileNameBuf.deleteCharAt(fileNameBuf.length() - 2); } resultBuf.append("<tr class=filetitle><td style='font-size:13px;'>[??" + fileNameBuf.toString().trim() + "]</td></tr>"); resultBuf.append( "<tr><td style='font-size:13px;'><input type=\"submit\" class=\"cls-button\" name=\"submit\" value=\"\">"); resultBuf.append("</td></tr></table>"); return resultBuf.toString(); }
From source file:org.apache.velocity.util.ExtProperties.java
/** * Removes a backslash from every pair of backslashes. *///www.ja va 2 s. c o m private static String unescape(String s) { StringBuffer buf = new StringBuffer(s); for (int i = 0; i < buf.length() - 1; i++) { char c1 = buf.charAt(i); char c2 = buf.charAt(i + 1); if (c1 == '\\' && c2 == '\\') { buf.deleteCharAt(i); } } return buf.toString(); }
From source file:com.cisco.dvbu.ps.deploytool.services.RegressionManagerUtils.java
/** * Creates a String with comma-separated list of datasources from a RegressionDatasourcesType List. * /*w w w. ja va 2 s . com*/ * @param dsList - list of comma-separated datasources. * @param propertyFile - the name of the PDTool property file being used by this invocation * @return dsListStr - comma-separate list of datasources. */ public static String createDsListString(RegressionDatasourcesType dsList, String propertyFile) throws CompositeException { String dsListStr = null; if (dsList != null) { List<String> dsListArray = dsList.getDsName(); StringBuffer buf = new StringBuffer(); for (String ds : dsListArray) { if (!ds.isEmpty()) { buf.append("'" + CommonUtils.extractVariable("createDsListString", ds, propertyFile, false) + "'" + ","); } } if (buf.length() > 1) // at least one ds is populated { buf.deleteCharAt(buf.length() - 1); // remove the last comma } dsListStr = buf.toString(); } return dsListStr; }
From source file:org.latticesoft.util.common.MiscUtil.java
/** * Combines the elements in the collection. * @param c the collection/*from ww w . j av a2s . c o m*/ * @param size the size to combine. If the positive the algorithm is * from 1st element to last element. the number is the number of elements * to combine. */ public static Collection combineCollectionElement(Collection c, int size) { if (c.size() == 1) { return c; } ArrayList src = null; ArrayList retVal = new ArrayList(); if (c instanceof ArrayList) { src = (ArrayList) c; } else { src = new ArrayList(); src.addAll(c); } StringBuffer sb = new StringBuffer(); if (size > 0) { int start = 0; int end = start + Math.abs(size) + 1; for (int i = start; i < end; i++) { sb.append(src.get(i)).append("."); } sb.deleteCharAt(sb.length() - 1); retVal.add(sb.toString()); for (int i = end; i < src.size(); i++) { retVal.add(src.get(i)); } } else { int start = src.size() - 1; int end = start - Math.abs(size); for (int i = end; i <= start; i++) { sb.append(src.get(i)).append("."); } sb.deleteCharAt(sb.length() - 1); // add to retVal; retVal.add(sb.toString()); for (int i = end - 1; i >= 0; i--) { retVal.add(src.get(i)); } Collections.reverse(retVal); } if (log.isDebugEnabled()) { log.debug("Combined: " + retVal); } return retVal; }
From source file:com.hexin.core.dao.BaseDaoSupport.java
private void debugSql(String sql, List<Object[]> batchUpdateParams) { if (logger.isDebugEnabled()) { StringBuffer buffer = new StringBuffer(); buffer.append("sql: "); buffer.append(sql);/* ww w. j av a 2 s. c o m*/ buffer.append(", args: "); for (Object[] args : batchUpdateParams) { buffer.append("("); for (Object arg : args) { buffer.append(arg); buffer.append(","); } buffer.deleteCharAt(buffer.length() - 1); buffer.append("), "); } logger.debug(buffer.toString()); } }
From source file:com.wabacus.system.component.container.AbsContainerType.java
protected String showMetaDataDisplayStringStart() { StringBuffer resultBuf = new StringBuffer(); resultBuf.append(super.showMetaDataDisplayStringStart()); resultBuf.append(" childComponentIds=\""); for (String childidTmp : this.containerConfigBean.getLstChildrenIDs()) { resultBuf.append(childidTmp).append(";"); }// ww w . ja va 2s. c o m if (resultBuf.charAt(resultBuf.length() - 1) == ';') { resultBuf.deleteCharAt(resultBuf.length() - 1); } resultBuf.append("\""); return resultBuf.toString(); }
From source file:org.jboss.dashboard.commons.text.StringUtil.java
/** * Converts the given string to a Java valid identifier. * * @param str string to process//from w w w . j a v a 2 s . co m * @return A java based identifier. */ public static String toJavaIdentifier(String str) { if (str == null || str.trim().equals("")) return null; StringBuffer buf = new StringBuffer(str); int bufIdx = 0; while (bufIdx < buf.length()) { char c = buf.charAt(bufIdx); // Replace tilded by non-tilded chars. int tilded = TILDED_CHARS.indexOf(c); if (tilded != -1 && tilded < NON_TILDED_CHARS.length()) { buf.deleteCharAt(bufIdx); c = NON_TILDED_CHARS.charAt(tilded); buf.insert(bufIdx++, c); continue; } // Discard special chars and non-valid java identifiers. int special = SPECIAL_CHARS.indexOf(c); if (special != -1 || !Character.isJavaIdentifierPart(c)) { buf.deleteCharAt(bufIdx); continue; } // Adjust buffer index. bufIdx++; } if (buf.length() == 0) return ""; while (buf.length() > 0 && !Character.isJavaIdentifierStart(buf.charAt(0))) buf.deleteCharAt(0); // Avoid reserved java keywords. String javaId = buf.toString(); if (isJavaKeyword(javaId)) { if (javaId.equals("class")) javaId = "clazz"; else javaId = '_' + javaId; } return javaId; }
From source file:com.cettco.buycar.activity.BargainActivity.java
private void submit() { String cookieStr = null;/*ww w . j a v a 2 s . c o m*/ String cookieName = null; PersistentCookieStore myCookieStore = new PersistentCookieStore(BargainActivity.this); if (myCookieStore == null) { return; } List<Cookie> cookies = myCookieStore.getCookies(); for (Cookie cookie : cookies) { String name = cookie.getName(); cookieName = name; //System.out.println(name); if (name.equals("_JustBidIt_session")) { cookieStr = cookie.getValue(); //System.out.println("value:" + cookieStr); break; } } if (cookieStr == null || cookieStr.equals("")) { Toast toast = Toast.makeText(BargainActivity.this, "", Toast.LENGTH_SHORT); toast.show(); Intent intent = new Intent(); intent.setClass(BargainActivity.this, SignInActivity.class); startActivity(intent); return; } String tenderUrl = GlobalData.getBaseUrl() + "/tenders.json?"; // String price = priceEditText.getText().toString(); // String userName = userNameEditText.getText().toString(); String price = orderItemEntity.getPrice(); String userName = orderItemEntity.getName(); if (price == null || price.equals("")) { Toast toast = Toast.makeText(BargainActivity.this, "", Toast.LENGTH_SHORT); toast.show(); return; } if (colors == null || colors.size() == 0) { Toast toast = Toast.makeText(BargainActivity.this, "?", Toast.LENGTH_SHORT); toast.show(); return; } if (dealers == null || dealers.size() == 0) { Toast toast = Toast.makeText(BargainActivity.this, "4s", Toast.LENGTH_SHORT); toast.show(); return; } if (userName == null || userName.equals("")) { Toast toast = Toast.makeText(BargainActivity.this, "??", Toast.LENGTH_SHORT); toast.show(); return; } Tender tender = new Tender(); StringBuffer buffer = new StringBuffer(); for (int i = 0; i < colors.size(); i++) { buffer.append(colors.get(i) + ","); } if (buffer != null && buffer.length() > 0) { buffer.deleteCharAt(buffer.length() - 1); } tender.setColors_id(buffer.toString()); tender.setGot_licence(String.valueOf(plateSelection)); tender.setLoan_option(String.valueOf(loanSelection + 1)); tender.setTrim_id(trim_id); tender.setPickup_time(String.valueOf(getcarTimeSelection)); tender.setUser_name(userName); String locationString = locationList.get(locationSelection); tender.setLicense_location(locationString); tender.setPrice(price); String description = descriptionEditText.getText().toString(); // tender.setde tender.setDescription(description); Map<String, String> shops = new HashMap<String, String>(); for (int i = 0; i < dealers.size(); i++) { shops.put(dealers.get(i), "1"); } tender.setShops(shops); TenderEntity tenderEntity = new TenderEntity(); tenderEntity.setTender(tender); Gson gson = new Gson(); //System.out.println(gson.toJson(tenderEntity).toString()); StringEntity entity = null; try { // System.out.println(gson.toJson(bargainEntity).toString()); entity = new StringEntity(gson.toJson(tenderEntity).toString(), "utf-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } progressLayout.setVisibility(View.VISIBLE); HttpConnection.getClient().addHeader("Cookie", cookieName + "=" + cookieStr); HttpConnection.post(BargainActivity.this, tenderUrl, null, entity, "application/json;charset=utf-8", new JsonHttpResponseHandler() { @Override public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { // TODO Auto-generated method stub super.onFailure(statusCode, headers, throwable, errorResponse); progressLayout.setVisibility(View.GONE); //System.out.println("error"); //System.out.println("statusCode:" + statusCode); //System.out.println("headers:" + headers); if (statusCode == 401) { Message msg = new Message(); msg.what = RESULT_UNAUTHORIZED; handler.sendMessage(msg); } else if (statusCode == 422) { Message msg = new Message(); msg.what = RESULT_UNPROCESSABLE; handler.sendMessage(msg); } else { Toast toast = Toast.makeText(BargainActivity.this, "??,???", Toast.LENGTH_SHORT); toast.show(); } } @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { // TODO Auto-generated method stub super.onSuccess(statusCode, headers, response); progressLayout.setVisibility(View.GONE); //System.out.println("success"); //System.out.println("statusCode:" + statusCode); // for(int i=0;i<headers.length;i++){ // System.out.println(headers[0]); // } //System.out.println("response:" + response); String tender_id = ""; if (statusCode == 201) { try { //System.out.println("id:" //+ response.getString("id")); tender_id = response.getString("id"); orderItemEntity.setId(response.getString("id")); orderItemEntity.setState(response.getString("state")); DatabaseHelperOrder orderHelper = DatabaseHelperOrder .getHelper(BargainActivity.this); orderHelper.getDao().update(orderItemEntity); } catch (JSONException | SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } Toast toast = Toast.makeText(BargainActivity.this, "???", Toast.LENGTH_SHORT); toast.show(); Intent intent = new Intent(); // intent.putExtra("tenderId", id); intent.setClass(BargainActivity.this, AliPayActivity.class); intent.putExtra("tender_id", tender_id); startActivity(intent); // Intent intent = new Intent(); // // intent.putExtra("tenderId", id); // intent.setClass(BargainActivity.this, // MainActivity.class); // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // startActivity(intent); } } }); }
From source file:org.openadaptor.auxil.connector.jdbc.writer.AbstractSQLWriter.java
/** * Generate the SQL for a stored procedure call. * It will add placeholders for the required number of arguments also. * @param procName The name of the stored procedure to be used * @return String containing an SQL call ready for compilation as a PreparedStatement *///from ww w. ja v a2s . c o m protected String generateStoredProcSQL(String procName, int[] sqlTypes) { //Fudge for oracle Packages. //SC[99] if (oraclePackage != null) { log.debug("Prepending oracle package name to stored proc name"); procName = oraclePackage + "." + procName; } StringBuffer sqlString = new StringBuffer("{ CALL " + procName + "("); int args = sqlTypes.length;// Only need the number of args. for (int i = 0; i < args; i++) { sqlString.append("?,"); } if (args > 0) { //Drop the last comma. sqlString.deleteCharAt(sqlString.length() - 1); } sqlString.append(")}"); return sqlString.toString(); }
From source file:org.aselect.authspserver.authsp.delegator.HTTPSTrustAllDelegate.java
public int authenticate(Map<String, String> requestparameters, Map<String, List<String>> responseparameters) throws DelegateException { String sMethod = "authenticate"; int iReturnCode = -1; AuthSPSystemLogger _systemLogger;/*from w ww. jav a 2 s .co m*/ _systemLogger = AuthSPSystemLogger.getHandle(); _systemLogger.log(Level.FINEST, sModule, sMethod, "requestparameters=" + requestparameters + " , responseparameters=" + responseparameters); StringBuffer data = new StringBuffer(); String sResult = ""; ; try { final String EQUAL_SIGN = "="; final String AMPERSAND = "&"; final String NEWLINE = "\n"; for (String key : requestparameters.keySet()) { data.append(URLEncoder.encode(key, "UTF-8")); data.append(EQUAL_SIGN).append(URLEncoder.encode( ((String) requestparameters.get(key) == null) ? "" : (String) requestparameters.get(key), "UTF-8")); data.append(AMPERSAND); } if (data.length() > 0) data.deleteCharAt(data.length() - 1); // remove last AMPERSAND // data.append(NEWLINE).append(NEWLINE); // _systemLogger.log(Level.FINE, sModule, sMethod, "url=" + url.toString() + " data={" + data.toString() + "}"); // no data shown in production environment ///////////// HERE WE DO THE TRUST ALL STUFF /////////////////////////////// // Create a trust manager that does not validate certificate chains final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { public void checkClientTrusted(final X509Certificate[] chain, final String authType) { } public void checkServerTrusted(final X509Certificate[] chain, final String authType) { } public X509Certificate[] getAcceptedIssuers() { return null; } } }; ///////////// HERE WE DO THE TRUST ALL STUFF /////////////////////////////// // Install the all-trusting trust manager final SSLContext sslContext = SSLContext.getInstance("SSL"); sslContext.init(null, trustAllCerts, new java.security.SecureRandom()); // Create an ssl socket factory with our all-trusting manager final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); ///////////// HERE WE DO THE TRUST ALL STUFF /////////////////////////////// // Tell the url connection object to use our socket factory which bypasses security checks ((HttpsURLConnection) conn).setSSLSocketFactory(sslSocketFactory); ///////////// HERE WE DO THE TRUST ALL STUFF /////////////////////////////// // Basic authentication if (this.delegateuser != null) { byte[] bEncoded = Base64 .encodeBase64((this.delegateuser + ":" + (delegatepassword == null ? "" : delegatepassword)) .getBytes("UTF-8")); String encoded = new String(bEncoded, "UTF-8"); conn.setRequestProperty("Authorization", "Basic " + encoded); _systemLogger.log(Level.FINEST, sModule, sMethod, "Using basic authentication, user=" + this.delegateuser); } // conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); // They (the delegate party) don't accept charset !! conn.setDoOutput(true); conn.setRequestMethod("POST"); OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); wr.write(data.toString()); wr.flush(); wr.close(); // Get the response iReturnCode = conn.getResponseCode(); Map<String, List<String>> hFields = conn.getHeaderFields(); _systemLogger.log(Level.FINEST, sModule, sMethod, "response=" + iReturnCode); BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line; // Still to decide on response protocol while ((line = rd.readLine()) != null) { sResult += line; } _systemLogger.log(Level.INFO, sModule, sMethod, "sResult=" + sResult); // Parse response here // For test return request parameters // responseparameters.putAll(requestparameters); responseparameters.putAll(hFields); rd.close(); } catch (IOException e) { _systemLogger.log(Level.INFO, sModule, sMethod, "Error while reading sResult data, maybe no data at all. sResult=" + sResult); } catch (NumberFormatException e) { throw new DelegateException("Sending authenticate request, using \'" + this.url.toString() + "\' failed due to number format exception! " + e.getMessage(), e); } catch (Exception e) { throw new DelegateException("Sending authenticate request, using \'" + this.url.toString() + "\' failed (progress=" + iReturnCode + ")! " + e.getMessage(), e); } return iReturnCode; }