List of usage examples for java.lang StringBuffer charAt
@Override public synchronized char charAt(int index)
From source file:net.sf.morph.transform.converters.TextToNumberConverter.java
/** * Determines whether negation of the conversion result is needed based on * the presence and handling method of parentheses. * //from ww w . j a v a 2 s.com * @param charactersToParse * the characters to parse * @param locale * the locale * @return <code>true</code>, if the number is enclosed by parantheses * and parantheses handling is set to PARENTHESES_NEGATE or<br> * <code>false</code>, otherwise */ private boolean handleParenthesesNegation(StringBuffer charactersToParse, Locale locale) { int lastCharIndex = charactersToParse.length() - 1; // if this is a number enclosed with parentheses and we should be // negating values in parentheses if (getParenthesesHandling() == PARENTHESES_NEGATE && charactersToParse.charAt(0) == LEFT_PARENTHESES && charactersToParse.charAt(lastCharIndex) == RIGHT_PARENTHESES) { // delete the closing paran charactersToParse.deleteCharAt(lastCharIndex); // delete the opening paran charactersToParse.deleteCharAt(0); // return true to indicate negation should take place return true; } // return false to indicate negation should not happen return false; }
From source file:DummyAppletContext.java
/** * Gets the document URL./* w w w . j a v a 2 s. c o m*/ * * @return a "file:" URL for the current directory */ public URL getDocumentBase() { URL url = null; try { File dummy = new File("dummy.html"); String path = dummy.getAbsolutePath(); if (!File.separator.equals("/")) { StringBuffer buffer = new StringBuffer(); if (path.charAt(0) != File.separator.charAt(0)) { buffer.append("/"); } StringTokenizer st = new StringTokenizer(path, File.separator); while (st.hasMoreTokens()) { buffer.append(st.nextToken() + "/"); } if (File.separator.equals("\\") && (buffer.charAt(2) == ':')) { buffer.setCharAt(2, '|'); } else { } path = buffer.toString(); path = path.substring(0, path.length() - 1); } url = new URL("file", "", -1, path); } catch (MalformedURLException mue) { mue.printStackTrace(); } return url; }
From source file:com.wabacus.system.fileupload.AbsFileUpload.java
protected String showDataImportFileUpload(List<String> lstDataImportFileNames) { if (lstDataImportFileNames == null || lstDataImportFileNames.size() == 0) return ""; StringBuffer resultBuf = new StringBuffer(); resultBuf.append(//from ww w . j a v a 2s .c om "<table border=0 cellspacing=1 cellpadding=2 style=\"margin:0px\" width=\"98%\" ID=\"Table1\" align=\"center\">"); resultBuf.append("<tr class=filetitle><td style='font-size:13px;'>?</td></tr>"); StringBuffer fileNameBuf = new StringBuffer(); int idx = 0; for (String filenameTmp : lstDataImportFileNames) { fileNameBuf.append(filenameTmp).append("; "); resultBuf.append( "<tr><td style='font-size:13px;'><input type=\"file\" contentEditable=\"false\" name=\"uploadfile" + (idx++) + "\"></td></tr>"); } if (fileNameBuf.length() > 2 && fileNameBuf.charAt(fileNameBuf.length() - 2) == ';') { fileNameBuf.deleteCharAt(fileNameBuf.length() - 2); } resultBuf.append("<tr class=filetitle><td style='font-size:13px;'>[??" + fileNameBuf.toString().trim() + "]</td></tr>"); resultBuf.append( "<tr><td style='font-size:13px;'><input type=\"submit\" class=\"cls-button\" name=\"submit\" value=\"\">"); resultBuf.append("</td></tr></table>"); return resultBuf.toString(); }
From source file:gtu._work.etc.EnglishAdd.java
void addWordTable(String word) { try {// w ww . java 2s .c o m StringBuffer sb = new StringBuffer(wordTextArea.getText()); List<String> contains = new ArrayList<String>(); BufferedReader reader = new BufferedReader(new StringReader(sb.toString())); try { for (String line = null; (line = reader.readLine()) != null;) { contains.add(line); } reader.close(); } catch (IOException e) { e.printStackTrace(); } if (contains.contains(word)) { return; } if (sb.length() != 0 && sb.charAt(sb.length() - 1) != '\n') { sb.append("\r\n"); } sb.append(word + "\r\n"); wordTextArea.setText(sb.toString()); if (sb.length() > 0 && currentFile != null) { FileUtil.saveToFile(currentFile, sb.toString(), "BIG5"); } } catch (Exception ex) { JCommonUtil.handleException(ex); } }
From source file:cx.fbn.nevernote.threads.IndexRunner.java
private String removeTags(String text) { StringBuffer buffer = new StringBuffer(text); boolean inTag = false; for (int i = buffer.length() - 1; i >= 0; i--) { if (buffer.charAt(i) == '>') inTag = true;// w ww. j av a 2s. com if (buffer.charAt(i) == '<') inTag = false; if (inTag || buffer.charAt(i) == '<') buffer.deleteCharAt(i); } return buffer.toString(); }
From source file:org.apache.sling.osgi.obr.OSGiBundleRepositoryServlet.java
private String getRelativeURI(HttpServletRequest req, String relPath) { StringBuffer url = req.getRequestURL(); if (url.charAt(url.length() - 1) != '/') url.append('/'); url.append(relPath);//from ww w . j a v a 2s . c om return url.toString(); }
From source file:org.eclipse.xtend.typesystem.xsd.builder.OawXSDEcoreBuilder.java
@Override protected String validName(String name, int casing, String prefix) { List<String> parsedName = parseName(name, '_'); StringBuffer result = new StringBuffer(); for (String nameComponent : parsedName) { if (nameComponent.length() > 0) { if (casing != UNCHANGED_CASE && isUppercase(nameComponent)) nameComponent = nameComponent.toLowerCase(); if (result.length() > 0 || casing == UPPER_CASE) { result.append(Character.toUpperCase(nameComponent.charAt(0))); result.append(nameComponent.substring(1)); } else { result.append(nameComponent); }/*w w w . j av a2 s . c om*/ } } return result.length() == 0 ? prefix : Character.isJavaIdentifierStart(result.charAt(0)) ? casing == LOWER_CASE ? uncapName(result.toString()) : result.toString() : prefix + result; }
From source file:com.wabacus.system.component.container.AbsContainerType.java
protected String showMetaDataDisplayStringStart() { StringBuffer resultBuf = new StringBuffer(); resultBuf.append(super.showMetaDataDisplayStringStart()); resultBuf.append(" childComponentIds=\""); for (String childidTmp : this.containerConfigBean.getLstChildrenIDs()) { resultBuf.append(childidTmp).append(";"); }/*from w w w . ja va2 s .c o m*/ if (resultBuf.charAt(resultBuf.length() - 1) == ';') { resultBuf.deleteCharAt(resultBuf.length() - 1); } resultBuf.append("\""); return resultBuf.toString(); }
From source file:org.josso.auth.scheme.X509CertificateAuthScheme.java
/** * Parses a Compound name/*from w w w.j a v a 2 s . c o m*/ * (ie. CN=Java Duke, OU=Java Software Division, O=Sun Microsystems Inc, C=US) and * builds a HashMap object with key-value pairs. * * @param s a string containing the compound name to be parsed * @return a HashMap object built from the parsed key-value pairs * @throws IllegalArgumentException if the compound name * is invalid */ private HashMap parseCompoundName(String s) { String valArray[] = null; if (s == null) { throw new IllegalArgumentException(); } HashMap hm = new HashMap(); // Escape characters noticed, so use "extended/escaped parser" if ((s.indexOf("\"") > 0) || (s.indexOf("\\") > 0)) { StringBuffer sb = new StringBuffer(s); boolean escaped = false; StringBuffer buff = new StringBuffer(); String key = ""; String value = ""; for (int i = 0; i < sb.length(); i++) { // Quotes are begin/end, so keep a flag of escape-state if ('"' == sb.charAt(i)) { if (escaped) { escaped = false; continue; } else { escaped = true; continue; } // Single-character escape/advance // but check the length, too. } else if ('\\' == sb.charAt(i)) { i++; if (i >= sb.length()) { break; } // Split on '=' between key/value } else if ('=' == sb.charAt(i)) { key = buff.toString(); buff = new StringBuffer(); continue; // We've reached a valid delimiter, as long as we're not // still reading 'escaped' data } else if ((',' == sb.charAt(i)) && (!escaped)) { value = buff.toString(); buff = new StringBuffer(); key = key.trim().toLowerCase(); value = value.trim(); hm.put(key, value); continue; } buff.append(sb.charAt(i)); } // for... // And the last one... value = buff.toString(); key = key.trim().toLowerCase(); value = value.trim(); hm.put(key, value); } else { // Otherwise, no (known) escape characters, so continue on with // the faster parse. StringTokenizer st = new StringTokenizer(s, ","); while (st.hasMoreTokens()) { String pair = (String) st.nextToken(); int pos = pair.indexOf('='); if (pos == -1) { // XXX // should give more detail about the illegal argument throw new IllegalArgumentException(); } String key = pair.substring(0, pos).trim().toLowerCase(); String val = pair.substring(pos + 1, pair.length()).trim(); hm.put(key, val); } } return hm; }
From source file:cx.fbn.nevernote.threads.IndexRunner.java
private void addToIndex(String guid, String word, String type) { if (foundWords.contains(word)) return;//from w w w .jav a 2 s . c o m StringBuffer buffer = new StringBuffer(word.toLowerCase()); for (int i = buffer.length() - 1; i >= 0; i--) { if (!Character.isLetterOrDigit(buffer.charAt(i)) && specialIndexCharacters.indexOf(buffer.charAt(i)) == -1) buffer.deleteCharAt(i); else break; } buffer = buffer.reverse(); for (int i = buffer.length() - 1; i >= 0; i--) { if (!Character.isLetterOrDigit(buffer.charAt(i))) buffer.deleteCharAt(i); else break; } buffer = buffer.reverse(); if (buffer.length() > 0) { // We have a good word, now let's trim off junk at the beginning or end if (!foundWords.contains(buffer.toString())) { foundWords.add(buffer.toString()); foundWords.add(word); conn.getWordsTable().addWordToNoteIndex(guid, buffer.toString(), type, 100); uncommittedCount++; if (uncommittedCount > 100) { conn.commitTransaction(); uncommittedCount = 0; } } } return; }