List of usage examples for java.lang StringBuffer setLength
@Override public synchronized void setLength(int newLength)
From source file:com.clustercontrol.infra.view.action.EnableInfraManagementAction.java
@Override public Object execute(ExecutionEvent event) throws ExecutionException { this.window = HandlerUtil.getActiveWorkbenchWindow(event); // In case this action has been disposed if (null == this.window || !isEnabled()) { return null; }/*from w w w .j a v a2 s . co m*/ // ??? this.viewPart = HandlerUtil.getActivePart(event); if (!(viewPart instanceof InfraManagementView)) { return null; } InfraManagementView infraManagementView = null; try { infraManagementView = (InfraManagementView) viewPart.getAdapter(InfraManagementView.class); } catch (Exception e) { m_log.info("execute " + e.getMessage()); return null; } if (infraManagementView == null) { m_log.info("execute: view is null"); return null; } StructuredSelection selection = null; if (infraManagementView.getComposite().getTableViewer().getSelection() instanceof StructuredSelection) { selection = (StructuredSelection) infraManagementView.getComposite().getTableViewer().getSelection(); } if (selection == null) { return null; } List<?> sList = (List<?>) selection.toList(); Map<String, List<String>> managementIdMap = new ConcurrentHashMap<String, List<String>>(); for (Object obj : sList) { List<?> list = (List<?>) obj; String managerName = null; if (list == null) { continue; } managerName = (String) list.get(GetInfraManagementTableDefine.MANAGER_NAME); if (managementIdMap.get(managerName) == null) { managementIdMap.put(managerName, new ArrayList<String>()); } } StringBuffer idbuf = new StringBuffer(); int size = 0; for (Object obj : sList) { List<?> list = (List<?>) obj; String managementId = null; String managerName = null; if (list != null) { managementId = (String) list.get(GetInfraManagementTableDefine.MANAGEMENT_ID); managerName = (String) list.get(GetInfraManagementTableDefine.MANAGER_NAME); managementIdMap.get(managerName).add(managementId); if (size > 0) { idbuf.append(", "); } idbuf.append(managementId); size++; } } if (MessageDialog.openConfirm(null, Messages.getString("confirmed"), Messages.getString("message.infra.confirm.action", new Object[] { Messages.getString("infra.management.id"), Messages.getString("infra.enable.setting"), idbuf.toString() })) == false) { return null; } StringBuffer sucManagementIds = new StringBuffer(); StringBuffer failManagementIds = new StringBuffer(); for (Map.Entry<String, List<String>> entry : managementIdMap.entrySet()) { String managerName = entry.getKey(); InfraEndpointWrapper wrapper = InfraEndpointWrapper.getWrapper(managerName); for (String managementId : entry.getValue()) { try { InfraManagementInfo info = wrapper.getInfraManagement(managementId); info.setValidFlg(true); try { wrapper.modifyInfraManagement(info); sucManagementIds.append(managementId + "(" + managerName + ")" + ", "); } catch (InvalidSetting_Exception | NotifyDuplicate_Exception | HinemosUnknown_Exception | InvalidRole_Exception | InvalidUserPass_Exception | InfraManagementNotFound_Exception | InfraManagementDuplicate_Exception e) { m_log.debug("execute modifyInfraManagement, " + e.getMessage()); failManagementIds.append(managementId + ", "); } } catch (HinemosUnknown_Exception | InvalidRole_Exception | InvalidUserPass_Exception | NotifyNotFound_Exception | InfraManagementNotFound_Exception e) { m_log.debug("execute getInfraManagement, " + e.getMessage()); failManagementIds.append(managementId + ", "); } } } //????? if (sucManagementIds.length() > 0) { sucManagementIds.setLength(sucManagementIds.length() - 2); MessageDialog.openInformation(null, Messages.getString("successful"), Messages.getString("message.infra.action.result", new Object[] { Messages.getString("infra.management.id"), Messages.getString("infra.enable.setting"), Messages.getString("successful"), sucManagementIds })); } //???? if (failManagementIds.length() > 0) { failManagementIds.setLength(failManagementIds.length() - 2); MessageDialog.openError(null, Messages.getString("failed"), Messages.getString("message.infra.action.result", new Object[] { Messages.getString("infra.management.id"), Messages.getString("infra.enable.setting"), Messages.getString("failed"), failManagementIds })); } infraManagementView.update(); return null; }
From source file:XmlReader.java
private void useEncodingDecl(PushbackInputStream pb, String encoding) throws IOException { byte buffer[] = new byte[MAXPUSHBACK]; int len;//from w ww . j a v a 2 s. c om Reader r; int c; // // Buffer up a bunch of input, and set up to read it in // the specified encoding ... we can skip the first four // bytes since we know that "<?xm" was read to determine // what encoding to use! // len = pb.read(buffer, 0, buffer.length); pb.unread(buffer, 0, len); r = new InputStreamReader(new ByteArrayInputStream(buffer, 4, len), encoding); // // Next must be "l" (and whitespace) else we conclude // error and choose UTF-8. // if ((c = r.read()) != 'l') { setEncoding(pb, "UTF-8"); return; } // // Then, we'll skip any // S version="..." [or single quotes] // bit and get any subsequent // S encoding="..." [or single quotes] // // We put an arbitrary size limit on how far we read; lots // of space will break this algorithm. // StringBuffer buf = new StringBuffer(); StringBuffer keyBuf = null; String key = null; boolean sawEq = false; char quoteChar = 0; boolean sawQuestion = false; XmlDecl: for (int i = 0; i < MAXPUSHBACK - 5; ++i) { if ((c = r.read()) == -1) break; // ignore whitespace before/between "key = 'value'" if (c == ' ' || c == '\t' || c == '\n' || c == '\r') continue; // ... but require at least a little! if (i == 0) break; // terminate the loop ASAP if (c == '?') sawQuestion = true; else if (sawQuestion) { if (c == '>') break; sawQuestion = false; } // did we get the "key =" bit yet? if (key == null || !sawEq) { if (keyBuf == null) { if (Character.isWhitespace((char) c)) continue; keyBuf = buf; buf.setLength(0); buf.append((char) c); sawEq = false; } else if (Character.isWhitespace((char) c)) { key = keyBuf.toString(); } else if (c == '=') { if (key == null) key = keyBuf.toString(); sawEq = true; keyBuf = null; quoteChar = 0; } else keyBuf.append((char) c); continue; } // space before quoted value if (Character.isWhitespace((char) c)) continue; if (c == '"' || c == '\'') { if (quoteChar == 0) { quoteChar = (char) c; buf.setLength(0); continue; } else if (c == quoteChar) { if ("encoding".equals(key)) { assignedEncoding = buf.toString(); // [81] Encname ::= [A-Za-z] ([A-Za-z0-9._]|'-')* for (i = 0; i < assignedEncoding.length(); i++) { c = assignedEncoding.charAt(i); if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) continue; if (i == 0) break XmlDecl; if (i > 0 && (c == '-' || (c >= '0' && c <= '9') || c == '.' || c == '_')) continue; // map illegal names to UTF-8 default break XmlDecl; } setEncoding(pb, assignedEncoding); return; } else { key = null; continue; } } } buf.append((char) c); } setEncoding(pb, "UTF-8"); }
From source file:com.tremolosecurity.provisioning.core.providers.AlfrescoProviderREST.java
private AlfrescoUser userLookup(String userID, String token) throws IOException, ClientProtocolException, ProvisioningException { StringBuffer b = new StringBuffer(); b.append(this.endpoint).append("/people/").append(userID).append("?alf_ticket=").append(token); HttpGet httpget = new HttpGet(b.toString()); try {//from w ww .java2 s .c o m try { LastMileUtil.addLastMile(cfg, loginId, HEADER_NAME, httpget, lastMileKeyAlias, useLastMile); } catch (Exception e) { throw new ProvisioningException("Error generating provisioning last mile", e); } //httpget.addHeader("X-Alfresco-Remote-User", this.loginId); CloseableHttpResponse response = httpclient.execute(httpget); if (response.getStatusLine().getStatusCode() == 404) { throw new ProvisioningException("User does not exist"); } BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer sb = new StringBuffer(); String line = null; while ((line = in.readLine()) != null) { sb.append(line).append('\n'); } in.close(); response.close(); line = sb.toString(); int index = line.indexOf("\"capabilities\""); index = line.lastIndexOf(',', index); b.setLength(0); b.append(line.substring(0, index)).append("\n}"); line = b.toString(); Gson gson = new Gson(); AlfrescoUser userDetails = gson.fromJson(line, AlfrescoUser.class); return userDetails; } finally { httpget.releaseConnection(); } }
From source file:com.pureinfo.srm.outlay.action.SearchCheckCodeAction.java
/** * // w ww.j a v a 2 s.co m * @param _content * @return */ public String formTable(String _content) { String tableInfo = ""; if (_content != null && !"".equals(_content.trim())) { String[] rowData = _content.split("\\n"); StringBuffer tableStr = new StringBuffer(); for (int i = 0; (rowData.length >= 20 ? i < 20 : i < rowData.length); i++) { tableStr.append("<TR id=\"tr_37431\" bgcolor=\"#F6F6F6\">"); String[] columnData = rowData[i].split("~"); tableStr.append("<TD align=\"center\" class=\"tablebody\">" + i + "</TD>"); for (int j = 0; j < columnData.length; j++) { if (j == 0) { String datatemp = ""; if (!"".equals(columnData[3])) { datatemp = columnData[3].substring(0, 10); } tableStr.append( "<td class=\"tablebody\" align=\"left\" ><a href=\"javascript:top.opener.insertCheckCodeInfo('" + columnData[0] + "','" + datatemp + "','" + columnData[5] + "','" + columnData[4] + "');top.window.close();\" target=\"\" title=\"\" >" + columnData[0] + "</a> </td>"); } else { tableStr.append("<td class=\"tablebody\" align=\"left\" NOWRAP>"); if (j == 3) { if (!"".equals(columnData[j])) { tableStr.append(columnData[j].substring(0, 10)); } } else { tableStr.append(columnData[j]); } tableStr.append("</td>"); } } tableStr.append("</TR>"); } tableStr.append("</td></tr>"); tableInfo = tableStr.toString(); tableStr.setLength(0); } return tableInfo; }
From source file:com.wavemaker.runtime.ws.salesforce.SalesforceSupport.java
private Tuple.Two<Integer, List<Tuple.Two<String, Integer>>> getInitSubQueries(int parentId, String qry, int pfnum) { List<String> words = QueryHandler.parseSQL(qry); List<Tuple.Two<String, Integer>> qryList = new ArrayList<Tuple.Two<String, Integer>>(); List<String> fieldList = new ArrayList<String>(); MultiValueMap relFieldList = new MultiValueMap(); this.lastQryId = this.lastQryId + 1; String objName = null;//from ww w. j ava 2s . c o m int depth = 0; int remainingOpens = 0; int counter = 0; int qryStartPos = 0; boolean inSubQuery = false; boolean inFrom = false; StringBuffer subQry = new StringBuffer(); for (String word : words) { if (word.equalsIgnoreCase("select")) { if (!inSubQuery) { if (depth == 0) { depth++; } else { // select statement of a subquery qryStartPos = counter; subQry.append(word); subQry.append(" "); inSubQuery = true; } } } else if (word.equals(")")) { if (inSubQuery) { if (remainingOpens == 0) { Tuple.Two<String, Integer> elem = new Tuple.Two<String, Integer>(subQry.toString(), qryStartPos); qryList.add(elem); counter++; subQry.setLength(0); inSubQuery = false; } else { remainingOpens--; } } } else if (word.equals("(")) { if (inSubQuery) { remainingOpens++; } } else if (word.equalsIgnoreCase("from")) { if (!inSubQuery) { inFrom = true; } else { subQry.append(word); subQry.append(" "); } } else { if (inSubQuery) { subQry.append(word); subQry.append(" "); } else { if (!QueryHandler.isDelimiter(word)) { if (inFrom) { objName = word; inFrom = false; break; } else { int indx = word.indexOf("."); if (indx < 0) { fieldList.add(word); } else { relFieldList.put(word.substring(0, indx), word.substring(indx + 1)); } counter++; } } } } } SingleQuery sq = new SingleQuery(this.lastQryId, parentId, objName, fieldList, relFieldList, pfnum); this.queryMap.put(this.lastQryId, sq); this.parentQueryMap.put(parentId, sq); Tuple.Two<Integer, List<Tuple.Two<String, Integer>>> rtn = new Tuple.Two<Integer, List<Tuple.Two<String, Integer>>>( this.lastQryId, qryList); return rtn; }
From source file:ClassFile.java
/** * print out the method, much as you would see it in the source * file. The string ClassName is substituted for <init> when * printing.//from w w w .ja v a 2 s .c o m */ public String toString(String className) { StringBuffer x = new StringBuffer(); boolean isArray = false; String paramSig; String returnSig; int ndx = 0; StringBuffer parameterList = new StringBuffer(); char initialParameter = 'a'; StringBuffer varName = new StringBuffer(); String s = signature.strValue; paramSig = s.substring(s.indexOf('(') + 1, s.indexOf(')')); returnSig = s.substring(s.indexOf(')') + 1); x.append(ClassFile.accessString(accessFlags)); /* catch constructors */ if ((className != null) && (name.toString().startsWith("<init>"))) parameterList.append(className); else parameterList.append(name.toString()); parameterList.append("("); if ((paramSig.length() > 0) && paramSig.charAt(0) != 'V') { while (paramSig.length() > 0) { varName.setLength(0); varName.append(initialParameter); initialParameter++; parameterList.append(ClassFile.typeString(paramSig, varName.toString())); paramSig = ClassFile.nextSig(paramSig); if (paramSig.length() > 0) parameterList.append(", "); } } parameterList.append(")"); x.append(ClassFile.typeString(returnSig, parameterList.toString())); x.append(";"); return (x.toString()); }
From source file:ExposedInt.java
void UpdateNumberFields() { decimalField.setText(Integer.toString(value)); int v = value; StringBuffer buf = new StringBuffer(); for (int i = 0; i < 8; ++i) { // Get lowest bit int remainder = v & 0xf; // Convert bit to a character and insert it into the beginning of the string switch (remainder) { case 0:/* w w w . j av a2 s. c o m*/ buf.insert(0, "0"); break; case 1: buf.insert(0, "1"); break; case 2: buf.insert(0, "2"); break; case 3: buf.insert(0, "3"); break; case 4: buf.insert(0, "4"); break; case 5: buf.insert(0, "5"); break; case 6: buf.insert(0, "6"); break; case 7: buf.insert(0, "7"); break; case 8: buf.insert(0, "8"); break; case 9: buf.insert(0, "9"); break; case 10: buf.insert(0, "a"); break; case 11: buf.insert(0, "b"); break; case 12: buf.insert(0, "c"); break; case 13: buf.insert(0, "d"); break; case 14: buf.insert(0, "e"); break; case 15: buf.insert(0, "f"); break; } // Shift the int to the right one bit v >>>= 4; } hexField.setText(buf.toString()); v = value; buf.setLength(0); for (int i = 0; i < 32; ++i) { // Get lowest bit int remainder = v & 0x1; // Convert bit to a character and insert it into the beginning of the string if (remainder == 0) { buf.insert(0, "0"); } else { buf.insert(0, "1"); } // Shift the int to the right one bit v >>>= 1; } binaryField.setText(buf.toString()); }
From source file:com.vladium.emma.report.html.ReportGenerator.java
private void addItemRow(final IItem item, final boolean odd, final HTMLTable table, final int[] columns, final String nameHREF, final boolean anchor) { if ($assert.ENABLED) { $assert.ASSERT(item != null, "null input: item"); $assert.ASSERT(table != null, "null input: table"); $assert.ASSERT(columns != null, "null input: columns"); }/*from w w w. j a v a 2s . c o m*/ final HTMLTable.IRow row = table.newRow(); if (odd) row.setClass(CSS_ODDROW); final StringBuffer buf = new StringBuffer(11); // TODO: reuse a buffer for (int c = 0; c < columns.length; ++c) { final int attrID = columns[c]; final IItemAttribute attr = item.getAttribute(attrID, m_settings.getUnitsType()); if (attr != null) { final HTMLTable.ICell cell = row.newCell(); if ((nameHREF != null) && (attrID == IItemAttribute.ATTRIBUTE_NAME_ID)) { buf.setLength(0); attr.format(item, buf); trimForDisplay(buf); final String fullHREFName = anchor ? "#".concat(nameHREF) : nameHREF; cell.add(new HyperRef(fullHREFName, buf.toString(), true)); } else { final boolean fail = (m_metrics[attrID] > 0) && !attr.passes(item, m_metrics[attrID]); buf.setLength(0); attr.format(item, buf); trimForDisplay(buf); cell.setText(buf.toString(), true); if (fail) cell.setClass(CSS_DATA_HIGHLIGHT); } } else { // note: by design this puts empty cells for nonexistent attribute types final HTMLTable.ICell cell = row.newCell(); cell.setText(" ", true); } } }
From source file:com.pureinfo.dolphinview.function.dolphin.ShowRelativesExFunctionHandler.java
/** * @see com.pureinfo.dolphinview.parser.function.FunctionHandlerDVImplBase#perform(java.lang.Object[], * com.pureinfo.dolphinview.context.model.IDVContext) *//*from w ww .j av a 2s .c o m*/ public Object perform(Object[] _args, IDVContext _context) throws PureException { FunctionHandlerUtil.validateArgsNum(_args, MIN_ARG_NUM); // 1. to read parameters String sAlias = (String) _args[ARG_ALIAS]; String sViewScript = (String) _args[ARG_VIEW_SCRIPT]; ScriptBlock viewScript = ScriptReader.readBlock(sViewScript); String sDelim = (String) _args[ARG_DELIM]; String sOrderBy; if (_args.length > ARG_ORDERBY) { sOrderBy = (String) _args[ARG_ORDERBY]; } else { sOrderBy = null; } int nFrom = 0; int nMaxSize = 0; if (_args.length > ARG_POS_FROM) { nFrom = FunctionHandlerUtil.getIntArg(_args, ARG_POS_FROM, 0); if (nFrom < 0) { nFrom = 0; } if (_args.length > ARG_MAX_SIZE) { nMaxSize = FunctionHandlerUtil.getIntArg(_args, ARG_MAX_SIZE, 0); if (nMaxSize < 0) { nMaxSize = 0; } } } // 2. to find the relative objects StringBuffer sbuff = null; List params = null; IStatement query = null; IObjects objs = null; QueryFilter filter = new QueryFilter(); try { // 2.1 to render query SQL DolphinObject object = _context.getObject(); Class relativeClass = RelativeUtil.renderFilter(object, sAlias, filter); if (StringUtils.isEmpty(filter.getSelect())) { filter.setSelect("{" + sAlias + ".*}"); } if (sOrderBy != null && (sOrderBy = sOrderBy.trim()).length() > 0) { filter.setOrder(sOrderBy); } // 2.2 to prepare query params = new ArrayList(); String strSQL = filter.toSQL(params); logger.debug("SQL: " + strSQL); // 2.3 to execute query ISession session = LocalContextHelper.currentSession(); query = session.createQuery(strSQL, relativeClass, nMaxSize > 0 ? nFrom + nMaxSize : 0); filter.registerEntitiesInQuery(query); query.setParameters(0, params); objs = query.executeQuery(false); if (nFrom > 0) { objs.skip(nFrom); } // 2.4 to render the view content sbuff = new StringBuffer(); while ((object = objs.next()) != null) { if (sbuff.length() > 0) { sbuff.append(sDelim); } SimpleDVContext context = new SimpleDVContext(object); context.setParent(_context); String sResult = Executer.execute(viewScript, context); sbuff.append(sResult); } return sbuff.toString(); } finally { DolphinHelper.clear(objs, query); if (sbuff != null) sbuff.setLength(0); if (params != null) params.clear(); } }
From source file:com.pureinfo.srm.product.action.Product3indexDuplicateAction.java
public String getHeadTable() throws PureException { StringBuffer sbuff = new StringBuffer(); try {/*from ww w. j a v a2 s . c o m*/ sbuff.append("<tr><TD align=\"right\"> \n"); sbuff.append( SRMWebHelper.renderCountOfPage(request.getInt(SRMWebHelper.COUNT_OF_PAGE, "", 15))); sbuff.append("<input type=\"button\" onclick='changeCountOfPage()' value=\"\">"); sbuff.append("<script language=\"javascript\">\n"); sbuff.append(" function changeCountOfPage() {\n"); sbuff.append(" var objs = document.getElementsByName('").append(SRMWebHelper.COUNT_OF_PAGE) .append("');\n"); sbuff.append(" var obj;"); sbuff.append(" for (var i = 0; i < objs.length; i ++) {"); sbuff.append(" if (objs[i].tagName == 'SELECT') obj = objs[i];"); sbuff.append(" }\n"); sbuff.append(" var nValue = obj.options[obj.selectedIndex].value;\n"); sbuff.append(" if (HideForm.").append(SRMWebHelper.COUNT_OF_PAGE).append("==null) {"); sbuff.append(" var sAction = HideForm.action;\n"); sbuff.append(" if (sAction.indexOf('?')>0) {\n"); sbuff.append(" sAction += '&").append(SRMWebHelper.COUNT_OF_PAGE).append("='+nValue;\n"); sbuff.append(" } else {\n"); sbuff.append(" sAction += '?").append(SRMWebHelper.COUNT_OF_PAGE).append("='+nValue;\n"); sbuff.append(" }\n"); sbuff.append(" HideForm.action=sAction;\n"); sbuff.append(" } else { \n"); sbuff.append(" HideForm.").append(SRMWebHelper.COUNT_OF_PAGE).append(".value=nValue\n"); sbuff.append(" }"); sbuff.append(" HideForm.submit();"); sbuff.append("}"); sbuff.append("</script>"); sbuff.append("</td></tr>"); return sbuff.toString(); } finally { sbuff.setLength(0); } }