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

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

Introduction

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

Prototype

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

Source Link

Document

Replaces a String with another String inside a larger String, once.

Usage

From source file:org.andromda.maven.plugin.bootstrap.install.BootstrapInstallMojo.java

/**
 * Retrieves the project's bootstrap groupId from the given <code>artifact</code>.
 *
 * @param artifact the artifact from which to retrieve the group Id.
 * @return the bootstrap groupId.//from w  w  w .j  a v a  2 s.c o  m
 */
private String getBootstrapGroupId(final Artifact artifact) {
    return StringUtils.replaceOnce(artifact.getGroupId(), this.projectGroupId, this.projectBootstrapGroupId);
}

From source file:org.apache.cassandra.cql3.subquery.SubQueryProcessor.java

public List<ByteBuffer> executePreparedSubqery(SubQuery sq, ConsistencyLevel cLevel, ThriftClientState cState)
        throws InvalidRequestException, RequestExecutionException, RequestValidationException {

    List<ByteBuffer> queryResultList = new ArrayList<ByteBuffer>();
    List<ByteBuffer> bindValriables = new ArrayList<ByteBuffer>();
    List<ByteBuffer> bindValueAndChildQueryResultsTogether = new ArrayList<ByteBuffer>();
    List<List<ByteBuffer>> childReturedRowsAsListOfList = new ArrayList<List<ByteBuffer>>();

    bindValriables = sq.getBindVariables();
    childReturedRowsAsListOfList = sq.childReturedRowsAsList;
    int iteration = 1;

    if (childReturedRowsAsListOfList.size() != 0) {
        if (childReturedRowsAsListOfList.get(0).size() >= 0) {
            iteration = childReturedRowsAsListOfList.get(0).size();
        }//from  w  w w .j  a  va2s  .co m
    }

    ParsedStatement.Prepared prepared = cState.getCQLQueryHandler().getPreparedForThrift(sq.getItemId());
    if (prepared == null)
        throw new InvalidRequestException(String.format("Prepared query with ID %d not found"
                + " (either the query was not prepared on this host (maybe the host has been restarted?)"
                + " or you have prepared too many queries and it has been evicted from the internal cache)",
                sq.getItemId()));
    logger.trace("Retrieved prepared statement #{} with {} bind markers", sq.getItemId(),
            prepared.statement.getBoundTerms());

    for (int i = 0; i < iteration; i++) {

        bindValueAndChildQueryResultsTogether.clear();
        String tempQuery = sq.getQuery();
        String tempQueryWithMarker = sq.getQueryWithMarker();
        int childListChooser = 0;
        int bindVariableChooser = 0;
        while (tempQueryWithMarker.contains("?")) {
            if (tempQuery.charAt(tempQueryWithMarker.indexOf("?")) == '?') {
                tempQueryWithMarker = StringUtils.replaceOnce(tempQueryWithMarker, "?", "#");
                bindValueAndChildQueryResultsTogether.add(bindValriables.get(bindVariableChooser));

            } else {
                bindValueAndChildQueryResultsTogether
                        .add(childReturedRowsAsListOfList.get(childListChooser).get(i));

                tempQueryWithMarker = StringUtils.replaceOnce(tempQueryWithMarker, "?", "#");
                childListChooser++;
            }
        }

        CqlResult cqlResult = cState.getCQLQueryHandler()
                .processPrepared(prepared.statement, cState.getQueryState(), QueryOptions.fromProtocolV2(
                        ThriftConversion.fromThrift(cLevel), bindValueAndChildQueryResultsTogether))
                .toThriftResult();
        List<CqlRow> cqlRows = cqlResult.getRows();
        for (CqlRow cqlRow : cqlRows) {
            queryResultList.add(ByteBuffer.wrap(cqlRow.getColumns().get(0).getValue()));
        }

    }

    return queryResultList;
}

From source file:org.apache.cassandra.cql3.subquery.SubQueryProcessor.java

