List of usage examples for java.lang StringBuffer indexOf
@Override public synchronized int indexOf(String str, int fromIndex)
From source file:net.sf.xmm.moviemanager.http.HttpUtil.java
public static StringBuffer getHtmlNiceFormat(StringBuffer buffer) { int index = 0; // Format html Pattern p = Pattern.compile("</.+?>"); Matcher m = p.matcher(buffer); while (m.find(index)) { index = m.start();//from ww w . j a v a 2 s . c o m int index2 = buffer.indexOf(">", index) + 1; buffer.insert(index2, SysUtil.getLineSeparator()); index++; } return buffer; }
From source file:org.protorabbit.model.impl.DefaultEngine.java
public static List<ICommand> getDocumentCommands(Config cfg, StringBuffer doc) { List<ICommand> commands = new ArrayList<ICommand>(); if (doc == null) return null; int index = 0; int len = doc.length(); while (index < len) { index = doc.indexOf(COMMAND_START, index); int end = doc.indexOf(COMMAND_END, index); if (index == -1 || end == -1) { break; }// www . j a v a2 s .co m // find the full expression String exp = doc.substring(index + 2, end); //find the command int paramStart = exp.indexOf("("); int paramEnd = exp.lastIndexOf(")"); if (paramStart != -1 && paramEnd != -1 && paramEnd > paramStart) { // get commandType String commandTypeString = exp.substring(0, paramStart).trim(); ICommand cmd = cfg.getCommand(commandTypeString); if (cmd != null) { // get the params String paramsString = exp.substring(paramStart + 1, paramEnd); // need to parse out JSON IParameter[] params = getParams(paramsString); if (params != null) { cmd.setParams(params); } cmd.setStartIndex(index); cmd.setEndIndex(end + 2); if ("include".equals(commandTypeString) && params.length > 0) { if ("scripts".equals(params[0]) || "styles".equals(params[0])) { cmd.setType(ICommand.INCLUDE_RESOURCES); } else { cmd.setType(ICommand.INCLUDE); } } else if ("insert".equals(commandTypeString)) { cmd.setType(ICommand.INSERT); } else { cmd.setType(ICommand.CUSTOM); } commands.add(cmd); } } // start the process over index = end + 2; } return commands; }
From source file:util.io.IOUtilities.java
/** * Replaces in <code>buffer</code> the <code>pattern</code> by <code>str</code>. * * @param buffer The buffer to replace in. * @param pattern The pattern to replace. * @param str The str that should replace the pattern. *//*from w w w .j av a 2 s .c o m*/ public static void replace(StringBuffer buffer, String pattern, String str) { int offset = 0; int patternIdx; do { patternIdx = buffer.indexOf(pattern, offset); if (patternIdx != -1) { buffer.replace(patternIdx, patternIdx + pattern.length(), str); } offset = patternIdx + str.length(); } while (patternIdx != -1); }
From source file:org.qedeq.base.utility.StringUtility.java
/** * Replaces all occurrences of <code>search</code> in <code>text</code> * by <code>replace</code>./* www . j ava 2 s. c o m*/ * * @param text Text to work on. Must not be <code>null</code>. * @param search replace this text by <code>replace</code>. Can be <code>null</code>. * @param replace replacement for <code>search</code>. Can be <code>null</code>. * @throws NullPointerException <code>text</code> is <code>null</code>. */ public static void replace(final StringBuffer text, final String search, final String replace) { if (search == null || search.length() <= 0) { return; } final StringBuffer result = new StringBuffer(text.length() + 16); int pos1 = 0; int pos2; final int len = search.length(); while (0 <= (pos2 = text.indexOf(search, pos1))) { result.append(text.substring(pos1, pos2)); result.append(replace != null ? replace : ""); pos1 = pos2 + len; } if (pos1 < text.length()) { result.append(text.substring(pos1)); } text.setLength(0); text.append(result); }
From source file:org.millr.slick.utils.TrimString.java
public TrimString(String input, int length, boolean soft) { LOGGER.info(">>>> Trimming String"); // Replace basic HTML. Will break if HTML is malformed. String contentString = input.replaceAll("<[^>]*>", ""); if (contentString == null || contentString.trim().isEmpty()) { LOGGER.info("String is empty"); trimmedString = contentString;// w ww. j a va 2s . co m } try { StringBuffer sb = new StringBuffer(contentString); int desiredLength = length; int endIndex = sb.indexOf(" ", desiredLength); //If soft, remove three characters to make room for elipsis. if (soft) { desiredLength = length - 3; endIndex = sb.indexOf(" ", desiredLength); contentString = escapeHtml(sb.insert(endIndex, "...").substring(0, endIndex + 3)); } else { contentString = escapeHtml(sb.substring(0, endIndex)); } } catch (Exception e) { LOGGER.error("Exception: " + e.getMessage(), e); } trimmedString = contentString; }
From source file:ar.com.zauber.commons.social.openid.security.OpenIDAuthenticationProcessingFilter.java
/** * @see AbstractAuthenticationProcessingFilter * #attemptAuthentication(HttpServletRequest, HttpServletResponse) *///from www.ja v a 2 s . c o m @Override public final Authentication attemptAuthentication(final HttpServletRequest request, final HttpServletResponse response) throws AuthenticationException, IOException, ServletException { OpenIdUser user = null; try { user = relyingParty.discover(request); if (user == null) { if (RelyingParty.isAuthResponse(request)) { // authentication timeout return null; } else { // set error msg if the openid_identifier is not resolved. if (request.getParameter(relyingParty.getIdentifierParameter()) != null) { request.setAttribute(OpenIdServletFilter.ERROR_MSG_ATTR, "as"); } // error response.sendRedirect(errorUrl); return null; } } if (user.isAuthenticated()) { // user already authenticated return this.getAuthenticationManager() .authenticate(new OpenIDAuthenticationToken(new OpenIDIdentity(user.getIdentity()))); } if (user.isAssociated() && RelyingParty.isAuthResponse(request)) { // verify authentication if (relyingParty.verifyAuth(user, request, response)) { // authenticated return this.getAuthenticationManager() .authenticate(new OpenIDAuthenticationToken(new OpenIDIdentity(user.getIdentity()))); } else { // failed verification throw new BadCredentialsException("open id authentication failed"); } } // associate and authenticate user StringBuffer url = request.getRequestURL(); String trustRoot = url.substring(0, url.indexOf("/", 9)); String realm = url.substring(0, url.lastIndexOf("/")); String returnTo = url.toString(); if (relyingParty.associateAndAuthenticate(user, request, response, trustRoot, realm, returnTo)) { // successful association return null; } } catch (Exception e) { throw new AuthenticationServiceException( "Exception while authenticating with openID: " + e.getMessage(), e); } return null; }
From source file:net.riezebos.thoth.configuration.persistence.dbs.DDLExecuter.java
private StringBuffer stripMultiLineComment(StringBuffer commandBuffer) { int beginComment = commandBuffer.indexOf("/*", 0); int endComment = 0;// w ww . j a v a 2 s . c o m while (beginComment != -1) { endComment = commandBuffer.indexOf("*/", beginComment); commandBuffer = commandBuffer.delete(beginComment, endComment + 2); beginComment = commandBuffer.indexOf("/*"); } return commandBuffer; }
From source file:org.soitoolkit.commons.mule.util.MiscUtil.java
static public String parseStringValue(String strVal, Properties props) { StringBuffer buf = new StringBuffer(strVal); int startIndex = strVal.indexOf(placeholderPrefix); while (startIndex != -1) { int endIndex = findPlaceholderEndIndex(buf, startIndex); if (endIndex != -1) { String placeholder = buf.substring(startIndex + placeholderPrefix.length(), endIndex); String propVal = props.getProperty(placeholder); if (propVal != null) { // Recursive invocation, parsing placeholders contained in the previously resolved placeholder value. // E.g. a variable value like: VARIABLE1=Var${VARIABLE2}Value propVal = parseStringValue(propVal, props); buf.replace(startIndex, endIndex + placeholderSuffix.length(), propVal); if (logger.isTraceEnabled()) { logger.trace("Resolved placeholder '" + placeholder + "'"); }/*ww w .j a v a 2 s.c o m*/ startIndex = buf.indexOf(placeholderPrefix, startIndex + propVal.length()); } else { throw new RuntimeException("Could not resolve placeholder '" + placeholder + "'"); } } else { startIndex = -1; } } return buf.toString(); }
From source file:com.dyuproject.demos.openidservlet.HomeServlet.java
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (request.getSession().getAttribute(WebConstants.SessionConstants.RC_USER) != null) { response.sendRedirect("/login/logged.html"); return;/*from www .j av a 2s. c o m*/ } String loginWith = request.getParameter("loginWith"); if (loginWith != null) { // If the ui supplies a LoginWithGoogle or LoginWithYahoo // link/button, // this will speed up the openid process by skipping discovery. // The override is done by adding the OpenIdUser to the request // attribute. if (loginWith.equals("google")) { OpenIdUser user = OpenIdUser.populate("https://www.google.com/accounts/o8/id", YadisDiscovery.IDENTIFIER_SELECT, "https://www.google.com/accounts/o8/ud"); request.setAttribute(OpenIdUser.ATTR_NAME, user); } else if (loginWith.equals("yahoo")) { OpenIdUser user = OpenIdUser.populate("http://https://me.yahoo.com/user", YadisDiscovery.IDENTIFIER_SELECT, "https://open.login.yahooapis.com/openid/op/auth"); request.setAttribute(OpenIdUser.ATTR_NAME, user); } } String errorMsg = OpenIdServletFilter.DEFAULT_ERROR_MSG; try { OpenIdUser user = _relyingParty.discover(request); if (user == null) { if (RelyingParty.isAuthResponse(request)) { // authentication timeout response.sendRedirect(request.getRequestURI()); } else { // set error msg if the openid_identifier is not resolved. if (request.getParameter(_relyingParty.getIdentifierParameter()) != null) { request.setAttribute(OpenIdServletFilter.ERROR_MSG_ATTR, errorMsg); } // new user request.getRequestDispatcher("/login/login.jsp").forward(request, response); } return; } if (user.isAuthenticated()) { // user already authenticated request.getRequestDispatcher("/preAuth").forward(request, response); return; } if (user.isAssociated() && RelyingParty.isAuthResponse(request)) { // verify authentication if (_relyingParty.verifyAuth(user, request, response)) { // authenticated // redirect to home to remove the query params instead of // doing: // request.getRequestDispatcher("/home.jsp").forward(request, // response); response.sendRedirect(request.getContextPath() + "/home/"); } else { // failed verification request.getRequestDispatcher("/login/login.jsp").forward(request, response); } return; } // associate and authenticate user StringBuffer url = request.getRequestURL(); String trustRoot = url.substring(0, url.indexOf("/", 9)); String realm = url.substring(0, url.lastIndexOf("/")); String returnTo = url.toString(); if (_relyingParty.associateAndAuthenticate(user, request, response, trustRoot, realm, returnTo)) { // successful association return; } } catch (UnknownHostException uhe) { System.err.println("not found"); errorMsg = OpenIdServletFilter.ID_NOT_FOUND_MSG; } catch (FileNotFoundException fnfe) { System.err.println("could not be resolved"); errorMsg = OpenIdServletFilter.DEFAULT_ERROR_MSG; } catch (Exception e) { errorMsg = OpenIdServletFilter.DEFAULT_ERROR_MSG; } request.setAttribute(OpenIdServletFilter.ERROR_MSG_ATTR, errorMsg); request.getRequestDispatcher("/login/login.jsp").forward(request, response); }
From source file:org.exoplatform.wiki.rendering.render.confluence.ConfluenceSyntaxEscapeHandler.java
private void replaceAll(StringBuffer accumulatedBuffer, String match, String replacement) { int pos = -replacement.length(); while ((pos + replacement.length() < accumulatedBuffer.length()) && ((pos = accumulatedBuffer.indexOf(match, pos + replacement.length())) != -1)) { accumulatedBuffer.replace(pos, pos + match.length(), replacement); }//ww w .j a v a 2s .c o m }