Example usage for org.apache.commons.lang3 StringUtils replace

List of usage examples for org.apache.commons.lang3 StringUtils replace

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils replace.

Prototype

public static String replace(final String text, final String searchString, final String replacement) 

Source Link

Document

Replaces all occurrences of a String within another String.

A null reference passed to this method is a no-op.

 StringUtils.replace(null, *, *)        = null StringUtils.replace("", *, *)          = "" StringUtils.replace("any", null, *)    = "any" StringUtils.replace("any", *, null)    = "any" StringUtils.replace("any", "", *)      = "any" StringUtils.replace("aba", "a", null)  = "aba" StringUtils.replace("aba", "a", "")    = "b" StringUtils.replace("aba", "a", "z")   = "zbz" 

Usage

From source file:de.micromata.genome.gwiki.page.search.IndexTextFilesContentSearcher.java

public static String reworkRawTextForPreview(String str) {
    str = WebUtils.escapeHtml(str);/*w  ww.ja  va  2  s.  co m*/
    str = StringUtils.replace(str, "\n", "<br/>\n");
    return str;
}

From source file:com.callidusrobotics.object.actor.AbstractActor.java

public Item makeCorpse() {
    // TODO: Refactor this to use the item factory?
    final String identifier = StringUtils.replace(name, "\\s+", "_") + "_corpse";
    return new Item(identifier, new ConsoleGraphic('%', getForeground(), getBackground()), 1,
            new InventoriableData(name + " Corpse", "The remains of a " + name + ".", false),
            new UseableData(false, false, -1, null, null, null, null), new EquipableData(0, 0, null, null));
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleDeclaration2Test.java

/**
 * @throws Exception if the test fails/*from w w  w . j av a2 s  . c  o  m*/
 */
@Test
public void properties() throws Exception {
    final String expected = loadExpectation("CSSStyleDeclaration2Test.properties", ".txt");

    final String html = "<html>\n" + "<head><title>Tester</title>\n" + "<script>\n" + "function test() {\n"
            + "  var style = document.getElementById('myDiv').style;\n" + "  var array = [];\n"
            + "  for (var i in style) {\n" + "    try {\n"
            + "      if (eval('style.' + i) == '') { array.push(i); }\n" + "    } catch(e) {}\n" // ignore strange properties like '@@iterator'
            + "  }\n" + "  array.sort();\n"
            + "  document.getElementById('myTextarea').value = array.join('\\n');\n" + "}\n"
            + "</script></head>\n" + "<body onload='test()'>\n" + "  <div id='myDiv'><br></div>\n"
            + "  <textarea id='myTextarea' cols='120' rows='20'></textarea>\n" + "</body></html>";

    final WebDriver driver = loadPage2(html);

    String actual = driver.findElement(By.id("myTextarea")).getAttribute("value");
    actual = StringUtils.replace(actual, "\r\n", "\n");
    assertEquals(expected, actual);
}

From source file:com.utdallas.s3lab.smvhunter.enumerate.UIEnumerator.java

private static String getStringFromViewNode(ViewNode node) {
    String temp = getProperty("text:mText", node);
    System.out.println(temp);//from   w ww .  j a  v a2  s .  com
    return StringUtils.replace(getProperty("text:mText", node), "f)", "");
}

From source file:de.micromata.genome.gdbfs.StdFileSystem.java

/**
 * List files.// w  w  w.j av a 2s  . co  m
 *
 * @param absRootName the abs root name
 * @param f the f
 * @param matcher the matcher
 * @param searchType the search type
 * @param ret the ret
 * @param recursive the recursive
 */
protected void listFiles(String absRootName, File f, Matcher<String> matcher, final Character searchType,
        List<FsObject> ret, boolean recursive) {

    File[] files = f.listFiles();
    if (files == null) {
        return;
    }
    for (File el : files) {
        if (isSystemFile(el) == true) {
            continue;
        }
        boolean matches = true;
        if (matcher != null) {
            String tb = canonPath(el);
            String relp = tb.substring(absRootName.length());
            relp = StringUtils.replace(relp, "\\", "/");
            if (relp.startsWith("/") == true) {
                relp = relp.substring(1);
            }
            if (matcher.match(relp) == false) {
                matches = false;
            }
        }
        if (el.isDirectory() == true) {
            if (matches == true && (searchType == null || searchType == 'D')) {
                ret.add(fileToFsObject(el));
            }
            if (recursive == true) {
                listFiles(absRootName, el, matcher, searchType, ret, recursive);
            }
        } else if (el.isFile() == true) {
            if (matches == true && (searchType == null || searchType == 'F')) {
                ret.add(fileToFsObject(el));
            }
        }
    }
}

From source file:info.magnolia.security.app.dialog.action.SaveRoleDialogAction.java

/**
 * Validates the ACLs present in the dialog. The validation is done on the JcrNodeAdapter because we have to validate
 * before calling applyChanges. applyChanges() modifies the adapter and it needs to be untouched when validation
 * fails because it is then still used in the dialog.
 *///from   w  w w  . j  a  v  a  2  s  .  c om
private boolean validateAccessControlLists(JcrNodeAdapter roleItem) throws ActionExecutionException {

    if (MgnlContext.getUser().hasRole(AccessDefinition.DEFAULT_SUPERUSER_ROLE)) {
        return true;
    }

    try {
        if (roleItem instanceof JcrNewNodeAdapter) {
            Node parentNode = roleItem.getJcrItem();

            // Make sure this user is allowed to add a role here, the role manager would happily do it and then we'd fail to read the node
            parentNode.getSession().checkPermission(parentNode.getPath(), Session.ACTION_ADD_NODE);
        }

        for (AbstractJcrNodeAdapter aclItem : roleItem.getChildren().values()) {

            String aclNodeName = aclItem.getNodeName();

            if (aclNodeName.startsWith("acl_")) {

                if (aclItem.getItemProperty(
                        WorkspaceAccessFieldFactory.INTERMEDIARY_FORMAT_PROPERTY_NAME) != null) {

                    // This is an ACL added using WorkspaceAccessFieldFactory

                    for (AbstractJcrNodeAdapter entryItem : aclItem.getChildren().values()) {

                        String path = (String) entryItem.getItemProperty(AccessControlList.PATH_PROPERTY_NAME)
                                .getValue();
                        long accessType = (Long) entryItem
                                .getItemProperty(WorkspaceAccessFieldFactory.ACCESS_TYPE_PROPERTY_NAME)
                                .getValue();
                        long permissions = (Long) entryItem
                                .getItemProperty(AccessControlList.PERMISSIONS_PROPERTY_NAME).getValue();

                        String workspaceName = StringUtils.replace(aclItem.getNodeName(), "acl_", "");

                        if (!isCurrentUserEntitledToGrantRights(workspaceName, path, accessType, permissions)) {
                            throw new ActionExecutionException(
                                    "Access violation: could not create role. Have you the necessary grants to create such a role?");
                        }
                    }
                } else if (aclNodeName.equals("acl_uri")) {

                    // This is an ACL added using WebAccessFieldFactory

                    for (AbstractJcrNodeAdapter entryItem : aclItem.getChildren().values()) {

                        String path = (String) entryItem.getItemProperty(AccessControlList.PATH_PROPERTY_NAME)
                                .getValue();
                        long permissions = (Long) entryItem
                                .getItemProperty(AccessControlList.PERMISSIONS_PROPERTY_NAME).getValue();

                        if (!isCurrentUserEntitledToGrantUriRights(path, permissions)) {
                            throw new ActionExecutionException(
                                    "Access violation: could not create role. Have you the necessary grants to create such a role?");
                        }
                    }
                }
            }
        }

        return true;

    } catch (AccessControlException e) {
        throw new ActionExecutionException(e);
    } catch (RepositoryException e) {
        throw new ActionExecutionException(e);
    }
}

From source file:com.sonicle.webtop.core.app.ContextLoader.java

private String expandLogDirVariables(String logDir, String webappFullName) {
    if (logDir == null)
        return logDir;
    String s = StringUtils.replace(logDir, "${WEBAPP_FULLNAME}", webappFullName);
    s = StringUtils.replace(s, "${WEBAPP_NAME}", ContextUtils.stripWebappVersion(webappFullName));
    return s;//www. ja v a 2  s  .c  o  m
}

From source file:de.blizzy.documentr.search.PageIndex.java

private String replaceHtmlEntities(String html) {
    for (;;) {// w w w. j a va  2s  .c om
        int pos = html.indexOf('&');
        if (pos < 0) {
            break;
        }
        int endPos = html.indexOf(';', pos + 1);
        if (endPos < 0) {
            break;
        }
        String entityName = html.substring(pos + 1, endPos);
        int c = HTMLEntities.get(entityName);
        html = StringUtils.replace(html, "&" + entityName + ";", //$NON-NLS-1$ //$NON-NLS-2$
                (c >= 0) ? String.valueOf((char) c) : StringUtils.EMPTY);
    }
    return html;
}

From source file:com.sk89q.craftbook.sponge.mechanics.area.complex.ComplexArea.java

public boolean triggerMechanic(Location<World> location, Sign sign, Boolean forceState) {
    boolean save = "[SaveArea]".equals(SignUtil.getTextRaw(sign, 1));

    String namespace = sign.get(CraftBookKeys.NAMESPACE).orElse(null);
    String id = StringUtils.replace(SignUtil.getTextRaw(sign, 2), "-", "").toLowerCase();
    String inactiveID = StringUtils.replace(SignUtil.getTextRaw(sign, 3), "-", "").toLowerCase();

    if (namespace == null) {
        return false;
    }/*from  ww  w.j  a v  a  2  s. c  o  m*/

    try {
        CuboidCopy copy;

        boolean state = checkToggleState(sign);
        if (forceState != null) {
            state = forceState;
        }

        if (state) {
            copy = CopyManager.load(location.getExtent(), namespace, id);

            if (save) {
                copy.copy();
                CopyManager.save(namespace, id, copy);
            }

            if (!inactiveID.isEmpty() && !"--".equals(inactiveID)) {
                copy = CopyManager.load(location.getExtent(), namespace, inactiveID);
                copy.paste();
            } else {
                copy.clear();
            }

            setToggleState(sign, false);
        } else {
            if (save && !inactiveID.isEmpty() && !"--".equals(inactiveID)) {
                copy = CopyManager.load(location.getExtent(), namespace, inactiveID);
                copy.copy();
                CopyManager.save(namespace, inactiveID, copy);
            }

            copy = CopyManager.load(location.getExtent(), namespace, id);
            copy.paste();
            setToggleState(sign, true);
        }

        return true;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return false;
}

From source file:io.wcm.devops.maven.nodejsproxy.resource.MavenProxyResource.java

private String buildBinaryUrl(ArtifactType artifactType, String version, String os, String arch, String type) {
    String url;/*ww w  .  j av  a  2s  .  co  m*/
    switch (artifactType) {
    case NODEJS:
        if (StringUtils.equals(os, "windows")) {
            if (isVersion4Up(version)) {
                url = config.getNodeJsBinariesUrlWindows();
            } else if (StringUtils.equals(arch, "x86")) {
                url = config.getNodeJsBinariesUrlWindowsX86Legacy();
            } else {
                url = config.getNodeJsBinariesUrlWindowsX64Legacy();
            }
        } else {
            url = config.getNodeJsBinariesUrl();
        }
        break;
    case NPM:
        url = config.getNpmBinariesUrl();
        break;
    default:
        throw new IllegalArgumentException("Illegal artifact type: " + artifactType);
    }
    url = config.getNodeJsBinariesRootUrl() + url;
    url = StringUtils.replace(url, "${version}", StringUtils.defaultString(version));
    url = StringUtils.replace(url, "${os}", StringUtils.defaultString(os));
    url = StringUtils.replace(url, "${arch}", StringUtils.defaultString(arch));
    url = StringUtils.replace(url, "${type}", StringUtils.defaultString(type));
    return url;
}