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.daum.DaumCafeBungImgList.java

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

    char[] c = str.toCharArray();
    char ch;/*from  w w w .  java2s.c  om*/
    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().replace("&nbsp;", "");
}

From source file:Leitura.Ecobertura.java

public ArrayList<Integer> qtdeLinhasCod() {
    char[] aux;// ww  w . j  av  a2 s. c  o  m
    StringBuffer sbLinha = new StringBuffer();
    Elements elements = document.getElementsByTag("tr");
    for (Element children : elements) {
        if (StringUtils.isNotBlank(children.getElementsByClass("numLineCover").text())) {
            aux = children.getElementsByClass("numLineCover").text().toCharArray();
            for (int i = 0; i < aux.length; i++) {
                //System.out.println("["+aux[i]+"]");
                if (aux[i] >= 48 && aux[i] <= 57) {
                    sbLinha.append(aux[i]); // exclui espaos na string
                }
            }
            if (StringUtils.isNotBlank(sbLinha.toString())) {
                linhasCod.add(Integer.parseInt(sbLinha.toString()));
                sbLinha.delete(0, sbLinha.length());
            }
        }
    }
    return linhasCod;
}

From source file:com.glaf.chart.web.springmvc.ChartController.java

@RequestMapping("/chooseQuery")
public ModelAndView chooseQuery(HttpServletRequest request, ModelMap modelMap) {
    RequestUtils.setRequestParameterToAttribute(request);
    request.removeAttribute("canSubmit");
    Map<String, Object> params = RequestUtils.getParameterMap(request);
    String rowId = ParamUtils.getString(params, "chartId");
    QueryDefinitionQuery query = new QueryDefinitionQuery();
    List<QueryDefinition> list = queryDefinitionService.list(query);
    request.setAttribute("unselecteds", list);
    Chart chart = null;//from   w w  w. j av a 2 s  . c om
    if (StringUtils.isNotEmpty(rowId)) {
        chart = chartService.getChart(rowId);
        request.setAttribute("chart", chart);
        if (StringUtils.isNotEmpty(chart.getQueryIds())) {
            StringBuffer sb01 = new StringBuffer();
            StringBuffer sb02 = new StringBuffer();
            List<String> selecteds = new java.util.ArrayList<String>();
            for (QueryDefinition q : list) {
                if (StringUtils.contains(chart.getQueryIds(), q.getId())) {
                    selecteds.add(q.getId());
                    sb01.append(q.getId()).append(",");
                    sb02.append(q.getName()).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("queryIds", sb01.toString());

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

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

    return new ModelAndView("/bi/chart/chooseQuery", modelMap);
}

From source file:edu.education.ucsb.muster.MusterServlet.java

private String rowAsJson(ResultSet results, LinkedList<String> columns) {
    StringBuffer out = new StringBuffer("");
    int len;//from  ww w. j a  va  2  s .  co  m

    for (String column : columns) {
        // output "column" : "value". Escape for JavaScript.
        try {
            String value = results.getString(column);
            if (value != null) {
                out.append(String.format("      \"%s\": \"%s\",\n", column,
                        StringEscapeUtils.escapeJavaScript(value.replaceAll("\r\n|\r", "\n"))));
            }
        } catch (SQLException e) {
            addException(e, "Couldn't get column `" + column + "`");
        }
    }

    // remove the trailing ", " and add a line break and close the
    // object
    len = out.length();
    out.delete(len - 2, len);

    return "    {\n" + out + "\n    },\n";
}

From source file:com.seajas.search.contender.service.modifier.ModifierFilterProcessor.java

/**
 * Process the given reader using this filter.
 * // w  ww . j  av  a2s.co  m
 * @param filter
 * @param reader
 * @return Reader
 * @throws IOException
 */
public Reader process(final ModifierFilter filter, final Reader reader) throws IOException {
    StringBuffer stringBuffer = new StringBuffer();

    for (int c; (c = reader.read()) != -1;)
        stringBuffer.append((char) c);

    reader.close();

    if (!filter.getIsExpression()) {
        Pattern pattern = Pattern.compile(
                Pattern.quote(filter.getFragmentStart()) + ".*" + Pattern.quote(filter.getFragmentEnd()),
                Pattern.DOTALL | Pattern.CASE_INSENSITIVE);

        return new StringReader(
                pattern.matcher(stringBuffer).replaceAll(filter.getFragmentStart() + filter.getFragmentEnd()));
    } else {
        Matcher startMatcher = Pattern.compile(filter.getFragmentStart(), Pattern.CASE_INSENSITIVE)
                .matcher(stringBuffer),
                endMatcher = Pattern.compile(filter.getFragmentEnd(), Pattern.CASE_INSENSITIVE)
                        .matcher(stringBuffer);

        while (startMatcher.find() && endMatcher.find(startMatcher.end()))
            if (startMatcher.end() != endMatcher.start()) {
                stringBuffer.delete(startMatcher.end(), endMatcher.start());

                startMatcher.reset();
                endMatcher.reset();
            }

        // Store the result

        return new StringReader(stringBuffer.toString());
    }
}

From source file:net.refractions.udig.ui.CRSChooser.java

private Control createStandardCRSControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    layout.verticalSpacing = 7;//from  ww  w . ja v  a  2 s .c  o  m
    layout.marginWidth = layout.marginHeight = 10;
    composite.setLayout(layout);

    GridData gridData = new GridData();
    Label codesLabel = new Label(composite, SWT.NONE);
    codesLabel.setText(Messages.get("CRSChooser_label_crs"));
    codesLabel.setLayoutData(gridData);

    gridData = new GridData(SWT.FILL, SWT.NONE, true, false);
    searchText = new Text(composite, SWT.SINGLE | SWT.BORDER /*_p3:| SWT.SEARCH*/ | SWT.CANCEL);
    searchText.setToolTipText(Messages.get("CRSChooser_tooltip"));
    searchText.setLayoutData(gridData);
    searchText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            fillCodesList();
        }
    });
    //        searchText.addListener(SWT.KeyUp, new Listener(){
    //         public void handleEvent(Event event) {
    //            if( event.keyCode==SWT.ARROW_DOWN){
    //               codesList.getControl().setFocus();
    //            }
    //         }
    //        });
    gridData = new GridData();
    gridData.minimumWidth = 400;
    gridData.minimumHeight = 200;
    gridData.horizontalAlignment = SWT.FILL;
    gridData.verticalAlignment = SWT.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalSpan = 2;
    codesList = new ListViewer(composite);
    codesList.setContentProvider(new ArrayContentProvider());
    codesList.setLabelProvider(new LabelProvider());
    codesList.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            selectedCRS = null;
            String crsCode = (String) ((IStructuredSelection) codesList.getSelection()).getFirstElement();
            if (crsCode == null)
                return;
            matcher.reset(crsCode);
            if (matcher.matches()) {
                selectedCRS = createCRS(matcher.group(1));
                if (selectedCRS != null && wktText != null) {
                    wktText.setEditable(true);
                    String wkt = null;
                    try {
                        wkt = selectedCRS.toWKT();
                    } catch (Exception e) {
                        /*
                         *  if unable to generate WKT, just return the 
                         *  string and make the text area non editable. 
                         */
                        wkt = selectedCRS.toString();
                        wktText.setEditable(false);
                    }
                    wktText.setText(wkt);
                    Preferences node = findNode(matcher.group(1));
                    if (node != null) {
                        Preferences kn = node.node(ALIASES_ID);
                        try {
                            String[] keywords = kn.keys();
                            if (keywords.length > 0) {
                                StringBuffer buffer = new StringBuffer();
                                for (String string : keywords) {
                                    buffer.append(", "); //$NON-NLS-1$
                                    buffer.append(string);
                                }
                                buffer.delete(0, 2);
                                keywordsText.setText(buffer.toString());
                            }
                        } catch (BackingStoreException e) {
                            UiPlugin.log("", e); //$NON-NLS-1$
                        }

                    } else {
                        keywordsText.setText(""); //$NON-NLS-1$
                    }
                }
            }

        }

    });

    codesList.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            parentPage.handleOk();
            parentPage.handleClose();

        }
    });
    codesList.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            parentPage.handleSelect();
        }
    });

    codesList.getControl().setLayoutData(gridData);
    /*
     * fillCodesList() by itself resizes the Preferences Page but in the paintlistener it
     * flickers the window
     */
    fillCodesList();

    return composite;
}

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