public CqlResult executeParentQery(SubQuery sq, ConsistencyLevel cLevel, ThriftClientState cState)
        throws InvalidRequestException, RequestExecutionException, RequestValidationException {

    CqlResult cqlResult = null;/*w  w  w.  jav a2  s.  co m*/
    List<CqlRow> allCqlRows = new ArrayList<CqlRow>();

    List<ByteBuffer> bindValriables = new ArrayList<ByteBuffer>();
    List<ByteBuffer> bindValueAndChildQueryResultsTogether = new ArrayList<ByteBuffer>();
    List<List<ByteBuffer>> childReturedRowsAsListOfList = new ArrayList<List<ByteBuffer>>();

    bindValriables = sq.getBindVariables();
    childReturedRowsAsListOfList = sq.childReturedRowsAsList;

    int iteration = 1;

    if (childReturedRowsAsListOfList.get(0).size() >= 0) {

        iteration = childReturedRowsAsListOfList.get(0).size();
    }

    ParsedStatement.Prepared prepared = cState.getCQLQueryHandler().getPreparedForThrift(sq.getItemId());
    if (prepared == null)
        throw new InvalidRequestException(String.format("Prepared query with ID %d not found"
                + " (either the query was not prepared on this host (maybe the host has been restarted?)"
                + " or you have prepared too many queries and it has been evicted from the internal cache)",
                sq.getItemId()));
    logger.trace("Retrieved prepared statement #{} with {} bind markers", sq.getItemId(),
            prepared.statement.getBoundTerms());

    for (int i = 0; i < iteration; i++) {

        bindValueAndChildQueryResultsTogether.clear();
        String tempQuery = sq.getQuery();
        String tempQueryWithMarker = sq.getQueryWithMarker();
        int childListChooser = 0;
        while (tempQueryWithMarker.contains("?")) {
            if (tempQuery.charAt(tempQueryWithMarker.indexOf("?")) == '?') {
                tempQueryWithMarker = StringUtils.replaceOnce(tempQueryWithMarker, "?", "#");
                bindValueAndChildQueryResultsTogether.add(bindValriables.get(i));

            } else {
                bindValueAndChildQueryResultsTogether
                        .add(childReturedRowsAsListOfList.get(childListChooser).get(i));

                tempQueryWithMarker = StringUtils.replaceOnce(tempQueryWithMarker, "?", "#");
                childListChooser++;
            }
        }

        cqlResult = cState.getCQLQueryHandler()
                .processPrepared(prepared.statement, cState.getQueryState(), QueryOptions.fromProtocolV2(
                        ThriftConversion.fromThrift(cLevel), bindValueAndChildQueryResultsTogether))
                .toThriftResult();
        List<CqlRow> cqlRows = cqlResult.getRows();
        for (CqlRow cqlRow : cqlRows) {
            allCqlRows.add(cqlRow);
        }

    }
    cqlResult.setRows(allCqlRows);
    return cqlResult;

}

From source file:org.apache.click.Page.java

/**
 * Set the request to forward to the given page class.
 *
 * @see #setForward(java.lang.String)/*from ww  w .  j  ava  2s  .  c  o m*/
 *
 * @param pageClass the class of the Page to forward the request to
 * @throws IllegalArgumentException if the Page Class is not configured
 * with a unique path
 */
public void setForward(Class<? extends Page> pageClass) {
    String target = getContext().getPagePath(pageClass);

    // If page class maps to a jsp, convert to htm which allows ClickServlet
    // to process the redirect
    if (target != null && target.endsWith(".jsp")) {
        target = StringUtils.replaceOnce(target, ".jsp", ".htm");
    }
    setForward(target);
}

From source file:org.apache.click.Page.java

/**
 * Set the request to redirect to the given page class and and append
 * the map of request parameters to the page URL.
 * <p/>/*from   ww w. j av  a 2s  .  c  o  m*/
 * The map keys will be used as the request parameter names and the map
 * values will be used as the request parameter values.
 *
 * @see #setRedirect(java.lang.String, java.util.Map)
 * @see #setRedirect(java.lang.String)
 *
 * @param pageClass the class of the Page to redirect the request to
 * @param params the map of request parameter name and value pairs
 * @throws IllegalArgumentException if the Page Class is not configured
 * with a unique path
 */
public void setRedirect(Class<? extends Page> pageClass, Map<String, ?> params) {

    String target = getContext().getPagePath(pageClass);

    // If page class maps to a jsp, convert to htm which allows ClickServlet
    // to process the redirect
    if (target != null && target.endsWith(".jsp")) {
        target = StringUtils.replaceOnce(target, ".jsp", ".htm");
    }

    setRedirect(target, params);
}

