List of usage examples for java.lang StringBuffer charAt
@Override public synchronized char charAt(int index)
From source file:cn.remex.core.util.StringUtils.java
/** * ?//from w ww .j a va2s. c om * Trim leading whitespace from the given String. * @param str the String to check * @return the trimmed String * @see java.lang.Character#isWhitespace */ public static String trimLeadingWhitespace(final String str) { if (!hasLength(str)) { return str; } StringBuffer buf = new StringBuffer(str); while (buf.length() > 0 && Character.isWhitespace(buf.charAt(0))) { buf.deleteCharAt(0); } return buf.toString(); }
From source file:cn.remex.core.util.StringUtils.java
/** * /*w w w. jav a 2s .co m*/ * Trim trailing whitespace from the given String. * @param str the String to check * @return the trimmed String ?? * @see java.lang.Character#isWhitespace */ public static String trimTrailingWhitespace(final String str) { if (!hasLength(str)) { return str; } StringBuffer buf = new StringBuffer(str); while (buf.length() > 0 && Character.isWhitespace(buf.charAt(buf.length() - 1))) { buf.deleteCharAt(buf.length() - 1); } return buf.toString(); }
From source file:cn.remex.core.util.StringUtils.java
/** * /*w w w.j a v a 2 s . c om*/ * Trim leading and trailing whitespace from the given String. * @param str the String to check * @return the trimmed String ?? * @see java.lang.Character#isWhitespace */ public static String trimWhitespace(final String str) { if (!hasLength(str)) { return str; } StringBuffer buf = new StringBuffer(str); while (buf.length() > 0 && Character.isWhitespace(buf.charAt(0))) { buf.deleteCharAt(0); } while (buf.length() > 0 && Character.isWhitespace(buf.charAt(buf.length() - 1))) { buf.deleteCharAt(buf.length() - 1); } return buf.toString(); }
From source file:org.eclipse.e4.emf.internal.xpath.LangAttributePointer.java
@Override public String asPath() { StringBuffer buffer = new StringBuffer(); if (parent != null) { buffer.append(parent.asPath());/* ww w . java 2 s.co m*/ if (buffer.length() == 0 || buffer.charAt(buffer.length() - 1) != '/') { buffer.append('/'); } } buffer.append("@xml:lang"); return buffer.toString(); }
From source file:cn.remex.core.util.StringUtils.java
/** * /*from ww w . jav a 2 s .c om*/ * Trim <i>all</i> whitespace from the given String: * leading, trailing, and inbetween characters. * @param str the String to check ?? * @return the trimmed String ?? * @see java.lang.Character#isWhitespace */ public static String trimAllWhitespace(final String str) { if (!hasLength(str)) { return str; } StringBuffer buf = new StringBuffer(str); int index = 0; while (buf.length() > index) { if (Character.isWhitespace(buf.charAt(index))) { buf.deleteCharAt(index); } else { index++; } } return buf.toString(); }
From source file:com.netfinworks.rest.convert.MultiPartFormDataParamConvert.java
private <T> Object getPropertyValue(T pojo, Class<?> clazz, String propertyName, String prefix) throws NoSuchMethodException { StringBuffer buf = new StringBuffer(propertyName); int char0 = buf.charAt(0); buf.setCharAt(0, (char) (char0 >= 97 ? char0 - 32 : char0)); buf.insert(0, prefix);//from w w w . j ava 2 s . c o m Method m = null; try { m = clazz.getMethod(buf.toString(), emptyClazzArray); return m.invoke(pojo, new Object[0]); } catch (SecurityException e) { logger.debug("property can't be access! "); return null; } catch (NoSuchMethodException e) { logger.debug("property '{}' doesn't exist! ", buf.toString()); throw e; } catch (IllegalArgumentException e) { logger.debug("method can't be invoke! wrong argument. " + e.toString()); return null; } catch (IllegalAccessException e) { logger.debug("method can't be invoke! access exception. " + e.toString()); return null; } catch (InvocationTargetException e) { logger.debug("method can't be invoke! invocation target. " + e.toString()); return null; } }
From source file:org.j2free.util.HtmlFilter.java
/** * * @param msg// w w w . j av a 2s . c o m * @param allowedTags * @return */ public String filter(String msg, String[] allowedTags) { if (msg == null) return ""; else if (msg.length() == 0 || msg.equals("") || !msg.contains("<")) return msg; okayTags.clear(); if (allowedTags != null && allowedTags.length > 0) okayTags.addAll(Arrays.asList(allowedTags)); StringBuffer line = new StringBuffer(msg); for (int i = 0; i < line.length(); i++) { if (line.charAt(i) == '<') { int begin = i, end = i; for (int j = i + 1; j < line.length(); j++) { if (line.charAt(j) == '>') { end = j + 1; break; } } if (!isOkayTag(new String(line.substring(begin, end)))) { line = line.delete(begin, end); } } } return new String(line); }
From source file:org.j2free.util.ServletUtils.java
/** * Redirects the user to the current url over HTTP * * @param request a HttpServletRequest/*w ww .jav a 2 s .c om*/ * @param response a HttpServletResponse * @param nonSslPort the port Non-SSL requests should be forwarded to * @throws ServletException * @throws IOException */ public static void redirectOverNonSSL(HttpServletRequest request, HttpServletResponse response, int nonSslPort) throws ServletException, IOException { StringBuffer url = request.getRequestURL(); // Make sure we're on http if (url.charAt(4) == 's') url.deleteCharAt(4); // If there is a non-ssl port, make sure we're on it, // otherwise assume we're already on the right port if (nonSslPort > 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, nonSslPort); // 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:org.j2free.util.ServletUtils.java
/** * Redirects the user to the current url over SSL * * @param request a HttpServletRequest/*from w ww.j a va 2 s . co m*/ * @param response a HttpServletResponse * @param sslPort the port SSL requests should be forwarded to * @throws ServletException * @throws IOException */ public static void redirectOverSSL(HttpServletRequest request, HttpServletResponse response, int sslPort) throws ServletException, IOException { StringBuffer url = request.getRequestURL(); // 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:org.j2free.util.ServletUtils.java
/** * Redirects the user to the current url over HTTPS * * @param request a HttpServletRequest/*www. j a v a 2 s . com*/ * @param response a HttpServletResponse * @param urlStr * @param nonSslPort the port Non-SSL requests should be forwarded to * @throws ServletException * @throws IOException */ public static void redirectOverNonSSL(HttpServletRequest request, HttpServletResponse response, String urlStr, int nonSslPort) throws ServletException, IOException { StringBuffer url = new StringBuffer(urlStr); // Make sure we're on http if (url.charAt(4) == 's') url.deleteCharAt(4); // If there is a non-ssl port, make sure we're on it, // otherwise assume we're already on the right port if (nonSslPort > 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, nonSslPort); // Insert the right port where it should be } LogFactory.getLog(ServletUtils.class).debug("redirectOverSSL sending 301: " + url.toString()); sendPermanentRedirect(response, url.toString()); }