Example usage for org.springframework.util StringUtils endsWithIgnoreCase

List of usage examples for org.springframework.util StringUtils endsWithIgnoreCase

Introduction

In this page you can find the example usage for org.springframework.util StringUtils endsWithIgnoreCase.

Prototype

public static boolean endsWithIgnoreCase(@Nullable String str, @Nullable String suffix) 

Source Link

Document

Test if the given String ends with the specified suffix, ignoring upper/lower case.

Usage

From source file:org.zalando.baigan.model.EndsWith.java

@Override
public boolean eval(final String forValue) {
    for (final String endsWith : endsWithValue) {
        if (StringUtils.endsWithIgnoreCase(forValue, endsWith)) {
            return true;
        }/*from  ww  w. j  av a  2s .c o m*/
    }
    return false;
}

From source file:org.fosstrak.ale.server.type.FileSubscriberOutputChannel.java

public FileSubscriberOutputChannel(String notificationURI) throws InvalidURIException {
    super(notificationURI);
    try {/*  ww w. ja v  a 2 s  .  com*/
        uri = new URI(notificationURI.replaceAll("\\\\", "/"));
        path = StringUtils.startsWithIgnoreCase(uri.getPath(), "/") ? uri.getPath().substring(1)
                : uri.getPath();
        if ("".equalsIgnoreCase(path) || StringUtils.endsWithIgnoreCase(path, "/")) {
            throw new InvalidURIException("missing filename");
        }
        host = (uri.getHost() == null) ? LOCALHOST.toLowerCase() : uri.getHost();
        if (!(LOCALHOST.equalsIgnoreCase(getHost()))) {
            throw new InvalidURIException("This implementation can not write reports to a remote file.");
        }
        if (!("FILE".equalsIgnoreCase(uri.getScheme()))) {
            LOG.error("invalid scheme: " + uri.getScheme());
            throw new InvalidURIException("invalid scheme: " + uri.getScheme());
        }
    } catch (Exception e) {
        LOG.error("malformed URI");
        throw new InvalidURIException("malformed URI: ", e);
    }
}

From source file:eionet.web.filter.ContentNegotiationFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    request.setCharacterEncoding("utf-8");

    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse = (HttpServletResponse) response;
    String requestUrl = httpRequest.getRequestURL().toString();

    if (!StringUtils.endsWithIgnoreCase(requestUrl, "/rdf")) {
        if (isRdfXmlPreferred(httpRequest)) {
            String redirectUrl = requestUrl + "/rdf";
            httpResponse.sendRedirect(redirectUrl);
            return;
        }/*  w w  w  .  j a  va 2 s .com*/
    }

    chain.doFilter(request, response);
}

From source file:org.kuali.kra.award.service.impl.AwardHierarchyUIServiceImpl.java

protected Map<String, AwardHierarchyNode> getAwardHierarchyNodes(String awardNumber, String currentAwardNumber,
        String currentSequenceNumber) {
    if (awardHierarchyNodes == null || awardHierarchyNodes.size() == 0
            || StringUtils.endsWithIgnoreCase(LAST_5_CHARS_OF_ROOT, awardNumber.substring(8))) {
        if (canUseExistingTMSessionObject(awardNumber)) {
            awardHierarchyNodes = ((TimeAndMoneyDocument) GlobalVariables.getUserSession()
                    .retrieveObject(GlobalVariables.getUserSession().getKualiSessionId()
                            + Constants.TIME_AND_MONEY_DOCUMENT_STRING_FOR_SESSION)).getAwardHierarchyNodes();
        } else {/*from  w w w  .  ja v  a 2s  . c  o m*/
            Map<String, AwardHierarchy> awardHierarchyItems = awardHierarchyService
                    .getAwardHierarchy(awardNumber, new ArrayList<String>());
            awardHierarchyService.populateAwardHierarchyNodes(awardHierarchyItems, awardHierarchyNodes,
                    currentAwardNumber, currentSequenceNumber);
        }
    }
    return awardHierarchyNodes;
}

From source file:org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader.java

/**
 * Load bean definitions from the specified Groovy script or XML file.
 * <p>Note that {@code ".xml"} files will be parsed as XML content; all other kinds
 * of resources will be parsed as Groovy scripts.
 * @param encodedResource the resource descriptor for the Groovy script or XML file,
 * allowing specification of an encoding to use for parsing the file
 * @return the number of bean definitions found
 * @throws BeanDefinitionStoreException in case of loading or parsing errors
 *//*from  w w  w  . j  a v  a 2 s  .  c  om*/