From source file:org.apache.manifoldcf.crawler.connectors.cmis.CmisRepositoryConnectorUtils.java

/**
 * Utility method to consider the objectId whenever it is not present in the select clause
 * @param cmisQuery/* www.  j av  a  2  s  .c  o m*/
 * @return the cmisQuery with the cmis:objectId property added in the select clause
 */
public static String getCmisQueryWithObjectId(String cmisQuery) {
    String cmisQueryResult = StringUtils.EMPTY;
    String selectClause = getSelectClause(cmisQuery);
    if (selectClause.equalsIgnoreCase(SELECT_STAR_CLAUSE)) {
        cmisQueryResult = cmisQuery;
    } else {
        //get the second term and add the cmis:objectId term
        StringTokenizer selectClauseTokenized = new StringTokenizer(selectClause.trim());
        boolean firstTermSelectClause = true;
        String secondTerm = StringUtils.EMPTY;
        while (selectClauseTokenized.hasMoreElements()) {
            String term = selectClauseTokenized.nextToken();
            if (firstTermSelectClause) {
                firstTermSelectClause = false;
            } else if (!firstTermSelectClause) {
                //this is the second term
                secondTerm = term;
                break;
            }
        }
        cmisQueryResult = StringUtils.replaceOnce(cmisQuery, secondTerm, OBJECT_ID_TERM + secondTerm);
    }
    return cmisQueryResult;
}

From source file:org.apache.rya.export.accumulo.util.AccumuloRyaUtils.java

/**
 * Converts a {@link RyaURI} to the contained data string.
 * @param namespace the namespace.//from   www .j  a va 2s  . com
 * @param the {@link RyaURI} to convert.
 * @return the data value without the namespace.
 */
public static String convertRyaUriToString(final String namespace, final RyaURI ryaUri) {
    return StringUtils.replaceOnce(ryaUri.getData(), namespace, "");
}

From source file:org.apache.sling.superimposing.impl.SuperimposingResourceProviderImpl.java

/**
 * Maps a path below the superimposing root to the target resource's path without check for overlaying.
 * @param provider Superimposing resource provider
 * @param resolver Resource resolver/*from  w ww  .  ja  v a 2 s.co  m*/
 * @param path Path to map
 * @return Mapped path or null if no mapping available
 */
static String mapPathWithoutOverlay(SuperimposingResourceProviderImpl provider, ResourceResolver resolver,
        String path) {
    final String mappedPath;
    if (StringUtils.equals(path, provider.rootPath)) {
        mappedPath = provider.sourcePath;
    } else if (StringUtils.startsWith(path, provider.rootPrefix)) {
        mappedPath = StringUtils.replaceOnce(path, provider.rootPrefix, provider.sourcePathPrefix);
    } else {
        mappedPath = null;
    }
    return mappedPath;
}

From source file:org.apache.sling.superimposing.impl.SuperimposingResourceProviderImpl.java

/**
 * Maps a path below the target resource to the superimposed resource's path.
 *
 * @param provider/*from   w w w.j  a va2  s.c  o m*/
 * @param path
 * @return
 */
static String reverseMapPath(SuperimposingResourceProviderImpl provider, String path) {
    final String mappedPath;
    if (path.startsWith(provider.sourcePathPrefix)) {
        mappedPath = StringUtils.replaceOnce(path, provider.sourcePathPrefix, provider.rootPrefix);
    } else if (path.equals(provider.sourcePath)) {
        mappedPath = provider.rootPath;
    } else {
        mappedPath = null;
    }
    return mappedPath;
}

From source file:org.artifactory.rest.resource.artifact.ArtifactResource.java

private void fixPathIfNeeded() {
    // In case that the path reference to remote repository, then change the path to remote local
    RepoPath repoPath = RestUtils.calcRepoPathFromRequestPath(path);
    LocalRepoDescriptor descriptor = repositoryService.localOrCachedRepoDescriptorByKey(repoPath.getRepoKey());
    if (descriptor != null && descriptor.isCache()) {
        path = StringUtils.replaceOnce(path, repoPath.getRepoKey(), descriptor.getKey());
    }/*from   w  w w.j a va 2s . c o m*/
}