Example usage for java.lang StringBuffer delete

List of usage examples for java.lang StringBuffer delete

Introduction

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

Prototype

@Override
public synchronized StringBuffer delete(int start, int end) 

Source Link

Usage

From source file:com.da.img.SoStroyAllList.java

public String htmlRemove(String str) {
    StringBuffer t = new StringBuffer();
    StringBuffer t2 = new StringBuffer();

    char[] c = str.toCharArray();
    char ch;//from  w  w w  . ja  v a2s . c  o m
    int d = 0;
    boolean check = false;
    boolean scriptChkeck = false;
    boolean styleCheck = false;
    for (int i = 0, len = c.length; i < len; i++) {
        ch = c[i];
        if (ch == '<') {
            check = true;
        }

        if (!check & !scriptChkeck && !styleCheck) {

            t.append(ch);
        }

        d++;
        t2.append(ch);
        if (d > 9) {
            t2.delete(0, 1);

        }

        if (!scriptChkeck) {
            if (t2.toString().toLowerCase().indexOf("<script") == 0) {
                scriptChkeck = true;
            }

        }
        if (scriptChkeck) {
            if (t2.toString().toLowerCase().indexOf("</script>") == 0) {

                scriptChkeck = false;
            }

        }

        if (!styleCheck) {
            if (t2.toString().toLowerCase().indexOf("<style") == 0) {
                styleCheck = true;
            }

        }
        if (styleCheck) {

            if (t2.toString().toLowerCase().indexOf("</style>") == 0) {
                styleCheck = false;
            }

        }

        if (ch == '>') {
            check = false;
        }
    }

    return t.toString();
}

From source file:com.glaf.report.web.springmvc.MxReportTaskController.java

@RequestMapping("/edit")
public ModelAndView edit(HttpServletRequest request, ModelMap modelMap) {
    RequestUtils.setRequestParameterToAttribute(request);
    Map<String, Object> params = RequestUtils.getParameterMap(request);
    String reportTaskId = ParamUtils.getString(params, "reportTaskId");
    ReportTask reportTask = null;/*w  ww  .  ja  va 2s.  c  o m*/
    if (StringUtils.isNotEmpty(reportTaskId)) {
        reportTask = reportTaskService.getReportTask(reportTaskId);
        request.setAttribute("reportTask", reportTask);
        if (StringUtils.isNotEmpty(reportTask.getReportIds())) {
            StringBuffer sb01 = new StringBuffer();
            StringBuffer sb02 = new StringBuffer();
            List<String> selecteds = new java.util.ArrayList<String>();
            ReportQuery query = new ReportQuery();
            List<Report> list = reportService.list(query);
            for (Report r : list) {
                if (StringUtils.contains(reportTask.getReportIds(), r.getId())) {
                    selecteds.add(r.getId());
                    sb01.append(r.getId()).append(",");
                    sb02.append(r.getSubject()).append(",");
                }
            }
            if (sb01.toString().endsWith(",")) {
                sb01.delete(sb01.length() - 1, sb01.length());
            }
            if (sb02.toString().endsWith(",")) {
                sb02.delete(sb02.length() - 1, sb02.length());
            }
            request.setAttribute("selecteds", selecteds);
            request.setAttribute("reportIds", sb01.toString());

            request.setAttribute("reportNames", sb02.toString());
        }
    }

    String view = request.getParameter("view");
    if (StringUtils.isNotEmpty(view)) {
        return new ModelAndView(view, modelMap);
    }

    String x_view = ViewProperties.getString("reportTask.edit");
    if (StringUtils.isNotEmpty(x_view)) {
        return new ModelAndView(x_view, modelMap);
    }

    return new ModelAndView("/bi/reportTask/edit", modelMap);
}

From source file:org.etudes.tool.melete.SpecialAccessPage.java

