List of usage examples for java.lang StringBuilder deleteCharAt
@Override public StringBuilder deleteCharAt(int index)
From source file:com.vmware.admiral.compute.container.HostContainerListDataCollection.java
private String containerNamesToString(List<String> names) { if (names != null && names.size() > 0) { StringBuilder sb = new StringBuilder(); for (String name : names) { sb.append(name.startsWith("/") ? name.substring(1) : name); sb.append(ContainerListCallback.NAME_SEPARATOR); }/*from w w w .ja v a 2 s. c om*/ sb.deleteCharAt(sb.length() - 1); return sb.toString(); } else { return null; } }
From source file:com.flexive.faces.renderer.FxSelectRenderer.java
/** * Render the component as select list box * * @param context faces context//from w ww.j a v a 2s. c om * @param component the component * @throws IOException on errors */ protected void renderSelect(FacesContext context, UIComponent component) throws IOException { List<SelectItem> items = FxJsfComponentUtils.getSelectItems(context, component); boolean restrictToGroups = false; if ((component instanceof UISelectOne || component instanceof UISelectMany) && items.size() > 0 && items.get(0) instanceof FxJSFSelectItem && ((FxJSFSelectItem) items.get(0)).isFxSelectListItem()) { //we have an FxSelectListItem in a SelectOne -> check if cascaded final long itemId = (Long) items.get(0).getValue(); if (itemId >= 0) { FxSelectList list = CacheAdmin.getEnvironment().getSelectListItem(itemId).getList(); restrictToGroups = list.isOnlySameLevelSelect(); if (list.isCascaded()) { List<SelectItem> converted = new ArrayList<SelectItem>(items.size()); for (SelectItem check : items) { final Long currentItemId = (Long) check.getValue(); if (currentItemId < 0) { converted.add(check); continue; } final FxSelectListItem listItem = list.getItem(currentItemId); final boolean forceDisplay = ((FxJSFSelectItem) check).isForceDisplay(); if (!listItem.getHasChildren() || forceDisplay) { if (!forceDisplay) check.setLabel(listItem.getLabelBreadcrumbPath()); else restrictToGroups = false; //if forceDisplay is enabled, do not restrict to group! check.setDescription( listItem.hasParentItem() ? String.valueOf(listItem.getParentItem().getId()) : "0"); converted.add(check); } } items = converted; } } } ResponseWriter writer = context.getResponseWriter(); Map attrMap = component.getAttributes(); if (component instanceof UISelectMany && restrictToGroups) { /* full js code: var grpData_xx = [["1", 1],["2",1],["3",2],["4",2],["5",3],["6",1]]; function processChange() { var s = document.getElementById('xx'); function gg(v) { for(var x in grpData_xx) if(grpData_xx[x][0]==v) return grpData_xx[x][1]; return 0; } var g = -1; for(var o in s.childNodes) { if(!s.childNodes[o]) continue; if(s.childNodes[o].selected) { g = gg(s.childNodes[o].value); break; } } if (g == -1) return; for(var c in s.childNodes) { if(!s.childNodes[c]) continue; if(gg(s.childNodes[c].value)!=g && s.childNodes[c].selected!=undefined) s.childNodes[c].selected = false; } } } */ StringBuilder sb = new StringBuilder(750); sb.append("var msGrpData_").append(component.getId()).append("=["); if (items.size() > 0) { for (SelectItem check : items) { String grp = check.getDescription() == null ? "0" : check.getDescription(); sb.append("[\"").append(check.getValue()).append("\",").append(Long.valueOf(grp)).append("],"); } sb.deleteCharAt(sb.length() - 1); } sb.append("];"); sb.append("function pc_").append(component.getId()).append("(){"); sb.append("var s=document.getElementById('").append(component.getClientId(context)); sb.append("');function gg(v){for(var x in msGrpData_").append(component.getId()) .append(")if(msGrpData_"); sb.append(component.getId()).append("[x][0]==v)return msGrpData_").append(component.getId()) .append("[x][1];return 0;}"); sb.append( "var g=-1;for(var o in s.childNodes){if(!s.childNodes[o])continue;if(s.childNodes[o].selected){g=gg(s.childNodes[o].value);break;}}"); sb.append( "if(g==-1)return;for(var c in s.childNodes){if(!s.childNodes[c])continue;if(gg(s.childNodes[c].value)!=g&&s.childNodes[c].selected!=undefined){s.childNodes[c].selected=false;}}"); if (!StringUtils.isEmpty(String.valueOf(attrMap.get("onchange")))) { //execute the original onchange event sb.append(String.valueOf(attrMap.get("onchange"))).append(";"); } sb.append("}\n"); FxJavascriptUtils.beginJavascript(writer); writer.write(sb.toString()); FxJavascriptUtils.endJavascript(writer); } writer.startElement("select", component); if (restrictToGroups) writer.writeAttribute("onchange", "pc_" + component.getId() + "();", null); String id; if (null != (id = component.getId()) && !id.startsWith(UIViewRoot.UNIQUE_ID_PREFIX)) //noinspection UnusedAssignment writer.writeAttribute("id", id = component.getClientId(context), "id"); writer.writeAttribute("name", component.getClientId(context), "clientId"); // render styleClass attribute if present. String styleClass; if (null != (styleClass = (String) component.getAttributes().get("styleClass"))) { writer.writeAttribute("class", styleClass, "styleClass"); } if (component instanceof UISelectMany) writer.writeAttribute("multiple", true, "multiple"); // If "size" is *not* set explicitly, we have to default it correctly Integer size = (Integer) component.getAttributes().get("size"); if (size == null || size == Integer.MIN_VALUE) { // Determine how many option(s) we need to render, and update // the component's "size" attribute accordingly; The "size" // attribute will be rendered as one of the "pass thru" attributes int itemCount; if ("javax.faces.Listbox".equals(component.getRendererType())) itemCount = 1; //only 1 item if we are a listbox else itemCount = FxJsfComponentUtils.getSelectlistOptionCount(items); size = itemCount; } writer.writeAttribute("size", size, "size"); //render the components default attributes if present for (String att : FxJsfComponentUtils.SELECTLIST_ATTRIBUTES) { if (restrictToGroups && "onchange".equals(att)) continue; if (attrMap.get(att) != null) writer.writeAttribute(att, attrMap.get(att), att); } //render each option renderOptions(context, component, items); writer.endElement("select"); }
From source file:com.krawler.spring.crm.accountModule.crmAccountDAOImpl.java
public Map<String, List<CrmProduct>> getAccountProducts(List<String> accountIds) { Map<String, List<CrmProduct>> productMap = new HashMap<String, List<CrmProduct>>(); if (accountIds != null && !accountIds.isEmpty()) { StringBuilder query = new StringBuilder( "select ap.accountId, ap.productId from AccountProducts ap where ap.accountId in ("); for (String accoundId : accountIds) { query.append('\''); query.append(accoundId);/* www. j av a 2 s.c om*/ query.append('\''); query.append(','); } query.deleteCharAt(query.length() - 1); query.append(')'); List<Object[]> results = getHibernateTemplate().find(query.toString()); if (results != null) { for (Object[] result : results) { String accountId = (String) result[0]; CrmProduct product = (CrmProduct) result[1]; if (productMap.containsKey(accountId)) { List<CrmProduct> productList = productMap.get(accountId); productList.add(product); } else { List<CrmProduct> productList = new ArrayList<CrmProduct>(); productList.add(product); productMap.put(accountId, productList); } } } } return productMap; }
From source file:fr.gael.dhus.olingo.v1.Processor.java
private URI makeLink(boolean remove_last_segment) throws ODataException { try {//from w ww .j a v a 2 s.c om URIBuilder ub = new URIBuilder(ServiceFactory.EXTERNAL_URL); StringBuilder sb = new StringBuilder(); String prefix = ub.getPath(); String path = getContext().getPathInfo().getRequestUri().getPath(); if (path == null || path.isEmpty() || prefix != null && !prefix.isEmpty() && !path.startsWith(ub.getPath())) { sb.append(prefix); if (path != null) { if (prefix.endsWith("/") && path.startsWith("/")) { sb.deleteCharAt(sb.length() - 1); } if (!prefix.endsWith("/") && !path.startsWith("/")) { sb.append('/'); } } } sb.append(path); if (remove_last_segment) { // Removes the last segment. int lio = sb.lastIndexOf("/"); while (lio != -1 && lio == sb.length() - 1) { sb.deleteCharAt(lio); lio = sb.lastIndexOf("/"); } if (lio != -1) { sb.delete(lio + 1, sb.length()); } // Removes the `$links` segment. lio = sb.lastIndexOf("$links/"); if (lio != -1) { sb.delete(lio, lio + 7); } } else if (!sb.toString().endsWith("/") && !sb.toString().endsWith("\\")) { sb.append("/"); } ub.setPath(sb.toString()); return ub.build(); } catch (NullPointerException | URISyntaxException e) { throw new ODataException(e); } }
From source file:com.naryx.tagfusion.cfm.http.cfHttpConnection.java
private void addFormData() throws cfmRunTimeException { Map<String, String> formData = httpData.getFormData(); Iterator<String> keys = formData.keySet().iterator(); String nextKey;/*from ww w . j a va2 s . c o m*/ if (message.getMethod().equalsIgnoreCase("POST")) { if (isMultipart || httpData.getFiles().size() > 0) { if (multipartEntityBuilder == null) multipartEntityBuilder = MultipartEntityBuilder.create().setCharset(charset); while (keys.hasNext()) { nextKey = keys.next(); multipartEntityBuilder.addPart(nextKey, new StringBody(formData.get(nextKey), ContentType.TEXT_PLAIN)); } } else { Header contentType = message.getFirstHeader("Content-type"); if (contentType == null) { // otherwise it's been set manually so don't override it message.setHeader("Content-type", "application/x-www-form-urlencoded"); } StringBuilder paramStr = new StringBuilder(); while (keys.hasNext()) { nextKey = keys.next(); paramStr.append(nextKey); paramStr.append('='); paramStr.append(formData.get(nextKey)); paramStr.append('&'); } if (paramStr.length() > 0) { paramStr.deleteCharAt(paramStr.length() - 1); // remove last & ((HttpPost) message).setEntity(new StringEntity(paramStr.toString(), this.charset)); } } } }
From source file:com.aliyun.openservices.odps.console.mapreduce.runtime.MapReduceJob.java
private String[] parseCmd(String cmd) throws IOException { cmd = cmd.trim();//from w w w . j a v a2 s. c om if (StringUtils.isEmpty(cmd)) { throw new IOException("cmd is empty, because main class not specified."); } List<String> result = new ArrayList<String>(); String[] ss = StringUtils.splitPreserveAllTokens(cmd); int idx = 0; boolean quot = false; StringBuilder buffer = new StringBuilder(); while (idx < ss.length) { if (quot) { buffer.append(' '); } // skip empty tokens; while (idx < ss.length && ss[idx].isEmpty()) { if (quot) { buffer.append(' '); } idx++; } if (idx >= ss.length) { break; } String tok = ss[idx]; if (tok.startsWith("\"") || tok.endsWith("\"")) { if (tok.startsWith("\"")) { if (quot) { buffer.append(tok); } else { buffer.append(tok.substring(1)); } quot = true; } if (tok.endsWith("\"") && tok.length() > 1) { quot = false; if (tok.startsWith("\"")) { buffer.deleteCharAt(buffer.length() - 1); } else { buffer.append(tok.substring(0, tok.length() - 1)); } result.add(buffer.toString()); buffer = new StringBuilder(); } } else { if (quot) { buffer.append(tok); } else { result.add(tok); } } idx++; } if (quot) { throw new IOException("exist unmatched quotations: " + cmd); } return result.toArray(new String[result.size()]); }
From source file:dk.netarkivet.harvester.harvesting.controller.AbstractJMXHeritrixController.java
/** * Create a BnfHeritrixController object. * * @param files//from w ww . ja v a2s . co m * Files that are used to set up Heritrix. */ public AbstractJMXHeritrixController(HeritrixFiles files) { ArgumentNotValid.checkNotNull(files, "HeritrixFile files"); this.files = files; SystemUtils.checkPortNotUsed(guiPort); SystemUtils.checkPortNotUsed(jmxPort); hostName = SystemUtils.getLocalHostName(); try { log.info("Starting Heritrix for " + this); /* * To start Heritrix, we need to do the following (taken from the * Heritrix startup shell script): - set heritrix.home to base dir * of Heritrix stuff - set com.sun.management.jmxremote.port to JMX * port - set com.sun.management.jmxremote.ssl to false - set * com.sun.management.jmxremote.password.file to JMX password file - * set heritrix.out to heritrix_out.log - set * java.protocol.handler.pkgs=org.archive.net - send processOutput & * stderr into heritrix.out - let the Heritrix GUI-webserver listen * on all available network interfaces: This is done with argument * "--bind /" (default is 127.0.0.1) - listen on a specific port * using the port argument: --port <GUI port> * * We also need to output something like the following to * heritrix.out: `date Starting heritrix uname -a java -version * JAVA_OPTS ulimit -a */ File heritrixOutputFile = files.getHeritrixOutput(); StringBuilder settingProperty = new StringBuilder(); for (File file : Settings.getSettingsFiles()) { settingProperty.append(File.pathSeparator); String absolutePath = file.getAbsolutePath(); // check that the settings files not only exist but // are readable boolean readable = new File(absolutePath).canRead(); if (!readable) { final String errMsg = "The file '" + absolutePath + "' is missing. "; log.warn(errMsg); throw new IOFailure("Failed to read file '" + absolutePath + "'"); } settingProperty.append(absolutePath); } if (settingProperty.length() > 0) { // delete last path-separator settingProperty.deleteCharAt(0); } List<String> allOpts = new LinkedList<String>(); allOpts.add(new File(new File(System.getProperty("java.home"), "bin"), "java").getAbsolutePath()); allOpts.add("-Xmx" + Settings.get(HarvesterSettings.HERITRIX_HEAP_SIZE)); allOpts.add("-Dheritrix.home=" + files.getCrawlDir().getAbsolutePath()); String jvmOptsStr = Settings.get(HarvesterSettings.HERITRIX_JVM_OPTS); if ((jvmOptsStr != null) && (!jvmOptsStr.isEmpty())) { String[] add = jvmOptsStr.split(" "); allOpts.addAll(Arrays.asList(add)); } allOpts.add("-Dcom.sun.management.jmxremote.port=" + jmxPort); allOpts.add("-Dcom.sun.management.jmxremote.ssl=false"); // check that JMX password and access files are readable. // TODO This should probably be extracted to a method? File passwordFile = files.getJmxPasswordFile(); String pwAbsolutePath = passwordFile.getAbsolutePath(); if (!passwordFile.canRead()) { final String errMsg = "Failed to read the password file '" + pwAbsolutePath + "'. It is possibly missing."; log.warn(errMsg); throw new IOFailure(errMsg); } File accessFile = files.getJmxAccessFile(); String acAbsolutePath = accessFile.getAbsolutePath(); if (!accessFile.canRead()) { final String errMsg = "Failed to read the access file '" + acAbsolutePath + "'. It is possibly missing."; log.warn(errMsg); throw new IOFailure(errMsg); } allOpts.add("-Dcom.sun.management.jmxremote.password.file=" + new File(pwAbsolutePath)); allOpts.add("-Dcom.sun.management.jmxremote.access.file=" + new File(acAbsolutePath)); allOpts.add("-Dheritrix.out=" + heritrixOutputFile.getAbsolutePath()); allOpts.add("-Djava.protocol.handler.pkgs=org.archive.net"); allOpts.add("-Ddk.netarkivet.settings.file=" + settingProperty); allOpts.add(Heritrix.class.getName()); allOpts.add("--bind"); allOpts.add("/"); allOpts.add("--port=" + guiPort); allOpts.add("--admin=" + getHeritrixAdminName() + ":" + getHeritrixAdminPassword()); String[] args = allOpts.toArray(new String[allOpts.size()]); log.info("Starting Heritrix process with args" + Arrays.toString(args)); log.debug("The JMX timeout is set to " + TimeUtils.readableTimeInterval(JMXUtils.getJmxTimeout())); ProcessBuilder builder = new ProcessBuilder(args); updateEnvironment(builder.environment()); FileUtils.copyDirectory(new File("lib/heritrix"), files.getCrawlDir()); builder.directory(files.getCrawlDir()); builder.redirectErrorStream(true); writeSystemInfo(heritrixOutputFile, builder); FileUtils.appendToFile(heritrixOutputFile, "Working directory: " + files.getCrawlDir()); addProcessKillerHook(); heritrixProcess = builder.start(); ProcessUtils.writeProcessOutput(heritrixProcess.getInputStream(), heritrixOutputFile, collectionThreads); } catch (IOException e) { throw new IOFailure("Error starting Heritrix process", e); } }
From source file:com.krawler.spring.crm.accountModule.crmAccountDAOImpl.java
@Override public Map<String, List<AccountOwnerInfo>> getAccountOwners(List<String> accountIds) { Map<String, List<AccountOwnerInfo>> ownerMap = new HashMap<String, List<AccountOwnerInfo>>(); if (accountIds != null && !accountIds.isEmpty()) { StringBuilder query = new StringBuilder( "select ao.accountId, ao.usersByUserid, ao from accountOwners ao where ao.accountId in ("); for (String accoundId : accountIds) { query.append('\''); query.append(accoundId);/*from www . jav a2s . c o m*/ query.append('\''); query.append(','); } query.deleteCharAt(query.length() - 1); query.append(')'); List<Object[]> results = getHibernateTemplate().find(query.toString()); if (results != null) { for (Object[] result : results) { String accountId = (String) result[0]; AccountOwnerInfo info = new AccountOwnerInfo(); info.setUser((User) result[1]); info.setOwner((accountOwners) result[2]); if (ownerMap.containsKey(accountId)) { List<AccountOwnerInfo> ownerList = ownerMap.get(accountId); ownerList.add(info); } else { List<AccountOwnerInfo> ownerList = new ArrayList<AccountOwnerInfo>(); ownerList.add(info); ownerMap.put(accountId, ownerList); } } } } return ownerMap; }
From source file:com.pidoco.juri.JURI.java
public StringBuilder buildRawPathString(boolean absolute, boolean slashAtEnd, String[] segments) { StringBuilder result = new StringBuilder(); if (absolute) { result.append('/'); }//from w w w . j a v a 2 s .c om boolean addedOne = false; for (String s : segments) { result.append(UrlEscapers.urlPathSegmentEscaper().escape(s)); result.append('/'); addedOne = true; } if (addedOne && !slashAtEnd) { result.deleteCharAt(result.length() - 1); } return result; }
From source file:com.taobao.adfs.util.Utilities.java
public static String deepToString(Object object) { if (object == null) { return "null"; } else if (object instanceof Throwable) { return getThrowableStackTrace((Throwable) object); } else if (object.getClass().isEnum()) { return object.toString(); } else if (object.getClass().isArray()) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(object.getClass().getSimpleName()); int length = Array.getLength(object); stringBuilder.insert(stringBuilder.length() - 1, Array.getLength(object)).append("{"); for (int i = 0; i < length; i++) { stringBuilder.append(deepToString(Array.get(object, i))); if (i < length - 1) stringBuilder.append(','); }/*from w w w . j a v a 2 s . c o m*/ return stringBuilder.append("}").toString(); } else if (List.class.isAssignableFrom(object.getClass())) { List<?> listObject = ((List<?>) object); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(object.getClass().getSimpleName()).append('[').append(listObject.size()) .append(']'); stringBuilder.append("{"); for (Object subObject : listObject) { stringBuilder.append(deepToString(subObject)).append(','); } if (!listObject.isEmpty()) stringBuilder.deleteCharAt(stringBuilder.length() - 1); return stringBuilder.append('}').toString(); } else { try { Method toStringMethod = Invocation.getPublicMethod(object.getClass(), "toString"); if (toStringMethod.getDeclaringClass() == Object.class) return toStringByFields(object, false); } catch (Throwable t) { } try { return object.toString(); } catch (Throwable t) { return "FailToString"; } } }