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

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

Introduction

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

Prototype

public static String replaceEach(String text, String[] searchList, String[] replacementList) 

Source Link

Document

Replaces all occurrences of Strings within another String.

Usage

From source file:org.jahia.services.render.filter.cache.AclCacheKeyPartGenerator.java

private String decodeSpecificChars(String toDecode) {
    return StringUtils.replaceEach(toDecode, SUBSTITUTION_STR, SPECIFIC_STR);
}

From source file:org.jfrog.build.client.ArtifactoryDependenciesClient.java

public PropertySearchResult searchArtifactsByProperties(String properties) throws IOException {
    PreemptiveHttpClient client = httpClient.getHttpClient();
    String replacedProperties = StringUtils.replaceEach(properties, new String[] { ";", "+" },
            new String[] { "&", "" });
    String url = artifactoryUrl + "/api/search/prop?" + replacedProperties;
    PropertySearchResult result = readResponse(client.execute(new HttpGet(url)),
            new TypeReference<PropertySearchResult>() {
            }, "Failed to search artifact by the properties '" + properties + "'");
    return result;
}

From source file:org.jfrog.build.extractor.clientConfiguration.client.ArtifactoryDependenciesClient.java

public PropertySearchResult searchArtifactsByProperties(String properties) throws IOException {
    PreemptiveHttpClient client = httpClient.getHttpClient();
    String replacedProperties = StringUtils.replaceEach(properties, new String[] { ";", "+" },
            new String[] { "&", "" });
    String url = artifactoryUrl + "/api/search/prop?" + replacedProperties;
    PropertySearchResult result = readResponse(client.execute(new HttpGet(url)),
            new TypeReference<PropertySearchResult>() {
            }, "Failed to search artifact by the properties '" + properties + "'", false);
    return result;
}

From source file:org.kuali.rice.krad.lookup.LookupUtils.java

/**
 * Removes query characters (such as wildcards) from the given string value.
 *
 * @param criteriaValue string to clean// w w w  .j  a  v  a2 s .com
 * @return string with query characters removed
 */
public static String scrubQueryCharacters(String criteriaValue) {
    return StringUtils.replaceEach(criteriaValue, searchList, replacementList);
}

From source file:org.mule.modules.quickbooks.online.api.QuickBooksOnlinePaginatedIterableTest.java

@Before
public void setUp() throws Exception {
    credentials = mock(OAuthCredentials.class);
    dataServiceHelper = mock(QuickBooksOnlineDataServiceHelper.class);
    DataService dataService = mock(DataService.class);

    when(dataService.executeQuery(anyString())).thenAnswer(new Answer<QueryResult>() {

        @Override/* w  ww  .  j  av  a2  s.c  o  m*/
        public QueryResult answer(InvocationOnMock invocation) throws Throwable {
            QueryResult queryResult = new QueryResult();

            String query = (String) invocation.getArguments()[0];

            if (StringUtils.contains(query, ITEM_QUERY)) {
                String parsedQuery = StringUtils.replaceEach(query,
                        new String[] { ITEM_QUERY, START_POSITION_KEY, MAX_RESULTS_KEY },
                        new String[] { "", "", "" });

                String[] parameters = StringUtils.split(parsedQuery);

                Integer startPosition = new Integer(parameters[0]) - 1;
                Integer maxResults = new Integer(parameters[1]);

                Integer toIndex = (startPosition + maxResults > itemList.size() ? itemList.size()
                        : startPosition + maxResults);
                Integer fromIndex = (startPosition > toIndex ? toIndex : startPosition);

                queryResult.setEntities(itemList.subList(fromIndex, toIndex));
                queryResult.setMaxResults(queryResult.getEntities().size());
                return queryResult;

            } else if (StringUtils.contains(query, ITEM_QUERY_COUNT)) {
                queryResult.setTotalCount(itemList.size());
                return queryResult;
            } else {
                throw new IllegalArgumentException("The query cannot be tested.");
            }
        }
    });

    when(dataServiceHelper.createIntuitDataService(credentials)).thenReturn(dataService);
}

From source file:org.musicrecital.service.impl.UserManagerImpl.java

@Override
public String buildRecoveryPasswordUrl(final User user, final String urlTemplate) {
    final String token = generateRecoveryToken(user);
    final String username = user.getUsername();
    return StringUtils.replaceEach(urlTemplate, new String[] { "{username}", "{token}" },
            new String[] { username, token });
}

From source file:org.nuxeo.ecm.platform.preview.adapter.PlainTextPreviewer.java

public String htmlContent(String content) {
    // & and < are the only two that we really need to escape
    // then we also make newlines visible
    String escaped = StringUtils.replaceEach(content, //
            new String[] { "&", "<", "\n" }, //
            new String[] { "&amp;", "&lt;", "<br/>" });
    return "<pre>" + escaped + "</pre>";
}

