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.core.wizards.ProjectWizardTest.java

public void test_for20() throws Exception {
    Activator.getStore().setValue(Constants.P_GWT_LOCATION, GTestUtils.getLocation_20());
    ProjectWizard.configureProjectAsGWTProject(m_javaProject);
    assertTrue(Utils.isGWTProject(m_javaProject));
    {//from  w  w  w  .j av a 2s  . c o m
        String classPath = getFileContent(".classpath");
        classPath = StringUtils.replace(classPath, "\r\n", "\n");
        assertEquals(
                getSourceDQ(new String[] { "<?xml version='1.0' encoding='UTF-8'?>", "<classpath>",
                        "  <classpathentry kind='con' path='org.eclipse.jdt.launching.JRE_CONTAINER'/>",
                        "  <classpathentry kind='src' path='src'/>",
                        "  <classpathentry kind='var' path='GWT_HOME/gwt-user.jar'/>",
                        "  <classpathentry kind='output' path='war/WEB-INF/classes'/>", "</classpath>" }),
                classPath);
    }
    assertTrue(getFolder0("war").exists());
    assertTrue(getFolder0("war/WEB-INF").exists());
    assertTrue(getFolder0("war/WEB-INF/classes").exists());
    assertTrue(getFolder0("war/WEB-INF/lib").exists());
    assertTrue(getFile("war/WEB-INF/lib/gwt-servlet.jar").exists());
}

From source file:com.ctc.storefront.web.wrappers.UrlEncodeHttpRequestWrapper.java

@Override
public String getServletPath() {
    final String originalServletPath = super.getServletPath();
    if ("/".equals(originalServletPath) || ("/" + pattern).equals(originalServletPath)
            || ("/" + pattern + "/").equals(originalServletPath)) {
        return "";
    } else if (urlPatternChecker(originalServletPath, pattern)) {
        return StringUtils.replace(originalServletPath, "/" + pattern + "/", "/");
    }//from  w w w . j av  a  2  s  .co  m
    return originalServletPath;
}

From source file:com.ewcms.publication.freemarker.directive.PositionDirectiveTest.java

@Test
public void testBodyTemplate() throws Exception {
    Template template = cfg.getTemplate(getTemplatePath("position_body.html"));

    Map<String, Object> params = new HashMap<String, Object>();
    params.put(GlobalVariable.CHANNEL.toString(), initChannel());

    String value = this.process(template, params);
    String expected = "<a href='http://www.jict.org/grand'>grand</a>&gt;"
            + "<a href='http://www.jict.org/parent'>parent</a>&gt;"
            + "<a href='http://www.jict.org/channel'>channel</a>";

    value = StringUtils.replace(value, "\n", "");
    Assert.assertEquals(expected, value);
}

From source file:com.ms.commons.test.treedb.Objects2XmlFileUtil.java

private static File getFile(String testMethodName, BuiltInCacheKey prePareOrResult) {
    // basePathsrcPath
    basePath = StringUtils.replace(basePath, "target/classes.eclipse_test", "src/java.test");

    File file = new File(basePath);
    if (!file.exists()) {
        file.mkdir();//  w w w . j  ava2 s  .c  o m
    }

    if (testMethodName.indexOf('_') <= 0) {
        testMethodName = testMethodName + "_" + prePareOrResult.getValue();
    }

    String defaultExt = DataReaderUtil.getDefaultExt(DataReaderType.TreeXml);
    String relativePath = basePath + "/" + testMethodName;
    if (!relativePath.endsWith(defaultExt)) {
        relativePath = relativePath + defaultExt;
    }
    return new File(relativePath);
}

From source file:com.alibaba.stonelab.toolkit.autoconf.Autoconf.java