@RequestMapping("/chooseQuery")
public ModelAndView chooseQuery(HttpServletRequest request, ModelMap modelMap) {
    RequestUtils.setRequestParameterToAttribute(request);
    request.removeAttribute("canSubmit");
    Map<String, Object> params = RequestUtils.getParameterMap(request);
    String rowId = ParamUtils.getString(params, "reportId");
    QueryDefinitionQuery query = new QueryDefinitionQuery();
    List<QueryDefinition> list = queryDefinitionService.list(query);
    request.setAttribute("unselecteds", list);
    Report report = null;/*from  w  w  w  .  j a va2s  .  co m*/
    if (StringUtils.isNotEmpty(rowId)) {
        report = reportService.getReport(rowId);
        request.setAttribute("report", report);
        if (StringUtils.isNotEmpty(report.getQueryIds())) {
            StringBuffer sb01 = new StringBuffer();
            StringBuffer sb02 = new StringBuffer();
            List<String> selecteds = new java.util.ArrayList<String>();
            for (QueryDefinition q : list) {
                if (StringUtils.contains(report.getQueryIds(), q.getId())) {
                    selecteds.add(q.getId());
                    sb01.append(q.getId()).append(",");
                    sb02.append(q.getName()).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("queryIds", sb01.toString());

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

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

    return new ModelAndView("/bi/report/chooseQuery", modelMap);
}

From source file:org.nuxeo.ecm.platform.ui.web.auth.cas2.Cas2Authenticator.java

protected String getAppURL(HttpServletRequest httpRequest) {
    if (isValidStartupPage(httpRequest)) {
        StringBuffer sb = new StringBuffer(VirtualHostHelper.getServerURL(httpRequest));
        if (VirtualHostHelper.getServerURL(httpRequest).endsWith("/")) {
            sb.deleteCharAt(sb.length() - 1);
        }//  w  w w.j  a v a2  s  .co m
        sb.append(httpRequest.getRequestURI());
        if (httpRequest.getQueryString() != null) {
            sb.append("?");
            sb.append(httpRequest.getQueryString());

            // remove ticket parameter from URL to correctly validate the
            // service
            int indexTicketKey = sb.lastIndexOf(ticketKey + "=");
            if (indexTicketKey != -1) {
                sb.delete(indexTicketKey - 1, sb.length());
            }
        }

        return sb.toString();
    }
    if (appURL == null || appURL.equals("")) {
        appURL = NUXEO_SERVER_PATTERN_KEY;
    }
    if (appURL.contains(NUXEO_SERVER_PATTERN_KEY)) {
        String nxurl = BaseURL.getBaseURL(httpRequest);
        return appURL.replace(NUXEO_SERVER_PATTERN_KEY, nxurl);
    } else {
        return appURL;
    }
}

From source file:com.glaf.activiti.web.springmvc.ActivitiTaskController.java

@RequestMapping("/taskListJson")
@ResponseBody//from  w  ww  .j a va  2  s.  c  om
@Transactional(readOnly = true)
public byte[] taskListJson(HttpServletRequest request, Model model) throws IOException {
    Map<String, Object> paramMap = RequestUtils.getParameterMap(request);
    int start = RequestUtils.getInt(request, "startIndex", 0);
    int limit = RequestUtils.getInt(request, "results", Paging.DEFAULT_PAGE_SIZE);

    long total = activitiTaskQueryService.getTaskCount(paramMap);

    List<Task> rows = activitiTaskQueryService.getTasks(start, limit, paramMap);

    List<Object> list = new java.util.ArrayList<Object>();

    if (rows != null && rows.size() > 0) {
        for (Task task : rows) {
            Map<String, Object> rowMap = new java.util.HashMap<String, Object>();
            rowMap.put("id", task.getId());
            rowMap.put("processInstanceId", task.getProcessInstanceId());
            rowMap.put("executionId", task.getExecutionId());
            rowMap.put("taskDefinitionKey", task.getTaskDefinitionKey());
            rowMap.put("name", task.getName());
            rowMap.put("description", task.getDescription());

            rowMap.put("priority", task.getPriority());
            rowMap.put("createTime", task.getCreateTime());
            rowMap.put("createDate", DateUtils.getDate(task.getCreateTime()));
            rowMap.put("createDateTime", DateUtils.getDateTime(task.getCreateTime()));

            if (task.getAssignee() != null) {
                rowMap.put("assignee", task.getAssignee());
                rowMap.put("actorId", task.getAssignee());
                rowMap.put("actorName", task.getAssignee());
                User userProfile = IdentityFactory.getUser(task.getAssignee());
                if (userProfile != null) {
                    rowMap.put("actorName", userProfile.getName());
                    // rowMap.put("deptName", userProfile.getDeptName());
                }
            } else {
                List<IdentityLink> identityLinks = activitiTaskQueryService.getTaskIdentityLinks(task.getId());
                if (identityLinks != null && identityLinks.size() > 0) {
                    StringBuffer buffer = new StringBuffer();
                    for (IdentityLink p : identityLinks) {
                        if (p.getUserId() != null) {
                            User userProfile = IdentityFactory.getUser(p.getUserId());
                            if (userProfile != null && userProfile.getName() != null) {
                                buffer.append(userProfile.getName()).append(", ");
                            } else {
                                buffer.append(p.getUserId()).append(", ");
                            }
                        } else if (p.getGroupId() != null) {
                            buffer.append(p.getGroupId()).append("(group), ");
                        }
                    }
                    buffer.delete(buffer.length() - 2, buffer.length());
                    rowMap.put("actorName", buffer.toString());
                }
            }

            list.add(rowMap);
        }
    }

    Map<String, Object> pageInfo = new java.util.HashMap<String, Object>();
    // ?
    pageInfo.put("startIndex", start);

    // ?
    pageInfo.put("pageSize", limit);

    // ??
    pageInfo.put("totalRecords", total);
    pageInfo.put("records", list);

    JSONObject object = new JSONObject(pageInfo);

    return object.toString().getBytes("UTF-8");
}

From source file:playground.andreas.bln.ana.events2counts.PtCountCountComparisonKMLWriter.java

/**
 * Creates the CountsErrorGraph for all the data
 *
 * @param kmlFilename//from  ww  w  .j av  a  2 s. co m
 *            the filename of the kml file
 * @param visible
 *            true if initially visible
 * @return the ScreenOverlay Feature
 */
private ScreenOverlayType createBiasErrorGraphBoard(String kmlFilename) {
    int index = kmlFilename.lastIndexOf(System.getProperty("file.separator"));
    if (index == -1) {
        index = kmlFilename.lastIndexOf('/');
    }
    String outdir;
    if (index == -1) {
        outdir = "";
    } else {
        outdir = kmlFilename.substring(0, index) + System.getProperty("file.separator");
    }
    // ------------------------------------------------------------------------------

    PtBiasErrorGraph epBoard = new PtBiasErrorGraph(this.boardCountComparisonFilter.getCountsForHour(null),
            this.iter, null, "error graph - boarding");
    epBoard.createChart(0);

    double[] meanErrorBoard = epBoard.getMeanRelError();
    double[] meanBiasBoard = epBoard.getMeanAbsBias();

    String fileBoard = outdir + "biasErrorGraphDataBoard.txt";
    log.info("writing chart data to " + new File(fileBoard).getAbsolutePath());
    try {
        BufferedWriter bwriter = IOUtils.getBufferedWriter(fileBoard);
        StringBuffer buffer = new StringBuffer(200);
        buffer.append("hour \t mean relative error \t mean absolute bias");
        bwriter.write(buffer.toString());
        bwriter.newLine();
        for (int i = 0; i < meanErrorBoard.length; i++) {
            buffer.delete(0, buffer.length());
            buffer.append(i + 1);
            buffer.append('\t');
            buffer.append(meanErrorBoard[i]);
            buffer.append('\t');
            buffer.append(meanBiasBoard[i]);
            bwriter.write(buffer.toString());
            bwriter.newLine();
        }
        bwriter.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    String chartBoard = "errorGraphErrorBiasBoard.png";
    try {
        writeChartToKmz(chartBoard, epBoard.getChart());
        return createOverlayBottomRight(chartBoard, "Error Graph [Error/Bias]");
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}