List of usage examples for java.lang StringBuffer charAt
@Override public synchronized char charAt(int index)
From source file:org.j2free.util.ServletUtils.java
/** * Redirects the user to the provided url over SSL * * @param request a HttpServletRequest// w w w. ja v a 2 s. c om * @param response a HttpServletResponse * @param urlStr * @param sslPort the port SSL requests should be forwarded to * @throws ServletException * @throws IOException */ public static void redirectOverSSL(HttpServletRequest request, HttpServletResponse response, String urlStr, int sslPort) throws ServletException, IOException { StringBuffer url = new StringBuffer(urlStr); // Make sure we're on https if (url.charAt(4) != 's') url.insert(4, 's'); // If there is a ssl port, make sure we're on it, // otherwise assume we're already on the right port if (sslPort > 0) { int portStart = url.indexOf(":", 8) + 1; int portEnd = url.indexOf("/", 8); if (portEnd == -1) // If their isn't a trailing slash, then the end is the last char portEnd = url.length() - 1; if (portStart > 0 && portStart < portEnd) { // If we detected a : before the trailing slash or end of url, delete the port url.delete(portStart, portEnd); } else { url.insert(portEnd, ':'); // If the url didn't have a port, add in the : portStart = portEnd; } url.insert(portStart, sslPort); // Insert the right port where it should be } LogFactory.getLog(ServletUtils.class).debug("redirectOverSSL sending 301: " + url.toString()); sendPermanentRedirect(response, url.toString()); }
From source file:com.flipkart.polyguice.dropwiz.DropConfigProvider.java
private String getNameFromMethod(Method method) { if (method.getParameterCount() > 0) { return null; }// w w w. j ava 2s. co m if (method.getReturnType().equals(Void.TYPE)) { return null; } String mthdName = method.getName(); if (mthdName.startsWith("get")) { if (mthdName.length() <= 3) { return null; } if (method.getReturnType().equals(Boolean.class) || method.getReturnType().equals(Boolean.TYPE)) { return null; } StringBuffer buffer = new StringBuffer(StringUtils.removeStart(mthdName, "get")); buffer.setCharAt(0, Character.toLowerCase(buffer.charAt(0))); return buffer.toString(); } else if (!mthdName.startsWith("is")) { if (mthdName.length() <= 2) { return null; } if (!method.getReturnType().equals(Boolean.class) && !method.getReturnType().equals(Boolean.TYPE)) { return null; } StringBuffer buffer = new StringBuffer(StringUtils.removeStart(mthdName, "is")); buffer.setCharAt(0, Character.toLowerCase(buffer.charAt(0))); return buffer.toString(); } return null; }
From source file:org.apache.cocoon.components.flow.javascript.ScriptablePropertyPointer.java
public String asPath() { Object obj = getBaseValue();/* w w w .jav a2 s .c o m*/ if (!(obj instanceof Scriptable)) { return super.asPath(); } StringBuffer buffer = new StringBuffer(); buffer.append(getParent().asPath()); if (buffer.length() == 0) { buffer.append("/."); } else if (buffer.charAt(buffer.length() - 1) == '/') { buffer.append('.'); } buffer.append("[@name = '"); buffer.append(escape(getPropertyName())); buffer.append("']"); if (index != WHOLE_COLLECTION && (obj instanceof NativeArray)) { buffer.append('[').append(index + 1).append(']'); } return buffer.toString(); }
From source file:util.Seeks.java
/** * Creates a UTF-8 encoded search URL to a random Seeks server, specified in SystemConfiguration **///from w ww .java 2 s . co m private String composeSearch(final String query, final int randomNumber) throws IllegalArgumentException { // final String search = "http://seeks.ru/search/txt/Refined+prediction+of+week+12+response+and+SVR+based+on+week+4+response+in+HCV+genotype+1+patients?output=json"; if (query == null || "".equals(query)) { throw new IllegalArgumentException("query must not be empty!"); } final CodeUrl coder = new CodeUrl(); // get Seeks server to query final StringBuffer buf = new StringBuffer(128); buf.append(ReadSystemConfigurations.getSeeksServer()[randomNumber]); if (buf.charAt(buf.length() - 1) != '/') { buf.append("/"); } buf.append("search/txt/"); buf.append(coder.encode(query, "utf-8")); buf.append("?output=json"); buf.append("&rpp=10"); // limit number of records return buf.toString(); }
From source file:ShowFileDialog.java
/** * Creates the contents for the window/*w w w . java 2s . c o m*/ * * @param shell the parent shell */ public void createContents(final Shell shell) { shell.setLayout(new GridLayout(5, true)); new Label(shell, SWT.NONE).setText("File Name:"); final Text fileName = new Text(shell, SWT.BORDER); GridData data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 4; fileName.setLayoutData(data); Button multi = new Button(shell, SWT.PUSH); multi.setText("Open Multiple..."); multi.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // User has selected to open multiple files FileDialog dlg = new FileDialog(shell, SWT.MULTI); dlg.setFilterNames(FILTER_NAMES); dlg.setFilterExtensions(FILTER_EXTS); String fn = dlg.open(); if (fn != null) { // Append all the selected files. Since getFileNames() returns only // the names, and not the path, prepend the path, normalizing // if necessary StringBuffer buf = new StringBuffer(); String[] files = dlg.getFileNames(); for (int i = 0, n = files.length; i < n; i++) { buf.append(dlg.getFilterPath()); if (buf.charAt(buf.length() - 1) != File.separatorChar) { buf.append(File.separatorChar); } buf.append(files[i]); buf.append(" "); } fileName.setText(buf.toString()); } } }); Button open = new Button(shell, SWT.PUSH); open.setText("Open..."); open.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // User has selected to open a single file FileDialog dlg = new FileDialog(shell, SWT.OPEN); dlg.setFilterNames(FILTER_NAMES); dlg.setFilterExtensions(FILTER_EXTS); String fn = dlg.open(); if (fn != null) { fileName.setText(fn); } } }); Button save = new Button(shell, SWT.PUSH); save.setText("Save..."); save.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // User has selected to save a file FileDialog dlg = new FileDialog(shell, SWT.SAVE); dlg.setFilterNames(FILTER_NAMES); dlg.setFilterExtensions(FILTER_EXTS); String fn = dlg.open(); if (fn != null) { fileName.setText(fn); } } }); }
From source file:org.exoplatform.wiki.rendering.render.confluence.ConfluenceSyntaxEscapeHandler.java
private void escapeURI(StringBuffer accumulatedBuffer, String match) { int pos = accumulatedBuffer.indexOf(match); if (pos > -1 && accumulatedBuffer.length() > pos + match.length() && accumulatedBuffer.charAt(pos + match.length()) > 32) { // Escape the ":" symbol accumulatedBuffer.replace(pos + match.length() - 1, pos + match.length(), "~:"); }/*from ww w . java 2 s . c o m*/ }
From source file:org.apache.ftpserver.usermanager.LdapUserManager.java
/** * Get the distinguished name (DN) for this user name. *//*from www . j ava 2 s .c o m*/ private String getDN(String userName) throws NamingException { StringBuffer valBuf = new StringBuffer(userName); for (int i = 0; i < valBuf.length(); i++) { char ch = valBuf.charAt(i); if (ch == '\\' || ch == ',' || ch == '+' || ch == '\"' || ch == '<' || ch == '>' || ch == ';') { valBuf.insert(i, '\\'); i++; } } return CN + '=' + valBuf.toString() + ',' + m_userBaseDn; }
From source file:org.apache.ojb.broker.accesslayer.conversions.StringList2VarcharFieldConversion.java
public Object sqlToJava(Object source) throws ConversionException { if (source == null) { return null; }/* ww w. j a v a2s . co m*/ if (source.toString().equals(NULLVALUE)) { return null; } if (source.toString().equals(EMPTYCOLLEC)) { return new ArrayList(); } List v = new ArrayList(); StringBuffer input = new StringBuffer(); StringBuffer newString = new StringBuffer(); int pos = 0; int length; input.append(source.toString()); length = input.length(); while (pos < length) { if (input.charAt(pos) != '#') { newString.append(input.charAt(pos)); } else { if (input.charAt(pos + 1) != '#') { v.add(newString.toString()); newString = new StringBuffer(); } else { newString.append('#'); ++pos; } } ++pos; } v.add(newString.toString()); return v; }
From source file:org.zkoss.poi.ss.format.CellNumberFormatter.java
private static StringBuffer pureInteger(int index, StringBuffer descBuf) { final int len = descBuf.length(); final StringBuffer sb = new StringBuffer(len); for (int j = index; j < len; ++j) { char ch = descBuf.charAt(j); if ('0' <= ch && ch <= '9') { sb.append(ch);//from ww w . j av a2s.co m } else { break; } } return sb; }
From source file:com.tasktop.internal.hp.qc.core.model.comments.mylyn3_8.HtmlStreamTokenizer_m3_8.java
/** * Replaces (in-place) HTML escapes in a StringBuffer with their corresponding characters. * /*from w w w.jav a2s.c o m*/ * @deprecated use {@link StringEscapeUtils#unescapeHtml(String)} instead */ @Deprecated public static StringBuffer unescape(StringBuffer sb) { int i = 0; // index into the unprocessed section of the buffer int j = 0; // index into the processed section of the buffer while (i < sb.length()) { char ch = sb.charAt(i); if (ch == '&') { int start = i; String escape = null; for (i = i + 1; i < sb.length(); i++) { ch = sb.charAt(i); if (!Character.isLetterOrDigit(ch) && !(ch == '#' && i == (start + 1))) { escape = sb.substring(start + 1, i); break; } } if (i == sb.length() && i != (start + 1)) { escape = sb.substring(start + 1); } if (escape != null) { Character character = parseReference(escape); if (character != null && !((0x0A == character || 0x0D == character || 0x09 == ch) || (character >= 0x20 && character <= 0xD7FF) || (character >= 0xE000 && character <= 0xFFFD) || (character >= 0x10000 && character <= 0x10FFFF))) { // Character is an invalid xml character // http://www.w3.org/TR/REC-xml/#charsets character = null; } if (character != null) { ch = character.charValue(); } else { // not an HTML escape; rewind i = start; ch = '&'; } } } sb.setCharAt(j, ch); i++; j++; } sb.setLength(j); return sb; }