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

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

Introduction

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

Prototype

public static String removeEnd(String str, String remove) 

Source Link

Document

Removes a substring only if it is at the end of a source string, otherwise returns the source string.

Usage

From source file:msi.gama.util.GAML.java

public static String getDocumentationOn(final String query) {
    final String keyword = StringUtils.removeEnd(StringUtils.removeStart(query.trim(), "#"), ":");
    final Multimap<GamlIdiomsProvider<?>, IGamlDescription> results = GamlIdiomsProvider.forName(keyword);
    if (results.isEmpty()) {
        return "No result found";
    }/*from w  ww  . j a  va 2s  .  com*/
    final StringBuilder sb = new StringBuilder();
    final int max = results.keySet().stream().mapToInt(each -> each.name.length()).max().getAsInt();
    final String separator = StringUtils.repeat("", max + 6).concat(Strings.LN);
    results.asMap().forEach((provider, list) -> {
        sb.append("").append(separator).append("|| ");
        sb.append(StringUtils.rightPad(provider.name, max));
        sb.append(" ||").append(Strings.LN).append(separator);
        for (final IGamlDescription d : list) {
            sb.append("== ").append(toText(d.getTitle())).append(Strings.LN)
                    .append(toText(provider.document(d))).append(Strings.LN);
        }
    });

    return sb.toString();

    //
}

From source file:com.pedra.storefront.filters.cms.CMSSiteFilter.java

/**
 * Processing normal request (i.e. when user goes directly to that application - not from cmscockpit)
 * <p/>//from   w w  w  . ja v a 2  s  . c o m
 * <b>Note:</b> <br/>
 * We preparing application by setting correct:
 * <ul>
 * <li>Current Site</li>
 * <li>Current Catalog Versions</li>
 * <li>Enabled language fallback</li>
 * </ul>
 * 
 * @see ContextInformationLoader#initializeSiteFromRequest(String)
 * @see ContextInformationLoader#setCatalogVersions()
 * @param httpRequest
 *           current request
 * @param httpResponse
 *           the http response
 * @throws java.io.IOException
 */
protected boolean processNormalRequest(final HttpServletRequest httpRequest,
        final HttpServletResponse httpResponse) throws IOException {
    final String queryString = httpRequest.getQueryString();
    final String currentRequestURL = httpRequest.getRequestURL().toString();

    //set current site
    CMSSiteModel cmsSiteModel = getCurrentCmsSite();
    if (cmsSiteModel == null || StringUtils.contains(queryString, CLEAR_CMSSITE_PARAM)) {
        final String absoluteURL = StringUtils.removeEnd(currentRequestURL, "/")
                + (StringUtils.isBlank(queryString) ? "" : "?" + queryString);

        cmsSiteModel = getContextInformationLoader().initializeSiteFromRequest(absoluteURL);
    }

    if (cmsSiteModel == null) {
        // Failed to lookup CMS site
        httpResponse.sendError(MISSING_CMS_SITE_ERROR_STATUS, MISSING_CMS_SITE_ERROR_MESSAGE);
        return false;
    } else if (!SiteChannel.B2C.equals(cmsSiteModel.getChannel())) // Restrict to B2C channel
    {
        // CMS site that we looked up was for an unsupported channel
        httpResponse.sendError(MISSING_CMS_SITE_ERROR_STATUS, INCORRECT_CMS_SITE_CHANNEL_ERROR_MESSAGE);
        return false;
    }

    if (isNotActiveSite(cmsSiteModel)) {
        throw new IllegalStateException(
                "Site is not active. Active flag behaviour must be implement for this project.");
    }

    getContextInformationLoader().setCatalogVersions();
    //set fall back language enabled
    setFallbackLanguage(httpRequest, Boolean.TRUE);

    return true;
}

From source file:com.epam.cme.storefront.filters.cms.CMSSiteFilter.java

/**
 * Processing normal request (i.e. when user goes directly to that application - not from
 * cmscockpit)/*from w  ww  .ja  va  2  s .c  o  m*/
 * <p/>
 * <b>Note:</b> <br/>
 * We preparing application by setting correct:
 * <ul>
 * <li>Current Site</li>
 * <li>Current Catalog Versions</li>
 * <li>Enabled language fallback</li>
 * </ul>
 * 
 * @see ContextInformationLoader#initializeSiteFromRequest(String)
 * @see ContextInformationLoader#setCatalogVersions()
 * @param httpRequest
 *            current request
 * @param httpResponse
 *            the http response
 * @throws java.io.IOException
 */
