List of usage examples for java.lang StringBuffer substring
@Override public synchronized String substring(int start)
From source file:edu.stanford.mobisocial.dungbeetle.feed.DbObjects.java
public static String getFeedObjectClause(String[] types) { if (types == null) { types = DbObjects.getRenderableTypes(); }//from www.ja va2s .com StringBuffer allowed = new StringBuffer(); for (String type : types) { allowed.append(",'").append(type).append("'"); } return DbObject.TYPE + " in (" + allowed.substring(1) + ")"; }
From source file:de.uniluebeck.itm.spyglass.SpyglassEnvironment.java
/** * Sets the object used for affine operation within the drawing area * /*from w w w. j av a 2 s .c o m*/ * @param at * the object used for affine operation within the drawing area * @throws IOException * @see DrawingArea */ public static void setAffineTransformation(final AffineTransform at) throws IOException { final double[] flatmatrix = new double[6]; at.getMatrix(flatmatrix); final StringBuffer matrix = new StringBuffer(); for (final double d : flatmatrix) { matrix.append("," + d); } props.setProperty(PROPERTY_CONFIG_AFFINE_TRANSFORM_MATRIX, matrix.substring(1)); storeProps(props); }
From source file:org.locationtech.jtstest.util.StringUtil.java
/** * Returns the elements of c separated by commas. c must not be empty. *//*from w ww. j av a 2 s . c o m*/ public static String toCommaDelimitedString(Collection c) { if (c.isEmpty()) { throw new IllegalArgumentException(); } StringBuffer result = new StringBuffer(); for (Iterator i = c.iterator(); i.hasNext();) { Object o = i.next(); result.append(", " + o.toString()); } return result.substring(1); }
From source file:org.locationtech.jtstest.util.StringUtil.java
/** * Returns the elements of c separated by commas and enclosed in * single-quotes/*from ww w . j av a 2 s .c om*/ */ public static String toCommaDelimitedStringInQuotes(Collection c) { StringBuffer result = new StringBuffer(); for (Iterator i = c.iterator(); i.hasNext();) { Object o = i.next(); result.append(",'" + o.toString() + "'"); } return result.substring(1); }
From source file:org.apache.cocoon.util.IOUtils.java
/** * Return a modified filename suitable for replicating directory * structures below the store's base directory. The following * conversions are performed:/*from www . ja va2s. c o m*/ * <ul> * <li>Path separators are converted to regular directory names</li> * <li>File path components are transliterated to make them valid (?) * programming language identifiers. This transformation may well * generate collisions for unusual filenames.</li> * </ul> * @return The transformed filename */ public static String normalizedFilename(String filename) { if ("".equals(filename)) { return ""; } filename = (File.separatorChar == '\\') ? filename.replace('/', '\\') : filename.replace('\\', '/'); String[] path = StringUtils.split(filename, File.separator); int start = (path[0].length() == 0) ? 1 : 0; StringBuffer buffer = new StringBuffer(); for (int i = start; i < path.length; i++) { if (i > start) { buffer.append(File.separator); } if (path[i].equals("..")) { int lio; for (lio = buffer.length() - 2; lio >= 0; lio--) { if (buffer.substring(lio).startsWith(File.separator)) { break; } } if (lio >= 0) { buffer.setLength(lio); } } else { char[] chars = path[i].toCharArray(); if (chars.length < 1 || !Character.isLetter(chars[0])) { buffer.append('_'); } for (int j = 0; j < chars.length; j++) { if (org.apache.cocoon.util.StringUtils.isAlphaNumeric(chars[j])) { buffer.append(chars[j]); } else { buffer.append('_'); } } // Append the suffix if necessary. if (isJavaKeyword(path[i])) buffer.append(keywordSuffix); } } return buffer.toString(); }
From source file:StringUtils.java
/** * Makes sure that the POSTed data is conforms to certain rules. These * rules are:// w w w . java 2 s.c o m * <UL> * <LI>The data always ends with a newline (some browsers, such * as NS4.x series, does not send a newline at the end, which makes * the diffs a bit strange sometimes. * <LI>The CR/LF/CRLF mess is normalized to plain CRLF. * </UL> * * The reason why we're using CRLF is that most browser already * return CRLF since that is the closest thing to a HTTP standard. * * @param postData The data to normalize * @return Normalized data */ public static String normalizePostData(String postData) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < postData.length(); i++) { switch (postData.charAt(i)) { case 0x0a: // LF, UNIX sb.append("\r\n"); break; case 0x0d: // CR, either Mac or MSDOS sb.append("\r\n"); // If it's MSDOS, skip the LF so that we don't add it again. if (i < postData.length() - 1 && postData.charAt(i + 1) == 0x0a) { i++; } break; default: sb.append(postData.charAt(i)); break; } } if (sb.length() < 2 || !sb.substring(sb.length() - 2).equals("\r\n")) { sb.append("\r\n"); } return sb.toString(); }
From source file:org.jboss.drools.guvnor.importgenerator.PackageFile.java
/** * returns "approval.determine" where path is /home/mallen/workspace/rules/approval/determine/1.0.0.SNAPSHOT/file.xls * and options "start" is "rules" and end is "[0-9|.]*[SNAPSHOT]+[0-9|.]*" ie. any number, dot and word SNAPSHOT * * @param directory/* ww w. j a va 2s. c o m*/ * @param options * @return */ private static String getPackageName(File directory, CmdArgsParser options) { String startPath = directory.getPath(); Matcher m = Pattern.compile("([^/|\\\\]+)").matcher(startPath); // quad-backslash is for windows paths List<String> lpath = new ArrayList<String>(); while (m.find()) lpath.add(m.group()); String[] path = lpath.toArray(new String[lpath.size()]); StringBuffer sb = new StringBuffer(); for (int i = path.length - 1; i >= 0; i--) { String dir = path[i]; if ((dir.matches(options.getOption(Parameters.OPTIONS_PACKAGE_EXCLUDE)))) continue; if ((dir.equals(options.getOption(Parameters.OPTIONS_PACKAGE_START)))) break; //since we are working in reverse, it's time to exit sb.insert(0, PACKAGE_DELIMETER).insert(0, dir); } if (sb.substring(sb.length() - 1).equals(PACKAGE_DELIMETER)) sb.delete(sb.length() - 1, sb.length()); return sb.toString(); }
From source file:org.pentaho.platform.plugin.action.jasperreports.JasperReportsComponent.java
private static String quoteMe(Collection c) { if (c.size() == 0) { return ""; //$NON-NLS-1$ }/* ww w . j ava2 s. c om*/ StringBuffer sb = new StringBuffer(); for (Object value : c) { sb.append(",'"); //$NON-NLS-1$ sb.append(value.toString().replaceAll("'", "''")); //$NON-NLS-1$ //$NON-NLS-2$ sb.append("'"); //$NON-NLS-1$ } return sb.substring(1); }
From source file:org.exoplatform.forum.common.CommonUtils.java
/** * Truncates large Strings showing the string around the specific middle position with the specific length. * /*from w w w .j a v a 2 s . c o m*/ * @param str * the string to truncate * @param middlePosition * the middle position we will show string around * @param maxLength * the max length of string to show * @return the truncated string */ public static final String centerTrunc(String str, int middlePosition, int maxLength) { StringBuffer buf = null; // if (str.length() <= maxLength) { return str; } int halfLength = maxLength / 2; //start position int start = 0; if (middlePosition > halfLength) { start = (middlePosition - halfLength); } //end position int end = Math.min(str.length(), start + maxLength); buf = new StringBuffer(); buf.append(str.substring(start, end)); //complete first & last words String ret = buf.substring(buf.indexOf(" ")); // if (start > 0) ret = "..." + ret; ret = ret.substring(0, ret.lastIndexOf(" ")) + " ..."; return ret; }
From source file:com.panet.imeta.core.row.ValueDataUtil.java
/** * Replace value occurances in a String with another value. * @param string The original String.//from w w w .jav a 2s . c o m * @param repl The text to replace * @param with The new text bit * @return The resulting string with the text pieces replaced. */ public static final String replace(String string, String repl, String with) { StringBuffer str = new StringBuffer(string); for (int i = str.length() - 1; i >= 0; i--) { if (str.substring(i).startsWith(repl)) { str.delete(i, i + repl.length()); str.insert(i, with); } } return str.toString(); }