List of usage examples for java.lang StringBuffer substring
@Override public synchronized String substring(int start)
From source file:com.example.android.AudioArchive.model.RemoteJSONSource.java
private MediaMetadataCompat buildFromRSS(RSSItem rssItem, String genre) { String title = rssItem.getTitle(); String album = rssItem.categories.get(0).toString(); String artist = ""; if (rssItem.getDescription().contains("by")) { StringBuffer stringBuffer = new StringBuffer(rssItem.getDescription()); artist = stringBuffer.substring(stringBuffer.indexOf("by")); } else {// w w w .j a v a 2 s . c om artist = "Unknown"; } String source = rssItem.getEnclosures().get(0).getLink(); String iconUrl = "https://archive.org/services/get-item-image.php?identifier=afewmoreverses_1606_librivox&mediatype=audio&collection=librivoxaudio"; String html = rssItem.getDescription(); String imgRegex = "<[iI][mM][gG][^>]+[sS][rR][cC]\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>"; Pattern p = Pattern.compile(imgRegex); Matcher m = p.matcher(html); if (m.find()) { iconUrl = m.group(1); } // Since we don't have a unique ID in the server, we fake one using the hashcode of // the music source. In a real world app, this could come from the server. String id = String.valueOf(source.hashCode()); // Adding the music source to the MediaMetadata (and consequently using it in the // mediaSession.setMetadata) is not a good idea for a real world music app, because // the session metadata can be accessed by notification listeners. This is done in this // sample for convenience only. //noinspection ResourceType return new MediaMetadataCompat.Builder().putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, id) .putString(MusicProviderSource.CUSTOM_METADATA_TRACK_SOURCE, source) .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, album) .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, artist) // .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration) .putString(MediaMetadataCompat.METADATA_KEY_GENRE, genre) .putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI, iconUrl) .putString(MediaMetadataCompat.METADATA_KEY_TITLE, title) .putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, title) .putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_DESCRIPTION, title) // .putString(MediaMetadataCompat.METADATA_KEY_GENRE, genre) .build(); }
From source file:org.exoplatform.wiki.rendering.internal.parser.confluence.ConfluenceLinkReferenceParser.java
private String divideAfter(StringBuffer buffer, int index) { if (index < 0) { return null; }//from w ww .jav a2 s.c o m if (index == buffer.length() - 1) { buffer.deleteCharAt(buffer.length() - 1); return null; } String body = buffer.substring(index + 1); buffer.delete(index, buffer.length()); return body; }
From source file:com.hp.alm.ali.idea.model.type.PlainTextType.java
@Override public String translate(String value, ValueCallback callback) { try {/*from w w w. j a v a 2 s .com*/ final StringBuffer buf = new StringBuffer(); new ParserDelegator().parse(new StringReader(value), new HTMLEditorKit.ParserCallback() { @Override public void handleText(char[] data, int pos) { if (buf.length() > 0 && !StringUtils.isWhitespace(buf.substring(buf.length() - 1))) { buf.append(" "); } buf.append(data); } }, false); return buf.toString(); } catch (IOException e) { return StringEscapeUtils.escapeHtml(value); } }
From source file:edu.stanford.mobisocial.dungbeetle.ui.fragments.FeedListFragment.java
private String getFeedObjectClause() { // TODO: Enumerate all Object classes, look for FeedRenderables. String[] types = DbObjects.getRenderableTypes(); StringBuffer allowed = new StringBuffer(); for (String type : types) { allowed.append(",'").append(type).append("'"); }/*w w w . j av a2s . c o m*/ return DbObject.TYPE + " in (" + allowed.substring(1) + ") AND " + DbObject.TABLE + "." + DbObject.FEED_NAME + " NOT IN ('direct', 'friend', '')"; }
From source file:org.kuali.ole.sys.web.struts.KualiBatchInputFileAction.java
/** * Sends the uploaded file contents, requested file name, and batch type to the BatchInputTypeService for storage. If errors * were encountered, messages will be in GlobalVariables.errorMap, which is checked and set for display by the request * processor.// ww w . j a v a 2 s . co m */ public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { BatchUpload batchUpload = ((KualiBatchInputFileForm) form).getBatchUpload(); if (LOG.isDebugEnabled()) { LOG.debug("------------BatchInputTypeName---------->" + batchUpload.getBatchInputTypeName()); } BatchInputFileType batchType = retrieveBatchInputFileTypeImpl(batchUpload.getBatchInputTypeName()); BatchInputFileService batchInputFileService = SpringContext.getBean(BatchInputFileService.class); FormFile uploadedFile = ((KualiBatchInputFileForm) form).getUploadFile(); StringBuffer fileName = new StringBuffer(uploadedFile.getFileName()); int fileExtensionCount = fileName.indexOf("."); String extension = fileName.substring(fileExtensionCount + 1); if (uploadedFile == null || uploadedFile.getInputStream() == null || uploadedFile.getInputStream().available() == 0) { GlobalVariables.getMessageMap().putError(OLEConstants.GLOBAL_ERRORS, OLEKeyConstants.ERROR_BATCH_UPLOAD_NO_FILE_SELECTED_SAVE, new String[] {}); return mapping.findForward(OLEConstants.MAPPING_BASIC); } if (!batchInputFileService.isFileUserIdentifierProperlyFormatted(batchUpload.getFileUserIdentifer())) { GlobalVariables.getMessageMap().putError(OLEConstants.GLOBAL_ERRORS, OLEKeyConstants.ERROR_BATCH_UPLOAD_FILE_USER_IDENTIFIER_BAD_FORMAT, new String[] {}); return mapping.findForward(OLEConstants.MAPPING_BASIC); } InputStream fileContents = ((KualiBatchInputFileForm) form).getUploadFile().getInputStream(); byte[] fileByteContent = IOUtils.toByteArray(fileContents); Object parsedObject = null; try { parsedObject = batchInputFileService.parse(batchType, fileByteContent); } catch (ParseException e) { LOG.error("errors parsing xml " + e.getMessage(), e); GlobalVariables.getMessageMap().putError(OLEConstants.GLOBAL_ERRORS, OLEKeyConstants.ERROR_BATCH_UPLOAD_PARSING_XML, new String[] { e.getMessage() }); } if (parsedObject != null && GlobalVariables.getMessageMap().hasNoErrors()) { boolean validateSuccessful = batchInputFileService.validate(batchType, parsedObject); if (validateSuccessful && GlobalVariables.getMessageMap().hasNoErrors()) { try { InputStream saveStream = new ByteArrayInputStream(fileByteContent); String savedFileName = ""; if (batchUpload.getBatchInputTypeName().equalsIgnoreCase("marcInputFileType")) { if (batchUpload == null || batchUpload.getBatchDestinationFilePath() == null) { GlobalVariables.getMessageMap().putError(OLEConstants.GLOBAL_ERRORS, OLEKeyConstants.ERROR_BATCH_UPLOAD_NO_FILE_PATH_SELECTED_SAVE, new String[] {}); return mapping.findForward(OLEConstants.MAPPING_BASIC); } savedFileName = batchInputFileService.save(GlobalVariables.getUserSession().getPerson(), batchType, batchUpload.getFileUserIdentifer(), saveStream, parsedObject, batchUpload.getBatchDestinationFilePath(), extension); } else { savedFileName = batchInputFileService.save(GlobalVariables.getUserSession().getPerson(), batchType, batchUpload.getFileUserIdentifer(), saveStream, parsedObject); } KNSGlobalVariables.getMessageList().add(OLEKeyConstants.MESSAGE_BATCH_UPLOAD_SAVE_SUCCESSFUL); } catch (FileStorageException e1) { LOG.error("errors saving xml " + e1.getMessage(), e1); GlobalVariables.getMessageMap().putError(OLEConstants.GLOBAL_ERRORS, OLEKeyConstants.ERROR_BATCH_UPLOAD_SAVE, new String[] { e1.getMessage() }); } } } return mapping.findForward(OLEConstants.MAPPING_BASIC); }
From source file:com.jim.im.group.service.GroupServiceImpl.java
/** * ? "m"// ww w . ja v a 2 s. c o m * @param operaterType * @param topics TopicInfo? * @return */ private String buildSystemMessageBody(TopicOperaterType operaterType, Collection<TopicInfo> topics) { StringBuffer buf = new StringBuffer(); for (TopicInfo info : topics) { buf.append(",").append(info.getName()); } String strTopic = buf.substring(1); return buildSystemMessageBody(operaterType, strTopic); }
From source file:com.jivesoftware.sdk.client.JiveWebhookClient.java
private String getWebhookEvents(Object[] webhookTypes) { if (webhookTypes != null && webhookTypes.length > 0) { StringBuffer sbuf = new StringBuffer(); for (Object type : webhookTypes) { sbuf.append(",").append(type.toString()); } // end for each return sbuf.substring(1); } // end if//from ww w . j a v a 2 s . c om return ""; }
From source file:hudson.plugins.emailext.plugins.content.BuildLogMultilineRegexContent.java
private String getContent(BufferedReader reader) throws IOException { final Pattern pattern = Pattern.compile(regex); final boolean asHtml = matchedSegmentHtmlStyle != null; escapeHtml = asHtml || escapeHtml;//ww w . j av a 2 s .c o m StringBuilder line = new StringBuilder(); StringBuilder fullLog = new StringBuilder(); int ch; // Buffer log contents including line terminators, and remove console notes while ((ch = reader.read()) != -1) { if (ch == '\r' || ch == '\n') { if (line.length() > 0) { // Remove console notes (JENKINS-7402) fullLog.append(ConsoleNote.removeNotes(line.toString())); line.setLength(0); } fullLog.append((char) ch); } else { line.append((char) ch); } } // Buffer the final log line if it has no line terminator if (line.length() > 0) { // Remove console notes (JENKINS-7402) fullLog.append(ConsoleNote.removeNotes(line.toString())); } StringBuilder content = new StringBuilder(); int numMatches = 0; boolean insidePre = false; int lastMatchEnd = 0; final Matcher matcher = pattern.matcher(fullLog); while (matcher.find()) { if (maxMatches != 0 && ++numMatches > maxMatches) { break; } if (showTruncatedLines) { if (matcher.start() > lastMatchEnd) { // Append information about truncated lines. int numLinesTruncated = countLineTerminators( fullLog.subSequence(lastMatchEnd, matcher.start())); if (numLinesTruncated > 0) { insidePre = stopPre(content, insidePre); appendLinesTruncated(content, numLinesTruncated, asHtml); } } } if (asHtml) { insidePre = startPre(content, insidePre); } if (substText != null) { final StringBuffer substBuf = new StringBuffer(); matcher.appendReplacement(substBuf, substText); // Remove prepended text between matches final String segment = substBuf.substring(matcher.start() - lastMatchEnd); appendMatchedSegment(content, segment, escapeHtml, matchedSegmentHtmlStyle); } else { appendMatchedSegment(content, matcher.group(), escapeHtml, matchedSegmentHtmlStyle); } lastMatchEnd = matcher.end(); } if (showTruncatedLines) { if (fullLog.length() > lastMatchEnd) { // Append information about truncated lines. int numLinesTruncated = countLineTerminators(fullLog.subSequence(lastMatchEnd, fullLog.length())); if (numLinesTruncated > 0) { insidePre = stopPre(content, insidePre); appendLinesTruncated(content, numLinesTruncated, asHtml); } } } stopPre(content, insidePre); return content.toString(); }
From source file:org.squale.squalix.tools.pmd.PmdPersistor.java
/** * @param pMessage le message tronquer/*w w w. j a v a2s .c o m*/ * @return le message tronqu si il dpasse la limite */ private String truncMessage(StringBuffer pMessage) { StringBuffer result = pMessage; // Taille maximale pour les dtails final int MAX_LENGTH = 3000; // Troncature du message si besoin if (pMessage.length() > MAX_LENGTH) { pMessage.substring(MAX_LENGTH - 1); } return result.toString(); }
From source file:org.kuali.coeus.propdev.impl.person.creditsplit.CalculateCreditSplitEvent.java
@Override protected void logEvent() { StringBuffer logMessage = new StringBuffer(StringUtils.substringAfterLast(this.getClass().getName(), ".")); logMessage.append(" with "); for (ProposalPerson person : ((ProposalDevelopmentDocument) getDocument()).getDevelopmentProposal() .getProposalPersons()) {/*from ww w . ja va 2 s . co m*/ logMessage.append(person.toString()); logMessage.append(", "); } if (logMessage.substring(logMessage.length() - 2).equals(", ")) { logMessage.delete(logMessage.length() - 2, logMessage.length()); } LOG.debug(logMessage); }