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 synchronized int indexOf(String str, int fromIndex) 

Source Link

Usage

From source file:com.sap.research.connectivity.gw.parsers.JavaSourceFileEditor.java

private void initVarsAndMethods() {
    List<TypeDeclaration> types = compilationUnit.getTypes();
    for (TypeDeclaration type : types) {
        List<BodyDeclaration> members = type.getMembers();
        //We are dealing with class declaration
        StringBuffer s = new StringBuffer(type.toString());
        classDeclaration = type.toString().substring(0,
                s.indexOf("{", type.toString().indexOf(type.getName())));
        //log.severe(type.toString().substring(0, type.toString().indexOf(type.getName()) + type.getName().length()));
        for (BodyDeclaration member : members) {
            //We are dealing with methods
            if (member instanceof MethodDeclaration) {
                MethodDeclaration method = (MethodDeclaration) member;
                JavaSourceMethod methodTranslated = new JavaSourceMethod(method);
                globalMethodList.add(methodTranslated);
            } else
            //We are dealing with fields
            if (member instanceof FieldDeclaration) {
                FieldDeclaration field = (FieldDeclaration) member;
                JavaSourceField fieldTranslated = new JavaSourceField(field);
                globalFieldList.add(fieldTranslated);
            }/*  ww w .  j  a  v  a 2  s. c  o  m*/
        }
    }
}

From source file:org.j2free.util.ServletUtils.java

/**
 * Redirects the user to the current url over SSL
 *
 * @param request a HttpServletRequest/*from  w  w w.  j  a  v a 2  s  . c  o 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 provided url over SSL
 *
 * @param request a HttpServletRequest/* ww w .j a  va2  s. co  m*/
 * @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:org.j2free.util.ServletUtils.java

/**
 * Redirects the user to the current url over HTTP
 *
 * @param request a HttpServletRequest/*from   w w w  . j a  v a 2s  . c o  m*/
 * @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 HTTPS
 *
 * @param request a HttpServletRequest//from   w w w . ja  v a 2 s.c o m
 * @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());
}

From source file:URLUtilities.java

/**
 * Report the site name, e.g. http://www.openeditpro.com
 * /*from  ww  w .  ja  va2 s  .c om*/
 * @return The site's root URL
 */
public String siteRoot() {
    if (fieldRequest == null) {
        return null;
    }

    StringBuffer ctx = fieldRequest.getRequestURL();
    String siteRoot = ctx.substring(0, ctx.indexOf("/", 8)); //8 comes from https://
    return siteRoot;
}

From source file:URLUtilities.java

/**
 * Build an HTTP URL relative to the application context using the given path. This is a path
 * such as http://servername/webapp/path/myfile.html
 *
 * @return /webapp/path/myfile.html//from w ww  . j  a  va  2 s.  c  o m
 */
public String requestPath() {
    if (fieldRequest == null) {
        return null;
    }

    StringBuffer ctx = fieldRequest.getRequestURL();
    String requestPath = ctx.substring(ctx.indexOf("/", 7)); //just the path

    return requestPath;
}

From source file:URLUtilities.java

/**
 * This is the server name only // w w w  . j a v a 2  s.c o m
 *
 * returns http://www.acme.com/
 */
public String buildRoot() {
    if (fieldRequest == null) {
        return null;
    }

    StringBuffer ctx = fieldRequest.getRequestURL();
    String servername = ctx.substring(0, ctx.indexOf("/", 7));

    return servername + "/";
}

From source file:URLUtilities.java

/**
 * This includes the webapp name but not the page name
 *
 * @return http://www.acme.com/webapp//*from w  w  w .  j a v a 2s.  com*/
 */
public String buildBasePath(String path) {
    if (fieldRequest == null) {
        return null;
    }
    StringBuffer ctx = fieldRequest.getRequestURL();
    String servername = ctx.substring(0, ctx.indexOf("/", 7)); //just the server name

    if (path.lastIndexOf('/') > -1) {
        path = path.substring(0, path.lastIndexOf('/'));

        return servername + path + "/";
    } else {
        return servername + "/";
    }
}

From source file:CssCompressor.java