public String deleteAction() {
    FacesContext ctx = FacesContext.getCurrentInstance();
    List delAccs = null;/*  www  .  j a  v  a  2s  . c o  m*/
    count = 0;

    // added by rashmi
    if (!accessSelected) {
        ResourceLoader bundle = new ResourceLoader("org.etudes.tool.melete.bundle.Messages");
        String msg = bundle.getString("select_one_delete");
        addMessage(ctx, "Select  One", msg, FacesMessage.SEVERITY_ERROR);
    }
    // add end
    // access selected
    if (accessSelected) {
        SpecialAccess sa = null;
        if (delAccs == null) {
            delAccs = new ArrayList();
        }
        if (selectedAccIndices != null) {
            StringBuffer accTitlesBuf = new StringBuffer();
            for (ListIterator i = selectedAccIndices.listIterator(); i.hasNext();) {
                int saId = ((Integer) i.next()).intValue();
                sa = (SpecialAccess) saList.get(saId);
                delAccs.add(sa.getAccessId());
                accTitlesBuf.append(generateUserNames(sa.getUsers()));
                accTitlesBuf.append(", ");
            }
            setDeleteAccessIds(delAccs);
            accTitlesBuf.delete(accTitlesBuf.toString().length() - 2, accTitlesBuf.toString().length());
            setDeleteAccessTitles(accTitlesBuf.toString());
        }
    }

    count = 0;
    resetSelectedLists();
    return "delete_special_access";
}

From source file:com.newatlanta.appengine.vfs.provider.GaeFileNameParser.java

/**
 * Makes sure <code>filename</code> always specifies a path that is within a
 * sub-directory of the webapp root path.
 *//*from w w w .  j  a  va 2s .  c o m*/
public FileName parseUri(VfsComponentContext context, FileName baseName, String uri)
        throws FileSystemException {
    StringBuffer name = new StringBuffer();

    // Extract the scheme
    String scheme = UriParser.extractScheme(uri, name);
    if (scheme == null) { // this should never happen
        scheme = "gae";
    }

    // Remove encoding, and adjust the separators
    UriParser.canonicalizePath(name, 0, name.length(), this);
    UriParser.fixSeparators(name);

    // Normalise the path
    FileType fileType = UriParser.normalisePath(name);

    // all GAE files *must* be relative to the root file, which must be the
    // webapp root (though we have no way of enforcing this)
    String rootPath = "";
    if (baseName == null) { // this is the root object
        rootPath = name.toString();
        name.setLength(0);
    } else {
        rootPath = getRootPath(baseName);
        if (name.indexOf(rootPath) == 0) { // if ( name.startsWith( basePath ) )
            name.delete(0, rootPath.length());
        }
    }
    return new GaeFileName(scheme, rootPath, name.toString(), fileType);
}

From source file:yet.another.hackernews.reader.functions.DownloadText.java

@Override
protected String doInBackground(String... urlAdress) {
    /*/* w w w.j  av  a 2 s .  c o  m*/
     * Core of the class that does the background task.
     */

    id = urlAdress[0].hashCode();

    // If we want to use the cache, try and get it first
    String cacheResults = null;
    if (useCache) {
        cacheResults = HardCache.getString(id, context);

        if (cacheResults != null) {
            if (!forceUpdate && !Cache.doUpdate(context, id)) {
                return cacheResults;
            }
        }
    }

    // Set target url
    URL url;
    try {
        url = new URL(urlAdress[0]);
    } catch (MalformedURLException e) {
        // If listener is attached, report error.
        if (listener != null) {
            handler.post(new Runnable() {

                @Override
                public void run() {
                    listener.onError(MALFORMED_URL_ERROR);

                }

            });
        }

        return cacheResults;
    }

    // Stream to URL adress
    BufferedReader bufferedReader = null;
    LineIterator line = null;

    // Results, size set to 100 chars
    final StringBuffer textResults = new StringBuffer(0);

    try {
        // Open stream
        bufferedReader = new BufferedReader(new InputStreamReader(url.openStream(), charset), bufferSize);

        // Download text
        line = IOUtils.lineIterator(bufferedReader);
        while (line.hasNext()) {
            if (this.isCancelled()) {
                break;
            }

            textResults.append(line.nextLine());
        }

    } catch (IOException e) {
        if (textResults.length() > 0) {
            textResults.delete(0, textResults.length());
        }

        if (cacheResults != null) {
            textResults.append(cacheResults);
        }

        if (listener != null) {
            handler.post(new Runnable() {

                @Override
                public void run() {
                    listener.onError(IOEXCEPTION_ERROR);
                }

            });
        }
    } finally {
        // Close reader
        LineIterator.closeQuietly(line);
        IOUtils.closeQuietly(bufferedReader);
    }

    if (textResults.length() <= 0) {
        return null;
    }

    // If use cache, put it in cache
    if (useCache && (!textResults.toString().equals(cacheResults))) {

        HardCache.putString(id, textResults.toString(), context);
        Cache.saveUpdate(context, id);

    }

    return textResults.toString();
}

