List of usage examples for org.apache.commons.lang StringUtils replaceOnce
public static String replaceOnce(String text, String searchString, String replacement)
Replaces a String with another String inside a larger String, once.
From source file:org.ebayopensource.turmeric.eclipse.typelibrary.ui.wst.WTPCopyUtil.java
private static void updatePrefixes(Element element, Map<String, String> prefixMap) { NamedNodeMap namedNodeMap = element.getAttributes(); for (int i = 0; i < namedNodeMap.getLength(); i++) { String attrValue = namedNodeMap.item(i).getNodeValue(); String attrName = namedNodeMap.item(i).getNodeName(); for (String str : prefixMap.keySet()) { if (StringUtils.isNotEmpty(attrValue) && attrValue.trim().startsWith(str + ":")) { String trimmedAttrValue = attrValue.trim(); String newAttrValue = trimmedAttrValue; if (trimmedAttrValue.startsWith(str + ":xs:")) { newAttrValue = StringUtils.replaceOnce(trimmedAttrValue, str + ":xs:", "xs:"); } else if (StringUtils.countMatches(trimmedAttrValue, ":") == 2) { //already contains a prefix trimmedAttrValue = StringUtils.substringAfter(trimmedAttrValue, ":"); String oldPrefix = StringUtils.substringBefore(trimmedAttrValue, ":"); newAttrValue = StringUtils.replaceOnce(trimmedAttrValue, oldPrefix + ":", prefixMap.get(oldPrefix) + ":"); } else { newAttrValue = StringUtils.replaceOnce(trimmedAttrValue, str + ":", prefixMap.get(str) + ":"); }//from www . j av a 2 s .c om element.getAttributeNode(attrName).setValue(newAttrValue); } } } NodeList children = element.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child instanceof Element) updatePrefixes((Element) child, prefixMap); } }
From source file:org.ebayopensource.turmeric.eclipse.ui.AbstractSOAResourceWizardPage.java
@Override protected boolean dialogChanged() { if (super.dialogChanged() == false) return false; if (this.resourceNameText != null) { final String resourceName = getResourceName(); if (StringUtils.isBlank(resourceName)) { String resourceLabel = StringUtils.replaceOnce(resourceNameLabel.getText(), "&", SOAProjectConstants.EMPTY_STRING); if (resourceLabel.endsWith(SOAProjectConstants.DELIMITER_SEMICOLON)) resourceLabel = StringUtils.left(resourceLabel, resourceLabel.length() - 1); updateStatus(this.resourceNameText, resourceLabel + " must not be empty"); return false; }//from w w w . j ava 2 s . c om /*final InputObject inputObject = new InputObject(resourceName, RegExConstants.PROJECT_NAME_EXP, ErrorMessage.PROJECT_NAME_ERRORMSG); try { IStatus validationModel = NameValidator.getInstance().validate( inputObject); if (checkValidationResult(validationModel) == false) return false; } catch (ValidationInterruptedException e) { processException(e); }*/ if (validateName(this.resourceNameText, resourceName, RegExConstants.PROJECT_NAME_EXP, ErrorMessage.PROJECT_NAME_ERRORMSG + " The name [" + resourceName + "] is not valid against the pattern \"" + RegExConstants.PROJECT_NAME_EXP + "\"") == false) { return false; } } if (resourceVersionText != null) { if (StringUtils.isBlank(getResourceVersion())) { updateStatus(resourceVersionText, "Version must not be empty"); return false; } ServiceVersionValidator serviceVersionValidator = ServiceVersionValidator.getInstance(); try { IStatus validationModel = serviceVersionValidator.validate(getResourceVersion()); if (checkValidationResult(this.resourceVersionText, validationModel) == false) return false; } catch (ValidationInterruptedException e) { processException(e); } } return true; }
From source file:org.eclipse.che.plugin.openshift.client.kubernetes.KubernetesStringUtils.java
/** * @param containerID/*ww w. j av a 2 s .co m*/ * @return normalized version of 'ContainerID' without 'docker://' prefix and double quotes */ public static String normalizeContainerID(final String containerID) { return StringUtils.replaceOnce(containerID, DOCKER_PREFIX, "").replace("\"", ""); }
From source file:org.eclipse.che.plugin.openshift.client.OpenShiftConnector.java
/** * @param containerID// w ww .j a v a 2s . c o m * @return normalized version of 'ContainerID' without 'docker://' prefix and double quotes */ private String normalizeContainerID(final String containerID) { return StringUtils.replaceOnce(containerID, DOCKER_PREFIX, "").replace("\"", ""); }
From source file:org.eclipse.smarthome.binding.digitalstrom.internal.lib.serverconnection.impl.HttpTransportImpl.java
private String addSessionToken(String request, String sessionToken) { String correctedRequest = request; if (!correctedRequest.contains(ParameterKeys.TOKEN)) { if (correctedRequest.contains("?")) { correctedRequest = correctedRequest + "&" + ParameterKeys.TOKEN + "=" + sessionToken; } else {/* w w w.j a v a 2 s . co m*/ correctedRequest = correctedRequest + "?" + ParameterKeys.TOKEN + "=" + sessionToken; } } else { correctedRequest = StringUtils.replaceOnce(correctedRequest, StringUtils.substringBefore( StringUtils.substringAfter(correctedRequest, ParameterKeys.TOKEN + "="), "&"), sessionToken); } return correctedRequest; }
From source file:org.eclipse.smarthome.binding.homematic.internal.communicator.parser.CommonRpcParser.java
/** * Returns the address of a device, replacing group address identifier and illegal characters. */// w w w. j ava 2 s . co m protected String getSanitizedAddress(Object object) { String address = StringUtils.trimToNull(StringUtils.replaceOnce(toString(object), "*", "T-")); return MiscUtils.validateCharacters(address, "Address", "_"); }
From source file:org.exoplatform.cms.bbcode.core.BBCodeRenderer.java
String processList(String s) { int lastIndex; int tagIndex; int clsIndex; String str;//from ww w .j a v a 2 s.co m lastIndex = 0; tagIndex = 0; s = StringUtils.replace(s, "[LIST", "[list"); s = StringUtils.replace(s, "[/LIST]", "[/list]"); while ((tagIndex = s.indexOf("[list]", lastIndex)) != -1) { lastIndex = tagIndex + 1; try { clsIndex = s.indexOf("[/list]", tagIndex); str = s.substring(tagIndex + 6, clsIndex); String str_ = ""; str_ = StringUtils.replaceOnce(str, "[*]", "<li>"); str_ = StringUtils.replace(str_, "[*]", "</li><li>"); if (str_.lastIndexOf("</li><li>") > 0) { str_ = str_ + "</li>"; } if (str_.indexOf("<br/>") >= 0) { str_ = StringUtils.replace(str_, "<br/>", ""); } if (str_.indexOf("<p>") >= 0) { str_ = StringUtils.replace(str_, "<p>", ""); str_ = StringUtils.replace(str_, "</p>", ""); } s = StringUtils.replace(s, "[list]" + str + "[/list]", "<ul>" + str_ + "</ul>"); } catch (Exception e) { continue; } } lastIndex = 0; tagIndex = 0; while ((tagIndex = s.indexOf("[list=", lastIndex)) != -1) { lastIndex = tagIndex + 1; try { clsIndex = s.indexOf("[/list]", tagIndex); String content = s.substring(tagIndex + 6, clsIndex); int clsType = content.indexOf("]"); String type = content.substring(0, clsType); type = type.replaceAll("\"", "").replaceAll("'", ""); str = content.substring(clsType + 1); String str_ = ""; str_ = StringUtils.replaceOnce(str, "[*]", "<li>"); str_ = StringUtils.replace(str_, "[*]", "</li><li>"); if (str_.lastIndexOf("</li><li>") > 0) { str_ = str_ + "</li>"; } if (str_.indexOf("<br/>") >= 0) { str_ = StringUtils.replace(str_, "<br/>", ""); } if (str_.indexOf("<p>") >= 0) { str_ = StringUtils.replace(str_, "<p>", ""); str_ = StringUtils.replace(str_, "</p>", ""); } if (" 1 i I a A ".indexOf(type) > 0) { s = StringUtils.replace(s, "[list=" + content + "[/list]", "<ol type=\"" + type + "\">" + str_ + "</ol>"); } else { str_ = StringUtils.replace(str_, "<li>", "<li type=\"" + type + "\">"); s = StringUtils.replace(s, "[list=" + content + "[/list]", "<ul>" + str_ + "</ul>"); } } catch (Exception e) { continue; } } return s; }
From source file:org.exoplatform.cms.common.TransformHTML.java
public static String fixAddBBcodeAction(String b) { int tagIndex = 0; int lastIndex = 0; String start;//from w w w .j a va 2 s. c o m String end; String text_ = EMPTY_STR; StringBuilder builder = new StringBuilder(); String[] tagBBcode = new String[] { "quote", "code", "QUOTE", "CODE" }; for (int i = 0; i < tagBBcode.length; i++) { start = "[" + tagBBcode[i]; end = "[/" + tagBBcode[i] + "]"; while ((tagIndex = b.indexOf(start, lastIndex)) != -1) { lastIndex = tagIndex + 1; try { int clsIndex = b.indexOf(end, tagIndex); String text = b.substring(tagIndex, clsIndex); if (text == null || text.trim().length() == 0) continue; text_ = text; builder = new StringBuilder(); if (text.indexOf('<' + "p") > text.indexOf('<' + "/p")) { text = StringUtils.replaceOnce(text, "</p>", EMPTY_STR); int t = text.lastIndexOf('<' + "p>"); builder.append(text.substring(0, t)); if (text.length() > (t + 3)) { builder.append(text.substring(t + 3)); } } text = builder.toString(); if (text != null && text.length() > 0) { b = StringUtils.replace(b, text_, text); text_ = text; } else text = text_; builder = new StringBuilder(); if (text.indexOf('<' + "span") > text.indexOf('<' + "/span")) { text = StringUtils.replaceOnce(text, "</span>", EMPTY_STR); int t = text.lastIndexOf('<' + "span"); builder.append(text.substring(0, t)); if (text.length() > (t + 6)) { builder.append(text.substring((t + 6))); } } text = builder.toString(); if (text != null && text.length() > 0) { b = StringUtils.replace(b, text_, text); } } catch (Exception e) { continue; } } } return b; }
From source file:org.exoplatform.ecms.application.PortalResourceLifecycle.java
@Override public void onStartRequest(Application app, PortalRequestContext context) throws Exception { if (SiteType.PORTAL == context.getSiteType()) { // add current site js data String javascriptPath = StringUtils.replaceOnce(PATH, "{portalName}", context.getSiteName()); context.getJavascriptManager().addExtendedScriptURLs(context.getPortalContextPath() + javascriptPath); // add shared JS data for current site javascriptPath = StringUtils.replaceOnce(PATH, "{portalName}", "shared"); context.getJavascriptManager().addExtendedScriptURLs(context.getPortalContextPath() + javascriptPath); }// w ww .j a v a2s .c om }
From source file:org.exoplatform.forum.bbcode.core.BBCodeRenderer.java
String processList(String s) { int lastIndex; int tagIndex; int clsIndex; String str;/*from w ww .j av a2 s . c o m*/ lastIndex = 0; tagIndex = 0; s = StringUtils.replace(s, "[LIST", "[list"); s = StringUtils.replace(s, "[/LIST]", "[/list]"); while ((tagIndex = s.indexOf("[list]", lastIndex)) != -1) { lastIndex = tagIndex + 1; try { clsIndex = s.indexOf("[/list]", tagIndex); str = s.substring(tagIndex + 6, clsIndex); String str_ = ""; str_ = StringUtils.replaceOnce(str, "[*]", "<li>"); str_ = StringUtils.replace(str_, "[*]", "</li><li>"); if (str_.lastIndexOf("</li><li>") > 0) { str_ = str_ + "</li>"; } str_ = cleanHTMLTagInTagList(str_); str_ = StringUtils.replace(str_, "<li>", "<li " + getStyleList("o") + ">"); s = StringUtils.replace(s, "[list]" + str + "[/list]", "<ul>" + str_ + "</ul>"); } catch (Exception e) { continue; } } lastIndex = 0; tagIndex = 0; while ((tagIndex = s.indexOf("[list=", lastIndex)) != -1) { lastIndex = tagIndex + 1; try { clsIndex = s.indexOf("[/list]", tagIndex); String content = s.substring(tagIndex + 6, clsIndex); int clsType = content.indexOf("]"); String type = content.substring(0, clsType); type = type.replaceAll("\"", "").replaceAll("'", ""); str = content.substring(clsType + 1); String str_ = ""; str_ = StringUtils.replaceOnce(str, "[*]", "<li>"); str_ = StringUtils.replace(str_, "[*]", "</li><li>"); if (str_.lastIndexOf("</li><li>") > 0) { str_ = str_ + "</li>"; } str_ = cleanHTMLTagInTagList(str_); if (" 1 i I a A ".indexOf(type) > 0) { str_ = StringUtils.replace(str_, "<li>", "<li " + getStyleList(type) + ">"); s = StringUtils.replace(s, "[list=" + content + "[/list]", "<ol type=\"" + type + "\">" + str_ + "</ol>"); } else { str_ = StringUtils.replace(str_, "<li>", "<li style=\"list-style-type:" + type + ";\">"); s = StringUtils.replace(s, "[list=" + content + "[/list]", "<ul>" + str_ + "</ul>"); } } catch (Exception e) { continue; } } return s; }