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.sfs.whichdoctor.xml.writer.XmlWriter.java

/**
 * Static functions lifted from generationjava helper classes to make the
 * jar smaller.//from w  w w .  j a va 2  s.co  m
 *
 * @param str the str
 *
 * @return String
 */
public static String escapeXml(final String str) {

    String returnString = "";

    if (StringUtils.isNotBlank(str)) {
        returnString = StringUtils.replace(str, "& ", "& ");
        returnString = StringUtils.replace(returnString, "<", "&lt;");
        returnString = StringUtils.replace(returnString, ">", "&gt;");
        returnString = StringUtils.replace(returnString, "\"", "&quot;");
        returnString = StringUtils.replace(returnString, "'", "&apos;");
    }
    return returnString;
}

From source file:com.qualogy.qafe.business.test.BusinessActionTestCase.java

protected String getDirBasedUponPackage() {
    String pckName = ClassUtils.getPackageName(this.getClass());
    return StringUtils.replace(pckName, ".", "/") + "/";
}

From source file:com.neatresults.mgnltweaks.ui.field.FieldTypeSelectFieldFactory.java

@Override
public List<SelectFieldOptionDefinition> getSelectFieldOptionDefinition() {

    List<SelectFieldOptionDefinition> fields = new ArrayList<SelectFieldOptionDefinition>();
    try {/*  w  w w  . j a  v  a2s .c o  m*/
        if (registry.getClass().getDeclaredFields().length == 0) {
            // 5.4
            Collection<FieldTypeDefinition> defs = (Collection<FieldTypeDefinition>) registry.getClass()
                    .getMethod("getAllDefinitions").invoke(registry, null);
            for (FieldTypeDefinition fieldDef : defs) {
                if (fieldDef == null || fieldDef.getDefinitionClass() == null
                        || fieldDef.getDefinitionClass().getName() == null) {
                    System.out.println("field def is not valid: " + fieldDef);
                    continue;
                }
                SelectFieldOptionDefinition field = new SelectFieldOptionDefinition();
                String label = fieldDef.getDefinitionClass().getName();
                if (label.startsWith("com.neatresults.mgnltweaks")) {
                    label = StringUtils.replace(label, "com.neatresults.mgnltweaks.ui.field.", " NeatTweaks ");
                    label = StringUtils.removeEnd(label, "FieldFactory$Definition");
                }
                if (label.startsWith("info.magnolia")) {
                    label = StringUtils.replace(label, "info.magnolia.ui.form.field.definition.", " Default ");
                    label = StringUtils.removeStart(label, "info.magnolia.module.");
                    label = StringUtils.removeStart(label, "info.magnolia.");
                }
                field.setLabel(label);
                field.setName(definition.getName());
                field.setValue(fieldDef.getDefinitionClass().getName());
                fields.add(field);
            }
        } else {
            // 5.3
            Field registryField = registry.getClass().getDeclaredField("registry");
            registryField.setAccessible(true);
            RegistryMap<String, FieldTypeDefinitionProvider> providers = (RegistryMap<String, FieldTypeDefinitionProvider>) registryField
                    .get(registry);

            for (String id : providers.keySet()) {

                SelectFieldOptionDefinition field = new SelectFieldOptionDefinition();
                Class<? extends FieldDefinition> fieldDef = registry.get(id).getDefinitionClass();
                // directly defined label
                String label = id + " ("
                        + StringUtils.replaceOnce(fieldDef.getName(), "info.magnolia.module.", "i.m.m.") + ")";

                field.setLabel(label);
                field.setName(definition.getName());
                field.setValue(fieldDef.getName());
                fields.add(field);
            }
        }

    } catch (SecurityException | IllegalArgumentException | IllegalAccessException | RegistrationException
            | NoSuchFieldException | InvocationTargetException | NoSuchMethodException e) {
        log.error(e.getMessage(), e);
        SelectFieldOptionDefinition field = new SelectFieldOptionDefinition();
        field.setName(definition.getName());
        field.setLabel("It looks like an error has occured. Please contact admin or developers about it: "
                + e.getMessage());
        field.setValue(e.getMessage());
        fields.add(field);

    }
    return fields;
}

From source file:net.sf.zekr.common.util.VelocityUtils.java

public String processAya(String str) {
    if (StringUtils.isEmpty(str)) {
        return "";
    }//from  w  w w . j  av a2 s  .c  o  m

    str = StringUtils.replace(str, "\\\\", "<br/>");

    Matcher m;
    int i = 1;
    do {
        m = COMMENTARY.matcher(str);
        str = m.replaceFirst("<span class=\"commentHandle\">(" + i++
                + ")</span> <span class=\"commentText\" style=\"display: none\">$1</span>");
    } while (m.find());

    return str;

}

From source file:com.hpe.application.automation.tools.run.JobConfigRebrander.java

