List of usage examples for java.lang StringBuffer length
@Override public synchronized int length()
From source file:net.sf.groovyMonkey.ScriptMetadata.java
public static String reasonableFileName(final String menuName) { if (StringUtils.isBlank(menuName)) return "script" + FILE_EXTENSION; final StringBuffer buffer = new StringBuffer(); final String[] array = split(menuName, " "); for (final String t : array) { final String token = capitalize(stripIllegalChars(t)); if (StringUtils.isBlank(token)) continue; if (token.endsWith("__")) { buffer.append(token);//from www. j av a2 s .co m continue; } buffer.append(token).append("_"); if (buffer.toString().endsWith("___")) buffer.delete(buffer.length() - 2, buffer.length() - 1); } if (StringUtils.isBlank(buffer.toString())) return "script" + FILE_EXTENSION; while (buffer.toString().endsWith("_")) buffer.deleteCharAt(buffer.length() - 1); while (buffer.toString().startsWith("_")) buffer.deleteCharAt(0); return buffer + FILE_EXTENSION; }
From source file:net.alchemiestick.katana.winehqappdb.WineSearch.java
@Override protected void onPostExecute(StringBuffer res) { String str = "Processing responce! (" + Long.valueOf(res.length()).toString() + " bytes)"; tvlist.clear();/*from ww w . j av a 2 s . co m*/ // tvlist.add(str); int istart = res.indexOf("<table"); int iend = res.indexOf("</table>", istart); String tab; try { tab = res.substring(istart, iend); } catch (StringIndexOutOfBoundsException e) { tvlist.add(new str_link("No Match Found", "")); return; } iend = 0; String link; for (int i = 1; iend < tab.lastIndexOf("</td>"); i++) { istart = tab.indexOf("<tr class=\"color" + Long.valueOf(i % 2).toString() + "\">", iend); istart = tab.indexOf("<td>", istart) + 6; istart = tab.indexOf("href=", istart) + 6; iend = tab.indexOf("\"", istart); link = tab.substring(istart, iend); istart = tab.indexOf(">", istart) + 1; iend = tab.indexOf("</a>", istart); str = tab.substring(istart, iend); iend = tab.indexOf("</tr>", istart); tvlist.add(new str_link(str, link)); } }
From source file:com.concursive.connect.web.modules.search.utils.SearchUtils.java
/** * Generates the Lucene Query for finding public listings, user-public listings, and * user-member listings//from w w w . j av a 2 s . c o m * * @param search * @param userId * @return */ public static String generateProjectQueryString(SearchBean search, int userId, int instanceId, String projectList) { LOG.info("Search Query: " + search.getQuery() + " (" + search.getLocation() + ")"); // The search portal is being used String locationTerm = search.getParsedLocation(); // if search location is 5-digit number, then find the city and state to expand the search, // but boost the zip code if (StringUtils.hasText(locationTerm)) { if (StringUtils.isNumber(locationTerm) && locationTerm.length() == 5) { LocationBean location = LocationUtils.findLocationByZipCode(locationTerm); if (location != null) { locationTerm = "\"" + locationTerm + "\"^30 OR (\"" + location.getCity() + "\"^29 AND " + location.getState() + "^28)"; } } else { locationTerm = "\"" + locationTerm + "\"^30"; } } // Optimize the terms StringBuffer titleValues = new StringBuffer(); StringBuffer keywordValues = new StringBuffer(); StringBuffer termValues = new StringBuffer(); // Find the phrase as-is in quotes for exactness, in the title titleValues.append("\"").append(search.getParsedQuery()).append("\"^25"); // Find matches in the keywords keywordValues.append("\"").append(search.getParsedQuery()).append("\"^24"); // Exact description match termValues.append("\"").append(search.getParsedQuery()).append("\"^16"); // Find the words in the phrase ArrayList<String> terms = search.getTerms(); int titleCount = 23; int keywordCount = 19; int count = 15; for (String term : terms) { if (titleValues.length() > 0) { titleValues.append(" OR "); } if (keywordValues.length() > 0) { keywordValues.append(" OR "); } if (termValues.length() > 0) { termValues.append(" OR "); } if (count < 5) { count = 5; } titleValues.append(term).append("^").append(titleCount); --titleCount; keywordValues.append(term).append("^").append(count); --keywordCount; termValues.append(term).append("^").append(count); --count; } // Find wildcards for the words in the phrase count = 4; for (String term : terms) { if (termValues.length() > 0) { termValues.append(" OR "); } if (count < 1) { count = 1; } termValues.append(term).append("*").append("^").append(count); --count; } String thisQuery = "(approved:1) " + (instanceId > -1 ? "AND (instanceId:" + instanceId + ") " : "") + "AND (" + "(guests:1) " + (userId > 0 ? "OR (participants:1) " : "") + (StringUtils.hasText(projectList) ? "OR " + "(projectId:(" + projectList + ")) " : "") + ") " + "AND (closed:0) " + "AND (website:0) " + (search.getProjectId() > -1 ? "AND (projectId:" + search.getProjectId() + ") " : "") + (StringUtils.hasText(search.getQuery()) ? "AND (title:(" + titleValues.toString() + ") OR (keywords:(" + keywordValues.toString() + ")) OR (" + termValues.toString() + ")) " : "") + (StringUtils.hasText(locationTerm) ? "AND (location:(" + locationTerm + ")) " : ""); LOG.debug("Built Query: " + thisQuery); return thisQuery; }
From source file:es.javocsoft.android.lib.toucan.client.request.AppDevTagsOperationRequest.java
public String getDataAsString() { StringBuffer sBuffer = new StringBuffer(); for (String s : this.tags) { if (sBuffer.length() == 0) { sBuffer.append(s);//from w w w. ja v a2 s .c o m } else { sBuffer.append(";#;").append(s); } } return sBuffer.toString(); }
From source file:com.aurel.track.item.history.HistorySaverBL.java
public static String getAttachmentHistoryText(String fileName, String description, Long size, Locale locale, boolean isURL) { StringBuffer stringBuffer = new StringBuffer(); if (fileName != null) { if (isURL) { //stringBuffer.append(LocalizeUtil.getLocalizedTextFromApplicationResources(HistoryLoaderBL.ATTACHMENT_FILE, locale) + fieldLabelSeparator); stringBuffer.append(HistoryLoaderBL.ATTACHMENT_URL + fieldLabelSeparator); } else {/*from w ww.j a v a 2 s .c o m*/ stringBuffer.append(LocalizeUtil.getLocalizedTextFromApplicationResources( HistoryLoaderBL.ATTACHMENT_FILE, locale) + fieldLabelSeparator); } stringBuffer.append(fileName); } if (size != null) { if (stringBuffer.length() > 0) { stringBuffer.append(commonFieldsSeparator + lineBreak); } stringBuffer.append( LocalizeUtil.getLocalizedTextFromApplicationResources(HistoryLoaderBL.ATTACHMENT_SIZE, locale) + fieldLabelSeparator); stringBuffer.append(TAttachmentBean.getFileSizeString(size)); } if (description != null && !"".equals(description)) { if (stringBuffer.length() > 0) { stringBuffer.append(commonFieldsSeparator + lineBreak); } stringBuffer.append(LocalizeUtil.getLocalizedTextFromApplicationResources( HistoryLoaderBL.ATTACHMENT_DESCRIPTION, locale) + fieldLabelSeparator); stringBuffer.append(description); } return stringBuffer.toString(); }
From source file:lucee.runtime.chart.PieSectionLegendLabelGeneratorImpl.java
private void reorganize(StringBuilder sb, StringList list, StringBuilder rest) { // fill rest/*from ww w.j a v a 2 s . c o m*/ String item; while (list.hasNext()) { item = list.next(); rest.append(list.delimiter()); rest.append(item); } StringList words = ListUtil.toWordList(rest.toString()); StringBuffer line = new StringBuffer(); while (words.hasNext()) { item = words.next(); if (line.length() > 0 && metrics.stringWidth(item.concat(" ").concat(line.toString())) > with) { if (sb.length() > 0) sb.append('\n'); sb.append(line); //print.out("line:"+line); line = new StringBuffer(item); } else { //item=words.next(); if (line.length() > 0) line.append(words.delimiter() == 0 ? ' ' : words.delimiter()); line.append(item); } } if (line.length() > 0) { if (sb.length() > 0) sb.append('\n'); sb.append(line); } }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.ProgramMemberController.java
@RequestMapping(value = "/rest/" + RestConstants.VERSION_1 + "/program/{uuid}/member") @ResponseBody/* ww w .j a v a 2 s . com*/ public SimpleObject getMembers(@PathVariable("uuid") String uuid, HttpServletRequest request) throws ResponseException { Program p = Context.getProgramWorkflowService().getProgramByUuid(uuid); //i.e. c8e87b17-907f-4b50-8d23-0038e050bbbc List<PatientProgram> pplist = Context.getProgramWorkflowService().getPatientPrograms(null, p, null, null, null, null, false); // additional logic here eventually, state handling, etc. ... SimpleObject so = new SimpleObject(); List<Patient> patientList = new ArrayList<Patient>(); StringBuffer result = new StringBuffer(); for (PatientProgram pp : pplist) { patientList.add(pp.getPatient()); if (result.length() > 0) result.append(COMMA); result.append(CURLY_BRACKET_LEFT).append(LABEL_UUID).append(pp.getPatient().getUuid()).append(COMMA) .append(LABEL_DISPLAY).append(pp.getPatient().getGivenName()).append(SPACE) .append(pp.getPatient().getFamilyName()).append(CURLY_BRACKET_RIGHT); } String json = SQUARE_BRACKET_LEFT + result.append(SQUARE_BRACKET_RIGHT).toString(); so.add("results", json); // {"results":"[{uuid:68a8da76-7ca8-11e0-9450-00e0b6048124,display:TEST PATIENT}]"} return so; }
From source file:com.aw.core.util.QTTablaABeanMapper.java
public String buildSetterName(String name) { // no requiere transformacion if (name.indexOf('_') == -1) return name; StringTokenizer tokenizer = new StringTokenizer(name, "_"); List tokens = new ArrayList(); while (tokenizer.hasMoreTokens()) { tokens.add(tokenizer.nextToken()); }// w ww .ja va 2 s. c om String[] partes = (String[]) tokens.toArray(new String[tokens.size()]);//= name.split("_"); StringBuffer setter = new StringBuffer(); for (int i = 0; i < partes.length; i++) { String primLetra = partes[i].substring(0, 1).toUpperCase(); if (setter.length() == 0) primLetra = primLetra.toLowerCase(); String resto = partes[i].length() <= 1 ? "" : partes[i].substring(1).toLowerCase(); setter.append(primLetra).append(resto); } return setter.toString(); }
From source file:de.unidue.inf.is.ezdl.dlbackend.misc.TemplateParser.java
private StringBuffer replace(StringBuffer stringbuffer, String s, String s1) { StringBuffer sb = new StringBuffer(stringbuffer.toString()); if (stringbuffer.length() < 1 || s.length() < 1) { return sb; }/*from w ww .j a va 2 s . c om*/ int i; int j = 0; while ((i = sb.toString().indexOf(s, j)) != -1) { sb = sb.delete(i, i + s.length()); sb = sb.insert(i, s1); j = i + s1.length(); } return sb; }
From source file:com.sfs.dao.bugreport.EmailBugReportHandler.java
/** * File a bug report via email./*from w w w . java 2s .c o m*/ * * @param bugReport - the bug report details * * @throws SFSDaoException the SFS dao exception */ public final void submitReport(final BugReportBean bugReport) throws SFSDaoException { if (this.emailMessageDAO == null) { throw new SFSDaoException("The EmailMessageDAO object cannot be null"); } if (this.recipients == null) { throw new SFSDaoException("At least one bug report recipient must be identified"); } if (bugReport == null) { throw new SFSDaoException("BugReportBean cannot be null"); } if (bugReport.getUser() == null) { throw new SFSDaoException("Submission of a bug report requires a valid user object"); } if (bugReport.getReportClass() == null) { throw new SFSDaoException("The bug report class cannot be null"); } StringBuffer title = new StringBuffer(); if (StringUtils.isNotBlank(bugReport.getPriority())) { title.append(bugReport.getPriority()); title.append(": "); } if (StringUtils.isNotBlank(bugReport.getReportClass())) { title.append(bugReport.getReportClass()); if (StringUtils.isNotBlank(bugReport.getReportType())) { title.append(" - "); title.append(bugReport.getReportType()); } title.append(": "); } if (StringUtils.isNotBlank(bugReport.getTitle())) { title.append(bugReport.getTitle()); } StringBuffer emailRecipients = new StringBuffer(); for (String recipient : this.recipients) { if (emailRecipients.length() > 0) { emailRecipients.append(","); } emailRecipients.append(recipient); } EmailMessageBean emailMessage = new EmailMessageBean(); emailMessage.setSubject(title.toString()); emailMessage.setMessage(bugReport.getDescription()); emailMessage.setFrom(bugReport.getUser().getEmail()); emailMessage.setFromName(bugReport.getUser().getPreferredName() + " " + bugReport.getUser().getLastName()); emailMessage.setTo(emailRecipients.toString()); this.emailMessageDAO.send(emailMessage); }