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:com.hs.mail.imap.message.responder.AbstractImapResponder.java
protected void quote(String message) { message("\"" + StringUtils.replace(message, "\"", "\\\"") + "\""); }
From source file:com.opengamma.web.position.WebPositionResource.java
@PUT @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Produces(MediaType.APPLICATION_JSON)/*from ww w . j av a 2 s.c om*/ public Response putJSON(@FormParam("quantity") String quantityStr, @FormParam("tradesJson") String tradesJson) { PositionDocument doc = data().getPosition(); if (doc.isLatest() == false) { return Response.status(Status.FORBIDDEN).entity(getHTML()).build(); } quantityStr = StringUtils.replace(StringUtils.trimToNull(quantityStr), ",", ""); tradesJson = StringUtils.trimToNull(tradesJson); Collection<ManageableTrade> trades = null; if (tradesJson != null) { trades = parseTrades(tradesJson); } else { trades = Collections.<ManageableTrade>emptyList(); } BigDecimal quantity = quantityStr != null && NumberUtils.isNumber(quantityStr) ? new BigDecimal(quantityStr) : null; updatePosition(doc, quantity, trades); return Response.ok().build(); }
From source file:com.daveayan.rjson.utils.RjsonUtil.java
public static String unEscapeJsonCharactersIn(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.ecyrd.jspwiki.url.SilverpeasURLConstructor.java
/** * URLEncoder returns pluses, when we want to have the percent encoding. See * http://issues.apache.org/bugzilla/show_bug.cgi?id=39278 for more info. We also convert any * %2F's back to slashes to make nicer-looking URLs. *///w w w . j a v a 2 s. c o m private final String encodeURIWithPercent(String uri) { uri = m_engine.encodeName(uri); uri = StringUtils.replace(uri, "+", "%20"); uri = StringUtils.replace(uri, "%2F", "/"); return uri; }
From source file:de.iritgo.nexim.tools.XStreamStore.java
private void saveMap(Map map) { String xstreamData = xstream.toXML(map); if (substituteFrom != null && substituteTo != null) { xstreamData = StringUtils.replace(xstreamData, substituteFrom, substituteTo); }//w w w . j a va 2s. c om xstreamData = xmlProlog + "\n" + xstreamData; //getLogger().info("saving roster " + xstreamData); FileOutputStream fos = null; try { fos = new FileOutputStream(file); fos.write(xstreamData.getBytes()); } catch (IOException e) { getLogger().error(e.getMessage(), e); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { getLogger().error(e.getMessage()); } } } }
From source file:com.qpark.maven.plugin.relativeschemalocation.ToRelativeSchemaLocationMojo.java
/** * @see org.apache.maven.plugin.Mojo#execute() *//*w ww. j a v a 2 s . c om*/ @Override public void execute() throws MojoExecutionException, MojoFailureException { StaticLoggerBinder.getSingleton().setLog(this.getLog()); this.getLog().debug("+execute"); this.getLog().debug("get xsds"); Map<String, XsdContainer> map = XsdsUtil.getXsdContainers(this.baseDirectory); HashMap<String, String> replacements = new HashMap<String, String>(); for (XsdContainer xc : map.values()) { replacements.clear(); try { String xml = Util.readFile(xc.getFile()); String basePath = Util.getRelativePathTranslated(this.baseDirectory, xc.getFile()); this.getLog().debug(basePath); String backPath = this.getBackPath(basePath); String xsdPath; String newPath; int index = xml.indexOf("schemaLocation=\"http", 0); int quoteIndex; while (index > 0) { quoteIndex = xml.indexOf('"', index + 16); if (quoteIndex < 0) { break; } xsdPath = xml.substring(index + 16, quoteIndex); newPath = this.getNewPath(xsdPath, backPath, map.values()); if (newPath != null) { this.getLog().debug(new StringBuffer(xsdPath.length() + 5 + newPath.length()) .append(xsdPath).append(" => ").append(newPath).toString()); replacements.put(xsdPath, newPath); } index = xml.indexOf("schemaLocation=\"http", quoteIndex); } for (String key : replacements.keySet()) { xml = StringUtils.replace(xml, key, replacements.get(key)); } File f = Util.getFile(this.outputDirectory, basePath); this.getLog().info(new StringBuffer().append("Write ").append(f.getAbsolutePath())); Util.writeToFile(f, xml); } catch (IOException e) { this.getLog().error(e.getMessage()); e.printStackTrace(); } } this.getLog().debug("-execute"); }
From source file:me.eccentric_nz.plugins.FatPort.FatPortCmdUtils.java
public String getCommand(int pid, String name) { String command = ""; try {//from ww w . ja va 2 s. c om Connection connection = service.getConnection(); Statement statement = connection.createStatement(); String queryCmd = "SELECT * FROM commands WHERE p_id = " + pid + " ORDER BY RANDOM()"; ResultSet rsCmd = statement.executeQuery(queryCmd); String tmp = rsCmd.getString("command"); portCommand.put(name, rsCmd.getInt("c_id")); command = StringUtils.replace(tmp, "@p", name); rsCmd.close(); statement.close(); } catch (SQLException e) { plugin.debug("Could not get command! " + e); } return command; }
From source file:gool.generator.cpp.CppCodePrinter.java
@Override public List<File> print(ClassDef pclass) throws FileNotFoundException { // GOOL library classes are printed in a different manner if (pclass.isGoolLibraryClass()) { return printGoolLibraryClass(pclass); }// ww w. j a v a 2 s. c om /* * In C++ the parent class and the interfaces are used in the same * statement. Example: class Foo : public ClassBar1, InterfaceBar2 ... * {} */ if (pclass.getParentClass() != null) { pclass.getInterfaces().add(0, pclass.getParentClass()); } String headerFile = processTemplate("header.vm", pclass); PrintWriter writer; File dir = new File(getOutputDir().getAbsolutePath(), StringUtils.replace(pclass.getPackageName(), ".", File.separator)); dir.mkdirs(); File classFile = new File(dir, pclass.getName() + ".h"); writer = new PrintWriter(classFile); writer.println(headerFile); writer.close(); /* * Only generate header files if this element is an interface or an * enumeration. */ if (pclass.isEnum() || pclass.isInterface()) { List<File> r = new ArrayList<File>(); r.add(classFile); return r; } else { return super.print(pclass); } }
From source file:ams.fwk.customtag.AmsDownloadTag.java
/** * @return int//from ww w .ja va 2 s.c om * @throws JspException */ public int doEndTag() throws JspException { String context = getContextPath(pageContext); try { List uploads = getUploads(); JspWriter out = pageContext.getOut(); out.print(listOpen); for (Iterator all = uploads.iterator(); all.hasNext();) { Map each = (Map) all.next(); if ("IMG".equals(typeId)) { String temp = StringUtils.replace(imgTag, "$context$", context); temp = StringUtils.replace(temp, "$programId$", (String) each.get("PROGRAM_ID")); temp = StringUtils.replace(temp, "$fileSeqNo$", fileSeqNo); temp = StringUtils.replace(temp, "$fileId$", (String) each.get("FILE_ID")); out.print(temp); } else if ("URL".equals(typeId)) { String temp = StringUtils.replace(urlTag, "$context$", context); temp = StringUtils.replace(temp, "$programId$", (String) each.get("PROGRAM_ID")); temp = StringUtils.replace(temp, "$fileSeqNo$", fileSeqNo); temp = StringUtils.replace(temp, "$fileId$", (String) each.get("FILE_ID")); out.print(temp); } else { // ("N/A".equals(typeId) || typeId.equals(each.get("TYPE_ID"))) { String temp = ""; if ("N".equals(deleteOption)) { temp = StringUtils.replace(listItem, "$deleteImgTag$", ""); } else { temp = StringUtils.replace(listItem, "$deleteImgTag$", deleteImgTag); } temp = StringUtils.replace(temp, "$context$", context); temp = StringUtils.replace(temp, "$programId$", (String) each.get("PROGRAM_ID")); temp = StringUtils.replace(temp, "$fileSeqNo$", fileSeqNo); temp = StringUtils.replace(temp, "$fileId$", (String) each.get("FILE_ID")); temp = StringUtils.replace(temp, "$filename$", (String) each.get("FILE_NAME")); temp = StringUtils.replace(temp, "$filesize$", nexcore.framework.core.util.StringUtils .formatNumber(((BigDecimal) each.get("FILE_SIZE")).toString(), "FINT")); out.print(temp); } } out.print(listClose); return EVAL_PAGE; } catch (IOException e) { e.printStackTrace(); throw new JspException(e); } finally { typeId = "N/A"; } }
From source file:com.mmj.app.biz.service.impl.FileServiceImpl.java
@Override public Result saveFileByPath(String filePath, IFileHandle... ihandle) { if (StringUtils.isEmpty(filePath)) { return Result.failed(); }/*from w w w. ja v a 2 s . com*/ filePath = StringUtils.replace(filePath, STATIC_TMP_IMG, StringUtils.EMPTY); File file = new File(UPLOAD_TMP_PATH + filePath); if (file == null || file.isFile()) { try { String path = ihandle[0].parse(UPLOAD_BASE_PATH, filePath); FileUtils.copyFile(file, new File(path)); return Result.success(null, STATIC_BASE_IMG + path.replaceAll(UPLOAD_BASE_PATH, "")); } catch (Exception e) { logger.error(e.getMessage()); return Result.failed(); } } return Result.failed(); }