From source file:org.onebusaway.transit_data_federation.siri.SiriXmlSerializerV2.java

public String getXml(Siri siri) throws Exception {
    Marshaller marshaller = context.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);
    marshaller.setEventHandler(new ValidationEventHandler() {
        public boolean handleEvent(ValidationEvent event) {
            _log.error(event.getMessage(), event.getLinkedException());
            throw new RuntimeException(event.getMessage(), event.getLinkedException());
        }/*from   w  ww. j a v  a 2 s.c om*/
    });

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);

    Writer output = new StringWriter();
    marshaller.marshal(siri, output);

    // FIXME: strip off ns6 namespaces on siri root namespace. super hack, please fix me!
    String outputAsString = output.toString();

    /*outputAsString = outputAsString.replaceAll("<ns6:", "<");
    outputAsString = outputAsString.replaceAll("</ns6:", "</");
    outputAsString = outputAsString.replaceAll("xmlns:ns6", "xmlns");
    */

    String[] searchList = { "<siriExtensionWrapper>", "</siriExtensionWrapper>",
            "<siriUpcomingServiceExtension>", "</siriUpcomingServiceExtension>", "<siriPolyLinesExtension>",
            "</siriPolyLinesExtension>" };

    String[] replacementList = { "", "", "", "", "", "" };

    outputAsString = StringUtils.replaceEach(outputAsString, searchList, replacementList);

    return outputAsString;
}

From source file:org.openmrs.api.db.hibernate.HibernateUtil.java

/**
 * Escapes all sql wildcards in the given string, returns the same string if it doesn't contain
 * any sql wildcards//from   w w  w  .  ja  va2 s.  co m
 *
 * @param oldString the string in which to escape the sql wildcards
 * @param connection The underlying database connection
 * @return the string with sql wildcards escaped if any found otherwise the original string is
 *         returned
 */
public static String escapeSqlWildcards(String oldString, Connection connection) {

    //replace all sql wildcards if any
    if (!StringUtils.isBlank(oldString)) {
        String escapeCharacter = "";

        try {
            //get the database specific escape character from the metadata
            escapeCharacter = connection.getMetaData().getSearchStringEscape();
        } catch (SQLException e) {
            log.warn("Error generated", e);
        }
        //insert an escape character before each sql wildcard in the search phrase
        return StringUtils.replaceEach(oldString, new String[] { "%", "_", "*", "'" },
                new String[] { escapeCharacter + "%", escapeCharacter + "_", escapeCharacter + "*", "''" });
    } else {
        return oldString;
    }
}

From source file:org.openmrs.module.webservices.docs.ResourceDocCreator.java

/**
 * Fills a map of resource names and their documentation objects with resource urls.
 * /*from  ww  w.ja  va 2  s.c o m*/
 * @param baseUrl the base or root for all the urls. e.g http://localhost:8080/openmrs
 * @param resouceDocMap a map of each resource name and its corresponding documentation object.
 */
private static void fillUrls(String baseUrl, Map<String, ResourceDoc> resouceDocMap) throws IOException {
    List<ResourceOperation> resourceOperations = null;
    List<ResourceOperation> subResourceOperations = null;
    String resourceUrl = baseUrl + "/rest";

    for (ResourceDoc doc : resouceDocMap.values()) {
        //skip subclass handlers e.g DrugOrderSubclassHandler
        if (doc.isSubtypeHandler()) {
            continue;
        }

        if (doc.getSubResourceName() == null) {
            if (resourceOperations == null)
                resourceOperations = getResourceOperations(resourceUrl, MainResourceController.class, true);

            for (ResourceOperation ro : resourceOperations) {
                //Add the actual urls after replacing the {resource} string with the resource name
                doc.addOperation(new ResourceOperation(
                        StringUtils.replace(ro.getName(), "{resource}", doc.getResourceName()),
                        ro.getDescription()));
            }

            //Set the root url.
            doc.setUrl(resourceUrl + "/" + doc.getResourceName());
            setUrlInSubResources(doc.getUrl(), doc);
        } else {
            //This is a sub resource that has a parent
            if (subResourceOperations == null)
                subResourceOperations = getResourceOperations(resourceUrl, MainSubResourceController.class,
                        false);

            for (ResourceOperation sro : subResourceOperations) {
                //generate the actual url to match the parent resource and subresource
                String operationUrl = StringUtils.replaceEach(sro.getName(),
                        new String[] { "{resource}", "{subResource}" },
                        new String[] { doc.getResourceName(), doc.getSubResourceName() });
                doc.addOperation(new ResourceOperation(operationUrl, sro.getDescription()));
            }

            doc.setUrl(resourceUrl + "/" + doc.getResourceName() + "/{parentUuid}/" + doc.getSubResourceName());
            setUrlInSubResources(resourceUrl, doc);
        }
    }
}