Example usage for java.lang StringBuffer indexOf

List of usage examples for java.lang StringBuffer indexOf

Introduction

In this page you can find the example usage for java.lang StringBuffer indexOf.

Prototype

@Override
public int indexOf(String str) 

Source Link

Usage

From source file:com.sun.identity.provider.springsecurity.OpenSSOAuthenticationEntryPoint.java

private void redirectToLoginUrl(HttpServletRequest request, HttpServletResponse response) throws IOException {
    StringBuffer redirect = new StringBuffer();
    redirect.append(getLoginUrl());/*from   w  w  w .  j  a  v  a2  s  . co m*/
    boolean hasArguments = redirect.indexOf("?") > 0;

    if (hasArguments)
        redirect.append("&goto=");
    else
        redirect.append("?goto=");
    redirect.append(buildGotoUrl(request));

    if (getLoginParameters() != null && getLoginParameters().length() > 0) {
        redirect.append("&").append(loginParameters);
    }

    debug.message("Redirecting to " + redirect);
    response.sendRedirect(redirect.toString());
}

From source file:org.exoplatform.forum.common.CommonUtils.java

/**
 * Truncates large Strings showing the string around the specific middle position with the specific length.
 * /*from  ww  w .ja  v a2s.  com*/
 * @param str
 *            the string to truncate
 * @param middlePosition
 *            the middle position we will show string around 
 * @param maxLength
 *            the max length of string to show
 * @return the truncated string
 */
public static final String centerTrunc(String str, int middlePosition, int maxLength) {
    StringBuffer buf = null;
    //
    if (str.length() <= maxLength) {
        return str;
    }

    int halfLength = maxLength / 2;
    //start position
    int start = 0;

    if (middlePosition > halfLength) {
        start = (middlePosition - halfLength);
    }

    //end position
    int end = Math.min(str.length(), start + maxLength);

    buf = new StringBuffer();
    buf.append(str.substring(start, end));

    //complete first & last words
    String ret = buf.substring(buf.indexOf(" "));
    //
    if (start > 0)
        ret = "..." + ret;

    ret = ret.substring(0, ret.lastIndexOf(" ")) + " ...";

    return ret;
}

From source file:org.xwiki.rendering.internal.renderer.xwiki20.XWikiSyntaxEscapeHandler.java

private void escapeURI(StringBuffer accumulatedBuffer, String match) {
    int pos = accumulatedBuffer.indexOf(match);
    if (pos > -1) {
        // Escape the ":" symbol
        accumulatedBuffer.insert(pos + match.length() - 1, '~');
    }//from w ww  .ja va 2s .  c o  m
}

From source file:org.openmrs.module.idcards.web.controller.TemplateFormController.java

/**
 * Handles the user's submission of the form.
 */// w w w  .j ava  2  s .  c  o m
@RequestMapping(method = RequestMethod.POST, params = "action=saveAndPrintEmpty")
public void onSaveAndPrintEmpty(@ModelAttribute("template") IdcardsTemplate template,
        HttpServletRequest request, HttpServletResponse response) throws IOException {

    if (Context.isAuthenticated()) {
        IdcardsService service = (IdcardsService) Context.getService(IdcardsService.class);
        service.saveIdcardsTemplate(template);

        try {
            StringBuffer requestURL = request.getRequestURL();
            String baseURL = requestURL.substring(0, requestURL.indexOf("/module"));

            PrintEmptyIdcardsServlet.generateOutput(template, baseURL, response, Collections.nCopies(10, 0),
                    null);
        } catch (Exception e) {
            log.error("Unable to print cards", e);
            e.printStackTrace(response.getWriter());
        }
    }

}

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 .  jav  a2  s.c  o  m
}

From source file:org.exoplatform.wiki.rendering.internal.parser.confluence.ConfluenceLinkReferenceParser.java

private String divideAfter(StringBuffer buffer, char divider) {
    if (buffer.length() == 0) {
        return null;
    }// www  .  j  av a  2 s  . c  om
    return divideAfter(buffer, buffer.indexOf(Character.toString(divider)));
}

From source file:org.openmrs.module.idcards.web.controller.TemplateFormController.java

/**
 * Handles the user's submission of the form.
 *///from ww  w  .ja v a2  s.  co  m
@RequestMapping(method = RequestMethod.POST, params = "action=saveAndReprint")
public void onSaveAndReprint(@ModelAttribute("template") IdcardsTemplate template, HttpServletRequest request,
        HttpServletResponse response) throws IOException {

    if (Context.isAuthenticated()) {
        IdcardsService service = (IdcardsService) Context.getService(IdcardsService.class);
        service.saveIdcardsTemplate(template);

        Cohort cohort = new Cohort();
        cohort.addMember(1);
        cohort.addMember(2);

        try {
            StringBuffer requestURL = request.getRequestURL();
            String baseURL = requestURL.substring(0, requestURL.indexOf("/module"));

            PrintIdcardsServlet.generateOutput(template, baseURL, cohort, response);
        } catch (Exception e) {
            log.error("Unable to print cards", e);
            e.printStackTrace(response.getWriter());
        }
    }

}

From source file:de.betterform.agent.web.servlet.XSLTServlet.java

private StringBuffer generateError(String error) throws IOException, XFormsConfigException {

    String path = WebFactory.getRealPath("forms/incubator/editor", getServletContext());
    File f = new File(path, "callerror.html");
    FileInputStream fs = new FileInputStream(f);
    BufferedInputStream bis = new BufferedInputStream(fs);
    int numBytes = bis.available();
    byte b[] = new byte[numBytes];
    // read the template into a StringBuffer (via a byte array)
    bis.read(b);/*from w  w w  . j  av  a2s  .  c om*/
    StringBuffer buf = new StringBuffer();
    buf.append(b);
    int start = buf.indexOf(errorTemplate);
    int end = start + errorTemplate.length();
    // replace placeholder with errormessage
    // (will automatically adjust to take longer or shorter data into account)
    buf.replace(start, end, error);
    return buf;
}

From source file:de.bermuda.arquillian.example.ContentTypeProxyTest.java

@Test
public void checkURLTest() {
    String localPath = "/foo/bar";
    PostMethod postMethod = postRequest("TestContent", localPath);
    StringBuffer body = getHTTPBody(postMethod);

    Assert.assertTrue("HTTP Body is empty", body.length() > 0);
    String returnedPath = body.substring(body.indexOf("<path>") + 6, body.indexOf("</path>"));
    Assert.assertEquals("Path was not correctly mirrored", localPath, returnedPath);
}

From source file:de.bermuda.arquillian.example.ContentTypeProxyTest.java

@Test
public void checkBodyTest() {
    String content = "TestContent";
    PostMethod postMethod = postRequest(content);
    StringBuffer body = getHTTPBody(postMethod);

    Assert.assertTrue("HTTP Body is empty", body.length() > 0);
    String returnedContent = body.substring(body.indexOf("<content>") + 9, body.indexOf("</content>"));
    Assert.assertEquals("Body was not copied", content, returnedContent);
}