Java Code Examples for org.apache.commons.lang3.StringUtils.endsWithAny()

The following are Jave code examples for showing how to use endsWithAny() of the org.apache.commons.lang3.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: YiDu-Novel   File: SingleBookFilter.java   View Source Code Vote up 6 votes
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
        ServletException {
    YiDuConstants.singleBookFlag.set(false);
    HttpServletRequest req = (HttpServletRequest) request;
    String uri = req.getRequestURI();
    if (StringUtils.endsWithAny(uri, "css", "js", "jpg", "png", "gif")) {
        // 静态资源直接跳过
        logger.debug("ignore static resource." + uri);
        chain.doFilter(request, response);
    } else {
        // 非静态资源时,根据具体的信息去做判别,时候需要标识单本
        String rootDomian = YiDuConstants.yiduConf.getString(YiDuConfig.ROOT_DOMAIN);
        String aname = StringUtils.substringBeforeLast(req.getServerName(), "." + rootDomian);
        logger.debug("aname : " + aname);
        if (StringUtils.isNotBlank(aname)) {
            int articleno = SingleBookManager.getArticleno(aname);
            if (articleno != 0) {
                // TODO 即便找到对应的小说,也只做首页和阅读页,其他全部404吧
                Pattern p = Pattern.compile(regex);
                Matcher m = p.matcher(uri);
                boolean matchFlag = false;
                String newURI = "";
                if (m.find()) {
                    // 阅读页
                    newURI = ReaderAction.URL + "?chapterno="
                            + StringUtils.substringBeforeLast(m.group(1), ".html");
                    matchFlag = true;
                } else if (StringUtils.equals(uri, "/") || StringUtils.isEmpty(uri)) {
                    // 首页
                    newURI = InfoAction.URL + "?articleno=" + articleno;
                    matchFlag = true;
                } else {
                    // 返回404
                    YiDuConstants.singleBookFlag.set(true);
                    ((HttpServletResponse) response).sendError(HttpServletResponse.SC_NOT_FOUND);
                }
                logger.debug("newURI str: " + newURI);
                if (matchFlag) {
                    YiDuConstants.singleBookFlag.set(true);
                    YiDuConstants.singleBookServerName.set(req.getServerName());
                    req.getRequestDispatcher(newURI).forward(request, response);
                }
            } else {
                chain.doFilter(request, response);
            }
        } else {
            chain.doFilter(request, response);
        }
    }
}
 
Example 2
Project: GameResourceBot   File: Commands.java   View Source Code Vote up 4 votes
private static List<StockType> getTargetStockTypes(Scanner scanner, Message message,
        String operation) {
    Locale locale = getResponseLocale(message);
    List<StockType> stockTypes = new ArrayList<>();
    List<String> unknownStockTypes = new ArrayList<>();
    List<String> inputNames = new ArrayList<>();
    while (scanner.hasNext()) {
        String next = scanner.next();
        boolean groupStart = StringUtils.startsWithAny(next, "\"", "\'");
        if (!groupStart) {
            inputNames.add(next);
        } else {
            StringBuilder buffer = new StringBuilder(next);
            boolean groupEnd = false;
            while (scanner.hasNext() && !groupEnd) {
                next = scanner.next();
                groupEnd = StringUtils.endsWithAny(next, "\"", "\'");
                buffer.append(" ");
                buffer.append(next);
            }
            buffer.deleteCharAt(0);
            buffer.deleteCharAt(buffer.length() - 1);
            inputNames.add(buffer.toString());
        }
    }
    for (String inputName : inputNames) {
        try {
            // may throws IllegalArgumentException if there is no
            String key = Resource.getItemKey(inputName, locale);
            Optional<StockType> stockOpt = getStockTypeDao().findByKey(key);
            if (!stockOpt.isPresent()) {
                unknownStockTypes.add(inputName);
            } else {
                stockTypes.add(stockOpt.get());
            }
        } catch (Exception e) {
            unknownStockTypes.add(inputName);
        }
    }
    if (!unknownStockTypes.isEmpty()) {
        String msg = String.format(Resource.getString("GROUP_UNKNOWN_TYPE", locale),
                unknownStockTypes.toString());
        Speaker.err(message, msg);
    }
    return stockTypes;
}
 
Example 3
Project: Yidu   File: SingleBookFilter.java   View Source Code Vote up 4 votes
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
        ServletException {
    YiDuConstants.singleBookFlag.set(false);
    HttpServletRequest req = (HttpServletRequest) request;
    String uri = req.getRequestURI();
    if (StringUtils.endsWithAny(uri, "css", "js", "jpg", "png", "gif")) {
        // 静态资源直接跳过
        logger.debug("ignore static resource." + uri);
        chain.doFilter(request, response);
    } else {
        // 非静态资源时,根据具体的信息去做判别,时候需要标识单本
        String rootDomian = YiDuConstants.yiduConf.getString(YiDuConfig.ROOT_DOMAIN);
        String aname = StringUtils.substringBeforeLast(req.getServerName(), "." + rootDomian);
        logger.debug("aname : " + aname);
        if (StringUtils.isNotBlank(aname)) {
            int articleno = SingleBookManager.getArticleno(aname);
            if (articleno != 0) {
                // TODO 即便找到对应的小说,也只做首页和阅读页,其他全部404吧
                Pattern p = Pattern.compile(regex);
                Matcher m = p.matcher(uri);
                boolean matchFlag = false;
                String newURI = "";
                if (m.find()) {
                    // 阅读页
                    newURI = ReaderAction.URL + "?chapterno="
                            + StringUtils.substringBeforeLast(m.group(1), ".html");
                    matchFlag = true;
                } else if (StringUtils.equals(uri, "/") || StringUtils.isEmpty(uri)) {
                    // 首页
                    newURI = InfoAction.URL + "?articleno=" + articleno;
                    matchFlag = true;
                } else {
                    // 返回404
                    YiDuConstants.singleBookFlag.set(true);
                    ((HttpServletResponse) response).sendError(HttpServletResponse.SC_NOT_FOUND);
                }
                logger.debug("newURI str: " + newURI);
                if (matchFlag) {
                    YiDuConstants.singleBookFlag.set(true);
                    YiDuConstants.singleBookServerName.set(req.getServerName());
                    req.getRequestDispatcher(newURI).forward(request, response);
                }
            } else {
                chain.doFilter(request, response);
            }
        } else {
            chain.doFilter(request, response);
        }
    }
}