List of usage examples for java.lang StringBuffer substring
@Override public synchronized String substring(int start, int end)
From source file:org.jamwiki.servlets.RecentChangesFeedServlet.java
/** * TODO cache feed to avoid high load caused by RSS aggregators * * @throws Exception//from w ww . j a va 2s. co m */ private SyndFeed getFeed(HttpServletRequest request) throws Exception { List<RecentChange> changes = getChanges(request); SyndFeed feed = new SyndFeedImpl(); feed.setEncoding(FEED_ENCODING); feed.setTitle(Environment.getValue(Environment.PROP_RSS_TITLE)); StringBuffer requestURL = request.getRequestURL(); String feedURL = feedUrlPrefix + requestURL.substring(0, requestURL.length() - WikiUtil.getTopicFromURI(request).length()); feed.setLink(feedURL); feed.setDescription("List of the last " + changes.size() + " changed wiki pages."); boolean includeMinorEdits = ServletRequestUtils.getBooleanParameter(request, MINOR_EDITS, defaultIncludeMinorEdits); boolean linkToVersion = ServletRequestUtils.getBooleanParameter(request, LINK_TO_VERSION, defaultLinkToVersion); feed.setEntries(getFeedEntries(changes, includeMinorEdits, linkToVersion, feedURL)); return feed; }
From source file:pt.ua.tm.neji.evaluation.whatizit.XML2A1Module.java
private void addTrigger(StringBuffer yytext, int start, String tag, String group, boolean add) { String annotationTag = yytext.substring(startTag, start + tag.length() + 3); String annotation = annotationTag.substring(annotationTag.indexOf(">") + 1, annotationTag.lastIndexOf("<")); annotation = StringEscapeUtils.unescapeXml(annotation); int startAnnotation = text.length(); int endAnnotation = text.length() + annotation.length(); text.append(annotation);// ww w .j av a 2s. co m if (add) { Concept concept = new Concept(startAnnotation, endAnnotation, group, annotation); concept.getIdentifiers().addAll(getIDs(annotationTag, group)); conceptList.add(concept); } previousEnd = start + tag.length() + 3; }
From source file:com.sonicle.webtop.core.app.servlet.Login.java
private String getBaseUrl(HttpServletRequest request) { StringBuffer url = request.getRequestURL(); String uri = request.getRequestURI(); String ctx = request.getContextPath(); return url.substring(0, url.length() - uri.length() + ctx.length()) + "/"; }
From source file:org.hyperic.hq.plugin.nagios.parser.NagiosObj.java
protected String join(String delim, List l, int start) { if (l.size() == 0 || start >= l.size()) { return ""; }//from w w w . j a va 2 s .c o m StringBuffer buf = new StringBuffer(); for (int i = start; i < l.size(); i++) { buf.append(l.get(i).toString()).append(delim); } return buf.substring(0, buf.length() - 1).toString(); }
From source file:com.clustercontrol.HinemosManagerCli.java
private void printMBeanInfo(MBeanInfo mbeanInfo) { MBeanAttributeInfo[] attributeInfos = mbeanInfo.getAttributes(); System.out.println("Attributes:"); for (MBeanAttributeInfo attributeInfo : attributeInfos) { System.out.println(String.format("\t%s: %s", attributeInfo.getName(), attributeInfo.getType())); }/*from www .j a va2 s. com*/ MBeanOperationInfo[] operationInfos = mbeanInfo.getOperations(); System.out.println("Operations:"); for (MBeanOperationInfo operationInfo : operationInfos) { MBeanParameterInfo[] paramInfos = operationInfo.getSignature(); StringBuffer paramStr = new StringBuffer(); for (MBeanParameterInfo paramInfo : paramInfos) { paramStr.append(paramInfo.getType() + ","); } if (paramStr.length() != 0) { paramStr.append(paramStr.substring(0, paramStr.length() - 1)); } System.out.println( String.format("\t%s %s(%s)", operationInfo.getReturnType(), operationInfo.getName(), paramStr)); } }
From source file:ProducerTool.java
private String createMessageText(int index) { StringBuffer buffer = new StringBuffer(messageSize); buffer.append("Message: " + index + " sent at: " + new Date()); if (buffer.length() > messageSize) { return buffer.substring(0, messageSize); }//from ww w. j a v a2 s . c o m for (int i = buffer.length(); i < messageSize; i++) { buffer.append(' '); } return buffer.toString(); }
From source file:nz.ac.waikato.modeljunit.gui.visualisaton.VertexLabelTransformer.java
@SuppressWarnings("unchecked") public String transform(Object o) { if (show_) {// w ww. j av a2s .c o m if (o instanceof VertexInfo) { VertexInfo v = (VertexInfo) o; return (String) v.getName(); } if (o instanceof Graph) { StringBuffer str = new StringBuffer(); for (Object i : ((Graph) o).getVertices()) { if (i instanceof VertexInfo) { VertexInfo v = (VertexInfo) i; str.append(v.getName() + ","); } } return str .substring(0, (str.length() <= 20) ? ((str.length() - 1) >= 0 ? str.length() - 1 : 0) : 20) .toString() + (str.length() <= 20 ? "" : "..."); } } return ""; }
From source file:RequesterTool.java
/** * @param i//from w ww .j a va 2 s . c o m * @return */ private String createMessageText(int index) { StringBuffer buffer = new StringBuffer(messageSize); buffer.append("Message: " + index + " sent at: " + new Date()); if (buffer.length() > messageSize) { return buffer.substring(0, messageSize); } for (int i = buffer.length(); i < messageSize; i++) { buffer.append(' '); } return buffer.toString(); }
From source file:no.abmu.user.util.UserUtil.java
public static String generatePassword() { if (true) {/*from www . j av a 2 s .c om*/ String.valueOf(System.currentTimeMillis()); } StringBuffer passwd = new StringBuffer(10); try { char[] numChars = { '2', '3', '4', '5', '6', '7', '8', '9' }; char[] smallChars = { 'a', 'b', 'c', 'd', 'e', 'f', 'h', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; char[] capChars = { 'A', 'B', 'C', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' }; Random random = new Random((long) ((double) System.currentTimeMillis() * Math.random())); for (int i = 0; i <= 2; i++) { int j = random.nextInt(smallChars.length + 4); if (j < smallChars.length && j >= 0) { passwd.append(smallChars[j]); } j = random.nextInt(capChars.length + 4); if (j < capChars.length && j >= 0) { passwd.append(capChars[j]); } j = random.nextInt(numChars.length + 4); if (j < numChars.length && j >= 0) { passwd.append(numChars[j]); } } } catch (Exception e) { logger.error("[generatePassword]: had some problems ! " + e.toString()); } if (passwd.length() > 8) { return passwd.substring(0, 7); } return passwd.toString(); }
From source file:org.springframework.security.oauth2.common.OAuth2AccessTokenJackson2Serializer.java
@Override public void serialize(OAuth2AccessToken token, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException { jgen.writeStartObject();//from w ww .j ava 2 s . c o m jgen.writeStringField(OAuth2AccessToken.ACCESS_TOKEN, token.getValue()); jgen.writeStringField(OAuth2AccessToken.TOKEN_TYPE, token.getTokenType()); OAuth2RefreshToken refreshToken = token.getRefreshToken(); if (refreshToken != null) { jgen.writeStringField(OAuth2AccessToken.REFRESH_TOKEN, refreshToken.getValue()); } Date expiration = token.getExpiration(); if (expiration != null) { long now = System.currentTimeMillis(); jgen.writeNumberField(OAuth2AccessToken.EXPIRES_IN, (expiration.getTime() - now) / 1000); } Set<String> scope = token.getScope(); if (scope != null && !scope.isEmpty()) { StringBuffer scopes = new StringBuffer(); for (String s : scope) { Assert.hasLength(s, "Scopes cannot be null or empty. Got " + scope + ""); scopes.append(s); scopes.append(" "); } jgen.writeStringField(OAuth2AccessToken.SCOPE, scopes.substring(0, scopes.length() - 1)); } Map<String, Object> additionalInformation = token.getAdditionalInformation(); for (String key : additionalInformation.keySet()) { jgen.writeObjectField(key, additionalInformation.get(key)); } jgen.writeEndObject(); }