Java Code Examples for org.apache.commons.lang.StringUtils.replaceOnce()

The following are Jave code examples for showing how to use replaceOnce() of the org.apache.commons.lang.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: YiDu-Novel   File: GenerateHtmlFileInterceptor.java   Source Code and License Vote up 5 votes
@Override
public String intercept(final ActionInvocation invocation) throws Exception {
    String rtn = invocation.invoke();

    if (YiDuConstants.yiduConf.getBoolean(YiDuConfig.ENABLE_GENERATE_HTML_FILE, false)) {
        // 如果是阅读页的话,同时生成静态页面 并且不生成分卷阅读
        if (invocation.getAction() instanceof ReaderAction
                && ((ReaderAction) invocation.getAction()).getToChapterno() == 0) {
            ReaderAction action = (ReaderAction) invocation.getAction();
            logger.info("going to Generate Html file." + YiDuConstants.requestUri.get());

            String templatePath = "themes/" + YiDuConstants.yiduConf.getString(YiDuConfig.THEME_NAME) + "/pc/"
                    + action.getTempName() + ".ftl";

            StaticUtils.crateHTML(ServletActionContext.getServletContext(), action, templatePath,
                    YiDuConstants.requestUri.get());

            // 判断上一章的静态页是否存在
            ChapterDTO chapter = action.getChapter();
            if (chapter.getPreChapterno() != 0) {
                // TODO 如果章节ID和小说ID一样的话,会出现问题,将来改吧
                String preUri = StringUtils.replaceOnce(YiDuConstants.requestUri.get(),
                        String.valueOf(chapter.getChapterno()), String.valueOf(chapter.getPreChapterno()));

                String preChapterPath = ServletActionContext.getServletContext().getRealPath("/") + "/" + preUri;
                File preChpaterHtml = new File(preChapterPath);
                if (preChpaterHtml.exists() && preChpaterHtml.lastModified() < chapter.getPostdate().getTime()) {
                    // 只有当文件存在,并且最后修改时间比当前章节的发布时间小的情况才生成前一张,因为下一章已经更新啦!
                    action.setChapterno(chapter.getPreChapterno());
                    action.execute();
                    logger.info("going to Generate Html file." + preChapterPath);
                    StaticUtils.crateHTML(ServletActionContext.getServletContext(), action, templatePath, preUri);
                }

            }

        }
    }
    return rtn;
}
 
Example 2
Project: netty-socketio-demo   File: WebUtils.java   Source Code and License Vote up 5 votes
/**
 * 得到不包含项目名的链接
 * 
 * @param request
 * @return
 */
public static String getShortURI(HttpServletRequest request) {
    String shortUrl = StringUtils.replaceOnce(request.getRequestURI(), request.getContextPath(), StringUtils.EMPTY);
    // String shortUrl = request.getRequestURI().replaceFirst(request.getContextPath(), StringUtils.EMPTY);
    shortUrl = StringUtils.EMPTY.equals(shortUrl) ? SEPARATOR_SLASH : shortUrl;

    while (shortUrl.startsWith(DOUBLE_SPRIT)) {
        shortUrl = shortUrl.substring(1);
    }
    return shortUrl;
}
 
Example 3
Project: Yidu   File: GenerateHtmlFileInterceptor.java   Source Code and License Vote up 5 votes
@Override
public String intercept(final ActionInvocation invocation) throws Exception {
    String rtn = invocation.invoke();

    if (YiDuConstants.yiduConf.getBoolean(YiDuConfig.ENABLE_GENERATE_HTML_FILE, false)) {
        // 如果是阅读页的话,同时生成静态页面 并且不生成分卷阅读
        if (invocation.getAction() instanceof ReaderAction
                && ((ReaderAction) invocation.getAction()).getToChapterno() == 0) {
            ReaderAction action = (ReaderAction) invocation.getAction();
            logger.info("going to Generate Html file." + YiDuConstants.requestUri.get());

            String templatePath = "themes/" + YiDuConstants.yiduConf.getString(YiDuConfig.THEME_NAME) + "/pc/"
                    + action.getTempName() + ".ftl";

            StaticUtils.crateHTML(ServletActionContext.getServletContext(), action, templatePath,
                    YiDuConstants.requestUri.get());

            // 判断上一章的静态页是否存在
            ChapterDTO chapter = action.getChapter();
            if (chapter.getPreChapterno() != 0) {
                // TODO 如果章节ID和小说ID一样的话,会出现问题,将来改吧
                String preUri = StringUtils.replaceOnce(YiDuConstants.requestUri.get(),
                        String.valueOf(chapter.getChapterno()), String.valueOf(chapter.getPreChapterno()));

                String preChapterPath = ServletActionContext.getServletContext().getRealPath("/") + "/" + preUri;
                File preChpaterHtml = new File(preChapterPath);
                if (preChpaterHtml.exists() && preChpaterHtml.lastModified() < chapter.getPostdate().getTime()) {
                    // 只有当文件存在,并且最后修改时间比当前章节的发布时间小的情况才生成前一张,因为下一章已经更新啦!
                    action.setChapterno(chapter.getPreChapterno());
                    action.execute();
                    logger.info("going to Generate Html file." + preChapterPath);
                    StaticUtils.crateHTML(ServletActionContext.getServletContext(), action, templatePath, preUri);
                }

            }

        }
    }
    return rtn;
}
 
Example 4
Project: media_information_service   File: MediaOperations.java   Source Code and License Vote up 4 votes
public static String forceHTTPS(String s){
    String https = StringUtils.replaceOnce(s,"http","https");
    return https;
}