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

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

Introduction

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

Prototype

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

Source Link

Document

Replaces all occurrences of a String within another String.

Usage

From source file:com.google.gdt.eclipse.designer.actions.deploy.DeployModuleAction.java

/**
 * Creates build.xml file in same folder as module.
 *///w  ww .  j  a  va  2  s .  c o m
private void createBuildScript(DeployDialog deployDialog) throws Exception {
    String moduleId = m_selectedModule.getId();
    //
    IProject project = m_selectedModule.getProject();
    IFolder targetFolder = m_selectedModule.getModuleFolder();
    // prepare script
    String script = getScriptTemplate();
    // apply template values
    script = StringUtils.replace(script, "##GWT_HOME##", Utils.getGWTLocation(project));
    script = StringUtils.replace(script, "##PROJECT_ROOT##", project.getLocation().toOSString());
    script = StringUtils.replace(script, "##MODULE_ID##", moduleId);
    script = StringUtils.replace(script, "##WAR_NAME##", deployDialog.getWarName());
    script = StringUtils.replace(script, "##DEPLOY_DIR##", deployDialog.getServerPath());
    script = StringUtils.replace(script, "##COMPILER_STYLE##", deployDialog.getCompilerStyle());
    script = StringUtils.replace(script, "##COMPILER_MAX_MEMORY##", deployDialog.getCompilerMaxMemory());
    // set class path elements
    {
        String classpathElements = "";
        String[] classpath = getGWTProjectClasspath(project);
        for (int i = 0; i < classpath.length; i++) {
            String element = classpath[i].replace('\\', '/');
            classpathElements += "\t\t\t\t<pathelement location=\"" + element + "\" />";
            if (i != classpath.length - 1) {
                classpathElements += "\n";
            }
        }
        script = StringUtils.replace(script, "##CLASS_PATH_ELEMENTS##", classpathElements);
    }
    // set servlets
    {
        final StringBuffer buffer = new StringBuffer();
        ModuleVisitor.accept(m_selectedModule, new ModuleVisitor() {
            @Override
            public void endVisitModule(ModuleElement module) {
                List<ServletElement> servletElements = module.getServletElements();
                for (ServletElement servletElement : servletElements) {
                    String servletName = servletElement.getClassName();
                    {
                        buffer.append("\t<servlet>\n");
                        buffer.append("\t\t<servlet-name>" + servletName + "</servlet-name>\n");
                        buffer.append(
                                "\t\t<servlet-class>" + servletElement.getClassName() + "</servlet-class>\n");
                        buffer.append("\t</servlet>\n");
                    }
                    {
                        buffer.append("\t<servlet-mapping>\n");
                        buffer.append("\t\t<servlet-name>" + servletName + "</servlet-name>\n");
                        buffer.append("\t\t<url-pattern>" + servletElement.getPath() + "</url-pattern>\n");
                        buffer.append("\t</servlet-mapping>\n");
                    }
                }
            }
        });
        // apply sevlets
        script = StringUtils.replace(script, "##SERVLETS##", buffer.toString());
    }
    // create/copy jar's
    {
        String targetModulePath = WebUtils.getWebFolderName(project);
        String jarsScript = prepareJars(project, targetModulePath, true);
        jarsScript = StringUtils.chomp(jarsScript, "\n");
        script = StringUtils.replace(script, "<!--##PROJECT_AND_REQUIRED_JARS##-->", jarsScript);
    }
    // create build.xml
    IFile buildFile = targetFolder.getFile("build.xml");
    ByteArrayInputStream source = new ByteArrayInputStream(script.getBytes());
    if (buildFile.exists()) {
        buildFile.setContents(source, true, true, null);
    } else {
        buildFile.create(source, true, null);
    }
}

From source file:com.morty.podcast.writer.PodCastUtils.java

public static String replaceParameters(String original, Map<String, String> values) {
    //Replace the strings...
    String returnValue = original;
    Iterator it = values.keySet().iterator();
    while (it.hasNext()) {
        String key = (String) it.next();
        if (StringUtils.contains(returnValue, key) && key.startsWith("$")) {
            Object val = values.get(key);
            if (!(val instanceof String))
                val = "" + val;
            m_logger.debug("Replacing key [" + key + "] with [" + values.get(key) + "]");
            returnValue = StringUtils.replace(returnValue, key, values.get(key));
        }/*from   ww  w.j a  v  a  2 s  . c o m*/
    }
    m_logger.debug("After replacement, we have value of [" + returnValue + "]");
    return returnValue;
}

From source file:fitnesse.testsystems.slim.tables.ScenarioTable.java

