List of usage examples for java.lang StringBuffer substring
@Override public synchronized String substring(int start, int end)
From source file:org.kite9.diagram.server.AbstractKite9Controller.java
protected String sanitizeFilePath(String badFileName) { StringBuffer cleanFileName = new StringBuffer(); Matcher fileMatcher = filePattern.matcher(badFileName); boolean match = fileMatcher.find(); while (match) { fileMatcher.appendReplacement(cleanFileName, ""); match = fileMatcher.find();/*from w w w . j a va2 s . c o m*/ } fileMatcher.appendTail(cleanFileName); return cleanFileName.substring(0, cleanFileName.length() > 250 ? 250 : cleanFileName.length()); }
From source file:com.meiah.core.util.StringUtil.java
/** * /* w ww . j av a2 s.co m*/ * @description strKeyword?strSplit??? * @param strSplit * @author zhangj * @date Jun 14, 2012 */ public static List<String> getEngKeyword(StringBuffer sbKeyword, String strSplit) { if (Validator.isNull(strSplit)) { strSplit = "\""; //""???? } List<String> result = new ArrayList<String>(); int index = 0, end = 0; int start = sbKeyword.indexOf(strSplit); //"? int count = 1; while (index != -1) { index = sbKeyword.indexOf(strSplit, index + 1); if (index != -1) { if (index == start) { continue; } if (count % 2 == 0) { start = index; } else { end = index; } if (start < end) { result.add(sbKeyword.substring(start + 1, end)); sbKeyword.replace(start + 1, end, ""); index = start + 1; start = 0; end = 0; } count++; } } return result; }
From source file:org.kuali.ole.select.document.OleCorrectionReceivingDocument.java
/** * This method will set copies into list of copies for LineItem. * * @param singleItem// www . j a va2 s . c o m * @param workBibDocument * @return */ public List<OleCopies> setCopiesToLineItem(OleCorrectionReceivingItem singleItem, WorkBibDocument workBibDocument) { List<WorkInstanceDocument> instanceDocuments = workBibDocument.getWorkInstanceDocumentList(); List<OleCopies> copies = new ArrayList<OleCopies>(); for (WorkInstanceDocument workInstanceDocument : instanceDocuments) { List<WorkItemDocument> itemDocuments = workInstanceDocument.getItemDocumentList(); StringBuffer enumeration = new StringBuffer(); for (int itemDocs = 0; itemDocs < itemDocuments.size(); itemDocs++) { if (itemDocs + 1 == itemDocuments.size()) { enumeration = enumeration.append(itemDocuments.get(itemDocs).getEnumeration()); } else { enumeration = enumeration.append(itemDocuments.get(itemDocs).getEnumeration() + ","); } } int startingCopy = 0; if (singleItem.getItemReceivedTotalParts().intValue() != 0 && null != enumeration) { String enumerationSplit = enumeration.substring(1, 2); boolean isint = checkIsEnumerationSplitIsIntegerOrNot(enumerationSplit); if (isint) { startingCopy = Integer.parseInt(enumerationSplit); } } int parts = 1; if (null != singleItem.getPurchaseOrderIdentifier()) { parts = getPONoOfPartsOrdered(singleItem.getPurchaseOrderIdentifier()); } else { parts = singleItem.getItemReceivedTotalParts().intValue(); } /* * if (singleItem.getItemReceivedTotalQuantity().isGreaterThan(new KualiDecimal(1)) || * singleItem.getItemReceivedTotalParts().isGreaterThan(new KualiDecimal(1))) { */ int noOfCopies = workInstanceDocument.getItemDocumentList().size() / parts; OleRequisitionCopies copy = new OleRequisitionCopies(); copy.setParts(new KualiInteger(parts)); copy.setLocationCopies(workInstanceDocument.getHoldingsDocument().getLocationName()); copy.setItemCopies(new KualiDecimal(noOfCopies)); copy.setPartEnumeration(enumeration.toString()); copy.setStartingCopyNumber(new KualiInteger(startingCopy)); copies.add(copy); // } } return copies; }
From source file:uk.ac.liverpool.spreadsheet.ToXML.java
private void printSheetContent(Sheet sheet) { ensureColumnBounds(sheet);//from ww w. j a v a2 s. c o m printColumnHeads(); cellsToFormula = new HashMap<String, List<String>>(); cellToFormulaConverted = new HashMap<String, String>(); crToParent = new HashMap<String, List<String>>(); FormulaParsingWorkbook fpwb; FormulaRenderingWorkbook frwb; if (xswb != null) { XSSFEvaluationWorkbook w = XSSFEvaluationWorkbook.create(xswb); frwb = w; fpwb = w; } else if (hswb != null) { HSSFEvaluationWorkbook w = HSSFEvaluationWorkbook.create(hswb); frwb = w; fpwb = w; } else return; // first we need to determine all the dependencies ofr each formula Iterator<Row> rows = sheet.rowIterator(); while (rows.hasNext()) { Row row = rows.next(); for (int i = firstColumn; i < endColumn; i++) { if (i >= row.getFirstCellNum() && i < row.getLastCellNum()) { Cell cell = row.getCell(i); if (cell != null) { if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) try { parseFormula(cell, fpwb, frwb); } catch (Exception x) { } } } } } rows = sheet.rowIterator(); while (rows.hasNext()) { Row row = rows.next(); int rowNumber = row.getRowNum() + 1; out.format(" <TableRow>%n"); out.format(" <RowHeader>%d</RowHeader>%n", rowNumber); out.format(" <TableCells>%n"); for (int i = firstColumn; i < endColumn; i++) { String content = "0"; String attrs = ""; CellStyle style = null; String valueType = "float"; Cell cell = row.getCell(i); CellReference c = new CellReference(rowNumber - 1, i); attrs += " cellID=\"." + c.formatAsString() + "\""; String cr = c.formatAsString(); // if (i >= row.getFirstCellNum() && i < row.getLastCellNum()) { if (cell != null && cell.getCellType() == Cell.CELL_TYPE_FORMULA) { attrs += " readOnly=\"readOnly\""; try { attrs += " cellFormula=\"" + StringEscapeUtils.escapeXml(cell.getCellFormula()) + "\""; } catch (Exception x) { attrs += " cellFormula=\"FORMULA ERROR\""; } } else { List<String> cfrl = cellsToFormula.get(cr); StringBuffer formula = new StringBuffer(""); if (cfrl != null) { List<String> refs = new LinkedList<String>(); visit(cfrl, refs); System.out.println(refs); cleanup(refs); for (String s : refs) { formula.append(StringEscapeUtils.escapeXml(cellToFormulaConverted.get(s))); formula.append(" || "); } } if (formula.length() > 0) attrs += " formula=\"" + formula.substring(0, formula.length() - 4) + "\""; } if (cell != null) { style = cell.getCellStyle(); // Set the value that is rendered for the cell // also applies the format try { CellFormat cf = CellFormat.getInstance(style.getDataFormatString()); CellFormatResult result = cf.apply(cell); content = result.text; } catch (Exception x) { content = "DATA FORMULA ERROR "; } } // } attrs += " value_type=\"" + valueType + "\""; attrs += " value=\"" + StringEscapeUtils.escapeXml(content) + "\""; out.format(" <TableCell %s>%s</TableCell>%n", // class=%s // styleName(style), attrs, StringEscapeUtils.escapeXml(content)); } out.format(" </TableCells> </TableRow>%n%n"); } }
From source file:net.fenyo.mail4hotspot.dns.DnsListener.java
private VersionAndDomain getVersionAndDomain(final byte query[]) throws GeneralException { VersionAndDomain vad = new VersionAndDomain(); final StringBuffer tmpstr = new StringBuffer(); int offset = DNSFORMAT_DATAOFFSET; while (query[offset] != 0) { tmpstr.append(new String(query, offset + 1, query[offset], Charset.forName("US-ASCII"))); tmpstr.append("."); offset += query[offset] + 1;/* ww w .jav a 2s . com*/ } if (!tmpstr.toString().toLowerCase().endsWith(DNSDOMAIN + ".")) throw new GeneralException("bad domain: " + tmpstr.toString()); vad.domain = tmpstr.substring(0, tmpstr.length() - DNSDOMAIN.length() - 5).toString(); // version must be 2 char length beginning with 'v' vad.version = tmpstr.substring(tmpstr.length() - DNSDOMAIN.length() - 4, tmpstr.length() - DNSDOMAIN.length() - 2 - 3 + 2 + 1).toString(); if (vad.version.length() != 2 || !vad.version.substring(0, 1).toLowerCase().equals("v")) throw new GeneralException("bad version: " + tmpstr.toString()); return vad; }
From source file:com.lenovo.tensorhusky.common.utils.ProcfsBasedProcessTree.java
/** * Returns a string printing PIDs of process present in the * ProcfsBasedProcessTree. Output format : [pid pid ..] *//* w w w .j a v a 2 s. c om*/ @Override public String toString() { StringBuffer pTree = new StringBuffer("[ "); for (String p : processTree.keySet()) { pTree.append(p); pTree.append(" "); } return pTree.substring(0, pTree.length()) + "]"; }
From source file:org.oss.pdfreporter.engine.fill.JRFillObjectFactory.java
protected void checkUnresolvedReferences() { if (!delayedStyleSettersByName.isEmpty()) { StringBuffer errorMsg = new StringBuffer("Could not resolve style(s): "); for (Iterator<String> it = delayedStyleSettersByName.keySet().iterator(); it.hasNext();) { String name = it.next(); errorMsg.append(name);/*from w w w .j a va2s. c om*/ errorMsg.append(", "); } throw new JRRuntimeException(errorMsg.substring(0, errorMsg.length() - 2)); } }
From source file:com.globalsight.connector.mindtouch.CreateMindTouchJobThread.java
private String handleSpecialChars(String pathName) { StringBuffer sb = new StringBuffer(); String[] arr = pathName.split("/"); if (arr != null && arr.length > 0) { for (String str : arr) { str = str.replace("\\", ""); str = str.replace("/", ""); str = str.replace(":", ""); str = str.replace("*", ""); str = str.replace("?", ""); str = str.replace("\"", ""); str = str.replace("<", ""); str = str.replace(">", ""); str = str.replace("|", ""); sb.append(str).append(File.separator); }//from w w w .ja v a2s . c o m } if (sb.toString().endsWith(File.separator)) { return sb.substring(0, sb.length() - 1); } return sb.toString(); }
From source file:org.squale.squalix.tools.clearcase.configuration.ClearCaseConfiguration.java
/** * Cette mthode est appele dans le cas d'un audit de jalon pour mettre en minuscules une partie prcise (le nom de * la branche) de la commande.<br /> * Typiquement, elle modifie la chane de la faon suivante : <br /> * //from w w w .j a va 2 s .c om * <pre> * /usr/atria/bin/Perl -S /DINB/outils/gcl/script/mkview.pl -application * {APP_NAME} -vob /vobs/tonus_intranet -consultation TONUS_INTRANET_V1_2_ACT * -vws /app/SQUALE/clearcase/cc_storage/views/ * TONUS_INTRANET_V1_2_ACT_mon_application_mon_projet_squale.vws * -login mon_application_mon_projet_squale -snap -dir * /app/SQUALE/<b>TONUS_INTRANET_V1_2_ACT</b>_mon_application_mon_projet_squale * </pre> * * <br /> * en <br /> * * <pre> * /usr/atria/bin/Perl -S /DINB/outils/gcl/script/mkview.pl -application * {APP_NAME} -vob /vobs/tonus_intranet -consultation TONUS_INTRANET_V1_2_ACT * -vws /app/SQUALE/clearcase/cc_storage/views/ * TONUS_INTRANET_V1_2_ACT_mon_application_mon_projet_squale.vws * -login mon_application_mon_projet_squale -snap -dir * /app/SQUALE/<b>tonus_intranet_v1_2_act</b>_mon_application_mon_projet_squale * </pre> * * @param pCommand commande modifier. * @return la commande modifie. */ private String lowerBranchName(String pCommand) { StringBuffer buf = new StringBuffer(pCommand); /* * on cherche la position du caractre situ juste aprs le dernier sparateur UNIX ("/") de la chane. */ int pos = buf.lastIndexOf(ClearCaseConfiguration.UNIX_SEPARATOR) + 1; /* longueur de la chaine. */ int length = buf.length(); /* on met en minuscules la chaine comprise entre "pos" et "length". */ buf.replace(pos, length, buf.substring(pos, length).toLowerCase()); return buf.toString(); }