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.sk89q.craftbook.mech.area.CopyManager.java
/** * Checks if the area and namespace exists. * * @param namespace to check//from www. j ava 2s.c o m * @param area to check */ public static boolean isExistingArea(File dataFolder, String namespace, String area) { area = StringUtils.replace(area, "-", "") + getFileSuffix(); File file = new File(dataFolder, "areas/" + namespace); return new File(file, area).exists(); }
From source file:edu.cornell.med.icb.goby.util.LoggingOutputStream.java
/** * Replace __OUTPUT_TAG__ in prefix with this output tag. * @param outputTag the tag to put in the prefix (if the prefix contains "__OUTPUT_TAG__") *///from w w w . ja v a 2 s . co m final void setOutputTag(final String outputTag) { if (prefixStr == null) { return; } final String newPrefixStr = StringUtils.replace(prefixStr, "__OUTPUT_TAG__", outputTag); this.prefix = newPrefixStr.getBytes(); }
From source file:com.sfs.whichdoctor.beans.AgedDebtorsAnalysisBean.java
/** * Sets the parameters for the aged debtors analysis. * * @param asAtDateVal the as at date//w ww. ja v a 2s . c o m * @param periodLengthVal the period length * @param numberOfPeriodsVal the number of periods * @param showZeroBalancesVal the boolean whether to show zero balances */ public final void setParameters(final Date asAtDateVal, final String periodLengthVal, final int numberOfPeriodsVal, final boolean showZeroBalancesVal) { this.asAtDate = new Date(asAtDateVal.getTime()); this.periodLength = StringUtils.replace(periodLengthVal, " ", "").toLowerCase(); this.numberOfPeriods = numberOfPeriodsVal; this.showZeroBalances = showZeroBalancesVal; this.periods = constructPeriods(); }
From source file:com.runstate.util.XmlW.java
static public String unescapeXml(String str) { str = StringUtils.replace(str, "&", "&"); str = StringUtils.replace(str, "<", "<"); str = StringUtils.replace(str, ">", ">"); str = StringUtils.replace(str, """, "\""); str = StringUtils.replace(str, "'", "'"); return str;/*from w w w . j a va2s.c om*/ }
From source file:com.sfs.whichdoctor.beans.IsbMessageBean.java
/** * Try parsing the XML document and setting the relevant ISB message * attributes e.g. Source, Target, Identifier, Action, XmlPayload * * @param xmlPayloadVal the xml payload/*from ww w. ja v a 2 s .c om*/ * * @throws JDOMException the JDOM exception */ public final void parseXmlPayload(final String xmlPayloadVal) throws JDOMException { // Ensure there are no "& " characters String xmlPayload = StringUtils.replace(xmlPayloadVal, ">", "|gt;"); xmlPayload = StringUtils.replace(xmlPayload, "<", "|lt;"); xmlPayload = StringUtils.replace(xmlPayload, "&", "|amp;"); // Replace the & characters left xmlPayload = StringUtils.replace(xmlPayload, "&", "&"); // Bring the special characters back xmlPayload = StringUtils.replace(xmlPayload, "|gt;", ">"); xmlPayload = StringUtils.replace(xmlPayload, "|lt;", "<"); xmlPayload = StringUtils.replace(xmlPayload, "|amp;", "&"); if (xmlPayload.startsWith("<?xml ")) { xmlPayload = StringUtils.replace(xmlPayload, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", ""); } // Parse the ISB XML document to get the identifier final SAXBuilder saxBuilder = new SAXBuilder("org.apache.xerces.parsers.SAXParser"); final Reader stringReader = new StringReader(xmlPayload); Document isbDocument = null; try { isbDocument = saxBuilder.build(stringReader); } catch (JDOMException e) { // Error parsing the XML document throw new JDOMException("Error parsing XML into IsbMessageBean: " + e.getMessage() + "\n" + xmlPayload); } catch (IOException e) { // Error parsing the XML document throw new JDOMException("Error reading xmlPayload string: " + e.getMessage()); } if (isbDocument != null) { // Get the ISB source for this change try { this.setSource(isbDocument.getRootElement().getAttribute("source").getValue()); } catch (NullPointerException npe) { throw new JDOMException("The source element does not exist"); } // Get the ISB target of this change try { this.setTarget(isbDocument.getRootElement().getAttribute("target").getValue()); } catch (NullPointerException npe) { throw new JDOMException("The target element does not exist"); } Element isbIdentityElement = isbDocument.getRootElement().getChild("identity"); if (isbIdentityElement != null) { // Get the ISB identifier of this change try { this.setIdentifier(isbIdentityElement.getAttribute("id").getValue()); } catch (NullPointerException npe) { throw new JDOMException("The id element does not exist"); } // Get the ISB action of this change try { this.setAction(isbIdentityElement.getAttribute("action").getValue()); } catch (NullPointerException npe) { throw new JDOMException("The action element does not exist"); } } XMLOutputter outputter = new XMLOutputter(); outputter.setFormat(Format.getPrettyFormat()); if (isbPayload == null) { isbPayload = new IsbPayloadBean(); } isbPayload.setXmlPayload(outputter.outputString(isbDocument)); } else { throw new JDOMException("The parsed ISB XML document was null"); } }
From source file:com.opengamma.web.position.WebPositionResource.java
@PUT @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Produces(MediaType.TEXT_HTML)/*from ww w. j av a 2s .com*/ public Response putHTML(@FormParam("quantity") String quantityStr) { PositionDocument doc = data().getPosition(); if (doc.isLatest() == false) { return Response.status(Status.FORBIDDEN).entity(getHTML()).build(); } quantityStr = StringUtils.replace(StringUtils.trimToNull(quantityStr), ",", ""); BigDecimal quantity = quantityStr != null && NumberUtils.isNumber(quantityStr) ? new BigDecimal(quantityStr) : null; if (quantity == null) { FlexiBean out = createRootData(); if (quantityStr == null) { out.put("err_quantityMissing", true); } else { out.put("err_quantityNotNumeric", true); } String html = getFreemarker().build(HTML_DIR + "position-update.ftl", out); return Response.ok(html).build(); } URI uri = updatePosition(doc, quantity, null); return Response.seeOther(uri).build(); }
From source file:info.magnolia.module.delta.BootstrapConditionally.java
private static String determinePath(String filename) { String withoutExtensionAndRepository = StringUtils.substringAfter(cleanupFilename(filename), "."); String path = StringUtils.replace(withoutExtensionAndRepository, ".", "/"); return (StringUtils.isEmpty(path) ? "/" : "/" + path); }
From source file:com.sfs.whichdoctor.formatter.GroupFormatter.java
public static String getField(final GroupBean group, final Object object, final String section, final String field, final String format) { String value = ""; if (section == null) { return value; }//from www. ja v a 2 s .c o m if (field == null) { return value; } if (field.compareTo("GUID") == 0) { value = String.valueOf(group.getGUID()); } if (field.compareTo("Group Name") == 0) { value = group.getName(); } if (field.compareTo("Group Type") == 0) { value = group.getType(); } if (section.compareTo("Items") == 0) { ItemBean item = (ItemBean) object; if (field.compareTo("Item Name") == 0) { value = item.getName(); } if (field.compareTo("Item Title") == 0) { value = item.getTitle(); } if (field.compareTo("Item Comment") == 0) { value = StringUtils.replace(item.getComment(), "\n", "<br />"); } if (field.compareTo("Item Weighting") == 0) { value = String.valueOf(item.getWeighting()); } if (field.compareTo("Item Start") == 0) { value = Formatter.conventionalDate(item.getStartDate()); } if (field.compareTo("Item End") == 0) { value = Formatter.conventionalDate(item.getEndDate()); } } if (section.compareTo("Memos") == 0) { MemoBean memo = (MemoBean) object; if (field.compareTo("Type") == 0) { value = memo.getType(); } if (field.compareTo("Date Created") == 0) { value = Formatter.conventionalDate(memo.getCreatedDate()); } if (field.compareTo("Date Expires") == 0) { value = Formatter.conventionalDate(memo.getExpires()); } if (field.compareTo("Message") == 0) { value = memo.getMessage(); } } if (value == null) { value = ""; } return value; }
From source file:er.extensions.components.ERXErrorDictionaryPanel.java
public static String massageErrorMessage(String initialMessage, String displayErrorKey) { String result = StringUtils.replace(initialMessage, "EOValidationException:", ""); if (displayErrorKey != null) { result = StringUtils.replace(result, ERXEnterpriseObject.KEY_MARKER, displayErrorKey); }/* w w w.j a v a 2 s.c o m*/ if (result != null) { if (result.endsWith("is not allowed to be null.") || (result.startsWith(" The ") && result.indexOf(" property ") != -1 && result.indexOf(" must have a ") != -1 && result.endsWith(" assigned"))) { char c; if (displayErrorKey == null) { result = result.substring(result.indexOf("'") + 1, result.indexOf("is not allowed to be null.") - 2); c = result.charAt(0); } else { result = displayErrorKey; c = result.toLowerCase().charAt(0); } String article = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') ? "an" : "a"; result = "Please provide " + article + " <b>" + result + "</b>."; } else if (result.indexOf(": Invalid number") != -1) { int colon = result.indexOf(':'); result = "<b>" + (displayErrorKey == null ? result.substring(0, colon - 1) : displayErrorKey); result += "</b>: I could not understand the number you typed."; } else if (result.indexOf(eliminable) > 0) { result = result.substring(eliminable.length() + 1, result.length()); } if (result.indexOf(couldNotSave) > 0) { String replace = (String) ERXLocalizer.currentLocalizer().valueForKey(couldNotSave); if (replace != null) result = replace + result.substring(couldNotSave.length() + 1, result.length()); } } return result; }
From source file:com.fengduo.bee.commons.util.ObjectUtils.java
/** * string?trim?/*w w w.ja v a2s . c o m*/ * * @param object * @throws Exception */ @SuppressWarnings({ "unchecked", "rawtypes" }) private static void trimStringField(Object object, Class<?> clazz) throws Exception { if (object instanceof Map<?, ?>) { Map<Object, Object> target = new HashMap<Object, Object>(); for (Entry<?, ?> entry : ((Map<?, ?>) object).entrySet()) { Object key = entry.getKey(); Object value = entry.getValue(); if (key instanceof String) { key = StringUtils.trim((String) key); } else { trim(key); } if (value instanceof String) { value = StringUtils.trim((String) value); value = StringUtils.replace((String) value, "\"", StringUtils.EMPTY); } else { trim(value); } target.put(key, value); } ((Map<?, ?>) object).clear(); ((Map) object).putAll((Map) target); return; } Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { if (field.getType() == String.class) { boolean isFoolback = false; if (field.isAccessible() == false) { isFoolback = true; field.setAccessible(true); } String value = (String) field.get(object); if (StringUtils.isNotEmpty(value)) { value = value.trim(); field.set(object, value); } if (isFoolback) { field.setAccessible(false); } } } }