public int loadBeanDefinitions(EncodedResource encodedResource) throws BeanDefinitionStoreException {
    // Check for XML files and redirect them to the "standard" XmlBeanDefinitionReader
    String filename = encodedResource.getResource().getFilename();
    if (StringUtils.endsWithIgnoreCase(filename, ".xml")) {
        return this.standardXmlBeanDefinitionReader.loadBeanDefinitions(encodedResource);
    }

    Closure beans = new Closure(this) {
        public Object call(Object[] args) {
            invokeBeanDefiningClosure((Closure) args[0]);
            return null;
        }
    };
    Binding binding = new Binding() {
        @Override
        public void setVariable(String name, Object value) {
            if (currentBeanDefinition != null) {
                applyPropertyToBeanDefinition(name, value);
            } else {
                super.setVariable(name, value);
            }
        }
    };
    binding.setVariable("beans", beans);

    int countBefore = getRegistry().getBeanDefinitionCount();
    try {
        GroovyShell shell = new GroovyShell(getBeanClassLoader(), binding);
        shell.evaluate(encodedResource.getReader(), "beans");
    } catch (Throwable ex) {
        throw new BeanDefinitionParsingException(
                new Problem("Error evaluating Groovy script: " + ex.getMessage(),
                        new Location(encodedResource.getResource()), null, ex));
    }
    return getRegistry().getBeanDefinitionCount() - countBefore;
}

From source file:org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.java

private void loadBeanDefinitionsFromImportedResources(
        Map<String, Class<? extends BeanDefinitionReader>> importedResources) {

    Map<Class<?>, BeanDefinitionReader> readerInstanceCache = new HashMap<>();

    for (Map.Entry<String, Class<? extends BeanDefinitionReader>> entry : importedResources.entrySet()) {
        String resource = entry.getKey();
        Class<? extends BeanDefinitionReader> readerClass = entry.getValue();

        // Default reader selection necessary?
        if (BeanDefinitionReader.class == readerClass) {
            if (StringUtils.endsWithIgnoreCase(resource, ".groovy")) {
                // When clearly asking for Groovy, that's what they'll get...
                readerClass = GroovyBeanDefinitionReader.class;
            } else {
                // Primarily ".xml" files but for any other extension as well
                readerClass = XmlBeanDefinitionReader.class;
            }/*from   w  w  w  . ja  v a  2 s.  co  m*/
        }

        BeanDefinitionReader reader = readerInstanceCache.get(readerClass);
        if (reader == null) {
            try {
                // Instantiate the specified BeanDefinitionReader
                reader = readerClass.getConstructor(BeanDefinitionRegistry.class).newInstance(this.registry);
                // Delegate the current ResourceLoader to it if possible
                if (reader instanceof AbstractBeanDefinitionReader) {
                    AbstractBeanDefinitionReader abdr = ((AbstractBeanDefinitionReader) reader);
                    abdr.setResourceLoader(this.resourceLoader);
                    abdr.setEnvironment(this.environment);
                }
                readerInstanceCache.put(readerClass, reader);
            } catch (Throwable ex) {
                throw new IllegalStateException(
                        "Could not instantiate BeanDefinitionReader class [" + readerClass.getName() + "]");
            }
        }

        // TODO SPR-6310: qualify relative path locations as done in AbstractContextLoader.modifyLocations
        reader.loadBeanDefinitions(resource);
    }
}

From source file:org.springframework.data.hadoop.store.support.OutputStoreObjectSupport.java

/**
 * Rename file using prefix and suffix settings.
 *
 * @param path the path to rename/* w ww  . j a  v a 2s . c  om*/
 */
protected void renameFile(Path path) {
    // bail out if there's no in-writing settings
    if (!StringUtils.hasText(prefix) && !StringUtils.hasText(suffix)) {
        return;
    }
    String name = path.getName();
    if (StringUtils.startsWithIgnoreCase(name, prefix)) {
        name = name.substring(prefix.length());
    }
    if (StringUtils.endsWithIgnoreCase(name, suffix)) {
        name = name.substring(0, name.length() - suffix.length());
    }
    Path toPath = new Path(path.getParent(), name);
    try {
        FileSystem fs = path.getFileSystem(getConfiguration());

        boolean succeed;
        try {
            fs.delete(toPath, false);
            succeed = fs.rename(path, toPath);
        } catch (Exception e) {
            throw new StoreException("Failed renaming from " + path + " to " + toPath, e);
        }
        if (!succeed) {
            throw new StoreException(
                    "Failed renaming from " + path + " to " + toPath + " because hdfs returned false");
        }
    } catch (IOException e) {
        log.error("Error renaming file", e);
        throw new StoreException("Error renaming file", e);
    }
}

From source file:org.springframework.yarn.boot.YarnAppmasterAutoConfiguration.java

private static String explodedEntryIfZip(SpringYarnAppmasterLaunchContextProperties syalcp) {
    return StringUtils.endsWithIgnoreCase(syalcp.getArchiveFile(), ".zip") ? "./" + syalcp.getArchiveFile()
            : null;/*  w  w  w  .j  a  v a2  s .c  om*/
}