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:gov.nih.nci.caintegrator.ui.graphing.util.ImageMapUtil.java

public static String getBoundingRectImageMapTag(String name, boolean useOverlibToolTip,
        ChartRenderingInfo info) {//from  www . j  a  v  a  2 s .c o  m
    EntityCollection collection = info.getEntityCollection();
    Collection entities = collection.getEntities();

    Collection<ChartEntity> myBoundingEntities = getBoundingEntities(entities);

    System.out.println("Num entities=" + myBoundingEntities.size());
    StringBuffer sb = new StringBuffer();
    ChartEntity chartEntity;
    String areaTag;

    ToolTipTagFragmentGenerator ttg = null;

    if (useOverlibToolTip) {
        ttg = new CAIOverlibToolTipTagFragmentGenerator();
    } else {
        ttg = new CAIStandardToolTipTagFragmentGenerator();
    }

    StandardURLTagFragmentGenerator urlg = new StandardURLTagFragmentGenerator();
    sb.append("\n\n<MAP name=\"" + name + "\">");
    sb.append(StringUtils.getLineSeparator());
    for (Iterator i = myBoundingEntities.iterator(); i.hasNext();) {
        chartEntity = (ChartEntity) i.next();
        areaTag = chartEntity.getImageMapAreaTag(ttg, urlg).trim();
        if (areaTag.length() > 0) {
            if (sb.indexOf(chartEntity.getImageMapAreaTag(ttg, urlg)) == -1) {
                sb.append(chartEntity.getImageMapAreaTag(ttg, urlg));
                sb.append(StringUtils.getLineSeparator());
            }
        }
    }
    sb.append("</MAP>\n\n");
    return sb.toString();
}

From source file:org.ppwcode.vernacular.l10n_III.I18nExceptionHelpers.java

/**
 * Helper method for processTemplate to scan the full pattern, once the beginning of a pattern was found.
 *///from w  w  w . j a  v  a  2s .c o m
private static String processTemplatePattern(Object context, Locale locale, List<Object> objects,
        CharacterIterator iterator) throws I18nException {
    // previous token was "{", scan up to balanced "}"
    // scan full pattern now
    StringBuffer patternAcc = new StringBuffer(128);
    char token = ' '; // initialise with dummy value
    int balance = 1;
    while ((balance > 0) && (token != CharacterIterator.DONE)) {
        token = iterator.next();
        patternAcc.append(token);
        if (token == '{') {
            balance++;
        } else if (token == '}') {
            balance--;
        }
    }
    // done or bad template ?!?
    if (token == CharacterIterator.DONE) {
        throw new I18nTemplateException("Bad template pattern", patternAcc.toString());
    }
    // remove last "}"
    patternAcc.setLength(patternAcc.length() - 1);
    // prepare pattern, treat the "," for formatting parts
    int comma = patternAcc.indexOf(",");
    String pattern = null;
    String patternPostfix = "";
    if (comma == -1) {
        pattern = patternAcc.toString();
    } else if (comma == 0) {
        throw new I18nTemplateException("Bad template pattern", patternAcc.toString());
    } else {
        pattern = patternAcc.substring(0, comma);
        patternPostfix = patternAcc.substring(comma, patternAcc.length());
    }
    // process pattern
    String processedPattern = processPattern(pattern, context, locale, objects);
    return processedPattern + patternPostfix;
}

From source file:org.tobarsegais.webapp.RedirectFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    if (StringUtils.isEmpty(domain) || !(request instanceof HttpServletRequest)) {
        chain.doFilter(request, response);
    } else {//from w w  w .  ja v  a2  s  . c  o m
        final HttpServletRequest req = (HttpServletRequest) request;
        final HttpServletResponse resp = (HttpServletResponse) response;
        final String serverName = req.getServerName();
        if (domain.equalsIgnoreCase(serverName)) {
            chain.doFilter(request, response);
        } else {
            StringBuffer requestURL = req.getRequestURL();
            int index = requestURL.indexOf(serverName);
            requestURL.replace(index, index + serverName.length(), domain);
            final String queryString = req.getQueryString();
            if (queryString != null) {
                requestURL.append('?').append(queryString);
            }
            resp.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
            resp.setHeader("Location", requestURL.toString());
        }
    }
}

