List of usage examples for java.lang StringBuffer deleteCharAt
@Override public synchronized StringBuffer deleteCharAt(int index)
From source file:io.onedecision.engine.decisions.web.DecisionController.java
private String toJson(Map<String, Object> results) throws IOException { StringBuffer sb = new StringBuffer("{"); for (Entry<String, Object> entry : results.entrySet()) { sb.append("\"").append(entry.getKey()).append("\":"); Object val = entry.getValue(); if (val instanceof String && val.equals("{}")) { sb.append(val); } else {/* w w w. j a va 2 s . com*/ val = objectMapper.writeValueAsString(val); if (val instanceof String && ((String) val).startsWith("\"{")) { val = ((String) val).substring(1, ((String) val).length() - 1); } sb.append(((String) val).replaceAll("\\\\", "")); } sb.append(","); } if (sb.lastIndexOf(",") != -1) { sb.deleteCharAt(sb.lastIndexOf(",")).append("}"); } return sb.toString(); }
From source file:nl.nn.adapterframework.align.content.JsonDocumentContainer.java
protected void toString(StringBuffer sb, Object item, int indentLevel) { if (item == null) { sb.append("null"); } else if (item instanceof String) { sb.append(item);/*from w ww .jav a 2 s. c om*/ } else if (item instanceof Map) { sb.append("{"); if (indentLevel >= 0) indentLevel++; for (Entry<String, Object> entry : ((Map<String, Object>) item).entrySet()) { newLine(sb, indentLevel); sb.append('"').append(entry.getKey()).append("\": "); toString(sb, entry.getValue(), indentLevel); sb.append(","); } sb.deleteCharAt(sb.length() - 1); if (indentLevel >= 0) indentLevel--; newLine(sb, indentLevel); sb.append("}"); } else if (item instanceof List) { sb.append("["); if (indentLevel >= 0) indentLevel++; for (Object subitem : (List) item) { newLine(sb, indentLevel); toString(sb, subitem, indentLevel); sb.append(","); } sb.deleteCharAt(sb.length() - 1); if (indentLevel >= 0) indentLevel--; newLine(sb, indentLevel); sb.append("]"); } else { throw new NotImplementedException("cannot handle class [" + item.getClass().getName() + "]"); } }
From source file:net.duckling.ddl.web.controller.task.TaskBaseController.java
/** * Task??/*from w w w. j av a 2 s .c o m*/ * * @param userIds * ?? xx1@xx.com,xx2@xx.com.... * @param site * Site * @return string xxName%xxEmail,...,... * */ private String convert2TaskNameType(String uIds, Site site) { if (StringUtils.isEmpty(uIds)) { return ""; } String emails[] = uIds.split(","); StringBuffer sb = new StringBuffer(); for (String email : emails) { if (StringUtils.isEmpty(email)) { continue; } sb.append(aoneUserService.getUserNameByID(email)).append("%").append(email).append(","); } if (sb.indexOf(",") > -1) { sb.deleteCharAt(sb.lastIndexOf(",")); } return sb.toString(); }
From source file:com.callidusrobotics.swing.SwingConsole.java
@Override public String getline(final int maxLen, final Color foreground, final Color background) throws ArrayIndexOutOfBoundsException { final StringBuffer stringBuffer = new StringBuffer(maxLen); boolean keepPolling = true; while (keepPolling) { if (stringBuffer.length() < maxLen) { showCursor();/*from w w w .j a v a 2 s. co m*/ } else { hideCursor(); } render(); final char input = getKeyTyped(); switch (input) { case KeyEvent.VK_ENTER: keepPolling = false; break; case KeyEvent.VK_BACK_SPACE: if (stringBuffer.length() > 0) { stringBuffer.deleteCharAt(stringBuffer.length() - 1); moveCursor(cursorRow, cursorCol - 1); print(cursorRow, cursorCol, ' ', background, background); } break; case KeyEvent.CHAR_UNDEFINED: case KeyEvent.VK_DELETE: case KeyEvent.VK_ESCAPE: // ignore these characters break; default: if (stringBuffer.length() < maxLen) { stringBuffer.append(input); print(cursorRow, cursorCol, input, foreground, background); moveCursor(cursorRow, cursorCol + 1); } } } hideCursor(); render(); return stringBuffer.toString(); }
From source file:com.hexin.core.dao.BaseDaoSupport.java
private void debugSql(String sql, Map<String, ?> args) { if (logger.isDebugEnabled()) { StringBuffer buffer = new StringBuffer(); buffer.append("sql: "); buffer.append(sql);/* w w w. j av a2s . com*/ buffer.append(", args: "); for (Map.Entry<String, ?> entry : args.entrySet()) { buffer.append(entry.getValue()); buffer.append(","); } buffer.deleteCharAt(buffer.length() - 1); logger.debug(buffer.toString()); } }
From source file:com.wabacus.system.dataset.select.report.value.RelationalDBReportDataSetValueProvider.java
protected String getRowGroupStatiGroupByClause(AbsListReportRowGroupSubDisplayRowBean rowGroupSubDisplayRowBean, Map<String, String> mRowGroupColumnValues) { if (rowGroupSubDisplayRowBean == null) return null; ReportBean rbean = this.getReportBean(); String[] colsArr = rowGroupSubDisplayRowBean.getParentAndMyOwnRowGroupColumnsArray(rbean); StringBuffer groupbyBuf = new StringBuffer(); for (int i = 0; i < colsArr.length; i++) { groupbyBuf.append(colsArr[i]).append(","); }/*from w ww. j a va 2s . c o m*/ if (groupbyBuf.charAt(groupbyBuf.length() - 1) == ',') { groupbyBuf.deleteCharAt(groupbyBuf.length() - 1); } String realGroupByClause = " group by " + groupbyBuf.toString() + " having " + getStatiRowGroupConditionExpression(rowGroupSubDisplayRowBean); String colvalTmp; for (int i = 0; i < colsArr.length; i++) { colvalTmp = mRowGroupColumnValues.get(colsArr[i]); if (colvalTmp == null) colvalTmp = ""; realGroupByClause = Tools.replaceAll(realGroupByClause, "#" + colsArr[i] + "#", colvalTmp); } return realGroupByClause; }
From source file:org.latticesoft.util.container.MapKey.java
public int compareTo(Object o) { if (!(o instanceof MapKey)) { return 0; }/* w ww . j a v a2 s. co m*/ MapKey that = (MapKey) o; StringBuffer sb1 = new StringBuffer(); StringBuffer sb2 = new StringBuffer(); // sort the key in order ArrayList a = new ArrayList(); Iterator iter = null; a.clear(); a.addAll(this.getMap().keySet()); Collections.sort(a); iter = a.iterator(); sb1.append("{"); while (iter.hasNext()) { Object key = iter.next(); Object value = this.getMap().get(key); sb1.append(key).append("=").append(value).append(","); } if (sb1.charAt(sb1.length() - 1) == ',') { sb1.deleteCharAt(sb1.length() - 1); } sb1.append("}"); a.clear(); a.addAll(that.getMap().keySet()); Collections.sort(a); iter = a.iterator(); sb2.append("{"); while (iter.hasNext()) { Object key = iter.next(); Object value = that.getMap().get(key); sb2.append(key).append("=").append(value).append(","); } if (sb2.charAt(sb2.length() - 1) == ',') { sb2.deleteCharAt(sb2.length() - 1); } sb2.append("}"); //if (log.isInfoEnabled()) { log.info(sb1); } //if (log.isInfoEnabled()) { log.info(sb2); } return sb1.toString().compareTo(sb2.toString()); }
From source file:org.aselect.authspserver.authsp.delegator.HTTPDelegate.java
public int authenticate(Map<String, String> requestparameters, Map<String, List<String>> responseparameters) throws DelegateException { String sMethod = "authenticate"; int iReturnCode = -1; AuthSPSystemLogger _systemLogger;/*from ww w. ja va 2 s . c o 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 // _systemLogger.log(Level.FINE, sModule, sMethod, "url=" + url.toString() + " data={" + data.toString() + "}"); // no data shown in production environment HttpURLConnection conn = (HttpURLConnection) url.openConnection(); // 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); 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(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; }
From source file:org.kuali.ole.select.service.impl.OleDocStoreLookupServiceImpl.java
/** * This method returns relationships in datadictionary * * @param c/*w w w . j av a2 s .c o m*/ * @return */ public Map<String, List<String>> getDDRelationship(Class c) { LOG.debug("Inside getDDRelationship of OleDocStoreLookupServiceImpl"); Map<String, List<String>> result = new HashMap<String, List<String>>(0); DataDictionaryEntry entryBase = SpringContext.getBean(DataDictionaryService.class).getDataDictionary() .getDictionaryObjectEntry(c.getName()); if (entryBase == null) { return null; } List<RelationshipDefinition> ddRelationships = entryBase.getRelationships(); RelationshipDefinition relationship = null; int minKeys = Integer.MAX_VALUE; for (RelationshipDefinition def : ddRelationships) { // favor key sizes of 1 first if (def.getPrimitiveAttributes().size() == 1) { for (PrimitiveAttributeDefinition primitive : def.getPrimitiveAttributes()) { if (def.getObjectAttributeName() != null) { List<String> data = new ArrayList<String>(0); Class cc = getDocClass(c, def.getObjectAttributeName());//cc= null;data.remove("java.lang.String"); if (cc != null) { data.add(cc.getName()); StringBuffer sb = new StringBuffer(); List<PrimitiveAttributeDefinition> res = def.getPrimitiveAttributes(); for (PrimitiveAttributeDefinition pdef : res) { sb.append(pdef.getSourceName() + "," + pdef.getTargetName() + ":"); } sb.deleteCharAt(sb.length() - 1); data.add(sb.toString()); result.put(def.getObjectAttributeName(), data); } } } } } LOG.debug("Leaving getDDRelationship of OleDocStoreLookupServiceImpl"); return result; }
From source file:com.fujitsu.dc.test.jersey.box.acl.AclTest.java
() { String testBox = "testBox01"; String testRole = "testRole01"; try {/* w ww . jav a 2s.c o m*/ // Box?? BoxUtils.create(TEST_CELL1, testBox, TOKEN); // Box????Role?? RoleUtils.create(TEST_CELL1, TOKEN, testBox, testRole, HttpStatus.SC_CREATED); // Box?Role?ACL DavResourceUtils.setACLwithBox(TEST_CELL1, TOKEN, HttpStatus.SC_OK, testBox, "", ACL_SETTING_TEST, testRole, testBox, "<D:read/>", ""); // PROPFIND TResponse res = DavResourceUtils.propfind("box/propfind-box-allprop.txt", TOKEN, HttpStatus.SC_MULTI_STATUS, testBox); // PROPFIND?? List<Map<String, List<String>>> list = new ArrayList<Map<String, List<String>>>(); Map<String, List<String>> map = new HashMap<String, List<String>>(); List<String> rolList = new ArrayList<String>(); rolList.add("read"); list.add(map); map.put(testRole, rolList); Element root = res.bodyAsXml().getDocumentElement(); String resorce = UrlUtils.box(TEST_CELL1, testBox); // UrlUtil???URL????? StringBuffer sb = new StringBuffer(resorce); sb.deleteCharAt(resorce.length() - 1); TestMethodUtils.aclResponseTest(root, sb.toString(), list, 1, UrlUtils.roleResource(TEST_CELL1, testBox, ""), null); } finally { // Role? RoleUtils.delete(TEST_CELL1, TOKEN, testBox, testRole); // Box1? BoxUtils.delete(TEST_CELL1, TOKEN, testBox); } }