protected boolean processNormalRequest(final HttpServletRequest httpRequest,
        final HttpServletResponse httpResponse) throws IOException {
    final String queryString = httpRequest.getQueryString();
    final String currentRequestURL = httpRequest.getRequestURL().toString();

    // set current site
    CMSSiteModel cmsSiteModel = getCurrentCmsSite();
    if (cmsSiteModel == null || StringUtils.contains(queryString, CLEAR_CMSSITE_PARAM)) {
        final String absoluteURL = StringUtils.removeEnd(currentRequestURL, "/")
                + (StringUtils.isBlank(queryString) ? "" : "?" + queryString);

        cmsSiteModel = getContextInformationLoader().initializeSiteFromRequest(absoluteURL);
    }

    if (cmsSiteModel == null) {
        // Failed to lookup CMS site
        httpResponse.sendError(MISSING_CMS_SITE_ERROR_STATUS, MISSING_CMS_SITE_ERROR_MESSAGE);
        return false;
    } else if (!SiteChannel.B2C.equals(cmsSiteModel.getChannel())
            && !SiteChannel.TELCO.equals(cmsSiteModel.getChannel())) // Restrict to B2C and
                                                                                                                                   // Telco channel
    {
        // CMS site that we looked up was for an unsupported channel
        httpResponse.sendError(MISSING_CMS_SITE_ERROR_STATUS, INCORRECT_CMS_SITE_CHANNEL_ERROR_MESSAGE);
        return false;
    }

    if (!isActiveSite(cmsSiteModel)) {
        throw new IllegalStateException(
                "Site is not active. Active flag behaviour must be implement for this project.");
    }

    getContextInformationLoader().setCatalogVersions();
    // set fall back language enabled
    setFallbackLanguage(httpRequest, Boolean.TRUE);

    return true;
}

From source file:de.hybris.platform.ytelcoacceleratorstorefront.filters.cms.CMSSiteFilter.java

/**
 * Processing normal request (i.e. when user goes directly to that application - not from cmscockpit)
 * <p/>/*from  w  ww  .j  av a 2 s . com*/
 * <b>Note:</b> <br/>
 * We preparing application by setting correct:
 * <ul>
 * <li>Current Site</li>
 * <li>Current Catalog Versions</li>
 * <li>Enabled language fallback</li>
 * </ul>
 * 
 * @see ContextInformationLoader#initializeSiteFromRequest(String)
 * @see ContextInformationLoader#setCatalogVersions()
 * @param httpRequest
 *           current request
 * @param httpResponse
 *           the http response
 * @throws java.io.IOException
 */
protected boolean processNormalRequest(final HttpServletRequest httpRequest,
        final HttpServletResponse httpResponse) throws IOException {
    final String queryString = httpRequest.getQueryString();
    final String currentRequestURL = httpRequest.getRequestURL().toString();

    //set current site
    CMSSiteModel cmsSiteModel = getCurrentCmsSite();
    if (cmsSiteModel == null || StringUtils.contains(queryString, CLEAR_CMSSITE_PARAM)) {
        final String absoluteURL = StringUtils.removeEnd(currentRequestURL, "/")
                + (StringUtils.isBlank(queryString) ? "" : "?" + queryString);

        cmsSiteModel = getContextInformationLoader().initializeSiteFromRequest(absoluteURL);
    }

    if (cmsSiteModel == null) {
        // Failed to lookup CMS site
        httpResponse.sendError(MISSING_CMS_SITE_ERROR_STATUS, MISSING_CMS_SITE_ERROR_MESSAGE);
        return false;
    } else if (!SiteChannel.B2C.equals(cmsSiteModel.getChannel())
            && !SiteChannel.TELCO.equals(cmsSiteModel.getChannel())) // Restrict to B2C and Telco channel
    {
        // CMS site that we looked up was for an unsupported channel
        httpResponse.sendError(MISSING_CMS_SITE_ERROR_STATUS, INCORRECT_CMS_SITE_CHANNEL_ERROR_MESSAGE);
        return false;
    }

    if (!isActiveSite(cmsSiteModel)) {
        throw new IllegalStateException(
                "Site is not active. Active flag behaviour must be implement for this project.");
    }

    getContextInformationLoader().setCatalogVersions();
    //set fall back language enabled
    setFallbackLanguage(httpRequest, Boolean.TRUE);

    return true;
}

