Package org.apache.roller.weblogger.ui.rendering.util

Examples of org.apache.roller.weblogger.ui.rendering.util.WeblogSearchRequest


            throws ServletException, IOException {
       
        log.debug("Entering");
       
        Weblog weblog = null;
        WeblogSearchRequest searchRequest = null;
       
        // first off lets parse the incoming request and validate it
        try {
            searchRequest = new WeblogSearchRequest(request);
           
            // now make sure the specified weblog really exists
            UserManager userMgr = WebloggerFactory.getWeblogger().getUserManager();
            weblog = userMgr.getWebsiteByHandle(searchRequest.getWeblogHandle(), Boolean.TRUE);
           
        } catch(Exception e) {
            // invalid search request format or weblog doesn't exist
            log.debug("error creating weblog search request", e);
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
       
        // do we need to force a specific locale for the request?
        if(searchRequest.getLocale() == null && !weblog.isShowAllLangs()) {
            searchRequest.setLocale(weblog.getLocale());
        }
       
        // lookup template to use for rendering
        ThemeTemplate page = null;
        try {
            // first try looking for a specific search page
            page = weblog.getTheme().getTemplateByAction(ThemeTemplate.ACTION_SEARCH);
           
            // if not found then fall back on default page
            if(page == null) {
                page = weblog.getTheme().getDefaultTemplate();
            }
           
            // if still null then that's a problem
            if(page == null) {
                throw new WebloggerException("Could not lookup default page "+
                        "for weblog "+weblog.getHandle());
            }
        } catch(Exception e) {
            log.error("Error getting default page for weblog "+
                    weblog.getHandle(), e);
        }
       
        // set the content type
        response.setContentType("text/html; charset=utf-8");
       
        // looks like we need to render content
        Map model = new HashMap();
        try {
            PageContext pageContext = JspFactory.getDefaultFactory().getPageContext(
                    this, request, response,"", false, 8192, true);
           
            // populate the rendering model
            Map initData = new HashMap();
            initData.put("request", request);
            initData.put("pageContext", pageContext);
           
            // this is a little hacky, but nothing we can do about it
            // we need the 'weblogRequest' to be a pageRequest so other models
            // are properly loaded, which means that searchRequest needs its
            // own custom initData property aside from the standard weblogRequest.
            // possible better approach is make searchRequest extend pageRequest.
            WeblogPageRequest pageRequest = new WeblogPageRequest();
            pageRequest.setWeblogHandle(searchRequest.getWeblogHandle());
            pageRequest.setWeblogCategoryName(searchRequest.getWeblogCategoryName());
            initData.put("parsedRequest", pageRequest);
            initData.put("searchRequest", searchRequest);
           
            // define url strategy
            initData.put("urlStrategy", WebloggerFactory.getWeblogger().getUrlStrategy());
View Full Code Here


            throws ServletException, IOException {
       
        log.debug("Entering");
       
        Weblog weblog = null;
        WeblogSearchRequest searchRequest = null;
       
        // first off lets parse the incoming request and validate it
        try {
            searchRequest = new WeblogSearchRequest(request);
           
            // now make sure the specified weblog really exists
            weblog = WebloggerFactory.getWeblogger().getWeblogManager()
                    .getWeblogByHandle(searchRequest.getWeblogHandle(), Boolean.TRUE);
           
        } catch(Exception e) {
            // invalid search request format or weblog doesn't exist
            log.debug("error creating weblog search request", e);
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
       
        // do we need to force a specific locale for the request?
        if(searchRequest.getLocale() == null && !weblog.isShowAllLangs()) {
            searchRequest.setLocale(weblog.getLocale());
        }
       
        // lookup template to use for rendering
        ThemeTemplate page = null;
        try {
            // first try looking for a specific search page
            page = weblog.getTheme().getTemplateByAction(ThemeTemplate.ACTION_SEARCH);
           
            // if not found then fall back on default page
            if(page == null) {
                page = weblog.getTheme().getDefaultTemplate();
            }
           
            // if still null then that's a problem
            if(page == null) {
                throw new WebloggerException("Could not lookup default page "+
                        "for weblog "+weblog.getHandle());
            }
        } catch(Exception e) {
            log.error("Error getting default page for weblog "+
                    weblog.getHandle(), e);
        }
       
        // set the content type
        response.setContentType("text/html; charset=utf-8");
       
        // looks like we need to render content
        Map model = new HashMap();
        try {
            PageContext pageContext = JspFactory.getDefaultFactory().getPageContext(
                    this, request, response,"", false, 8192, true);
           
            // populate the rendering model
            Map initData = new HashMap();
            initData.put("request", request);
            initData.put("pageContext", pageContext);
           
            // this is a little hacky, but nothing we can do about it
            // we need the 'weblogRequest' to be a pageRequest so other models
            // are properly loaded, which means that searchRequest needs its
            // own custom initData property aside from the standard weblogRequest.
            // possible better approach is make searchRequest extend pageRequest.
            WeblogPageRequest pageRequest = new WeblogPageRequest();
            pageRequest.setWeblogHandle(searchRequest.getWeblogHandle());
            pageRequest.setWeblogCategoryName(searchRequest.getWeblogCategoryName());
            initData.put("parsedRequest", pageRequest);
            initData.put("searchRequest", searchRequest);
           
            // define url strategy
            initData.put("urlStrategy", WebloggerFactory.getWeblogger().getUrlStrategy());
           
            // Load models for pages
            String searchModels = WebloggerConfig.getProperty("rendering.searchModels");
            ModelLoader.loadModels(searchModels, model, initData, true);
           
            // Load special models for site-wide blog
            if(WebloggerRuntimeConfig.isSiteWideWeblog(weblog.getHandle())) {
                String siteModels = WebloggerConfig.getProperty("rendering.siteModels");
                ModelLoader.loadModels(siteModels, model, initData, true);
            }

            // Load weblog custom models
            ModelLoader.loadCustomModels(weblog, model, initData);
           
            // ick, gotta load pre-3.0 model stuff as well :(
            ModelLoader.loadOldModels(model, request, response, pageContext, pageRequest, WebloggerFactory.getWeblogger().getUrlStrategy());
           
            // manually add search model again to support pre-3.0 weblogs
            Model searchModel = new SearchResultsModel();
            searchModel.init(initData);
            model.put("searchResults", searchModel);
           
        } catch (WebloggerException ex) {
            log.error("Error loading model objects for page", ex);
           
            if(!response.isCommitted()) response.reset();
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            return;
        }

        // Development only. Reload if theme has been modified
    if (themeReload) {
      try {
        ThemeManager manager = WebloggerFactory.getWeblogger().getThemeManager();
        boolean reloaded = manager.reLoadThemeFromDisk(weblog.getEditorTheme());
        if (reloaded) {
          if (WebloggerRuntimeConfig.isSiteWideWeblog(searchRequest.getWeblogHandle())) {
            SiteWideCache.getInstance().clear();
          } else {
            WeblogPageCache.getInstance().clear();
          }
          I18nMessages.reloadBundle(weblog.getLocaleInstance());
View Full Code Here

TOP

Related Classes of org.apache.roller.weblogger.ui.rendering.util.WeblogSearchRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.