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:com.cognifide.actions.core.ActionRegistryService.java

private String createPath(String relPath) {
    String path;//w w w.ja v  a 2 s  . c om
    if (StringUtils.startsWith(relPath, "/")) {
        path = relPath;
    } else {
        final DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd/");
        path = actionRoot + dateFormat.format(new Date()) + relPath;
    }

    if (path.endsWith("/*")) {
        String generated = StringUtils.EMPTY + new Date().getTime() + "-" + random.nextInt(100);
        path = StringUtils.removeEnd(path, "*") + generated;
    }
    return path;
}

From source file:net.sourceforge.fenixedu.webServices.jersey.api.FenixJerseyAPIConfig.java

private static String ends(String path) {
    return StringUtils.removeStart(StringUtils.removeEnd(path, "/"), "/");
}

From source file:com.qualinsight.plugins.sonarqube.badges.internal.QualityGateStatusRetriever.java

private String responseBodyForKey(final String key) throws IOException, URISyntaxException {
    final URIBuilder uriBuilder = new URIBuilder(this.settings.getString(SERVER_BASE_URL_KEY));
    final String uriQuery = new StringBuilder().append("resource=").append(key)
            .append("&metrics=quality_gate_details&format=json").toString();
    this.httpGet.setURI(new URI(uriBuilder.getScheme(), null, uriBuilder.getHost(), uriBuilder.getPort(),
            StringUtils.removeEnd(uriBuilder.getPath(), URI_SEPARATOR) + "/api/resources/index/", uriQuery,
            null));/*from ww w  . j  a  v  a 2s.  co m*/
    LOGGER.debug("Http GET request line: {}", this.httpGet.getRequestLine());
    final String responseBody = this.httpclient.execute(this.httpGet, this.responseHandler);
    LOGGER.debug("Http GET response body: {}", responseBody);
    return responseBody;
}

From source file:com.jayway.jaxrs.hateoas.DefaultHateoasContext.java

private void mapMethod(Class<?> clazz, String rootPath, Method method) {
    String httpMethod = findHttpMethod(method);

    if (httpMethod != null) {
        String path = getPath(rootPath, method);
        String[] consumes = getConsumes(method);
        String[] produces = getProduces(method);

        if (method.isAnnotationPresent(Linkable.class)) {
            Linkable linkAnnotation = method.getAnnotation(Linkable.class);
            String id = linkAnnotation.value();
            if (linkableMapping.containsKey(id)) {
                throw new IllegalArgumentException(
                        "Id '" + id + "' mapped in class " + clazz + " is already mapped from another class");
            }/*  www. jav  a  2s  .co  m*/

            LinkableParameterInfo[] parameterInfo = extractMethodParameterInfo(method);

            LinkableInfo linkableInfo = new LinkableInfo(id, path, httpMethod, consumes, produces,
                    linkAnnotation.label(), linkAnnotation.description(), linkAnnotation.templateClass(),
                    parameterInfo);

            linkableMapping.put(id, linkableInfo);
        } else {
            logger.info("Method {} is missing Linkable annotation", method);
        }
    } else {
        //this might be a sub resource method
        if (method.isAnnotationPresent(Path.class)) {
            String path = method.getAnnotation(Path.class).value();
            if (path.endsWith("/")) {
                path = StringUtils.removeEnd(path, "/");
            }

            Class<?> subResourceType = method.getReturnType();

            mapClass(subResourceType, rootPath + path);
        }
    }
}

From source file:com.edgenius.wiki.render.filter.UserFilter.java

@Override
protected void replaceHTML(HTMLNode node, ListIterator<HTMLNode> nodeIter, RenderContext context) {
    if (node.getPair() == null) {
        AuditLogger.error("Unexpected case: Unable to find close </a> tag");
        return;/*  w ww .  j  av  a 2  s . co m*/
    }

    LinkModel link = new LinkModel();
    //we don't need view info,so just skip it
    link.fillToObject(node.getText(), null);

    //We put username into last part of anchor: /$CPAGE/up/admin
    String linkURL = link.getAnchor();
    if (StringUtils.endsWith(linkURL, "/")) {
        linkURL = StringUtils.removeEnd(linkURL, "/");
    }

    int idx = StringUtils.lastIndexOf(linkURL, "/");
    if (idx != -1) {
        String username = linkURL.substring(idx + 1);
        HTMLNode subnode = node.next();
        while (subnode != null && subnode != node.getPair()) {
            if (subnode.isTextNode())
                subnode.reset("", true);
            subnode = subnode.next();
        }
        node.getPair().reset("", true);
        String markupBorder = getSeparatorFilter(node);
        StringBuffer markup = new StringBuffer(markupBorder).append("@");
        markup.append(username);
        markup.append("@").append(markupBorder);

        node.reset(markup.toString(), true);
    }
}

From source file:hydrograph.ui.engine.ui.converter.impl.OutputDBUpdateUiConverter.java

/**
 *  Appends update keys using a comma/*from ww  w.j a v  a  2s  .c  om*/
 * @param typeUpdateKeys
 */
