List of usage examples for java.lang StringBuffer substring
@Override public synchronized String substring(int start)
From source file:lcmc.cluster.ui.ClusterBrowser.java
public void parseClusterOutput(final String output, final StringBuffer clusterStatusOutput, final Host host, final CountDownLatch firstTime, final Application.RunMode runMode) { final ClusterStatus clusterStatus0 = this.clusterStatus; clStatusLock();/* w w w . ja v a2 s. com*/ if (crmStatusCanceledByUser || clusterStatus0 == null) { clStatusUnlock(); firstTime.countDown(); return; } if (output == null || "".equals(output)) { clusterStatus0.setOnlineNode(host.getName(), "no"); setCrmStatus(host, false); firstTime.countDown(); } else { // TODO: if we get ERROR:... show it somewhere clusterStatusOutput.append(output); /* removes the string from the output. */ int s = clusterStatusOutput.indexOf(RESET_STRING); while (s >= 0) { clusterStatusOutput.delete(s, s + RESET_STRING_LEN); s = clusterStatusOutput.indexOf(RESET_STRING); } if (clusterStatusOutput.length() > 12) { final String e = clusterStatusOutput.substring(clusterStatusOutput.length() - 12); if (e.trim().equals("---done---")) { final int i = clusterStatusOutput.lastIndexOf("---start---"); if (i >= 0) { if (clusterStatusOutput.indexOf("is stopped") >= 0) { /* TODO: heartbeat's not running. */ } else { final String status = clusterStatusOutput.substring(i); clusterStatusOutput.delete(0, clusterStatusOutput.length()); if (CLUSTER_STATUS_ERROR.equals(status)) { final boolean oldStatus = host.isCrmStatusOk(); clusterStatus0.setOnlineNode(host.getName(), "no"); setCrmStatus(host, false); if (oldStatus) { crmGraph.repaint(); } } else { if (clusterStatus0.parseStatus(status)) { LOG.debug1("processClusterOutput: host: " + host.getName()); final ServicesInfo ssi = servicesInfo; rscDefaultsInfo.setParameters(clusterStatus0.getRscDefaultsValuePairs()); ssi.setGlobalConfig(clusterStatus0); resourceUpdaterProvider.get().updateAllResources(ssi, ssi.getBrowser(), clusterStatus0, runMode); if (firstTime.getCount() == 1) { /* one more time so that id-refs work.*/ resourceUpdaterProvider.get().updateAllResources(ssi, ssi.getBrowser(), clusterStatus0, runMode); } treeMenuController.repaintMenuTree(); clusterHostsInfo.updateTable(ClusterHostsInfo.MAIN_TABLE); } final String online = clusterStatus0.isOnlineNode(host.getName()); if ("yes".equals(online)) { setCrmStatus(host, true); setCrmStatus(); } else { setCrmStatus(host, false); } } } firstTime.countDown(); } } } Tools.chomp(clusterStatusOutput); } clStatusUnlock(); }
From source file:cn.jsprun.struts.action.BasicSettingsAction.java
public ActionForward datetime(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {/*from w w w . j a v a 2 s . c o m*/ try { if (submitCheck(request, "settingsubmit")) { String variables[] = { "dateformat", "timeformat", "timeoffset", "userdateformat", "visitbanperiods", "postbanperiods", "postmodperiods", "attachbanperiods", "searchbanperiods", }; Map<String, String> oldSettings = ForumInit.settings; Map<String, String> settings = new HashMap<String, String>(); for (String variable : variables) { String value = request.getParameter(variable); if ("dateformat".equals(variable) || "userdateformat".equals(variable)) { value = Common.htmlspecialchars(value); } else if ("timeformat".equals(variable)) { oldSettings.put("gtimeformat", "1".equals(value) ? "hh:mm a" : "HH:mm"); } else if ("visitbanperiods|postbanperiods|postmodperiods|attachbanperiods|searchbanperiods" .contains(variable)) { String[] periods = value.split("\n"); StringBuffer periodTemp = new StringBuffer(); for (String period : periods) { if (period.trim().matches("^\\d{1,2}\\:\\d{2}\\-\\d{1,2}\\:\\d{2}$")) { periodTemp.append("\n" + period.trim()); } } value = (periodTemp.length() > 0 ? periodTemp.substring(1) : ""); } this.putValue(variable, value, oldSettings, settings); } this.updateSettings(settings, oldSettings); return this.getForward(mapping, request); } } catch (Exception e) { request.setAttribute("message", e.getMessage()); return mapping.findForward("message"); } request.setAttribute("timeZoneIDs", Common.getTimeZoneIDs()); return mapping.findForward("setting_datetime"); }
From source file:lcmc.gui.ClusterBrowser.java
/** Process output from cluster. */ void processClusterOutput(final String output, final StringBuffer clusterStatusOutput, final Host host, final CountDownLatch firstTime, final boolean testOnly) { final ClusterStatus clStatus = clusterStatus; clStatusLock();/*ww w. j a va 2s .c om*/ if (clStatusCanceled || clStatus == null) { clStatusUnlock(); firstTime.countDown(); return; } if (output == null || "".equals(output)) { clStatus.setOnlineNode(host.getName(), "no"); setClStatus(host, false); firstTime.countDown(); } else { // TODO: if we get ERROR:... show it somewhere clusterStatusOutput.append(output); /* removes the string from the output. */ int s = clusterStatusOutput.indexOf(RESET_STRING); while (s >= 0) { clusterStatusOutput.delete(s, s + RESET_STRING_LEN); s = clusterStatusOutput.indexOf(RESET_STRING); } if (clusterStatusOutput.length() > 12) { final String e = clusterStatusOutput.substring(clusterStatusOutput.length() - 12); if (e.trim().equals("---done---")) { final int i = clusterStatusOutput.lastIndexOf("---start---"); if (i >= 0) { if (clusterStatusOutput.indexOf("is stopped") >= 0) { /* TODO: heartbeat's not running. */ } else { final String status = clusterStatusOutput.substring(i); clusterStatusOutput.delete(0, clusterStatusOutput.length()); if (CLUSTER_STATUS_ERROR.equals(status)) { final boolean oldStatus = host.isClStatus(); clStatus.setOnlineNode(host.getName(), "no"); setClStatus(host, false); if (oldStatus) { crmGraph.repaint(); } } else { if (clStatus.parseStatus(status)) { Tools.debug(this, "update cluster status: " + host.getName(), 1); final ServicesInfo ssi = servicesInfo; rscDefaultsInfo.setParameters(clStatus.getRscDefaultsValuePairs()); ssi.setGlobalConfig(clStatus); ssi.setAllResources(clStatus, testOnly); if (firstTime.getCount() == 1) { /* one more time so that id-refs work.*/ ssi.setAllResources(clStatus, testOnly); } repaintTree(); clusterHostsInfo.updateTable(ClusterHostsInfo.MAIN_TABLE); } final String online = clStatus.isOnlineNode(host.getName()); if ("yes".equals(online)) { setClStatus(host, true); setClStatus(); } else { setClStatus(host, false); } } } firstTime.countDown(); } } } Tools.chomp(clusterStatusOutput); } clStatusUnlock(); }
From source file:cn.jsprun.struts.action.BasicSettingsAction.java
public ActionForward basic(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {// w w w . ja v a 2 s . c o m Map<String, String> oldSettings = ForumInit.settings; try { if (submitCheck(request, "settingsubmit")) { String variables[] = { "forumfounders", "bbname", "sitename", "indexname", "siteurl", "icp", "boardlicensed", "bbclosed", "closedreason" }; Map<String, String> settings = new HashMap<String, String>(); for (String variable : variables) { String value = request.getParameter(variable); if (value != null) { if (variable.equals("forumfounders")) { StringBuffer uids = new StringBuffer(); String forumfounders[] = value.split(","); for (String forumfounder : forumfounders) { int uid = Common.toDigit(forumfounder); if (uid > 0) { uids.append("," + uid); } } StringBuffer valuebuffer = new StringBuffer(); if (uids.length() > 0) { List<Map<String, String>> founders = dataBaseService .executeQuery("select uid,adminid from jrun_members where uid in (" + uids.substring(1) + ")"); if (founders != null && founders.size() > 0) { for (Map<String, String> founder : founders) { if (founder.get("adminid").equals("1")) { valuebuffer.append("," + founder.get("uid")); } } } } value = valuebuffer.length() > 0 ? valuebuffer.substring(1) : ""; } this.putValue(variable, value.trim(), oldSettings, settings); } } this.updateSettings(settings, oldSettings); return this.getForward(mapping, request); } } catch (Exception e) { request.setAttribute("message", e.getMessage()); return mapping.findForward("message"); } boolean isfounder = (Boolean) request.getAttribute("isfounder"); if (!isfounder) { String forumfounder = oldSettings.get("forumfounders"); if (forumfounder != null && forumfounder.length() > 0) { List<Map<String, String>> founders = dataBaseService .executeQuery("select username from jrun_members where uid in (" + forumfounder + ")"); request.setAttribute("founderlist", founders); } } return mapping.findForward("setting_basic"); }
From source file:com.flexoodb.common.FlexUtils.java
static public String BufferedInputStreamToString(InputStream bufferedInput) { StringBuffer result = new StringBuffer(); byte[] buffer = new byte[1024]; try {//w w w .j av a2 s. com int bytesRead = 0; //Keep reading from the file while there is any content //when the end of the stream has been reached, -1 is returned while ((bytesRead = bufferedInput.read(buffer)) != -1) { //Process the chunk of bytes read //in this case we just construct a String and print it out String chunk = new String(buffer, 0, bytesRead); result.append(chunk); } } catch (IOException ex) { ex.printStackTrace(); } finally { //Close the BufferedInputStream try { if (bufferedInput != null) bufferedInput.close(); } catch (IOException ex) { ex.printStackTrace(); } } return result.substring(0); }
From source file:com.flexoodb.common.FlexUtils.java
static public String getRDBMSTableStructureAsXML(String tablename, ResultSet result) { StringBuffer res = new StringBuffer(); try {//from w w w . j a v a2 s . c o m RecordSet rec = new RecordSet(result); int size = rec.size(); if (size > 0) { Enumeration en = rec.getColumnNames(); res.append("<" + tablename + ">"); while (en.hasMoreElements()) { String cname = (String) en.nextElement(); String type = rec.getColumnType(cname); if (type.toUpperCase().indexOf("BLOB") > -1 && type.toUpperCase().indexOf("BINARY") > -1) { res.append("<" + cname + " type=\"byte[]\"/>"); } else { res.append("<" + cname + " type=\"" + type + "\"/>"); } } res.append("</" + tablename + ">"); } } catch (Exception e) { e.printStackTrace(); } return res.substring(0); }
From source file:org.apache.poi.ss.format.CellNumberFormatter.java
private void writeScientific(double value, StringBuffer output, Set<StringMod> mods) { StringBuffer result = new StringBuffer(); FieldPosition fractionPos = new FieldPosition(DecimalFormat.FRACTION_FIELD); decimalFmt.format(value, result, fractionPos); writeInteger(result, output, integerSpecials, mods, integerCommas); writeFractional(result, output);/*from www . j a v a 2 s . c o m*/ /* * Exponent sign handling is complex. * * In DecimalFormat, you never put the sign in the format, and the sign only * comes out of the format if it is negative. * * In Excel, you always say whether to always show the sign ("e+") or only * show negative signs ("e-"). * * Also in Excel, where you put the sign in the format is NOT where it comes * out in the result. In the format, the sign goes with the "e"; in the * output it goes with the exponent value. That is, if you say "#e-|#" you * get "1e|-5", not "1e-|5". This makes sense I suppose, but it complicates * things. * * Finally, everything else in this formatting code assumes that the base of * the result is the original format, and that starting from that situation, * the indexes of the original special characters can be used to place the new * characters. As just described, this is not true for the exponent's sign. * <p/> * So here is how we handle it: * * (1) When parsing the format, remove the sign from after the 'e' and put it * before the first digit of the exponent (where it will be shown). * * (2) Determine the result's sign. * * (3) If it's missing, put the sign into the output to keep the result * lined up with the output. (In the result, "after the 'e'" and "before the * first digit" are the same because the result has no extra chars to be in * the way.) * * (4) In the output, remove the sign if it should not be shown ("e-" was used * and the sign is negative) or set it to the correct value. */ // (2) Determine the result's sign. int ePos = fractionPos.getEndIndex(); int signPos = ePos + 1; char expSignRes = result.charAt(signPos); if (expSignRes != '-') { // not a sign, so it's a digit, and therefore a positive exponent expSignRes = '+'; // (3) If it's missing, put the sign into the output to keep the result // lined up with the output. result.insert(signPos, '+'); } // Now the result lines up like it is supposed to with the specials' indexes ListIterator<Special> it = exponentSpecials.listIterator(1); Special expSign = it.next(); char expSignFmt = expSign.ch; // (4) In the output, remove the sign if it should not be shown or set it to // the correct value. if (expSignRes == '-' || expSignFmt == '+') mods.add(replaceMod(expSign, true, expSign, true, expSignRes)); else mods.add(deleteMod(expSign, true, expSign, true)); StringBuffer exponentNum = new StringBuffer(result.substring(signPos + 1)); writeInteger(exponentNum, output, exponentDigitSpecials, mods, false); }
From source file:com.redsqirl.CanvasBean.java
public void paste() throws RemoteException { logger.info("paste"); String error = null;/*from w w w. j a v a2s . c om*/ if (wfCopyBuffer != null && getDf() != null) { error = getworkFlowInterface().copy(wfCopyBuffer.getDfCloneId(), wfCopyBuffer.getElementsToCopy(), getNameWorkflow()); if (error == null) { Iterator<String> elIt = getDf().getComponentIds().iterator(); Map<String, String> idMapWf = idMap.get(getNameWorkflow()); StringBuffer ans = new StringBuffer(); while (elIt.hasNext()) { String elCur = elIt.next(); if (!idMapWf.containsValue(elCur)) { idMapWf.put(elCur, elCur); ans = ans.append("," + elCur); } } if (ans.length() > 0) { setIdsToPaste(ans.substring(1)); logger.info(getIdsToPaste()); } } } displayErrorMessage(error, "PASTE"); }