當前位置: 首頁>>代碼示例>>Java>>正文


Java StringUtils.endsWithAny方法代碼示例

本文整理匯總了Java中org.apache.commons.lang3.StringUtils.endsWithAny方法的典型用法代碼示例。如果您正苦於以下問題:Java StringUtils.endsWithAny方法的具體用法?Java StringUtils.endsWithAny怎麽用?Java StringUtils.endsWithAny使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.lang3.StringUtils的用法示例。


在下文中一共展示了StringUtils.endsWithAny方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doFilter

import org.apache.commons.lang3.StringUtils; //導入方法依賴的package包/類
@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);
        }
    }
}
 
開發者ID:luckyyeah,項目名稱:YiDu-Novel,代碼行數:52,代碼來源:SingleBookFilter.java

示例2: getTargetStockTypes

import org.apache.commons.lang3.StringUtils; //導入方法依賴的package包/類
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;
}
 
開發者ID:BlackCraze,項目名稱:GameResourceBot,代碼行數:47,代碼來源:Commands.java


注:本文中的org.apache.commons.lang3.StringUtils.endsWithAny方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。