List of usage examples for java.lang StringBuffer charAt
@Override public synchronized char charAt(int index)
From source file:com.vmware.thinapp.common.util.AfUtil.java
/** * Convert into lowercase with uppercase initial. * * @param string Word like "hello"./*from w w w . j av a 2 s .c o m*/ * @return Word like "Hello" */ public static String toInitialCase(String string) { if (string.isEmpty()) { return string; } StringBuffer lower = new StringBuffer(string.toLowerCase()); lower.setCharAt(0, Character.toUpperCase(lower.charAt(0))); return lower.toString(); }
From source file:org.dspace.app.dav.DAVServlet.java
/** * Return portion of URI path relevant to the DAV resource. We go through * the extra pain of chopping up getRequestURI() because it is NOT * URL-decoded by the Servlet container, while unfortunately getPathInfo() * IS pre-decoded, leaving a redudndant "/" (and who knows what else) in the * handle. Since the "handle" may not even be a CNRI Handle, we don't want * to assume it even has a "/" (escaped or not). * <p>//from w w w. j a v a 2s.co m * Finally, search for doubled-up '/' separators and coalesce them. * * @param request the request * * @return String of undecoded path NOT starting with '/'. */ private static String getDavResourcePath(HttpServletRequest request) { String path = request.getRequestURI(); String ppath = path.substring(request.getContextPath().length()); String scriptName = request.getServletPath(); if (ppath.startsWith(scriptName)) { ppath = ppath.substring(scriptName.length()); } // log.debug("Got DAV URI: BEFORE // FIXUP: PATH_INFO=\"" + ppath+"\""); // turn all double '/' ("//") in URI into single '/' StringBuffer sb = new StringBuffer(ppath); int i = ppath.length() - 2; if (i > 0) { while ((i = ppath.lastIndexOf("//", i)) > -1) { sb.deleteCharAt(i + 1); --i; } } // remove leading '/' if (sb.length() > 0 && sb.charAt(0) == '/') { sb.deleteCharAt(0); } ppath = sb.toString(); log.debug("Got DAV URI: PATH_INFO=\"" + ppath + "\""); return ppath; }
From source file:com.jaspersoft.jasperserver.api.engine.common.service.impl.ActionModel.java
private static void generateAction(ActionModelSupport actionModelInterface, StringBuffer sb, Element action) throws Exception { String actionType = action.getName(); //Opener//ww w .jav a 2s . c om Character latestChar = sb.charAt(sb.length() - 1); if (latestChar == ']' || latestChar == '}') { sb.append(","); } sb.append("{"); //attributes appendType(actionType, sb); appendStandardProperty(ID_KEY, action.getAttributeValue(ID_ATTR), sb); appendStandardProperty(CLIENT_TEST_KEY, action.getAttributeValue(CLIENT_TEST_ATTR), sb); appendStandardArgs(CLIENT_TEST_ARGS_KEY, action.getAttributeValue(CLIENT_TEST_ARGS_ATTR), sb); appendStandardProperty(SELECTION_CONSTRAINT_KEY, action.getAttributeValue(SELECTION_CONSTRAINT_ATTR), sb); appendStandardProperty(ALLOWS_INPUT_TEST_KEY, action.getAttributeValue(ALLOWS_INPUT_TEST_ATTR), sb); appendStandardArgs(ALLOWS_INPUT_TEST_ARGS_KEY, action.getAttributeValue(ALLOWS_INPUT_TEST_ARGS_ATTR), sb); appendStandardProperty(NO_ICON_INDENT_KEY, action.getAttributeValue(NO_ICON_INDENT_ATTR), sb); appendStandardProperty(BUTTON_KEY, action.getAttributeValue(BUTTON_ATTR), sb); appendStandardProperty(DISABLED_KEY, action.getAttributeValue(DISABLED_ATTR), sb); if (action.getAttributeValue(CLASS_NAME) != null) { appendStandardProperty(CLASS_NAME, action.getAttributeValue(CLASS_NAME), sb); } if (hasText(actionType)) { appendText(action, actionModelInterface, sb); } if (firesAction(actionType)) { appendStandardProperty(ACTION_KEY, action.getAttributeValue(ACTION_ATTR), sb); appendStandardArgs(ACTION_ARGS_KEY, action.getAttributeValue(ACTION_ARGS_ATTR), sb); } if (indicatesSelection(action)) { appendStandardProperty(IS_SELECTED_TEST_KEY, action.getAttributeValue(IS_SELECTED_TEST_ATTR), sb); appendStandardArgs(IS_SELECTED_TEST_ARGS_KEY, action.getAttributeValue(IS_SELECTED_TEST_ARGS_ATTR), sb); } if (hasChildren(actionType)) { appendChildren(action, actionModelInterface, sb); } //Final closure sb.append("}"); }
From source file:tkwatch.Utilities.java
/** * Prepares a string to be stored in an SQL statement. That means that * single quoted (apostrophes) are doubled. * //from w w w . j a v a2s . c o m * @param inputString * The string to prepared for SQL handling. * @return The prepared string. */ static final String prep(final String inputString) { char c = '\0'; final StringBuffer inputBuffer = new StringBuffer(inputString); final StringBuffer outputBuffer = new StringBuffer(); for (int i = 0; i < inputBuffer.length(); i++) { c = inputBuffer.charAt(i); if (c == '\'') outputBuffer.append('\''); outputBuffer.append(c); } return outputBuffer.toString(); }
From source file:tkwatch.Utilities.java
/** * Prepares a retrieved string to be displayed without SQL-necessary doubled * single quotes (apostrophes)./* ww w.ja v a2 s . c o m*/ * * @param inputString * The string to be stripped of double apostrophes. * @return The string ready for display. */ static final String unPrep(final String inputString) { char c = '\0'; final StringBuffer inputBuffer = new StringBuffer(inputString); final StringBuffer outputBuffer = new StringBuffer(); for (int i = 0; i < inputBuffer.length(); i++) { c = inputBuffer.charAt(i); // Delete doubles apostrophes if (i > 0 && inputBuffer.charAt(i - 1) == '\'' && inputBuffer.charAt(i) == '\'') continue; outputBuffer.append(c); } return outputBuffer.toString(); }
From source file:org.opencms.xml.CmsXmlUtils.java
/** * Simplifies an Xpath by removing a leading and a trailing slash from the given path.<p> * /* www .j a va2 s . c o m*/ * Examples:<br> * <code>title/</code> becomes <code>title</code><br> * <code>/title[1]/</code> becomes <code>title[1]</code><br> * <code>/title/subtitle/</code> becomes <code>title/subtitle</code><br> * <code>/title/subtitle[1]/</code> becomes <code>title/subtitle[1]</code><p> * * @param path the path to process * @return the input with a leading and a trailing slash removed */ public static String simplifyXpath(String path) { StringBuffer result = new StringBuffer(path); if (result.charAt(0) == '/') { result.deleteCharAt(0); } int pos = result.length() - 1; if (result.charAt(pos) == '/') { result.deleteCharAt(pos); } return result.toString(); }
From source file:org.exoplatform.wcm.webui.formgenerator.UIFormGeneratorTabPane.java
/** * Clean string.//from ww w . ja v a2s . c o m * * @param str the str * * @return the string */ private static String cleanString(String str) { Transliterator accentsconverter = Transliterator .getInstance("Latin; NFD; [:Nonspacing Mark:] Remove; NFC;"); str = accentsconverter.transliterate(str); //the character ? seems to not be changed to d by the transliterate function StringBuffer cleanedStr = new StringBuffer(str.trim()); // delete special character for (int i = 0; i < cleanedStr.length(); i++) { char c = cleanedStr.charAt(i); if (c == ' ') { if (i > 0 && cleanedStr.charAt(i - 1) == '-') { cleanedStr.deleteCharAt(i--); } else { c = '_'; cleanedStr.setCharAt(i, c); } continue; } if (i > 0 && !(Character.isLetterOrDigit(c) || c == '-')) { cleanedStr.deleteCharAt(i--); continue; } if (i > 0 && c == '-' && cleanedStr.charAt(i - 1) == '-') cleanedStr.deleteCharAt(i--); } if (!Character.isLetterOrDigit(cleanedStr.charAt(0))) { cleanedStr.deleteCharAt(0); } if (cleanedStr.length() > 0 && !Character.isLetterOrDigit(cleanedStr.charAt(cleanedStr.length() - 1))) { cleanedStr.deleteCharAt(cleanedStr.length() - 1); } return cleanedStr.toString().toLowerCase().replaceAll("-", "_"); }
From source file:org.apache.cocoon.util.NetUtils.java
/** * Normalize a uri containing ../ and ./ paths. * * @param uri The uri path to normalize// w w w .j av a2 s .c o m * @return The normalized uri */ public static String normalize(String uri) { if ("".equals(uri)) { return uri; } int leadingSlashes = 0; for (leadingSlashes = 0; leadingSlashes < uri.length() && uri.charAt(leadingSlashes) == '/'; ++leadingSlashes) { } boolean isDir = (uri.charAt(uri.length() - 1) == '/'); StringTokenizer st = new StringTokenizer(uri, "/"); LinkedList clean = new LinkedList(); while (st.hasMoreTokens()) { String token = st.nextToken(); if ("..".equals(token)) { if (!clean.isEmpty() && !"..".equals(clean.getLast())) { clean.removeLast(); if (!st.hasMoreTokens()) { isDir = true; } } else { clean.add(".."); } } else if (!".".equals(token) && !"".equals(token)) { clean.add(token); } } StringBuffer sb = new StringBuffer(); while (leadingSlashes-- > 0) { sb.append('/'); } for (Iterator it = clean.iterator(); it.hasNext();) { sb.append(it.next()); if (it.hasNext()) { sb.append('/'); } } if (isDir && sb.length() > 0 && sb.charAt(sb.length() - 1) != '/') { sb.append('/'); } return sb.toString(); }
From source file:org.exoplatform.services.cms.impl.Utils.java
/** * Clean string.//w ww . j ava 2s .co m * * @param str the str * * @return the string */ public static String cleanString(String str) { Transliterator accentsconverter = Transliterator .getInstance("Latin; NFD; [:Nonspacing Mark:] Remove; NFC;"); str = accentsconverter.transliterate(str); //the character ? seems to not be changed to d by the transliterate function StringBuffer cleanedStr = new StringBuffer(str.trim()); // delete special character for (int i = 0; i < cleanedStr.length(); i++) { char c = cleanedStr.charAt(i); if (c == ' ') { if (i > 0 && cleanedStr.charAt(i - 1) == '-') { cleanedStr.deleteCharAt(i--); } else { c = '-'; cleanedStr.setCharAt(i, c); } continue; } if (i > 0 && !(Character.isLetterOrDigit(c) || c == '-')) { cleanedStr.deleteCharAt(i--); continue; } if (i > 0 && c == '-' && cleanedStr.charAt(i - 1) == '-') cleanedStr.deleteCharAt(i--); } while (StringUtils.isNotEmpty(cleanedStr.toString()) && !Character.isLetterOrDigit(cleanedStr.charAt(0))) { cleanedStr.deleteCharAt(0); } String clean = cleanedStr.toString().toLowerCase(); if (clean.endsWith("-")) { clean = clean.substring(0, clean.length() - 1); } return clean; }
From source file:jdiff.API.java
/** * Convert text with stuffed HTML tags ("lEsS_tHaN", etc) into HTML text. *///from w w w. j av a 2 s. c o m public static String showHTMLTags(String text) { StringBuffer sb = new StringBuffer(text); StringBuffer res = new StringBuffer(); int len = sb.length(); res.setLength(len); int i = 0; int resIdx = 0; while (i < len) { char c = sb.charAt(i); if (len - i > 8 && c == 'l' && sb.charAt(i + 1) == 'E' && sb.charAt(i + 2) == 's' && sb.charAt(i + 3) == 'S' && sb.charAt(i + 4) == '_' && sb.charAt(i + 5) == 't' && sb.charAt(i + 6) == 'H' && sb.charAt(i + 7) == 'a' && sb.charAt(i + 8) == 'N') { res.setCharAt(resIdx, '<'); i += 8; } else if (len - i > 9 && c == 'q' && sb.charAt(i + 1) == 'U' && sb.charAt(i + 2) == 'o' && sb.charAt(i + 3) == 'T' && sb.charAt(i + 4) == 'e' && sb.charAt(i + 5) == '_' && sb.charAt(i + 6) == 'c' && sb.charAt(i + 7) == 'H' && sb.charAt(i + 8) == 'a' && sb.charAt(i + 9) == 'R') { res.setCharAt(resIdx, '"'); i += 9; } else if (len - i > 7 && c == 'a' && sb.charAt(i + 1) == 'N' && sb.charAt(i + 2) == 'd' && sb.charAt(i + 3) == '_' && sb.charAt(i + 4) == 'c' && sb.charAt(i + 5) == 'H' && sb.charAt(i + 6) == 'a' && sb.charAt(i + 7) == 'R') { res.setCharAt(resIdx, '&'); i += 7; } else { res.setCharAt(resIdx, c); } i++; resIdx++; } res.setLength(resIdx); return res.toString(); }