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:net.sf.zekr.engine.server.HttpServer.java
public String toRealPath(String url) { String baseDir;// w w w . j ava2 s .com String path; if (url.startsWith(CACHED_RESOURCE)) { baseDir = (String) pathLookup.get(CACHED_RESOURCE); path = baseDir + "/" + url.substring(CACHED_RESOURCE.length()); } else if (url.startsWith(WORKSPACE_RESOURCE)) { baseDir = Naming.getWorkspace(); path = baseDir + "/" + url.substring(WORKSPACE_RESOURCE.length()); } else if (url.startsWith(BASE_RESOURCE)) { baseDir = (String) pathLookup.get(BASE_RESOURCE); path = baseDir + "/" + url.substring(BASE_RESOURCE.length()); } else if (url.startsWith(WORKSPACE_OR_BASE_RESOURCE)) { path = toRealPath(StringUtils.replace(url, WORKSPACE_OR_BASE_RESOURCE, WORKSPACE_RESOURCE)); if (!new File(path).exists()) path = toRealPath(StringUtils.replace(url, WORKSPACE_OR_BASE_RESOURCE, BASE_RESOURCE)); } else if (url.startsWith(ABSOLUTE_RESOURCE)) { path = url.substring(ABSOLUTE_RESOURCE.length()); } else { path = url; } return new File(path).getAbsolutePath(); }
From source file:com.prowidesoftware.swift.model.field.Field35BTest.java
@Test public void testGetValue_3() { Field35B f = new Field35B(); String v = "AAAA\nBBBB\nCCCC\nDDDD"; f = new Field35B(v); assertEquals(StringUtils.replace(v, "\n", FINWriterVisitor.SWIFT_EOL), f.getValue()); }
From source file:com.qpark.maven.plugin.relativeschemalocation.ToWebappSchemaLocationMojo.java
private String changeSchemaLocation(final XsdContainer xc, final Map<String, XsdContainer> map) throws IOException { HashMap<String, String> replacements = new HashMap<String, String>(); String xml = Util.readFile(xc.getFile()); String basePath = Util.getRelativePathTranslated(this.baseDirectory, xc.getFile()); this.getLog().debug(basePath); String namespace;//from www. ja v a2s. c o m String schemaLocation; XsdContainer imported; int importEndIndex; String importString = "<import"; int importLength = importString.length(); int importStartIndex = xml.indexOf(importString, 0); while (importStartIndex > 0) { importEndIndex = xml.indexOf('>', importStartIndex + importLength); if (importEndIndex < 0) { break; } namespace = Util.getAttributeValue(xml, "namespace", importStartIndex, importEndIndex); imported = map.get(namespace); if (imported != null) { schemaLocation = Util.getAttributeValue(xml, "schemaLocation", importStartIndex, importEndIndex); replacements.put( new StringBuffer(64).append("schemaLocation=\"").append(schemaLocation).append("\"") .toString(), new StringBuffer(64).append("schemaLocation=\"/").append(imported.getRelativeName()) .append("\"").toString()); } importStartIndex = xml.indexOf(importString, importEndIndex); } for (String key : replacements.keySet()) { xml = StringUtils.replace(xml, key, replacements.get(key)); } return xml; }
From source file:info.magnolia.module.delta.PropertyValuesTask.java
/** * Checks if property contains concrete string. If contains then change this part of string, logs otherwise. *///w w w. j av a 2 s . c o m protected void checkAndModifyPartOfPropertyValue(InstallContext ctx, Node node, String propertyName, String expectedValue, String newValue) throws RepositoryException { if (node.hasProperty(propertyName)) { final Property prop = node.getProperty(propertyName); final String currentvalue = prop.getString(); if (currentvalue.contains(expectedValue)) { prop.setValue(StringUtils.replace(currentvalue, expectedValue, newValue)); } else { final String msg = format( "Property \"{0}\" was expected to exist at {1} with part string \"{2}\" but does not contain this string.", propertyName, node.getPath(), expectedValue); ctx.warn(msg); } } else { final String msg = format( "Property \"{0}\" was expected to exist at {1} with part string \"{2}\" but does not exist.", propertyName, node.getPath(), expectedValue); ctx.warn(msg); } }
From source file:de.fhg.iais.commons.fs.FileSystemScanner.java
private void expandFileMask(String[] in) { if (in == null) { return;//from w w w . j a va 2s .c o m } this.patterns = new Pattern[in.length]; for (int i = 0; i < in.length; i++) { String p = in[i].toLowerCase(Locale.GERMAN); p = StringUtils.replace(p, ".", "\\."); p = StringUtils.replace(p, "?", ".?"); p = StringUtils.replace(p, "*", ".*"); this.patterns[i] = Pattern.compile(p); } }
From source file:com.voa.weixin.task.Task.java
/** * ?/*from ww w .jav a 2s . c o m*/ */ @Override public void run() { String responseStr = null; String sendMessage = ""; if (message != null) sendMessage = message.toJson(); try { url = StringUtils.replace(url, "ACCESS_TOKEN", Carp.token); generateUrl(); logger.debug("url : " + url); if (method.equals(METHOD_POST)) responseStr = HttpUtils.doHttpsPost(url, sendMessage); else responseStr = HttpUtils.doHttpsGet(url, sendMessage); logger.debug("json result : " + responseStr); WeixinResult result = new WeixinResult(); result.setJson(responseStr); callbackWork(result); } catch (Exception e) { logger.error("url error : " + url); e.printStackTrace(); throw new WorkException("url error : " + url, e); } }
From source file:edu.ku.brc.specify.toycode.FixSQLString.java
/** * //from www.j a va2s. com */ private void fixFromtextToSQL() { String srcStr = srcTA.getText(); srcStr = StringUtils.replace(srcStr, "\"", ""); srcStr = StringUtils.replace(srcStr, "+", ""); srcStr = StringUtils.replace(srcStr, ";", ""); dstTA.setText(srcStr); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { dstTA.requestFocus(); dstTA.selectAll(); UIHelper.setTextToClipboard(dstTA.getText()); } }); }
From source file:net.kamhon.ieagle.struts2.interceptor.JasperReportInterceptor.java
public String intercept(ActionInvocation actionInvocation) throws Exception { File reportFile;/* w ww. j av a 2s .c o m*/ String jasperPath = ""; String path = ""; // HttpServletRequest req = ServletActionContext.getRequest(); // path = req.getRealPath("/"); path = ServletActionContext.getServletContext().getRealPath("/"); if (actionInvocation.getAction() instanceof Action) { Action action = (Action) actionInvocation.getAction(); log.debug("action = " + action); } ActionProxy actionProxy = actionInvocation.getProxy(); log.debug("actionName() = " + actionProxy.getActionName()); if (!IS_PRODUCTION_MODE) { // Get Jasper Report Location if (actionProxy != null) { Map<String, ResultConfig> results = actionProxy.getConfig().getResults(); for (ResultConfig config : results.values()) { if (config != null) { Map<String, String> param = config.getParams(); if (StringUtils.isNotBlank(param.get("location"))) { if (StringUtils.contains(param.get("location"), "jasper")) { jasperPath = param.get("location"); log.debug("Jasper Path = " + jasperPath); break; } } } } } // Compile Jasper Report if (StringUtils.isNotBlank(jasperPath)) { jasperPath = path + jasperPath; jasperPath = StringUtils.replace(jasperPath, "/", File.separator); reportFile = new File(jasperPath); if (reportFile.exists()) { reportFile.delete(); } log.debug("Compile Jasper Report"); try { jasperPath = StringUtils.replace(jasperPath, ".jasper", ".jrxml"); JasperCompileManager.compileReportToFile(jasperPath); } catch (Exception e) { e.printStackTrace(); } } } return actionInvocation.invoke(); }
From source file:edu.ku.brc.specify.extras.FixSQLString.java
/** * /* w w w .j a v a 2 s . c o m*/ */ private void fixFromTextToSQL() { String srcStr = srcTA.getText(); srcStr = StringUtils.replace(srcStr, "\"", ""); srcStr = StringUtils.replace(srcStr, "+", ""); srcStr = StringUtils.replace(srcStr, ";", ""); while (srcStr.contains(" INNER")) { srcStr = StringUtils.replace(srcStr, " INNER", " INNER"); } while (srcStr.contains(" LEFT")) { srcStr = StringUtils.replace(srcStr, " LEFT", " LEFT"); } while (srcStr.contains(" WHERE")) { srcStr = StringUtils.replace(srcStr, " WHERE", " WHERE"); } while (srcStr.contains("\n")) { srcStr = StringUtils.replace(srcStr, " \n", ""); } dstTA.setText(srcStr); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { dstTA.requestFocus(); dstTA.selectAll(); UIHelper.setTextToClipboard(dstTA.getText()); } }); }
From source file:com.sfs.whichdoctor.export.writer.ExportWriterBase.java
/** * Gets the formatted address field.// w w w . j a v a2s . co m * * @param fieldVal the field val * * @return the formatted address field */ protected final String getFormattedAddressField(final String fieldVal) { String field = fieldVal; final String divider = keys.getString("ITEM_SUFFIX") + keys.getString("ITEM_DIVIDER") + keys.getString("ITEM_PREFIX"); int extraLines = ADDRESSFIELD_COUNT - 1; if (StringUtils.isNotBlank(field)) { extraLines = extraLines - ((field.length() - field.toLowerCase().replaceAll("<br />", "").length()) / (ADDRESSFIELD_COUNT - 2)); field = StringUtils.replace(field, "<br />", divider); } for (int x = 0; x < extraLines; x++) { field += divider; } return field; }