public List<SlimAssertion> call(final Map<String, String> scenarioArguments, SlimTable parentTable, int row)
        throws TestExecutionException {
    Table newTable = getTable().asTemplate(new Table.CellContentSubstitution() {
        @Override/* ww w  .  j a v  a2 s.  c  om*/
        public String substitute(String content) throws SyntaxError {
            for (Map.Entry<String, String> scenarioArgument : scenarioArguments.entrySet()) {
                String arg = scenarioArgument.getKey();
                if (getInputs().contains(arg)) {
                    String argument = scenarioArguments.get(arg);
                    content = StringUtils.replace(content, "@" + arg, argument);
                    content = StringUtils.replace(content, "@{" + arg + "}", argument);
                } else {
                    throw new SyntaxError(
                            String.format("The argument %s is not an input to the scenario.", arg));
                }
            }
            return content;
        }
    });
    ScenarioTestContext testContext = new ScenarioTestContext(parentTable.getTestContext());
    ScriptTable t = createChild(testContext, parentTable, newTable);
    parentTable.addChildTable(t, row);
    List<SlimAssertion> assertions = t.getAssertions();
    assertions.add(makeAssertion(Instruction.NOOP_INSTRUCTION, new ScenarioExpectation(t, row)));
    return assertions;
}

From source file:com.liferay.sync.engine.service.persistence.SyncFilePersistence.java

public List<SyncFile> findByParentFilePathName(String parentFilePathName) throws SQLException {

    QueryBuilder<SyncFile, Long> queryBuilder = queryBuilder();

    Where<SyncFile, Long> where = queryBuilder.where();

    FileSystem fileSystem = FileSystems.getDefault();

    parentFilePathName = StringUtils.replace(parentFilePathName + fileSystem.getSeparator(), "\\", "\\\\");

    where.like("filePathName", new SelectArg(parentFilePathName + "%"));

    return where.query();
}

From source file:net.sourceforge.fenixedu.presentationTier.backBeans.base.FenixBackingBean.java

private String formatMessage(String message, final String... args) {
    if (message != null && args != null) {
        for (int i = 0; args.length > i; i++) {
            String substring = "{" + i + "}";
            message = StringUtils.replace(message, substring, args[i]);
        }/* ww  w .ja va  2 s .  c om*/
    }
    return message;
}

From source file:net.sf.click.jquery.examples.page.SourceViewer.java

private String renderVelocityKeywords(String line, String token) {
    String markupToken = renderVelocityToken(token);

    line = StringUtils.replace(line, " " + token + " ", " " + markupToken + " ");

    if (line.startsWith(token)) {
        line = markupToken + line.substring(token.length());
    }/* ww  w  .j a v a2 s .c o m*/

    if (line.endsWith(token)) {
        line = line.substring(0, line.length() - token.length()) + markupToken;
    }

    return line;
}

From source file:cc.kune.core.server.utils.XmlW.java

/**
 * Unescape xml./*from  w w  w .ja va2s  .c  o m*/
 * 
 * @param str
 *          the str
 * @return the string
 */
static public String unescapeXml(String str) {
    str = StringUtils.replace(str, "&amp;", "&");
    str = StringUtils.replace(str, "&lt;", "<");
    str = StringUtils.replace(str, "&gt;", ">");
    str = StringUtils.replace(str, "&quot;", "\"");
    str = StringUtils.replace(str, "&apos;", "'");
    return str;
}

From source file:er.extensions.components.javascript.ERXJSPopUpRelationPicker.java

protected void updateVarNames() {
    String elementID = context().elementID();
    elementID = StringUtils.replace(elementID, ".", "_");
    pickerName = "picker_" + elementID;
    parentSelectName = "parent_" + elementID;
    childSelectName = "child_" + elementID;
    objectsArrayName = "parents_children_" + elementID;
}

From source file:com.vmware.appfactory.common.VelocityMultipleLayoutAndToolsViewResolver.java

/**
 * Compiles a "user regex" into a Java regex Pattern.
 *
 * The only thing different between a "user regex" and a java
 * standard one is that a user regex expects:
 *    *//from   ww w  . ja  v  a2 s. c  o m
 * instead of
 *    .*
 *
 * e.g. a user would enter
 *        /admin/*
 *      rather than
 *        /admin/.*
 *
 * If the user input is empty or null, a pattern representing
 * ".*" (stored in wildcardPattern) is returned.
 *
 * @param input
 * @return
 */
public static Pattern compileUserRegex(String input) {
    if (null == input) {
        return wildcardPattern;
    }
    String mappingRegex = StringUtils.replace(input, "*", ".*");
    return Pattern.compile(mappingRegex);
}

From source file:com.sun.socialsite.util.UtilitiesModel.java

public static String replace(String src, String target, String rWith) {
    return StringUtils.replace(src, target, rWith);
}