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

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

Introduction

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

Prototype

public static boolean endsWith(String str, String suffix) 

Source Link

Document

Check if a String ends with a specified suffix.

Usage

From source file:cec.easyshop.storefront.controllers.misc.StoreSessionController.java

protected String getReturnRedirectUrlForUrlEncoding(final HttpServletRequest request, final String old,
        final String current) {
    final String originalReferer = (String) request.getSession()
            .getAttribute(StorefrontFilter.ORIGINAL_REFERER);
    if (StringUtils.isNotBlank(originalReferer)) {
        return REDIRECT_PREFIX + StringUtils.replace(originalReferer, "/" + old + "/", "/" + current + "/");
    }/*w  w  w .j  a  v a2 s  .c o  m*/

    String referer = StringUtils.remove(request.getRequestURL().toString(), request.getServletPath());
    if (!StringUtils.endsWith(referer, "/")) {
        referer = referer + "/";
    }
    if (referer != null && !referer.isEmpty() && StringUtils.contains(referer, "/" + old + "/")) {
        return REDIRECT_PREFIX + StringUtils.replace(referer, "/" + old + "/", "/" + current + "/");
    }
    return REDIRECT_PREFIX + referer;
}

From source file:com.epam.trade.storefront.controllers.misc.StoreSessionController.java

protected String getReturnRedirectUrlForUrlEncoding(final HttpServletRequest request, final String old,
        final String current) {
    final String originalReferer = (String) request.getAttribute(StorefrontFilter.ORIGINAL_REFERER);
    if (StringUtils.isNotBlank(originalReferer)) {
        return REDIRECT_PREFIX + StringUtils.replace(originalReferer, "/" + old + "/", "/" + current + "/");
    }//ww w.  j  a va 2s . c  o m

    String referer = StringUtils.remove(request.getRequestURL().toString(), request.getServletPath());
    if (!StringUtils.endsWith(referer, "/")) {
        referer = referer + "/";
    }
    if (referer != null && !referer.isEmpty() && StringUtils.contains(referer, "/" + old + "/")) {
        return REDIRECT_PREFIX + StringUtils.replace(referer, "/" + old + "/", "/" + current + "/");
    }
    return REDIRECT_PREFIX + referer;
}

From source file:com.activecq.tools.flipbook.components.impl.FlipbookServiceImpl.java

public String getReadme(final Component component, final ResourceResolver resourceResolver) {

    String contents = "";

    final Resource cr = resourceResolver.resolve(component.getPath());
    final Resource flipbook = cr.getChild(COMPONENT_FLIPBOOK_NODE);

    if (flipbook == null) {
        return contents;
    }/*w  w w.j  a  va 2  s . c  o m*/

    Resource readme = null;

    for (String name : README_NAMES) {
        final Resource tmp = flipbook.getChild(name);

        if (tmp != null && ResourceUtil.isA(tmp, JcrConstants.NT_FILE)) {
            // Use the first README nt:file node found
            readme = tmp;
            break;
        }
    }

    try {
        if (readme != null) {
            final Node node = readme.adaptTo(Node.class);
            final Node jcrContent = node.getNode(JcrConstants.JCR_CONTENT);
            final InputStream content = jcrContent.getProperty(JcrConstants.JCR_DATA).getBinary().getStream();

            try {
                contents = IOUtils.toString(content);
            } catch (IOException e) {
                contents = "Could not read README";
            }

            /* Handle markdown */
            if (StringUtils.endsWith(readme.getName(), ".md")) {
                contents = new PegDownProcessor().markdownToHtml(contents);
            } else if (StringUtils.endsWith(readme.getName(), ".txt")) {
                // Wrap .txt with PRE tags
                contents = "<pre>" + contents + "</pre>";
            }

        }
    } catch (RepositoryException ex) {
        contents = "Could not read README";
    } catch (NullPointerException ex) {
        contents = "Could not read README";
    }
    return StringUtils.stripToEmpty(contents);

}

From source file:edu.cornell.med.icb.goby.reads.ReadsReader.java

/**
 * Return the basename corresponding to the input reads filename.  Note
 * that if the filename does have the extension known to be a compact read
 * the returned value is the original filename
 *
 * @param filename The name of the file to get the basename for
 * @return basename for the alignment file
 *//*ww  w .  j  a v a  2s  .  c o  m*/
public static String getBasename(final String filename) {
    for (final String ext : FileExtensionHelper.COMPACT_READS_FILE_EXTS) {
        if (StringUtils.endsWith(filename, ext)) {
            return StringUtils.removeEnd(filename, ext);
        }
    }

    // perhaps the input was a basename already.
    return filename;
}

From source file:de.devboost.emfcustomize.EcoreModelRefactorer.java

public Set<Method> getAnnotatedMethods(Class customClass) {
    Set<Method> annotatedMethods = new HashSet<Method>();

    List<Method> methods = customClass.getMethods();
    for (Method method : methods) {
        List<String> comments = method.getComments();
        if (comments != null && comments.size() > 0) {
            for (String comment : comments) {
                String[] lines = comment.split("[\\r\\n]+");
                for (String line : lines) {
                    String deleteWhitespace = StringUtils.deleteWhitespace(line);
                    if (StringUtils.endsWith(deleteWhitespace, MODEL_ANNOTATION)) {
                        String difference = StringUtils.removeEnd(deleteWhitespace, MODEL_ANNOTATION);
                        if (StringUtils.containsOnly(difference, VALID_PREFIX_CHARACTERS)
                                || difference.isEmpty()) {
                            annotatedMethods.add(method);
                        }//  w w  w. j  ava2 s.co m
                    }
                }
            }
        }
    }
    return annotatedMethods;
}

