List of usage examples for java.lang StringBuffer setLength
@Override public synchronized void setLength(int newLength)
From source file:com.modusoperandi.dragonfly.widgets.map.MapWidgetPage.java
private static void addGeojsonToMap(final AjaxRequestTarget target, final String indexName, final String geojsonFieldName) { final StringBuffer js = new StringBuffer(); final SearchRequestBuilder search = getEsClient().prepareSearch(indexName); search.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); search.setQuery(QueryBuilders.matchAllQuery()); search.setSize(MAX_HITS_TO_SHOW);/*from w w w .j a v a 2 s .c o m*/ final SearchResponse results = search.execute().actionGet(); for (final SearchHit hit : results.getHits()) { final String valueStr = (String) hit.getSource().get(geojsonFieldName); if (valueStr != null) { target.appendJavaScript("geoJsonLayer.clearLayers();"); js.setLength(0); js.append("geoJsonLayer.addData("); js.append(valueStr); js.append(");"); target.appendJavaScript(js.toString()); } } }
From source file:com.silverpeas.tags.navigation.PageListeTag.java
/** * Construction de la liste.//from w ww . java2 s . c om * @param out * @param rootTopic */ private void browse(JspWriter out, NodeDetail rootTopic) { try { Collection pubs = themetracker.getPublicationsByTopic(idTopicRoot + ",order,asc"); Iterator iPubs = pubs.iterator(); print(out, "<ul id='" + id + "'>", true); StringBuffer html = new StringBuffer(); int number = 1; while (iPubs.hasNext()) { PublicationDetail pub = (PublicationDetail) iPubs.next(); html.setLength(0); html.append("<li id='"); html.append(buildId(TOPIC_ID_PREFIX, rootTopic, number)); html.append("' class='"); html.append(getClassNameByPublication(pub, number)); html.append("'"); html.append(">"); html.append("<a href='"); html.append(generateFullSemanticPath(rootTopic, pub, number)); html.append("' title='"); html.append(StringEscapeUtils.escapeHtml(rootTopic.getDescription())); html.append("'><span>"); html.append(pub.getName()); html.append("</span></a>"); print(out, html.toString(), true); number++; } print(out, "</ul>", true); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
/** * Adds the specified line to the output sequence, performing line wrapping if necessary. * * @param lines The sequence of display lines, must not be <code>null</code>. * @param line The line to add, must not be <code>null</code>. *///w w w. ja va 2 s . c om private void toLines(List lines, String line) { int lineIndent = getIndentLevel(line); StringBuffer buf = new StringBuffer(256); String[] tokens = line.split(" +"); for (int i = 0; i < tokens.length; i++) { String token = tokens[i]; if (i > 0) { if (buf.length() + token.length() >= lineLength) { lines.add(buf.toString()); buf.setLength(0); buf.append(repeat(" ", lineIndent * indentSize)); } else { buf.append(' '); } } for (int j = 0; j < token.length(); j++) { char c = token.charAt(j); if (c == '\t') { buf.append(repeat(" ", indentSize - buf.length() % indentSize)); } else if (c == '\u00A0') { buf.append(' '); } else { buf.append(c); } } } lines.add(buf.toString()); }
From source file:org.muse.mneme.tool.FormatPartSummaryDelegate.java
/** * {@inheritDoc}/*from w ww. ja va 2 s .co m*/ */ public String format(Context context, Object value) { // value is a part if (value == null) return null; if (!(value instanceof Part)) return value.toString(); Part part = (Part) value; if (part instanceof ManualPart) { // manual-part-summary=Manually Selected Questions ({0}) Object[] args = new Object[1]; args[0] = ((ManualPart) part).getNumQuestions().toString(); return context.getMessages().getFormattedMessage("manual-part-summary", args); } if (part instanceof DrawPart) { // draw-part-summary=Random from Pool{0} ({1}): {2} DrawPart p = (DrawPart) part; Object[] args = new Object[3]; args[0] = ((p.getDraws().size() == 1) ? "" : "s"); args[1] = p.getNumQuestions().toString(); StringBuffer buf = new StringBuffer(); for (PoolDraw draw : p.getDraws()) { Pool pool = draw.getPool(); if (pool != null) { buf.append(pool.getTitle()); buf.append(", "); } } if (buf.length() > 0) buf.setLength(buf.length() - 2); args[2] = buf.toString(); return context.getMessages().getFormattedMessage("draw-part-summary", args); } return null; }
From source file:com.camel.framework.tag.CssLinkTag.java
/** * ??? Minify?link??/*from w w w . j a va2 s .co m*/ * * @param sb * @param out */ private void parseToConventionalStyle(StringBuffer sb, String resourcesUrl, JspWriter out) { // css??? String[] hrefArray = href.split(ITagBasic.SEPARATOR_COMMA); for (String hrefStr : hrefArray) { sb.setLength(0); sb.append("<link type='").append(type).append("' rel='").append(rel).append("' href='") .append(resourcesUrl); if (StringUtils.isNotBlank(path)) { sb.append(path).append("/"); } sb.append(hrefStr.trim()).append("'/>"); try { // ? out.println(sb.toString()); } catch (IOException e) { logger.error("Could not print out value '" + sb.toString(), e); } } }
From source file:net.unicon.academus.apps.blogger.access.AcademusAuthorizationProvider.java
protected Principal getPrincipal(String username) throws Exception { Principal result = null;/*from ww w . j ava 2 s . co m*/ try { IAcademusGroup[] groups = _facade.getAllContainingGroups(username); // Need to create two identities for each group, one with the group // key appended to the path, one without. This enables backwards // compatibility with existing access entrys after group keys are // added to Access Entry Identity Names as a result of AC-393 Identity[] ids = new Identity[(groups.length * 2) + 1]; StringBuffer path = new StringBuffer(); for (int i = 0, j = 0; i < groups.length; i++) { path.setLength(0); // Clear buffer path.append(groups[i].getGroupPaths(IAcademusGroup.GROUP_NAME_BASE_PATH_SEPARATOR, false)[0]); // Create Identity without the group key ids[j++] = new Identity(path.toString(), IdentityType.GROUP); // Create second Identity for group with the group key appended path.append("["); path.append(groups[i].getKey()); path.append("]"); ids[j++] = new Identity(path.toString(), IdentityType.GROUP); } ids[ids.length - 1] = new Identity(username, IdentityType.USER); result = new Principal(ids); } catch (Throwable t) { String msg = "Unable to evaluate the user's identity within academus."; throw new Exception(msg, t); } return result; }
From source file:org.dcm4chex.archive.hsm.FileCopyService.java
private String mkTarPath(String filePath) { StringBuffer sb = new StringBuffer(filePath); sb.setLength(filePath.lastIndexOf('/')); sb.append('-').append(System.currentTimeMillis() % 3600000).append(".tar"); return sb.toString(); }
From source file:JavascriptUtil.java
/** * <p>//from w w w . ja va 2 s . c o m * Unescapes any JavaScript literals found in the <code>String</code>. * </p> * <p> * For example, it will turn a sequence of <code>'\'</code> and * <code>'n'</code> into a newline character, unless the <code>'\'</code> is * preceded by another <code>'\'</code>. * </p> * * @param str * the <code>String</code> to unescape, may be null * @return A new unescaped <code>String</code>, <code>null</code> if null * string input */ public static String unescapeJavaScript(String str) { if (str == null) { return null; } StringBuffer writer = new StringBuffer(str.length()); int sz = str.length(); StringBuffer unicode = new StringBuffer(4); boolean hadSlash = false; boolean inUnicode = false; for (int i = 0; i < sz; i++) { char ch = str.charAt(i); if (inUnicode) { // if in unicode, then we're reading unicode // values in somehow unicode.append(ch); if (unicode.length() == 4) { // unicode now contains the four hex digits // which represents our unicode chacater try { int value = Integer.parseInt(unicode.toString(), 16); writer.append((char) value); unicode.setLength(0); inUnicode = false; hadSlash = false; } catch (NumberFormatException nfe) { throw new IllegalArgumentException( "Unable to parse unicode value: " + unicode + " cause: " + nfe); } } continue; } if (hadSlash) { // handle an escaped value hadSlash = false; switch (ch) { case '\\': writer.append('\\'); break; case '\'': writer.append('\''); break; case '\"': writer.append('"'); break; case 'r': writer.append('\r'); break; case 'f': writer.append('\f'); break; case 't': writer.append('\t'); break; case 'n': writer.append('\n'); break; case 'b': writer.append('\b'); break; case 'u': // uh-oh, we're in unicode country.... inUnicode = true; break; default: writer.append(ch); break; } continue; } else if (ch == '\\') { hadSlash = true; continue; } writer.append(ch); } if (hadSlash) { // then we're in the weird case of a \ at the end of the // string, let's output it anyway. writer.append('\\'); } return writer.toString(); }
From source file:org.jbpm.bpel.tools.WebServicesDescriptorTool.java
protected String generateServletName(Port port) { String portName = port.getName(); StringBuffer servletName = new StringBuffer(portName); // remove "Port" suffix, if any if (portName.endsWith("Port")) servletName.setLength(servletName.length() - 4); // append "Servlet" suffix servletName.append("Servlet"); return servletName.toString(); }
From source file:org.jbpm.bpel.tools.WebServicesDescriptorTool.java
protected String generateHandlerName(Port port) { String portName = port.getName(); StringBuffer handlerName = new StringBuffer(portName); // remove "Port" suffix, if any if (portName.endsWith("Port")) handlerName.setLength(handlerName.length() - 4); // append "Handler" suffix handlerName.append("Handler"); return handlerName.toString(); }