public void compress(Writer out, int linebreakpos) throws IOException {

    Pattern p;/*  ww w  .  j  a va  2  s . co m*/
    Matcher m;
    String css;
    StringBuffer sb;
    int startIndex, endIndex;

    // Remove all comment blocks...
    startIndex = 0;
    boolean iemac = false;
    boolean preserve = false;
    sb = new StringBuffer(srcsb.toString());
    while ((startIndex = sb.indexOf("/*", startIndex)) >= 0) {
        preserve = sb.length() > startIndex + 2 && sb.charAt(startIndex + 2) == '!';
        endIndex = sb.indexOf("*/", startIndex + 2);
        if (endIndex < 0) {
            if (!preserve) {
                sb.delete(startIndex, sb.length());
            }
        } else if (endIndex >= startIndex + 2) {
            if (sb.charAt(endIndex - 1) == '\\') {
                // Looks like a comment to hide rules from IE Mac.
                // Leave this comment, and the following one, alone...
                startIndex = endIndex + 2;
                iemac = true;
            } else if (iemac) {
                startIndex = endIndex + 2;
                iemac = false;
            } else if (!preserve) {
                sb.delete(startIndex, endIndex + 2);
            } else {
                startIndex = endIndex + 2;
            }
        }
    }

    css = sb.toString();

    // Normalize all whitespace strings to single spaces. Easier to work
    // with that way.
    css = css.replaceAll("\\s+", " ");

    // Make a pseudo class for the Box Model Hack
    css = css.replaceAll("\"\\\\\"}\\\\\"\"", "___PSEUDOCLASSBMH___");

    // ---------where zk modify it
    sb = new StringBuffer();
    p = Pattern.compile("\\$\\{([^\\}]+)\\}");
    Matcher m1 = p.matcher(css);
    while (m1.find()) {
        String s1 = m1.group();
        s1 = s1.replaceAll("\\$\\{", "__EL__");
        s1 = s1.replaceAll(":", "__ELSP__");
        s1 = s1.replaceAll("\\}", "__ELEND__");

        m1.appendReplacement(sb, s1);
    }
    m1.appendTail(sb);
    css = sb.toString();

    // ---------where zk modify it----end

    // Remove the spaces before the things that should not have spaces
    // before them.
    // But, be careful not to turn "p :link {...}" into "p:link{...}"
    // Swap out any pseudo-class colons with the token, and then swap back.
    sb = new StringBuffer();
    p = Pattern.compile("(^|\\})(([^\\{:])+:)+([^\\{]*\\{)");
    m = p.matcher(css);
    while (m.find()) {
        String s = m.group();
        s = s.replaceAll(":", "___PSEUDOCLASSCOLON___");
        m.appendReplacement(sb, s);
    }
    m.appendTail(sb);
    css = sb.toString();
    css = css.replaceAll("\\s+([!{};:>+\\(\\)\\],])", "$1");
    css = css.replaceAll("___PSEUDOCLASSCOLON___", ":");

    // Remove the spaces after the things that should not have spaces after
    // them.
    css = css.replaceAll("([!{}:;>+\\(\\[,])\\s+", "$1");

    // Add the semicolon where it's missing.
    css = css.replaceAll("([^;\\}])}", "$1;}");

    // Replace 0(px,em,%) with 0.
    css = css.replaceAll("([\\s:])(0)(px|em|%|in|cm|mm|pc|pt|ex)", "$1$2");

    // Replace 0 0 0 0; with 0.
    css = css.replaceAll(":0 0 0 0;", ":0;");
    css = css.replaceAll(":0 0 0;", ":0;");
    css = css.replaceAll(":0 0;", ":0;");
    // Replace background-position:0; with background-position:0 0;
    css = css.replaceAll("background-position:0;", "background-position:0 0;");

    // Replace 0.6 to .6, but only when preceded by : or a white-space
    css = css.replaceAll("(:|\\s)0+\\.(\\d+)", "$1.$2");

    // Shorten colors from rgb(51,102,153) to #336699
    // This makes it more likely that it'll get further compressed in the
    // next step.
    p = Pattern.compile("rgb\\s*\\(\\s*([0-9,\\s]+)\\s*\\)");
    m = p.matcher(css);
    sb = new StringBuffer();
    while (m.find()) {
        String[] rgbcolors = m.group(1).split(",");
        StringBuffer hexcolor = new StringBuffer("#");
        for (int i = 0; i < rgbcolors.length; i++) {
            int val = Integer.parseInt(rgbcolors[i]);
            if (val < 16) {
                hexcolor.append("0");
            }
            hexcolor.append(Integer.toHexString(val));
        }
        m.appendReplacement(sb, hexcolor.toString());
    }
    m.appendTail(sb);
    css = sb.toString();

    // Shorten colors from #AABBCC to #ABC. Note that we want to make sure
    // the color is not preceded by either ", " or =. Indeed, the property
    // filter: chroma(color="#FFFFFF");
    // would become
    // filter: chroma(color="#FFF");
    // which makes the filter break in IE.
    p = Pattern.compile(
            "([^\"'=\\s])(\\s*)#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])");
    m = p.matcher(css);
    sb = new StringBuffer();
    while (m.find()) {
        // Test for AABBCC pattern
        if (m.group(3).equalsIgnoreCase(m.group(4)) && m.group(5).equalsIgnoreCase(m.group(6))
                && m.group(7).equalsIgnoreCase(m.group(8))) {
            m.appendReplacement(sb, m.group(1) + m.group(2) + "#" + m.group(3) + m.group(5) + m.group(7));
        } else {
            m.appendReplacement(sb, m.group());
        }
    }
    m.appendTail(sb);
    css = sb.toString();

    // Remove empty rules.
    css = css.replaceAll("[^\\}]+\\{;\\}", "");

    if (linebreakpos >= 0) {
        // Some source control tools don't like it when files containing
        // lines longer
        // than, say 8000 characters, are checked in. The linebreak option
        // is used in
        // that case to split long lines after a specific column.
        int i = 0;
        int linestartpos = 0;
        sb = new StringBuffer(css);
        while (i < sb.length()) {
            char c = sb.charAt(i++);
            if (c == '}' && i - linestartpos > linebreakpos) {
                sb.insert(i, '\n');
                linestartpos = i;
            }
        }

        css = sb.toString();
    }

    // Replace the pseudo class for the Box Model Hack
    css = css.replaceAll("___PSEUDOCLASSBMH___", "\"\\\\\"}\\\\\"\"");

    // Replace multiple semi-colons in a row by a single one
    // See SF bug #1980989
    css = css.replaceAll(";;+", ";");

    // ---------where zk modify it
    css = css.replaceAll("__EL__", "\\$\\{");
    css = css.replaceAll("__ELSP__", ":");
    css = css.replaceAll("__ELEND__", "\\}");

    // ---------where zk modify it----end

    // Trim the final string (for any leading or trailing white spaces)
    css = css.trim();

    // Write the output...
    out.write(css);
}