@SuppressWarnings("unchecked")
private void parser(String base, String file) throws Exception {
    SAXReader reader = new SAXReader();
    Document doc = reader.read(new File(file));
    List<DefaultElement> pnodes = doc.selectNodes("config/group/property");

    StringBuilder defaults = new StringBuilder();
    for (DefaultElement node : pnodes) {
        String prop = node.attributeValue("name");
        props.add(new Propinfo(StringUtils.replace(prop, ".", "_"), file));
        // default valus
        defaults.append(node.attributeValue("defaultValue"));
    }//from  w w  w  . j  a v  a 2 s . c om

    List<DefaultElement> tnodes = doc.selectNodes("config/script/generate");
    for (DefaultElement node : tnodes) {
        templates.add(new AutoconfTemplate(base + "/" + node.attribute("template").getText()));
    }

    Set<String> tmp = AutoconfUtil.parsePlaceholder(defaults.toString());
    for (String str : tmp) {
        usedProps.add(StringUtils.replace(str, ".", "_"));
    }
}

From source file:info.magnolia.cms.gui.controlx.impl.TemplatedRenderer.java

/**
 * @return//from www. j a  v  a 2s. com
 */
protected String getTemplateName(Control control) {
    if (this.templateName == null) {
        return "/" + StringUtils.replace(control.getClass().getName(), ".", "/") + ".html";
    } else {
        return this.templateName;
    }
}

From source file:com.opengamma.id.ExternalId.java

/**
 * Parses an {@code ExternalId} from a formatted scheme and value.
 * <p>//from  w w w .  j  a v  a2  s .c  o  m
 * This parses the identifier from the form produced by {@code toString()}
 * which is {@code <SCHEME>~<VALUE>}.
 * 
 * @param str  the external identifier to parse, not null
 * @return the external identifier, not null
 * @throws IllegalArgumentException if the identifier cannot be parsed
 */
@FromString
public static ExternalId parse(String str) {
    ArgumentChecker.notEmpty(str, "str");
    str = StringUtils.replace(str, "::", "~"); // leniently parse old data
    int pos = str.indexOf("~");
    if (pos < 0) {
        throw new IllegalArgumentException("Invalid identifier format: " + str);
    }
    return new ExternalId(ExternalScheme.of(str.substring(0, pos)), str.substring(pos + 1));
}

From source file:info.magnolia.cms.i18n.MessagesUtil.java

/**
 * @param title/*ww  w.j av  a 2 s .co  m*/
 * @return
 */
public static String javaScriptString(String msg) {
    return StringUtils.replace(StringUtils.replace(msg, "'", "\\'"), "\n", "\\n");
}

From source file:com.ctrip.api.CtripApiTemplate.java

@Override
public SoapResponse send(String uri, SoapRequest soapRequest) {
    // requestResult
    StringResult requestResult = new StringResult();
    jaxb2Marshaller.marshal(soapRequest, requestResult);
    String requestContent = requestResult.toString();
    log.debug("requestContent - " + requestContent);
    // responseResult
    StringResult responseResult = new StringResult();
    webServiceTemplate.sendSourceAndReceiveToResult(uri, new StringSource(requestContent),
            new SoapActionCallback(SOAP_ACTION), responseResult);
    String responseContent = responseResult.toString();
    log.debug("responseContent - " + responseContent);
    // delete responseContent xmlns, fixed unmarshal bugs.
    responseContent = StringUtils.replace(responseContent, CtripApiTemplate.SOAP_RESPONSE_NS,
            StringUtils.EMPTY);/*from  w  w w  .jav a2s . co m*/
    return (SoapResponse) jaxb2Marshaller.unmarshal(new StringSource(responseContent));
}

From source file:com.ewcms.publication.uri.UriRule.java

@Override
public String getUri() throws PublishException {
    Assert.notNull(parameters);//w  w  w  . ja v a 2 s.  co  m

    Map<String, String> variables = ruleParse.getVariables();
    if (variables.isEmpty()) {
        return ruleParse.getPatter();
    }

    String uri = ruleParse.getPatter();
    for (String name : variables.keySet()) {
        String format = variables.get(name);
        String exp = (format == null ? String.format("${%s}", name) : String.format("${%s?%s}", name, format));
        Object value = getVariableValue(name, parameters);
        String formatValue = formatValue(value, format);
        uri = StringUtils.replace(uri, exp, formatValue);
    }
    uri = uri.replace("\\", "/").replace("//", "/");
    return FilenameUtils.normalize(uri);
}