From source file:info.magnolia.link.LinkUtil.java

/**
 * Make a absolute path relative. It adds ../ until the root is reached
 * @param absolutePath absolute path/*from w  ww  .  j  a v a2  s  .  c  o m*/
 * @param url page to be relative to
 * @return relative path
 */
public static String makePathRelative(String url, String absolutePath) {
    String fromPath = StringUtils.substringBeforeLast(url, "/");
    String toPath = StringUtils.substringBeforeLast(absolutePath, "/");

    // reference to parent folder
    if (StringUtils.equals(fromPath, toPath) && StringUtils.endsWith(absolutePath, "/")) {
        return ".";
    }

    String[] fromDirectories = StringUtils.split(fromPath, "/");
    String[] toDirectories = StringUtils.split(toPath, "/");

    int pos = 0;
    while (pos < fromDirectories.length && pos < toDirectories.length
            && fromDirectories[pos].equals(toDirectories[pos])) {
        pos++;
    }

    StringBuilder rel = new StringBuilder();
    for (int i = pos; i < fromDirectories.length; i++) {
        rel.append("../");
    }

    for (int i = pos; i < toDirectories.length; i++) {
        rel.append(toDirectories[i] + "/");
    }

    rel.append(StringUtils.substringAfterLast(absolutePath, "/"));

    return rel.toString();
}

From source file:mitm.common.util.MiscStringUtils.java

/**
 * If input does not end with endsWith it will append endsWith and return the result. If input does end with
 * endsWith input will be returned.//from w w  w.jav a2s.com
 */
public static String ensureEndsWith(String input, String endsWith) {
    return StringUtils.endsWith(input, endsWith) ? StringUtils.defaultString(input)
            : StringUtils.defaultString(input) + StringUtils.defaultString(endsWith);
}

From source file:com.adobe.acs.commons.wcm.impl.AemEnvironmentIndicatorFilter.java

@SuppressWarnings("squid:S3923")
private boolean accepts(final HttpServletRequest request) {
    if (StringUtils.isBlank(css) && StringUtils.isBlank(titlePrefix)) {
        // Only accept is properly configured
        log.warn("AEM Environment Indicator is not properly configured; If this feature is unwanted, "
                + "remove the OSGi configuration and disable completely.");
        return false;
    } else if (!StringUtils.equalsIgnoreCase("get", request.getMethod())) {
        // Only inject on GET requests
        return false;
    } else if (StringUtils.startsWithAny(request.getRequestURI(), REJECT_PATH_PREFIXES)) {
        // Reject any request to well-known rejection-worthy path prefixes
        return false;
    } else if (StringUtils.equals(request.getHeader("X-Requested-With"), "XMLHttpRequest")) {
        // Do not inject into XHR requests
        return false;
    } else if (StringUtils.endsWith(request.getHeader("Referer"), "/editor.html" + request.getRequestURI())) {
        // Do not apply to pages loaded in the TouchUI editor.html
        return false;
    } else if (StringUtils.endsWith(request.getHeader("Referer"), "/cf")) {
        // Do not apply to pages loaded in the Classic Content Finder
        return false;
    }/*from www . j  a  v  a2  s .  c om*/
    return true;
}

From source file:eionet.meta.dao.domain.DataElement.java

/**
 * Sets related base uri if input is not empty string.
 *
 * @param relatedConceptBaseURI/*from www .  j av  a2s. c  om*/
 *            base uri
 */
public void setRelatedConceptBaseURI(String relatedConceptBaseURI) {
    this.relatedConceptBaseURI = StringUtils.trimToNull(relatedConceptBaseURI);
    if (StringUtils.isNotBlank(this.relatedConceptBaseURI)
            && !StringUtils.endsWith(this.relatedConceptBaseURI, "/")
            && !StringUtils.endsWith(this.relatedConceptBaseURI, ":")
            && !StringUtils.endsWith(this.relatedConceptBaseURI, "#")) {
        this.relatedConceptBaseURI += "/";
    }
}

From source file:com.cimmyt.model.dao.impl.AbstractDAO.java

/**
 * Find single by values/*from ww w . ja  v a2s. co m*/
 * @param clazz
 * @param properties
 * @param values
 * @return
 * @throws Exception
 */
public T findSingleByValues(T clazz, Object[] properties, Object[] values) throws Exception {

    if (properties.length != values.length) {
        throw new Exception("The number of properties must be the same than the number of values");
    }
    String strClazz = type.getSimpleName();
    StringBuilder builder = new StringBuilder("SELECT DISTINCT a FROM " + strClazz + " a" + " WHERE ");
    for (int i = 0; i < values.length; i++) {
        if (values[i] instanceof String) {
            builder.append("a." + properties[i] + " LIKE ?");
        } else {
            builder.append("a." + properties[i] + " = ?");
        }
        builder.append(" AND ");
    }
    String query = builder.toString().trim();
    if (StringUtils.endsWith(query, "AND")) {
        query = StringUtils.removeEnd(query, "AND");
    }
    @SuppressWarnings("unchecked")
    List<T> list = (List<T>) getHibernateTemplate().find(query, values);
    if (list != null && !list.isEmpty()) {
        return list.get(0);
    } else {
        return null;
    }
}