From source file:edu.cornell.mannlib.vitro.webapp.visualization.coprincipalinvestigator.CoPIGrantCountRequestHandler.java

private String getCoPINamesAsString(Set<Collaborator> coInvestigators) {

    StringBuilder coPIsMerged = new StringBuilder();

    String coPISeparator = ";";
    for (Collaborator currentCoPI : coInvestigators) {
        coPIsMerged.append(currentCoPI.getCollaboratorName() + coPISeparator);
    }// www  .ja  v  a 2s  .  c o m

    return StringUtils.removeEnd(coPIsMerged.toString(), coPISeparator);
}

From source file:cec.easyshop.storefront.filters.cms.CMSSiteFilter.java

/**
 * Processing normal request (i.e. when user goes directly to that application - not from cmscockpit)
 * <p/>/*w  w w. j a v a 2 s.c  o  m*/
 * <b>Note:</b> <br/>
 * We preparing application by setting correct:
 * <ul>
 * <li>Current Site</li>
 * <li>Current Catalog Versions</li>
 * <li>Enabled language fallback</li>
 * </ul>
 * 
 * @see ContextInformationLoader#initializeSiteFromRequest(String)
 * @see ContextInformationLoader#setCatalogVersions()
 * @param httpRequest
 *           current request
 * @param httpResponse
 *           the http response
 * @throws java.io.IOException
 */
protected boolean processNormalRequest(final HttpServletRequest httpRequest,
        final HttpServletResponse httpResponse) throws IOException {
    final String queryString = httpRequest.getQueryString();
    final String currentRequestURL = httpRequest.getRequestURL().toString();

    //set current site
    CMSSiteModel cmsSiteModel = getCurrentCmsSite();
    if (cmsSiteModel == null || StringUtils.contains(queryString, CLEAR_CMSSITE_PARAM)) {
        final String absoluteURL = StringUtils.removeEnd(currentRequestURL, "/")
                + (StringUtils.isBlank(queryString) ? "" : "?" + queryString);

        cmsSiteModel = getContextInformationLoader().initializeSiteFromRequest(absoluteURL);
    }

    if (cmsSiteModel == null) {
        // Failed to lookup CMS site
        httpResponse.sendError(MISSING_CMS_SITE_ERROR_STATUS, MISSING_CMS_SITE_ERROR_MESSAGE);
        return false;
    } else if (!SiteChannel.B2C.equals(cmsSiteModel.getChannel())) // Restrict to B2C channel
    {
        // CMS site that we looked up was for an unsupported channel
        httpResponse.sendError(MISSING_CMS_SITE_ERROR_STATUS, INCORRECT_CMS_SITE_CHANNEL_ERROR_MESSAGE);
        return false;
    }

    if (!isActiveSite(cmsSiteModel)) {
        throw new IllegalStateException(
                "Site is not active. Active flag behaviour must be implement for this project.");
    }

    getContextInformationLoader().setCatalogVersions();
    //set fall back language enabled
    setFallbackLanguage(httpRequest, Boolean.TRUE);

    return true;
}

From source file:edu.cornell.mannlib.vitro.webapp.visualization.coauthorship.CoAuthorshipRequestHandler.java

private String getCoauthorNamesAsString(Set<Collaborator> coAuthors) {

    StringBuilder coAuthorsMerged = new StringBuilder();

    String coAuthorSeparator = "; ";
    for (Collaborator currCoAuthor : coAuthors) {
        coAuthorsMerged.append(currCoAuthor.getCollaboratorName() + coAuthorSeparator);
    }/*from   ww  w. j a va 2s.  c  o m*/

    return StringUtils.removeEnd(coAuthorsMerged.toString(), coAuthorSeparator);
}

