List of usage examples for org.apache.commons.lang StringUtils replace
public static String replace(String text, String searchString, String replacement)
Replaces all occurrences of a String within another String.
From source file:dpfmanager.shell.modules.report.util.ReportHtml.java
/** * Parse a global report to XML format./*ww w . ja va 2 s .c om*/ * * @param outputfile the output file. * @param gr the global report. */ public void parseGlobal(String outputfile, GlobalReport gr, ReportGenerator generator) { String templatePath = "templates/global.html"; String imagePath = "templates/image.html"; String newHtmlFolder = outputfile.substring(0, outputfile.lastIndexOf("/")); String imagesBody = ""; String pieFunctions = ""; // Parse individual Reports int index = 0; for (IndividualReport ir : gr.getIndividualReports()) { if (!ir.containsData()) continue; String imageBody; imageBody = generator.readFilefromResources(imagePath); // Image String imgPath = "html/img/" + new File(ir.getReportPath()).getName() + ".jpg"; boolean check = tiff2Jpg(ir.getFilePath(), newHtmlFolder + "/" + imgPath); if (!check) { imgPath = "html/img/noise.jpg"; } imageBody = StringUtils.replace(imageBody, "##IMG_PATH##", encodeUrl(imgPath)); // Basic int percent = ir.calculatePercent(); imageBody = StringUtils.replace(imageBody, "##PERCENT##", "" + percent); imageBody = StringUtils.replace(imageBody, "##INDEX##", "" + index); imageBody = StringUtils.replace(imageBody, "##IMG_NAME##", "" + ir.getFileName()); /** * Errors / warnings resume (individual) */ String rowTmpl = "<tr>\n" + "\t\t\t\t\t\t <td class=\"c1\">##NAME##</td>\n" + "\t\t\t\t\t\t <td class=\"c2 ##ERR_C##\">##ERR_N## errors</td>\n" + "\t\t\t\t\t\t <td class=\"c2 ##WAR_C##\">##WAR_N## warnings</td>\n" + "\t\t\t\t\t\t <td></td>\n" + "\t\t\t\t\t\t </tr>"; String rows = ""; int totalWarnings = 0; for (String iso : ir.getCheckedIsos()) { if (ir.hasValidation(iso)) { String name = ImplementationCheckerLoader.getIsoName(iso); String row = rowTmpl; int errorsCount = ir.getNErrors(iso); int warningsCount = ir.getNWarnings(iso); totalWarnings += warningsCount; row = StringUtils.replace(row, "##NAME##", name); row = StringUtils.replace(row, "##ERR_N##", "" + errorsCount); row = StringUtils.replace(row, "##WAR_N##", "" + warningsCount); if (errorsCount > 0) { row = StringUtils.replace(row, "##ERR_C##", "error"); } else { row = StringUtils.replace(row, "##ERR_C##", ""); } if (warningsCount > 0) { row = StringUtils.replace(row, "##WAR_C##", "warning"); } else { row = StringUtils.replace(row, "##WAR_C##", ""); } rows += row; } } imageBody = StringUtils.replace(imageBody, "##TABLE_RESUME_IMAGE##", rows); imageBody = StringUtils.replace(imageBody, "##HREF##", "html/" + encodeUrl(new File(ir.getReportPath()).getName() + ".html")); /** * Percent info */ if (percent == 100) { imageBody = StringUtils.replace(imageBody, "##CLASS##", "success"); imageBody = StringUtils.replace(imageBody, "##RESULT##", "Passed"); if (totalWarnings > 0) { imageBody = StringUtils.replace(imageBody, "##DISPLAY_WAR##", "inline-block"); } else { imageBody = StringUtils.replace(imageBody, "##DISPLAY_WAR##", "none"); } } else { imageBody = StringUtils.replace(imageBody, "##CLASS##", "error"); imageBody = StringUtils.replace(imageBody, "##RESULT##", "Failed"); imageBody = StringUtils.replace(imageBody, "##DISPLAY_WAR##", "none"); } /** * Percent chart */ int angle = percent * 360 / 100; int reverseAngle = 360 - angle; String functionPie = "plotPie('pie-" + index + "', " + angle + ", " + reverseAngle; if (percent < 100) { functionPie += ", '#CCCCCC', 'red'); "; } else { functionPie += ", '#66CC66', '#66CC66'); "; } pieFunctions += functionPie; imagesBody += imageBody; index++; } // Parse the sumary report numbers String htmlBody; htmlBody = generator.readFilefromResources(templatePath); Double doub = 1.0 * gr.getAllReportsOk() / gr.getReportsCount() * 100.0; int globalPercent = doub.intValue(); htmlBody = StringUtils.replace(htmlBody, "##IMAGES_LIST##", imagesBody); htmlBody = StringUtils.replace(htmlBody, "##PERCENT##", "" + globalPercent); String scount = gr.getReportsCount() + " "; if (gr.getReportsCount() == 1) scount += "file"; else scount += "files"; htmlBody = StringUtils.replace(htmlBody, "##COUNT##", "" + scount); htmlBody = StringUtils.replace(htmlBody, "##OK##", "" + gr.getAllReportsOk()); /** * Conforms table (all) */ String rows = ""; for (String iso : gr.getCheckedIsos()) { if (gr.getIsos().contains(iso) || gr.getReportsOk(iso) == gr.getReportsCount()) { rows += makeConformsRow(gr, iso, true); } } htmlBody = StringUtils.replace(htmlBody, "##TABLE_RESUME##", rows); htmlBody = StringUtils.replace(htmlBody, "##KO##", "" + gr.getAllReportsKo()); if (gr.getAllReportsOk() >= gr.getAllReportsKo()) { htmlBody = StringUtils.replace(htmlBody, "##OK_C##", "success"); htmlBody = StringUtils.replace(htmlBody, "##KO_C##", "info-white"); } else { htmlBody = StringUtils.replace(htmlBody, "##OK_C##", "info-white"); htmlBody = StringUtils.replace(htmlBody, "##KO_C##", "error"); } // Chart int angleG = globalPercent * 360 / 100; int reverseAngleG = 360 - angleG; String functionPie = ""; if (angleG > reverseAngleG) { functionPie = "plotPie('pie-global', " + angleG + ", " + reverseAngleG; if (gr.getAllReportsOk() >= gr.getAllReportsKo()) { functionPie += ", '#66CC66', '#F2F2F2'); "; } else { functionPie += ", '#F2F2F2', 'red'); "; } } else { functionPie = "plotPie('pie-global', " + reverseAngleG + ", " + angleG; if (gr.getAllReportsOk() >= gr.getAllReportsKo()) { functionPie += ", '#F2F2F2', '#66CC66'); "; } else { functionPie += ", 'red', '#F2F2F2'); "; } } pieFunctions += functionPie; // All charts calls htmlBody = StringUtils.replace(htmlBody, "##PLOT##", pieFunctions); // TO-DO htmlBody = StringUtils.replace(htmlBody, "##OK_PC##", "0"); htmlBody = StringUtils.replace(htmlBody, "##OK_EP##", "0"); // END TO-DO htmlBody = htmlBody.replaceAll("\\.\\./", ""); generator.writeToFile(outputfile, htmlBody); }
From source file:com.prowidesoftware.swift.model.field.Field35BTest.java
@Test public void testGetValue_2() { Field35B f = new Field35B(); String v = "ISIN 123456789012\nAAAA\nBBBB\nCCCC\nDDDD"; f = new Field35B(v); assertEquals(StringUtils.replace(v, "\n", FINWriterVisitor.SWIFT_EOL), f.getValue()); }
From source file:com.google.visualization.datasource.render.CsvRenderer.java
/** * Escapes a string that is written to a csv file. The escaping is as follows: * 1) surround with "./* ww w . j a v a 2s . c o m*/ * 2) double each internal ". * * @param input The input string. * * @return An escaped string. */ private static String escapeString(String input) { StringBuilder sb = new StringBuilder(); sb.append("\""); sb.append(StringUtils.replace(input, "\"", "\"\"")); sb.append("\""); return sb.toString(); }
From source file:com.adguard.compiler.SettingUtils.java
public static void updateManifestFile(File dest, Browser browser, String version, String extensionId, String updateUrl, String extensionNamePostfix) throws IOException { switch (browser) { case CHROMIUM: File manifestFile = new File(dest, "manifest.json"); String content = FileUtils.readFileToString(manifestFile, "utf-8").trim(); if (updateUrl != null) { content = StringUtils.removeEnd(content, "}").trim(); content = content + ",\r\n\r\n"; content = content + "\t\"update_url\": \"" + updateUrl + "\"\r\n}"; }//from w ww .j a v a2s . c om content = StringUtils.replace(content, "${version}", version); FileUtils.writeStringToFile(manifestFile, content); break; case SAFARI: File infoPlistFile = new File(dest, "Info.plist"); String contentInfoPlist = FileUtils.readFileToString(infoPlistFile, "utf-8"); contentInfoPlist = StringUtils.replace(contentInfoPlist, "${extensionId}", extensionId); contentInfoPlist = StringUtils.replace(contentInfoPlist, "${version}", version); contentInfoPlist = StringUtils.replace(contentInfoPlist, "${updateURL}", updateUrl != null ? updateUrl : ""); contentInfoPlist = StringUtils.replace(contentInfoPlist, "${extensionNamePostfix}", extensionNamePostfix); FileUtils.writeStringToFile(infoPlistFile, contentInfoPlist); break; case FIREFOX: case FIREFOX_LEGACY: File installRdf = new File(dest, "install.rdf"); String contentRdf = FileUtils.readFileToString(installRdf, "utf-8").trim(); //write update url link if (updateUrl == null) { updateUrl = ""; } else { updateUrl = "<em:updateURL>" + updateUrl + "</em:updateURL>"; } contentRdf = StringUtils.replace(contentRdf, "${updateUrl}", updateUrl); contentRdf = StringUtils.replace(contentRdf, "${version}", version); contentRdf = StringUtils.replace(contentRdf, "${extensionId}", extensionId); FileUtils.writeStringToFile(installRdf, contentRdf); //write version File packageJson = new File(dest, "package.json"); String contentPackageJson = FileUtils.readFileToString(packageJson); contentPackageJson = StringUtils.replace(contentPackageJson, "${version}", version); contentPackageJson = StringUtils.replace(contentPackageJson, "${extensionId}", extensionId); contentPackageJson = StringUtils.replace(contentPackageJson, "${extensionNamePostfix}", extensionNamePostfix); FileUtils.writeStringToFile(packageJson, contentPackageJson); break; } }
From source file:com.flexive.faces.javascript.FxJavascriptUtils.java
/** * Converts the given fully qualified widget name (e.g. dojo.widget.Menu2) to * the widget name used createWidget. The package prefix "flexive.widget" is converted * to the namespace prefix "flexive:".//w w w .ja v a 2 s.c o m * * @param fqn a fully qualified widget name, e.g. "dojo.widget.Menu2" * @return the widget name for dojo.widget.createWidget */ public static String getWidgetName(String fqn) { return StringUtils.replace(StringUtils.replace(fqn, "flexive.widget.", "flexive:"), "dojo.widget.", ""); }
From source file:co.marcin.novaguilds.enums.Permission.java
/** * Gets permission from string/* w ww . j a v a 2 s . c o m*/ * * @param path path * @return the permission */ public static Permission fromPath(String path) { try { return Permission.valueOf(StringUtils.replace(path, ".", "_").toUpperCase()); } catch (Exception e) { return null; } }
From source file:com.flexive.tests.embedded.jsf.bean.MessageBeanTest.java
@Test public void getMessageArgsInt() { String message = (String) messageBean.get(KEY_1 + ",42"); String expected = StringUtils.replace(MSG_1, "{0}", "42"); Assert.assertTrue(expected.equals(message), "Expected: " + expected + ", got: " + message); }
From source file:net.servicefixture.fitnesse.TestRunner.java
private String stripHtmlInfo(String testResults) { testResults = StringUtils.replace(testResults, " ", " "); StringBuilder builder = new StringBuilder(); boolean skip = false; for (int i = 0; i < testResults.length(); i++) { char c = testResults.charAt(i); switch (c) { case '<': skip = true;/* w w w .j av a2 s . c om*/ break; case '>': skip = false; break; default: if (!skip) { builder.append(c); } break; } } return builder.toString(); }
From source file:com.daveayan.rjson.utils.RjsonUtil.java
public static String escapeJsonCharactersIn(String string) { String newString = StringUtils.replace(string, "\"", ""); newString = StringUtils.replace(newString, "[", "\\["); newString = StringUtils.replace(newString, "]", "\\]"); newString = StringUtils.replace(newString, "{", "\\{"); newString = StringUtils.replace(newString, "}", "\\}"); return newString; }
From source file:com.sfs.DataFilter.java
/** * Gets the safe xml./*w w w. ja va 2s . c om*/ * * @param input the input * * @return the safe xml */ public static String getSafeXml(final String input) { String safeXML = ""; if (StringUtils.isNotBlank(input)) { // We do not want to convert these characters for this function safeXML = StringUtils.replace(input, ">", "#gt#;"); safeXML = StringUtils.replace(safeXML, "<", "#lt#;"); safeXML = StringUtils.replace(safeXML, "&", "#amp#;"); safeXML = HTMLUtil.convertCharacterEntities(safeXML); safeXML = StringUtils.replace(safeXML, "<br>", "<br/>"); // Now convert the < and > characters back to normal safeXML = StringUtils.replace(safeXML, "#gt#;", ">"); safeXML = StringUtils.replace(safeXML, "#lt#;", "<"); safeXML = StringUtils.replace(safeXML, "#amp#;", "&"); } return safeXML; }