List of usage examples for java.lang StringBuffer replace
@Override public synchronized StringBuffer replace(int start, int end, String str)
From source file:com.topsec.tsm.sim.report.web.TopoReportController.java
public String moreReport(SID sid, HttpServletRequest request, HttpServletResponse response) { boolean fromRest = false; if (request.getParameter("fromRest") != null) { fromRest = Boolean.parseBoolean(request.getParameter("fromRest")); }/*w ww. j a v a 2 s .c o m*/ JSONObject jsonObj = new JSONObject(); ReportBean bean = new ReportBean(); String onlyByDvctype = request.getParameter("onlyByDvctype"); bean = ReportUiUtil.tidyFormBean(bean, request); String[] talCategory = bean.getTalCategory(); RptMasterTbService rptMasterTbImp = (RptMasterTbService) SpringContextServlet.springCtx .getBean(ReportUiConfig.MstBean); List<Map> subList = rptMasterTbImp.queryTmpList(ReportUiConfig.PaginationSql, new Object[] { StringUtil.toInt(bean.getSubrptid(), 0) }); JSONObject obj = null; StringBuffer url = null; String surl = ""; boolean flag = false; String nodeType = request.getParameter("nodeType"); try { Map params = new HashMap(); if (!GlobalUtil.isNullOrEmpty(nodeType) && !"null".equalsIgnoreCase(nodeType)) { SID.setCurrentUser(sid); params.put("nodeType", nodeType); } if (subList.size() > 0) { Map subMap = (Map) subList.get(0); String subTitle = subMap.get("subName").toString(); String mstType = request.getParameter("msttype"); subTitle = ReportUiUtil.viewRptName(subTitle, mstType); request.setAttribute("subName", subTitle); if (fromRest) { jsonObj.put("subName", subTitle); } String paginationSql = null; if (!GlobalUtil.isNullOrEmpty(subMap) && !GlobalUtil.isNullOrEmpty(subMap.get("paginationSql"))) { paginationSql = subMap.get("paginationSql").toString(); } String deviceType = bean.getDvctype(); if (!GlobalUtil.isNullOrEmpty(paginationSql)) { if (deviceType.equals(LogKeyInfo.LOG_SYSTEM_TYPE) || deviceType.equals("Log/Global/Detail") || deviceType.startsWith("Comprehensive")) { paginationSql = paginationSql.replace("**", ReportUiConfig.PageSqlRule2); paginationSql = paginationSql.replace("*alias*", ReportUiConfig.PageSqlRuleAlias2); } else { if (onlyByDvctype != null && onlyByDvctype.equals("onlyByDvctype")) { paginationSql = paginationSql.replace("**", ReportUiConfig.PageSqlRule2); paginationSql = paginationSql.replace("*alias*", ReportUiConfig.PageSqlRuleAlias2); } else { paginationSql = paginationSql.replace("**", ReportUiConfig.PageSqlRule); paginationSql = paginationSql.replace("*alias*", ReportUiConfig.PageSqlRuleAlias); } } paginationSql = ReportModel.getTimeSql(paginationSql, bean.getTalStartTime(), bean.getTalEndTime()); } // ?lable String paginationViewFiled = null; String paginationHtmFiled = null; // sqlmap String paginationSqlFiled = null; String tableSql = null; if (!GlobalUtil.isNullOrEmpty(subMap)) { if (!GlobalUtil.isNullOrEmpty(subMap.get("paginationViewFiled"))) { paginationViewFiled = subMap.get("paginationViewFiled").toString(); } if (!GlobalUtil.isNullOrEmpty(subMap.get("paginationHtmFiled"))) { paginationHtmFiled = subMap.get("paginationHtmFiled").toString(); } if (!GlobalUtil.isNullOrEmpty(subMap.get("paginationSqlFiled"))) { paginationSqlFiled = subMap.get("paginationSqlFiled").toString(); } } List sqlParam = ReportUiUtil.getPaginationItem(request, paginationHtmFiled);// ?? sqlParam.add(bean.getTalStartTime());// 3? sqlParam.add(bean.getTalEndTime());// ?4? if (!bean.getDvcaddress().equals("")) { if (deviceType.equals(LogKeyInfo.LOG_SYSTEM_TYPE) || deviceType.equals("Log/Global/Detail")) { } else { if (onlyByDvctype != null && onlyByDvctype.equals("onlyByDvctype")) { } else { sqlParam.add(bean.getDvcaddress()); // dvcaddress 5? } } } if (!GlobalUtil.isNullOrEmpty(talCategory)) { for (String str : talCategory) { if (!GlobalUtil.isNullOrEmpty(str)) { sqlParam.add(str.substring(str.indexOf("***") + 3)); } } } /*String viewParam = ReportUiUtil.getViewPaginationItem(request, paginationHtmFiled); viewParam = viewParam.replace("'''", "\"'\""); request.setAttribute("viewParam", viewParam);*/ String pageNum = "1";// ? int pageSize = bean.getPagesize() == null ? 10 : Integer.parseInt(bean.getPagesize()); String pagein = request.getParameter("pagein"); String pageingo = request.getParameter("pageingo"); String pageIndex = request.getParameter("pageIndex"); if (ReportUiUtil.checkNull(pageIndex)) { pageNum = pageIndex; } else if (ReportUiUtil.checkNull(pagein) && ReportUiUtil.checkNull(pageingo)) { pageNum = pagein; } String[] nodeId = request.getParameterValues("nodeId"); Map<String, Object> rsMap = null; if (!GlobalUtil.isNullOrEmpty(paginationSql)) { List<String> deviceTypes = ReportModel.getDeviceTypeList(dataSourceService, SID.currentUser()); List<String> deviceIps = ReportModel.getDeviceIpList(dataSourceService, SID.currentUser()); rsMap = ReportModel.reformingSubTitleData(deviceTypes, deviceIps, paginationSql, sqlParam, subMap, pageSize, nodeId, bean.getTalStartTime(), bean.getTalEndTime(), true, request); } else { String subId = request.getParameter(ReportUiConfig.subrptid); String sTime = bean.getTalStartTime(); String eTime = bean.getTalEndTime(); List<Map> subList1 = rptMasterTbImp.queryTmpList(ReportUiConfig.SubTitleSql, new Object[] { StringUtil.toInt(subId, 0) }); JSONObject json = null; Map<String, Object> rsMap1 = null; if (subList1.size() > 0) { Map subMap1 = (Map) subList1.get(0); List<String> deviceTypes = ReportModel.getDeviceTypeList(dataSourceService, SID.currentUser()); List<String> deviceIps = ReportModel.getDeviceIpList(dataSourceService, SID.currentUser()); rsMap1 = ReportModel.getSubTitleData(rptMasterTbImp, deviceTypes, deviceIps, subMap1, sTime, eTime, subId, false, request); } rsMap = rsMap1; } String viewParamItem = ReportModel.createSearchItem(paginationViewFiled, paginationHtmFiled); request.setAttribute("viewParamItem", viewParamItem); if (fromRest) { jsonObj.put("viewParamItem", viewParamItem); } int sumPage = 0; if (rsMap != null) { sumPage = StringUtil.toInt(StringUtil.toString(rsMap.get("sumPage"), "0")); } // request.setAttribute("pages", ReportModel.getPages(sumPage, pageSize)); request.setAttribute("sumdata", sumPage); // ? request.setAttribute("pageIndex", pageNum); if (fromRest) { jsonObj.put("pages", ReportModel.getPages(sumPage, pageSize)); jsonObj.put("sumdata", sumPage); // ? jsonObj.put("pageIndex", pageNum); } Map<Object, Object> data = ReportModel.reformingResult(subMap, rsMap); int chartType = StringUtil.toInt(subMap.get("chartType").toString(), 0); if (chartType > 0 && chartType < 4) { flag = true; } params.put("dvcType", request.getParameter("dvctype")); params.put("talTop", request.getParameter("talTop")); params.put("sTime", bean.getTalStartTime()); params.put("eTime", bean.getTalEndTime()); String chartLink = StringUtil.toString(subMap.get("chartLink"), "0"); int _chartLink = Integer.valueOf(chartLink); String reportType = request.getParameter("reportType"); if ("comprehensiveReportIndex".equals(reportType)) { params.put("reportType", reportType); url = getUrl("/sim/topoReport/comprehensiveInformReport?", request, params, talCategory, true); } else { url = getUrl(ReportUiConfig.reportEvtUrl, request, params, bean.getTalCategory(), true); } surl = url.toString(); if (_chartLink > 0) { url.append("&superiorId=").append(subList.get(0).get("mstId")).append("&") .append(ReportUiConfig.mstrptid).append("=").append(chartLink); } data.put("url", _chartLink > 0 ? url.toString() : ""); url.replace(0, url.length(), surl).replace(0, ReportUiConfig.reportEvtUrl.length(), ReportUiConfig.moreEvtUrl); url.append("&").append(ReportUiConfig.mstrptid).append("=").append(subList.get(0).get("mstId")) .append("&").append(ReportUiConfig.subrptid).append("=").append(bean.getSubrptid()); data.put("moreUrl", url.toString()); request.setAttribute("moreUrl", url.toString()); if (fromRest) { jsonObj.put("moreUrl", url.toString()); } ChartTable table = CreateChartFactory.getInstance().reformingChartTable(data); obj = moreRptAssembleData(table, StringUtil.toInt(pageNum), pageSize); url.replace(0, url.length(), surl); if (!"comprehensiveReportIndex".equals(reportType)) { url.append("&").append(ReportUiConfig.mstrptid).append("=").append(subList.get(0).get("mstId")); } } if (subList != null) { request.setAttribute("title", subList.get(0).get("subName")); if (fromRest) { jsonObj.put("title", subList.get(0).get("subName")); } } List<SimDatasource> dslist = new ArrayList<SimDatasource>(); SimDatasource dsource = new SimDatasource(); if ("onlyByDvctype".equals(onlyByDvctype)) { dsource.setDeviceIp(""); dsource.setNodeId(""); } else { dsource.setDeviceIp(request.getParameter("dvcaddress")); dsource.setNodeId(request.getParameter("nodeId")); } dsource.setSecurityObjectType(bean.getDvctype()); dslist.add(0, dsource); request.setAttribute("dslist", dslist); request.setAttribute("flag", flag); request.setAttribute("goUrl", url != null ? url.toString() : ""); request.setAttribute("tableOptions", obj); request.setAttribute("bean", bean); if (fromRest) { jsonObj.put("dslist", dslist); jsonObj.put("flag", flag); jsonObj.put("goUrl", url != null ? url.toString() : ""); jsonObj.put("tableOptions", obj); jsonObj.put("bean", bean); return JSON.toJSONString(jsonObj); } } finally { if (!GlobalUtil.isNullOrEmpty(SID.currentUser())) { SID.removeCurrentUser(); } } return "/page/report/more_report"; }
From source file:marytts.tools.dbselection.WikipediaMarkupCleaner.java
public Vector<String> removeMarkup(String page) { StringBuffer str = new StringBuffer(""); StringBuffer line = null; Vector<String> textList = new Vector<String>(); boolean endOfText = false; Scanner s = null;/*from w w w .j a va2 s. c om*/ try { s = new Scanner(page); while (s.hasNext() && !endOfText) { line = new StringBuffer(s.nextLine()); // process text until it finds any of these labels: if (line.indexOf("==References") >= 0 || line.indexOf("== References") >= 0 || line.indexOf("==See also") >= 0 || line.indexOf("== See also") >= 0 || line.indexOf("==External links and sources") >= 0 || line.indexOf("==External links") >= 0 || line.indexOf("== External links") >= 0 || line.indexOf("== External Links") >= 0 || line.indexOf("== External links and sources") >= 0 || line.indexOf("==Notes") >= 0 || line.indexOf("== Notes") >= 0 || line.indexOf("==Sources") >= 0 || line.indexOf("== Sources") >= 0 || line.indexOf("==Foreign") >= 0 || line.indexOf("== Foreign") >= 0 || line.indexOf("==Discussion") >= 0) { endOfText = true; } else { // when removing sections it might add more lines that might contain again more labels to remove boolean clean = false; while (!clean && line.length() > 0) { clean = true; if (line.indexOf("<noinclude") >= 0) { line = removeSection(s, line, "<noinclude", "</noinclude>"); clean = false; } if (line.indexOf("<includeonly") >= 0) { line = removeSection(s, line, "<includeonly", "</includeonly>"); clean = false; } if (line.indexOf("<onlyinclude") >= 0) { line = removeSection(s, line, "<onlyinclude", "</onlyinclude>"); clean = false; } if (line.indexOf("<table") >= 0) { // tables line = removeSection(s, line, "<table", "</table>"); clean = false; } if (line.indexOf("<TABLE") >= 0) { line = removeSection(s, line, "<TABLE", "</TABLE>"); clean = false; } if (line.indexOf("{{col-begin}}") >= 0) { line = removeSection(s, line, "{{col-begin}}", "{{col-end}}"); clean = false; } if (line.indexOf("{|") >= 0) { // this is a table, this should go before {{ because a table can contain {{ }} line = removeSectionTable(s, line, "{|", "|}"); clean = false; } if (line.indexOf("<ref") >= 0) { // references line = removeSectionRef(s, line); // This is special because it can be <ref>, <ref, </ref> or /> clean = false; } if (line.indexOf("<REF") >= 0) { line = removeSection(s, line, "<REF", "</REF>"); clean = false; } if (line.indexOf("<Ref") >= 0) { line = removeSection(s, line, "<Ref", "</Ref>"); clean = false; } if (line.indexOf("<reF") >= 0) { line = removeSection(s, line, "<reF", "</reF>"); clean = false; } if (line.indexOf("{{start box}}") >= 0) { line = removeSection(s, line, "{{start box}}", "{{end box}}"); clean = false; } if (line.indexOf("{{") >= 0) { line = removeSection(s, line, "{{", "}}"); clean = false; } if (line.indexOf("<!--") >= 0) { line = removeSection(s, line, "<!--", "-->"); clean = false; } if (line.indexOf("\\mathrel{|") >= 0) { line = removeSection(s, line, "\\mathrel{|", "}"); clean = false; } if (line.indexOf("<gallery") >= 0) { // gallery might contain several images line = removeSection(s, line, "<gallery", "</gallery>"); clean = false; } if (line.indexOf("[[Image:") >= 0) { line = removeSectionImage(s, line, "[[Image:", "]]"); clean = false; } if (line.indexOf("<div") >= 0) { // span and div tags are used to separate images from text line = removeSection(s, line, "<div", "</div>"); clean = false; } if (line.indexOf("<DIV") >= 0) { line = removeSectionImage(s, line, "<DIV", "</DIV>"); clean = false; } if (line.indexOf("<span") >= 0) { line = removeSection(s, line, "<span", "</span>"); clean = false; } if (line.indexOf("<math>") >= 0) { line = removeSection(s, line, "<math>", "</math>"); clean = false; } if (line.indexOf("<timeline>") >= 0) { line = removeSection(s, line, "<timeline>", "</timeline>"); clean = false; } if (line.indexOf("<nowiki") >= 0) { line = removeSection(s, line, "<nowiki", "</nowiki>"); clean = false; } if (line.indexOf("<source") >= 0) { line = removeSection(s, line, "<source", "</source>"); clean = false; } if (line.indexOf("<code") >= 0) { line = removeSection(s, line, "<code", "</code>"); clean = false; } if (line.indexOf("<imagemap") >= 0) { line = removeSection(s, line, "<imagemap", "</imagemap>"); clean = false; } if (line.indexOf("<poem") >= 0) { line = removeSection(s, line, "<poem", "</poem>"); clean = false; } if (line.indexOf("<h1") >= 0) { line = removeSection(s, line, "<h1", "</h1>"); clean = false; } if (line.indexOf("<pre") >= 0) { line = removeSection(s, line, "<pre", "</pre>"); clean = false; } } // while the line/text is not clean (or does not have tags to remove) // here filter bulleted and numbered short lines if (line.length() > 0) { if ((line.toString().startsWith("*") || line.toString().startsWith("#") || line.toString().startsWith(";") || line.toString().startsWith(".") || line.toString().startsWith(",") || line.toString().startsWith("&") || line.toString().startsWith("}") || line.toString().startsWith("]") || line.toString().startsWith("|") || line.toString().startsWith("ca:") || line.toString().startsWith("cs:") || line.toString().startsWith("de:") || line.toString().startsWith("es:") || line.toString().startsWith("fr:") || line.toString().startsWith("it:") || line.toString().startsWith("hu:") || line.toString().startsWith("ja:") || line.toString().startsWith("no:") || line.toString().startsWith("pt:") || line.toString().startsWith("sl:") || line.toString().startsWith("fi:") || line.toString().startsWith("sv:") || line.toString().startsWith("tr:") || line.toString().startsWith("zh:") || line.toString().startsWith("Category:") || line.toString().startsWith("!style=") || line.toString().startsWith("! style=") || line.toString().startsWith("!align=") || line.toString().startsWith("::<code") || line.toString().endsWith("]]")) && line.length() < 200) line = new StringBuffer(""); } // Now if the line is not empty, remove: // '''''bold & italic''''' // '''bold''' // ''italic'' // Internal links: // [[Name of page]] // [[Name of page|Text to display]] // External links: // [http://www.example.org Text to display] // [http://www.example.org] // http://www.example.org if (line.length() > 0) { line = new StringBuffer(line.toString().replaceAll("'''''", "")); line = new StringBuffer(line.toString().replaceAll("'''", "")); line = new StringBuffer(line.toString().replaceAll("''", "")); line = processInternalAndExternalLinks(line); // this will convert HTML – etc. String strlineNoHTML = StringEscapeUtils.unescapeHtml(line.toString()); line = new StringBuffer(strlineNoHTML); // The previous does not remove all HTML stuff, so here it is done some manually line = new StringBuffer(line.toString().replaceAll("<big>", "")); line = new StringBuffer(line.toString().replaceAll("</big>", "")); line = new StringBuffer(line.toString().replaceAll("<blockquote>", "")); line = new StringBuffer(line.toString().replaceAll("</blockquote>", "")); line = new StringBuffer(line.toString().replaceAll("<BLOCKQUOTE>", "")); line = new StringBuffer(line.toString().replaceAll("</BLOCKQUOTE>", "")); line = new StringBuffer(line.toString().replaceAll("<sup>", "")); line = new StringBuffer(line.toString().replaceAll("</sup>", "")); line = new StringBuffer(line.toString().replaceAll("<sub>", "")); line = new StringBuffer(line.toString().replaceAll("</sub>", "")); line = new StringBuffer(line.toString().replaceAll("<small>", "")); line = new StringBuffer(line.toString().replaceAll("</small>", "")); line = new StringBuffer(line.toString().replaceAll("<ul>", "")); line = new StringBuffer(line.toString().replaceAll("</ul>", "")); line = new StringBuffer(line.toString().replaceAll("<UL>", "")); line = new StringBuffer(line.toString().replaceAll("</UL>", "")); line = new StringBuffer(line.toString().replaceAll("<br>", "")); line = new StringBuffer(line.toString().replaceAll("<br", "")); line = new StringBuffer(line.toString().replaceAll("<BR>", "")); line = new StringBuffer(line.toString().replaceAll("<br", "")); line = new StringBuffer(line.toString().replaceAll("<br/>", "")); line = new StringBuffer(line.toString().replaceAll("<Center>", "")); line = new StringBuffer(line.toString().replaceAll("<center>", "")); line = new StringBuffer(line.toString().replaceAll("</center>", "")); line = new StringBuffer(line.toString().replaceAll("<CENTER>", "")); line = new StringBuffer(line.toString().replaceAll("</CENTER>", "")); line = new StringBuffer(line.toString().replaceAll("<cite>", "")); line = new StringBuffer(line.toString().replaceAll("</cite>", "")); line = new StringBuffer(line.toString().replaceAll("<li>", "")); line = new StringBuffer(line.toString().replaceAll("</li>", "")); line = new StringBuffer(line.toString().replaceAll("<LI>", "")); line = new StringBuffer(line.toString().replaceAll("</LI>", "")); line = new StringBuffer(line.toString().replaceAll("<dl>", "")); line = new StringBuffer(line.toString().replaceAll("</dl>", "")); line = new StringBuffer(line.toString().replaceAll("<dt>", "")); line = new StringBuffer(line.toString().replaceAll("</dt>", "")); line = new StringBuffer(line.toString().replaceAll("<dd>", "")); line = new StringBuffer(line.toString().replaceAll("</dd>", "")); line = new StringBuffer(line.toString().replaceAll("<b>", "")); line = new StringBuffer(line.toString().replaceAll("</b>", "")); line = new StringBuffer(line.toString().replaceAll("<p>", "")); line = new StringBuffer(line.toString().replaceAll("</p>", "")); line = new StringBuffer(line.toString().replaceAll("<u>", "")); line = new StringBuffer(line.toString().replaceAll("</u>", "")); line = new StringBuffer(line.toString().replaceAll("<tt>", "")); line = new StringBuffer(line.toString().replaceAll("</tt>", "")); line = new StringBuffer(line.toString().replaceAll("<i>", "")); line = new StringBuffer(line.toString().replaceAll("</i>", "")); line = new StringBuffer(line.toString().replaceAll("<I>", "")); line = new StringBuffer(line.toString().replaceAll("</I>", "")); line = new StringBuffer(line.toString().replaceAll("<s>", "")); line = new StringBuffer(line.toString().replaceAll("</s>", "")); line = new StringBuffer(line.toString().replaceAll("<em>", "")); line = new StringBuffer(line.toString().replaceAll("</em>", "")); line = new StringBuffer(line.toString().replaceAll("</br>", "")); line = new StringBuffer(line.toString().replaceAll("</div>", "")); line = new StringBuffer(line.toString().replaceAll("</ref>", "")); line = new StringBuffer(line.toString().replaceAll("/>", "")); // Removing quotation marks line = new StringBuffer(line.toString().replaceAll("\"", "")); // these quotations have a strange/problematic symbol different from " line = new StringBuffer(line.toString().replaceAll("", "")); line = new StringBuffer(line.toString().replaceAll("?", "")); // these symbol are also problematic, here they are changed. line = new StringBuffer(line.toString().replaceAll("", "'")); line = new StringBuffer(line.toString().replaceAll("", "-")); line = new StringBuffer(line.toString().replaceAll("", "-")); line = new StringBuffer(line.toString().replaceAll("", " ")); line = new StringBuffer(line.toString().replaceAll("", " ")); // finally sections and lists boolean is_title = false; if (line.toString().startsWith("==")) { is_title = true; } line = new StringBuffer(line.toString().replaceAll("\\s*==+$|==+", "")); if (is_title) { line.append("."); } // bulleted list and numbered list if (line.toString().startsWith("***") || line.toString().startsWith("*#*")) line.replace(0, 3, ""); if (line.toString().startsWith("**") || line.toString().startsWith(":*") || line.toString().startsWith("*#") || line.toString().startsWith("##") || line.toString().startsWith("::")) line.replace(0, 2, ""); if (line.toString().startsWith("*") || line.toString().startsWith("#")) line.replace(0, 1, ""); if (line.toString().startsWith(";") || line.toString().startsWith(";")) // in glossaries definitions start with ; line.replace(0, 1, ""); // remove this when the text is almost clean if (line.indexOf("<font") >= 0) line = removeSection(s, line, "<font", ">"); line = new StringBuffer(line.toString().replaceAll("</font>", "")); if (line.indexOf("<blockquote") >= 0) line = removeSection(s, line, "<blockquote", ">"); if (line.indexOf("<ol") >= 0) line = removeSection(s, line, "<ol", ">"); if (line.indexOf("<http:") >= 0) line = removeSection(s, line, "<http:", ">"); // finally concatenate the line str.append(line); if (!str.toString().endsWith("\n")) str.append("\n"); line = null; // check length of the text if (str.length() > maxTextLength) { textList.add(str.toString()); //System.out.println("\n-----------\n" + str.toString()); str = new StringBuffer(""); } } } // endOfText=false } // while has more lines } finally { if (s != null) s.close(); } if (!str.toString().contentEquals("")) textList.add(str.toString()); return textList; }