From source file:hydrograph.ui.expression.editor.styletext.ExpressionEditorStyledText.java

private String getExpressionText(String expressionText) {
    StringBuffer buffer = new StringBuffer(expressionText);
    int startIndex = buffer.indexOf(RETURN_STATEMENT);
    if (startIndex > -1) {
        buffer.delete(0, startIndex);//from w w  w.j  av a2 s  .c o  m
        buffer.delete(0, buffer.indexOf("\n"));
    }
    return StringUtils.trim(buffer.toString());
}

From source file:org.deegree.console.webservices.ServiceConfig.java

public String getCapabilitiesUrl() {
    OWS ows = getWorkspace().getResource(OWSProvider.class, id);
    String type = ((OWSProvider) ows.getMetadata().getProvider()).getImplementationMetadata()
            .getImplementedServiceName()[0];

    HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext()
            .getRequest();//www .j ava 2 s. c o m
    StringBuffer sb = req.getRequestURL();

    // HACK HACK HACK
    int index = sb.indexOf("/console");
    return sb.substring(0, index) + "/services/" + id + "?service=" + type + "&request=GetCapabilities";
}

From source file:org.springframework.security.web.debug.Logger.java

public void info(String message, boolean dumpStack) {
    StringBuilder output = new StringBuilder(256);
    output.append("\n\n************************************************************\n\n");
    output.append(message).append("\n");

    if (dumpStack) {
        StringWriter os = new StringWriter();
        new Exception().printStackTrace(new PrintWriter(os));
        StringBuffer buffer = os.getBuffer();
        // Remove the exception in case it scares people.
        int start = buffer.indexOf("java.lang.Exception");
        buffer.replace(start, start + 19, "");
        output.append("\nCall stack: \n").append(os.toString());
    }// w w w. j  a  v  a 2 s .  c o  m

    output.append("\n\n************************************************************\n\n");

    logger.info(output.toString());
}

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

/**
 * Handles an upload of identifiers to print onto empty id cards
 *///from  w ww .  j a v  a 2s  .co m
@RequestMapping(method = RequestMethod.POST, value = "/module/idcards/uploadAndPrintIdCards")
public void uploadAndPrintIdCards(ModelMap model, HttpServletRequest request, HttpServletResponse response,
        @RequestParam(required = true, value = "templateId") Integer templateId,
        @RequestParam(required = true, value = "inputFile") MultipartFile inputFile,
        @RequestParam(required = true, value = "pdfPassword") String pdfPassword) throws Exception {

    // Get identifiers from file
    List<String> identifiers = new ArrayList<String>();
    BufferedReader r = null;
    try {
        r = new BufferedReader(new InputStreamReader(inputFile.getInputStream()));
        for (String s = r.readLine(); s != null; s = r.readLine()) {
            identifiers.add(s);
        }
    } finally {
        if (r != null) {
            r.close();
        }
    }

    IdcardsService is = (IdcardsService) Context.getService(IdcardsService.class);
    IdcardsTemplate card = is.getIdcardsTemplate(templateId);

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

    PrintEmptyIdcardsServlet.generateOutputForIdentifiers(card, baseURL, response, identifiers, pdfPassword);
}

From source file:com.sun.socialsite.util.Utilities.java

/**
 * Need need to get rid of any user-visible HTML tags once all text has been
 * removed such as &lt;BR&gt;. This sounds like a better approach than removing
 * all HTML tags and taking the chance to leave some tags un-closed.
 *
 * WARNING: this method has serious performance problems a
 *
 * @author Alexis Moussine-Pouchkine (alexis.moussine-pouchkine@france.sun.com)
 * @author Lance Lavandowska// ww  w . j a va 2  s. c  om
 * @param str the String object to modify
 * @return the new String object without the HTML "visible" tags
 */