private String getUpdateKeyUIValue(TypeUpdateKeys typeUpdateKeys) {
    StringBuffer buffer = new StringBuffer();
    if (typeUpdateKeys != null && typeUpdateKeys.getUpdateByKeys() != null) {
        TypeKeyFields keyFields = typeUpdateKeys.getUpdateByKeys();
        for (TypeFieldName fieldName : keyFields.getField()) {
            buffer.append(fieldName.getName());
            buffer.append(",");
        }
    }

    return StringUtils.removeEnd(buffer.toString(), ",");
}

From source file:com.neelo.glue.ApplicationModule.java

public RequestResolution resolve(Lifecycle lifecycle) throws ResolutionException {
    HttpServletRequest request = lifecycle.getRequest();
    HttpMethod method = HttpMethod.valueOf(request.getMethod());

    // TODO: These two lines depend on the servlet mapping (/app/*, /)
    // String path =
    // request.getRequestURI().substring(request.getContextPath().length());
    String path = request.getPathInfo();
    path = StringUtils.removeEnd(path, FORWARD_SLASH);

    for (Route route : routes) {
        if (!method.equals(route.getHttpMethod()))
            continue;

        if (StringUtils.isBlank(path) && StringUtils.isBlank(route.getFullPath()))
            return new RequestResolution(route, EMPTY_PARAMETERS);

        NamedPattern np = NamedPattern.compile(route.getFullPath());
        NamedMatcher nm = np.matcher(path);

        List<String> names = np.groupNames();

        if (nm.matches()) {
            if (names.size() > 0) {
                List<Parameter> params = new ArrayList<Parameter>();
                for (String name : names) {
                    params.add(new Parameter(name, nm.group(name)));
                }/*from   ww  w.j  av a 2  s  .  c  o m*/
                return new RequestResolution(route, params);
            }
            return new RequestResolution(route, EMPTY_PARAMETERS);
        }
    }

    throw new ResolutionException(404, "Resource not found @ " + path);
}

From source file:com.hangum.tadpole.engine.sql.util.SQLUtil.java

/**
 * sql     ./*w w  w  . j av  a  2s  .  c o  m*/
 * 
 * @param userDB
 * @param exeSQL
 * @return
 */
public static String removeCommentAndOthers(UserDBDAO userDB, String exeSQL) {
    exeSQL = StringUtils.trimToEmpty(exeSQL);
    exeSQL = removeComment(exeSQL);
    exeSQL = StringUtils.trimToEmpty(exeSQL);
    exeSQL = StringUtils.removeEnd(exeSQL, "/");
    exeSQL = StringUtils.trimToEmpty(exeSQL);
    //TO DO ?? ? ?  (;)  .  ?  .
    exeSQL = StringUtils.removeEnd(exeSQL, PublicTadpoleDefine.SQL_DELIMITER);

    return exeSQL;
}

From source file:info.magnolia.cms.util.SimpleUrlPattern.java

/**
 * Mainly used by ContentToBean.// w w w  .j a  v a2s .  c o m
 */
public void setPatternString(String patternString) {
    this.length = StringUtils.removeEnd(patternString, "*").length();
    this.pattern = Pattern.compile(getEncodedString(patternString), Pattern.DOTALL);
    this.patternString = patternString;
}

From source file:info.magnolia.cms.filters.Mapping.java

/**
 * See SRV.11.2 Specification of Mappings in the Servlet Specification for the syntax of
 * mappings. Additionally, you can also use plain regular expressions to map your servlets, by
 * prefix the mapping by "regex:". (in which case anything in the request url following the
 * expression's match will be the pathInfo - if your pattern ends with a $, extra pathInfo won't
 * match)/*from  w ww. ja  v  a  2s . c  o  m*/
 */
public void addMapping(final String mapping) {
    final String pattern;

    // we're building a Pattern with 3 groups: (1) servletPath (2) ignored (3) pathInfo

    if (isDefaultMapping(mapping)) {
        // the mapping is exactly '/*', the servlet path should be
        // an empty string and everything else should be the path info
        pattern = "^()(/)(" + SimpleUrlPattern.MULTIPLE_CHAR_PATTERN + ")";
    } else if (isPathMapping(mapping)) {
        // the pattern ends with /*, escape out metacharacters for
        // use in a regex, and replace the ending * with MULTIPLE_CHAR_PATTERN
        final String mappingWithoutSuffix = StringUtils.removeEnd(mapping, "/*");
        pattern = "^(" + escapeMetaCharacters(mappingWithoutSuffix) + ")(/)("
                + SimpleUrlPattern.MULTIPLE_CHAR_PATTERN + ")";
    } else if (isExtensionMapping(mapping)) {
        // something like '*.jsp', everything should be the servlet path
        // and the path info should be null
        final String regexedMapping = StringUtils.replace(mapping, "*.",
                SimpleUrlPattern.MULTIPLE_CHAR_PATTERN + "\\.");
        pattern = "^(" + regexedMapping + ")$";
    } else if (isRegexpMapping(mapping)) {
        final String mappingWithoutPrefix = StringUtils.removeStart(mapping, "regex:");
        pattern = "^(" + mappingWithoutPrefix + ")($|/)(" + SimpleUrlPattern.MULTIPLE_CHAR_PATTERN + ")";
    } else {
        // just literal text, ensure metacharacters are escaped, and that only
        // the exact string is matched.
        pattern = "^(" + escapeMetaCharacters(mapping) + ")$";
    }
    log.debug("Adding new mapping for {}", mapping);

    mappings.add(Pattern.compile(pattern));
}