From source file:com.exxonmobile.ace.hybris.storefront.filters.cms.CMSSiteFilter.java

/**
 * Processing normal request (i.e. when user goes directly to that application - not from cmscockpit)
 * <p/>/*from ww w  . j a va2  s  .c  om*/
 * <b>Note:</b> <br/>
 * We preparing application by setting correct:
 * <ul>
 * <li>Current Site</li>
 * <li>Current Catalog Versions</li>
 * <li>Enabled language fallback</li>
 * </ul>
 * 
 * @see ContextInformationLoader#initializeSiteFromRequest(String)
 * @see ContextInformationLoader#setCatalogVersions()
 * @param httpRequest
 *            current request
 * @param httpResponse
 *            the http response
 * @throws java.io.IOException
 */
protected boolean processNormalRequest(final HttpServletRequest httpRequest,
        final HttpServletResponse httpResponse) throws IOException {
    final String queryString = httpRequest.getQueryString();
    final String currentRequestURL = httpRequest.getRequestURL().toString();

    // set current site
    CMSSiteModel cmsSiteModel = getCurrentCmsSite();
    if (cmsSiteModel == null || StringUtils.contains(queryString, CLEAR_CMSSITE_PARAM)) {
        final String absoluteURL = StringUtils.removeEnd(currentRequestURL, "/")
                + (StringUtils.isBlank(queryString) ? "" : "?" + queryString);

        cmsSiteModel = getContextInformationLoader().initializeSiteFromRequest(absoluteURL);
    }

    if (cmsSiteModel == null) {
        // Failed to lookup CMS site
        httpResponse.sendError(MISSING_CMS_SITE_ERROR_STATUS, MISSING_CMS_SITE_ERROR_MESSAGE);
        return false;
    } else if (!SiteChannel.B2B.equals(cmsSiteModel.getChannel())) // Restrict to B2B channel
    {
        // CMS site that we looked up was for an unsupported channel
        httpResponse.sendError(MISSING_CMS_SITE_ERROR_STATUS, INCORRECT_CMS_SITE_CHANNEL_ERROR_MESSAGE);
        return false;
    }

    if (!isActiveSite(cmsSiteModel)) {
        throw new IllegalStateException(
                "Site is not active. Active flag behaviour must be implement for this project.");
    }

    getContextInformationLoader().setCatalogVersions();
    // set fall back language enabled
    setFallbackLanguage(httpRequest, Boolean.TRUE);

    return true;
}

From source file:hubert.team.paragraphs.AdvertsOverviewModel.java

private Link getLink(final Calendar monthToShow) {

    return new Link() {
        public String getHref() {
            String newURL = MagnoliaTemplatingUtilities.getInstance()
                    .createLink(MgnlContext.getAggregationState().getMainContent());
            newURL = StringUtils.removeEnd(newURL, ".html");
            newURL = StringUtils.removeEnd(newURL, "." + MgnlContext.getAggregationState().getSelector());
            newURL += DateFormatUtils.format(monthToShow, ".yyyy.MM") + ".html";
            return newURL;
        }/*w ww  . j a  va  2s . c om*/

        public String getNavigationTitle() {
            return null;
        }

        public String getTitle() {
            return DateFormatUtils.format(monthToShow, "MMMM",
                    I18nContentSupportFactory.getI18nSupport().getLocale());
        }
    };
}

From source file:info.magnolia.importexport.BootstrapUtil.java

/**
 * I.e. given a resource path like <code>/mgnl-bootstrap/foo/config.server.i18n.xml</code> and <code>.xml</code> extension it will return <code>config.server.i18n</code> (no trailing dot).
 * If extension is <code>null</code>, it defaults to <code>.xml</code>.
 *//*  www  . java  2  s  .  com*/
public static String getFilenameFromResource(final String resourcePath, final String extension) {
    String ext = StringUtils.defaultIfEmpty(extension, ".xml");
    String tmpResourcePath = resourcePath;
    if (resourcePath.contains("/")) {
        tmpResourcePath = StringUtils.substringAfterLast(resourcePath, "/");
    }
    return StringUtils.removeEnd(tmpResourcePath, ext.startsWith(".") ? ext : "." + ext);
}