private static String removeVisibleHTMLTags(String str) {
    str = stripLineBreaks(str);
    StringBuffer result = new StringBuffer(str);
    StringBuffer lcresult = new StringBuffer(str.toLowerCase());

    // <img should take care of smileys
    String[] visibleTags = { "<img" }; // are there others to add?
    int stringIndex;
    for (int j = 0; j < visibleTags.length; j++) {
        while ((stringIndex = lcresult.indexOf(visibleTags[j])) != -1) {
            if (visibleTags[j].endsWith(">")) {
                result.delete(stringIndex, stringIndex + visibleTags[j].length());
                lcresult.delete(stringIndex, stringIndex + visibleTags[j].length());
            } else {
                // need to delete everything up until next closing '>', for <img for instance
                int endIndex = result.indexOf(">", stringIndex);
                if (endIndex > -1) {
                    // only delete it if we find the end!  If we don't the HTML may be messed up, but we
                    // can't safely delete anything.
                    result.delete(stringIndex, endIndex + 1);
                    lcresult.delete(stringIndex, endIndex + 1);
                }
            }
        }
    }

    // TODO:  This code is buggy by nature.  It doesn't deal with nesting of tags properly.
    // remove certain elements with open & close tags
    String[] openCloseTags = { "li", "a", "div", "h1", "h2", "h3", "h4" }; // more ?
    for (int j = 0; j < openCloseTags.length; j++) {
        // could this be better done with a regular expression?
        String closeTag = "</" + openCloseTags[j] + ">";
        int lastStringIndex = 0;
        while ((stringIndex = lcresult.indexOf("<" + openCloseTags[j], lastStringIndex)) > -1) {
            lastStringIndex = stringIndex;
            // Try to find the matching closing tag  (ignores possible nesting!)
            int endIndex = lcresult.indexOf(closeTag, stringIndex);
            if (endIndex > -1) {
                // If we found it delete it.
                result.delete(stringIndex, endIndex + closeTag.length());
                lcresult.delete(stringIndex, endIndex + closeTag.length());
            } else {
                // Try to see if it is a self-closed empty content tag, i.e. closed with />.
                endIndex = lcresult.indexOf(">", stringIndex);
                int nextStart = lcresult.indexOf("<", stringIndex + 1);
                if (endIndex > stringIndex && lcresult.charAt(endIndex - 1) == '/'
                        && (endIndex < nextStart || nextStart == -1)) {
                    // Looks like it, so remove it.
                    result.delete(stringIndex, endIndex + 1);
                    lcresult.delete(stringIndex, endIndex + 1);

                }
            }
        }
    }

    return result.toString();
}

From source file:com.afis.jx.ckfinder.connector.utils.FileUtils.java

/**
 * This method removes any ".." characters from the path provided as parameter.
 *
 * @param path string representing path to remove unsafe characters from
 * @return filtered path without ".." characters.
 *//*from  ww  w . j  ava  2s . c  o  m*/
private static String filterRelativePathChars(String path) {
    StringBuffer s = new StringBuffer(path);
    int index = s.indexOf("..");
    if (index >= 0) {
        s = s.delete(index, index + 2);
    }
    return s.toString();
}

From source file:org.sakaiproject.tool.help.TableOfContentsTool.java

/** 
 * get base url// w  w  w  .  j a v  a2 s  .  c  o  m
 * @return base url
 */
private String getBaseUrl() {
    if (baseUrl == null) {
        HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext()
                .getRequest();
        StringBuffer base = request.getRequestURL();
        String contextPath = request.getContextPath();

        int pos = base.indexOf(contextPath);
        if (pos != -1) {
            base.setLength(pos);
        }
        baseUrl = base.toString();
    }
    return baseUrl;
}