From source file:com.isecpartners.gizmo.HttpRequest.java

private void removeLine(String header, StringBuffer contents) {
    header = header.toUpperCase();/*from w ww . ja  va  2 s .c om*/

    String proxyUpper = contents.toString().toUpperCase();
    if (proxyUpper.contains(header)) {
        int begin = proxyUpper.indexOf(header);
        int lineEnd = proxyUpper.indexOf("\r\n", begin) + 2;
        contents.delete(begin, lineEnd);
    }
}

From source file:com.chinamobile.bcbsp.graph.GraphDataMananger.java

@Override
public void getAllVertex(GraphStaffHandler graphStaffHandler, CommunicatorInterface communicator,
        RecordWriter output) throws IOException, InterruptedException {
    // TODO Auto-generated method stub
    try {// w  w  w  .j a va 2 s .  c  om
        Vertex v = vertexClass.newInstance();
        for (int i = (MetaDataOfGraph.BCBSP_DISKGRAPH_HASHNUMBER - 1); i >= 0; i--) {
            int counter = MetaDataOfGraph.VERTEX_NUM_PERBUCKET[i];
            if (counter == 0) {
                continue;
            }
            this.prepareBucket(i, this.lastSuperstepCounter + 1);
            graphStaffHandler.preBucket(i, this.lastSuperstepCounter + 1);
            for (int j = 0; j < counter; j++) {
                fillVertex(v);
                LOG.info("Feng test! vertex is null " + v.getVertexID().toString());
                //this.vertexlist.add(v);
                //graphStaffHandler.vertexProcessing(v, bsp, job, superStepCounter,
                //  context, true);
                //      //Vertex<?, ?, Edge> vertex = graphData.getForAll(i);
                String vertexID = v.getVertexID().toString();
                //Iterator<IMessage> it = communicator.getMessageIterator(vertexID);
                ConcurrentLinkedQueue<IMessage> messages = communicator
                        .getMessageQueue(String.valueOf(v.getVertexID()));
                if (messages.size() == 0) {
                    LOG.info("Feng test vertex " + v.getVertexID().toString() + " message is empty!");
                    continue;
                }
                Iterator<IMessage> messagesIter = messages.iterator();
                StringBuffer sb = new StringBuffer();
                //sb.append(vertexID + Constants.MESSAGE_SPLIT);
                while (messagesIter.hasNext()) {
                    IMessage msg = messagesIter.next();
                    String info = msg.intoString();
                    if (info != null) {
                        sb.append(info + Constants.SPACE_SPLIT_FLAG);
                    }
                }
                if (sb.length() > 0) {
                    int k = sb.length();
                    sb.delete(k - 1, k - 1);
                }
                //sb.append("\n");
                output.write(new Text(v.getVertexID() + Constants.MESSAGE_SPLIT), new Text(sb.toString()));
            }

            //  OUT.close()
            this.vManager.processVertexSave(v);

            this.finishPreparedBucket();
        }
    } catch (InstantiationException e) {
        throw new RuntimeException("[Graph Data Manageer] saveAllVertices", e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException("[Graph Data Manageer] saveAllVertices", e);
    }
}

From source file:com.gemstone.gemfire.management.internal.cli.parser.jopt.JoptOptionParser.java

public OptionSet parse(String userInput) throws CliCommandOptionException {
    OptionSet optionSet = new OptionSet();
    optionSet.setUserInput(userInput != null ? userInput.trim() : "");
    if (userInput != null) {
        TrimmedInput input = PreprocessorUtils.trim(userInput);
        String[] preProcessedInput = preProcess(input.getString());
        joptsimple.OptionSet joptOptionSet = null;
        CliCommandOptionException ce = null;
        // int factor = 0;
        try {/*from  w ww.j a v  a2  s  .  c  o  m*/
            joptOptionSet = parser.parse(preProcessedInput);
        } catch (Exception e) {
            if (e instanceof OptionException) {
                ce = processException(e);
                joptOptionSet = ((OptionException) e).getDetected();
            }
        }
        if (joptOptionSet != null) {

            // Make sure there are no miscellaneous, unknown strings that cannot be identified as
            // either options or arguments.
            if (joptOptionSet.nonOptionArguments().size() > arguments.size()) {
                String unknownString = joptOptionSet.nonOptionArguments().get(arguments.size());
                // If the first option is un-parseable then it will be returned as "<option>=<value>" since it's
                // been interpreted as an argument. However, all subsequent options will be returned as "<option>".
                // This hack splits off the string before the "=" sign if it's the first case.
                if (unknownString.matches("^-*\\w+=.*$")) {
                    unknownString = unknownString.substring(0, unknownString.indexOf('='));
                }
                ce = processException(
                        OptionException.createUnrecognizedOptionException(unknownString, joptOptionSet));
            }

            // First process the arguments
            StringBuffer argument = new StringBuffer();
            int j = 0;
            for (int i = 0; i < joptOptionSet.nonOptionArguments().size() && j < arguments.size(); i++) {
                argument = argument.append(joptOptionSet.nonOptionArguments().get(i));
                // Check for syntax of arguments before adding them to the
                // option set as we want to support quoted arguments and those
                // in brackets
                if (PreprocessorUtils.isSyntaxValid(argument.toString())) {
                    optionSet.put(arguments.get(j), argument.toString());
                    j++;
                    argument.delete(0, argument.length());
                }
            }
            if (argument.length() > 0) {
                // Here we do not need to check for the syntax of the argument
                // because the argument list is now over and this is the last
                // argument which was not added due to improper syntax
                optionSet.put(arguments.get(j), argument.toString());
            }

            // Now process the options
            for (Option option : options) {
                List<String> synonyms = option.getAggregate();
                for (String string : synonyms) {
                    if (joptOptionSet.has(string)) {
                        // Check whether the user has actually entered the
                        // full option or just the start
                        boolean present = false;
                        outer: for (String inputSplit : preProcessedInput) {
                            if (inputSplit.startsWith(SyntaxConstants.LONG_OPTION_SPECIFIER)) {
                                // Remove option prefix
                                inputSplit = StringUtils.removeStart(inputSplit,
                                        SyntaxConstants.LONG_OPTION_SPECIFIER);
                                // Remove value specifier
                                inputSplit = StringUtils.removeEnd(inputSplit,
                                        SyntaxConstants.OPTION_VALUE_SPECIFIER);
                                if (!inputSplit.equals("")) {
                                    if (option.getLongOption().equals(inputSplit)) {
                                        present = true;
                                        break outer;
                                    } else {
                                        for (String optionSynonym : option.getSynonyms()) {
                                            if (optionSynonym.equals(inputSplit)) {
                                                present = true;
                                                break outer;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (present) {
                            if (joptOptionSet.hasArgument(string)) {
                                List<?> arguments = joptOptionSet.valuesOf(string);
                                if (arguments.size() > 1
                                        && !(option.getConverter() instanceof MultipleValueConverter)
                                        && option.getValueSeparator() == null) {
                                    List<String> optionList = new ArrayList<String>(1);
                                    optionList.add(string);
                                    ce = processException(
                                            new MultipleArgumentsForOptionException(optionList, joptOptionSet));
                                } else if ((arguments.size() == 1
                                        && !(option.getConverter() instanceof MultipleValueConverter))
                                        || option.getValueSeparator() == null) {
                                    optionSet.put(option, arguments.get(0).toString().trim());
                                } else {
                                    StringBuffer value = new StringBuffer();
                                    String valueSeparator = option.getValueSeparator();
                                    for (Object object : joptOptionSet.valuesOf(string)) {
                                        if (value.length() == 0) {
                                            value.append((String) object);
                                        } else {
                                            if (valueSeparator != null) {
                                                value.append(valueSeparator + ((String) object).trim());
                                            } else {
                                                value.append(((String) object).trim());
                                            }
                                        }
                                    }
                                    optionSet.put(option, value.toString());
                                }
                            } else {
                                optionSet.put(option, option.getSpecifiedDefaultValue());
                            }
                            break;
                        }
                    }
                }
            }
        }

        // Convert the preProcessedInput into List<String>
        List<String> split = new ArrayList<String>();
        for (int i = 0; i < preProcessedInput.length; i++) {
            split.add(preProcessedInput[i]);
        }
        optionSet.setNoOfSpacesRemoved(input.getNoOfSpacesRemoved() /* + factor */);
        optionSet.setSplit(split);
        if (ce != null) {
            ce.setOptionSet(optionSet);
            throw ce;
        }
    }
    return optionSet;
}

From source file:com.m2a.struts.M2AProcessBridgeAction.java

/**
 * Added for eliminating java error text in the DB error message
 *///from  www  .  jav  a2 s  .c o  m
protected void catchException(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) {
    Exception exception = getException(request);
    exception.printStackTrace();
    ActionErrors errors = getErrors(request, true);
    //errors.add("org.apache.struts.action.GLOBAL_ERROR",new ActionError("error.general"));
    StringBuffer sb = new StringBuffer();
    if (exception instanceof BaseException) {
        BaseException e = (BaseException) exception;
        e.getMessage(sb);
        sb.delete(0, 74);
    } else {
        sb.append('\r');
        //sb.append("ERROR: ");     //20120528:1
        //sb.append(exception.toString());
        String message = exception.getMessage();
        if (null != message) {
            //sb.append('\r');
            //sb.append(" DETAILS: ");
            sb.append(message);
            //sb.append('\r');
        } // if (null
    } // if (exception
    errors.add("org.apache.struts.action.GLOBAL_ERROR", new ActionError("error.detail", sb.toString()));
}

From source file:org.apache.geode.management.internal.cli.parser.jopt.JoptOptionParser.java

public OptionSet parse(String userInput) throws CliCommandOptionException {
    OptionSet optionSet = new OptionSet();
    optionSet.setUserInput(userInput != null ? userInput.trim() : "");
    if (userInput != null) {
        TrimmedInput input = PreprocessorUtils.trim(userInput);
        String[] preProcessedInput = preProcess(new HyphenFormatter().formatCommand(input.getString()));
        joptsimple.OptionSet joptOptionSet = null;
        CliCommandOptionException ce = null;
        // int factor = 0;
        try {/* w  w  w.j a  v  a  2 s. c  o m*/
            joptOptionSet = parser.parse(preProcessedInput);
        } catch (OptionException e) {
            ce = processException(e);
            // TODO: joptOptionSet = e.getDetected(); // removed when geode-joptsimple was removed
        }
        if (joptOptionSet != null) {

            // Make sure there are no miscellaneous, unknown strings that cannot be identified as
            // either options or arguments.
            if (joptOptionSet.nonOptionArguments().size() > arguments.size()) {
                String unknownString = (String) joptOptionSet.nonOptionArguments().get(arguments.size()); // added
                                                                                                          // cast
                                                                                                          // when
                                                                                                          // geode-joptsimple
                                                                                                          // was
                                                                                                          // removed
                                                                                                          // If the first option is un-parseable then it will be returned as "<option>=<value>"
                                                                                                          // since it's
                                                                                                          // been interpreted as an argument. However, all subsequent options will be returned as
                                                                                                          // "<option>".
                                                                                                          // This hack splits off the string before the "=" sign if it's the first case.
                if (unknownString.matches("^-*\\w+=.*$")) {
                    unknownString = unknownString.substring(0, unknownString.indexOf('='));
                }
                // TODO: ce =
                // processException(OptionException.createUnrecognizedOptionException(unknownString,
                // joptOptionSet)); // removed when geode-joptsimple was removed
            }

            // First process the arguments
            StringBuffer argument = new StringBuffer();
            int j = 0;
            for (int i = 0; i < joptOptionSet.nonOptionArguments().size() && j < arguments.size(); i++) {
                argument = argument.append(joptOptionSet.nonOptionArguments().get(i));
                // Check for syntax of arguments before adding them to the
                // option set as we want to support quoted arguments and those
                // in brackets
                if (PreprocessorUtils.isSyntaxValid(argument.toString())) {
                    optionSet.put(arguments.get(j), argument.toString());
                    j++;
                    argument.delete(0, argument.length());
                }
            }
            if (argument.length() > 0) {
                // Here we do not need to check for the syntax of the argument
                // because the argument list is now over and this is the last
                // argument which was not added due to improper syntax
                optionSet.put(arguments.get(j), argument.toString());
            }

            // Now process the options
            for (Option option : options) {
                List<String> synonyms = option.getAggregate();
                for (String string : synonyms) {
                    if (joptOptionSet.has(string)) {
                        // Check whether the user has actually entered the
                        // full option or just the start
                        boolean present = false;
                        outer: for (String inputSplit : preProcessedInput) {
                            if (inputSplit.startsWith(SyntaxConstants.LONG_OPTION_SPECIFIER)) {
                                // Remove option prefix
                                inputSplit = StringUtils.removeStart(inputSplit,
                                        SyntaxConstants.LONG_OPTION_SPECIFIER);
                                // Remove value specifier
                                inputSplit = StringUtils.removeEnd(inputSplit,
                                        SyntaxConstants.OPTION_VALUE_SPECIFIER);
                                if (!inputSplit.equals("")) {
                                    if (option.getLongOption().equals(inputSplit)) {
                                        present = true;
                                        break outer;
                                    } else {
                                        for (String optionSynonym : option.getSynonyms()) {
                                            if (optionSynonym.equals(inputSplit)) {
                                                present = true;
                                                break outer;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (present) {
                            if (joptOptionSet.hasArgument(string)) {
                                List<?> arguments = joptOptionSet.valuesOf(string);
                                if (arguments.size() > 1
                                        && !(option.getConverter() instanceof MultipleValueConverter)
                                        && option.getValueSeparator() == null) {
                                    List<String> optionList = new ArrayList<String>(1);
                                    optionList.add(string);
                                    // TODO: ce = processException(new
                                    // MultipleArgumentsForOptionException(optionList, joptOptionSet)); // removed
                                    // when geode-joptsimple was removed
                                } else if ((arguments.size() == 1
                                        && !(option.getConverter() instanceof MultipleValueConverter))
                                        || option.getValueSeparator() == null) {
                                    optionSet.put(option, arguments.get(0).toString().trim());
                                } else {
                                    StringBuffer value = new StringBuffer();
                                    String valueSeparator = option.getValueSeparator();
                                    for (Object object : joptOptionSet.valuesOf(string)) {
                                        if (value.length() == 0) {
                                            value.append((String) object);
                                        } else {
                                            if (valueSeparator != null) {
                                                value.append(valueSeparator + ((String) object).trim());
                                            } else {
                                                value.append(((String) object).trim());
                                            }
                                        }
                                    }
                                    optionSet.put(option, value.toString());
                                }
                            } else {
                                optionSet.put(option, option.getSpecifiedDefaultValue());
                            }
                            break;
                        }
                    }
                }
            }
        }

        // Convert the preProcessedInput into List<String>
        List<String> split = new ArrayList<String>();
        for (int i = 0; i < preProcessedInput.length; i++) {
            split.add(preProcessedInput[i]);
        }
        optionSet.setNoOfSpacesRemoved(input.getNoOfSpacesRemoved() /* + factor */);
        optionSet.setSplit(split);
        if (ce != null) {
            ce.setOptionSet(optionSet);
            throw ce;
        }
    }
    return optionSet;
}