private void convertHpToHpe(@Nonnull TaskListener listener, XmlFile confXmlFile) {
    try {/*w w  w .j a v  a  2 s.  c  o m*/
        String configuration = FileUtils.readFileToString(confXmlFile.getFile());
        String newConfiguration = StringUtils.replace(configuration, ".hp.", ".hpe.");
        FileUtils.writeStringToFile(confXmlFile.getFile(), newConfiguration);
    } catch (IOException e) {
        listener.error("failed to convert configuration 5.1 to new 5.2 format (hp to HPE): " + e.getMessage());
    }
}

From source file:com.ecyrd.jspwiki.url.DefaultURLConstructor.java

/**
 *  URLEncoder returns pluses, when we want to have the percent
 *  encoding.  See http://issues.apache.org/bugzilla/show_bug.cgi?id=39278
 *  for more info./*ww w .j  a  v  a  2  s . c om*/
 *  
 *  We also convert any %2F's back to slashes to make nicer-looking URLs.
 */
private final String encodeURI(String uri) {
    uri = m_engine.encodeName(uri);

    uri = StringUtils.replace(uri, "+", "%20");
    uri = StringUtils.replace(uri, "%2F", "/");

    return uri;
}

From source file:com.amalto.core.storage.hibernate.MappingParsingTest.java

public void testInheritanceIndexLength() throws Exception {
    // Loads data model
    MetadataRepository repository = new MetadataRepository();
    InputStream dataModel = MappingParsingTest.class.getResourceAsStream("MappingParsingTest_1.xsd");//$NON-NLS-1$
    assertNotNull(dataModel);/* www .j  ava 2 s .c om*/
    repository.load(dataModel);
    // Creates storage (and overrides SQL name max length)
    Storage storage = new HibernateStorage("MappingParsingTest", StorageType.STAGING); //$NON-NLS-1$
    DataSourceDefinition definition = ServerContext.INSTANCE.get()
            .getDefinition(StorageTestCase.DATABASE + "-DS1", "MDM"); //$NON-NLS-1$//$NON-NLS-2$
    RDBMSDataSource stagingDataSource = (RDBMSDataSource) definition.getStaging();
    stagingDataSource.setNameMaxLength(30);
    storage.init(definition);
    // Prepares storage (and adds fields to index).
    ComplexTypeMetadata partyType = repository.getComplexType("Party"); //$NON-NLS-1$
    List<Expression> indexedExpressions = new LinkedList<>();
    indexedExpressions.add(
            UserQueryBuilder.from(partyType).where(isNull(partyType.getField("PartyType"))).getExpression()); //$NON-NLS-1$
    indexedExpressions
            .add(UserQueryBuilder.from(partyType).where(isNull(partyType.getField("SixtID"))).getExpression()); //$NON-NLS-1$
    storage.prepare(repository, new HashSet<>(indexedExpressions), true, true);
    // Storage preparation created a DDL file in java.io.tmpdir, compares it to expected DDL.
    InputStream expectedDataInputStream = this.getClass().getResourceAsStream("MappingParsingResult.ddl"); //$NON-NLS-1$
    assertNotNull(expectedDataInputStream);
    String tmpDir = System.getProperty("java.io.tmpdir"); //$NON-NLS-1$
    String filename = tmpDir + File.separator + "MappingParsingTest_STAGING_H2.ddl"; //$NON-NLS-1$
    InputStream resultDataInputStream = new FileInputStream(new File(filename));
    assertNotNull(resultDataInputStream);
    String[] extectedSQLs = IOUtils.toString(expectedDataInputStream).split("\n"); //$NON-NLS-1$
    String[] resultSQLs = IOUtils.toString(resultDataInputStream).split("\n"); //$NON-NLS-1$
    assertEquals(extectedSQLs.length, resultSQLs.length);
    for (int i = 0; i < extectedSQLs.length; i++) {
        assertEquals(StringUtils.replace(extectedSQLs[i], "\r", ""), resultSQLs[i]); //$NON-NLS-1$//$NON-NLS-2$
    }
}

From source file:er.extensions.formatters.ERXSimpleHTMLFormatter.java

/**
 * Applies the HTML formatting to a given string
 * object replacing ASCII formatting with HTML
 * formatting.//www  . j av  a2  s  . c o m
 * @param anObject to have the formatting applied to
 * @return formatted object
 */
public String applyFormat(Object anObject) throws IllegalArgumentException {
    String newString;

    if (anObject == null || !(anObject instanceof String))
        return null;

    // Convert tabs in the argument (which must be a String) to HTML spacers.
    newString = StringUtils.replace((String) anObject, ASCIITab, HTMLTab());
    // Convert new-lines in the argument (which must be a String) to HTML breaks.
    return StringUtils.replace(newString, ASCIIReturn, HTMLReturn);
}

From source file:com.flexive.tests.embedded.jsf.bean.MessageBeanTest.java

@Test
public void getMessageArgsElInt() {
    String message = (String) messageBean.get(KEY_1 + ",#{41+1}");
    String expected = StringUtils.replace(MSG_1, "{0}", "42");
    Assert.assertTrue(expected.equals(message), "Expected: " + expected + ", got: " + message);
}

From source file:co.marcin.novaguilds.enums.Config.java

/**
 * The constructor
 */
Config() {
    path = StringUtils.replace(name(), "_", ".").toLowerCase();
}