Package org.apache.roller.weblogger.pojos

Examples of org.apache.roller.weblogger.pojos.Weblog


    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        log.debug("Entering");

        Weblog weblog = null;
        boolean isSiteWide = false;

        WeblogFeedRequest feedRequest = null;
        try {
            // parse the incoming request and extract the relevant data
            feedRequest = new WeblogFeedRequest(request);

            weblog = feedRequest.getWeblog();
            if(weblog == null) {
                throw new WebloggerException("unable to lookup weblog: "+
                        feedRequest.getWeblogHandle());
            }

            // is this the site-wide weblog?
            isSiteWide = WebloggerRuntimeConfig.isSiteWideWeblog(feedRequest.getWeblogHandle());

        } catch(Exception e) {
            // invalid feed request format or weblog doesn't exist
            log.debug("error creating weblog feed request", e);
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }


        // determine the lastModified date for this content
        long lastModified = System.currentTimeMillis();
        if(isSiteWide) {
            lastModified = siteWideCache.getLastModified().getTime();
        } else if (weblog.getLastModified() != null) {
            lastModified = weblog.getLastModified().getTime();
        }

        // Respond with 304 Not Modified if it is not modified.
        if (ModDateHeaderUtil.respondIfNotModified(request,response,lastModified)) {
            return;
        }

        // set last-modified date
        ModDateHeaderUtil.setLastModifiedHeader(response, lastModified);

        // set content type
        String accepts = request.getHeader("Accept");
        String userAgent = request.getHeader("User-Agent");
        if (WebloggerRuntimeConfig.getBooleanProperty("site.newsfeeds.styledFeeds") &&
            accepts != null && accepts.indexOf("*/*") != -1 &&
            userAgent != null && userAgent.startsWith("Mozilla")) {
            // client is a browser and feed style is enabled so we want
            // browsers to load the page rather than popping up the download
            // dialog, so we provide a content-type that browsers will display
            response.setContentType("text/xml");
        } else if("rss".equals(feedRequest.getFormat())) {
            response.setContentType("application/rss+xml; charset=utf-8");
        } else if("atom".equals(feedRequest.getFormat())) {
            response.setContentType("application/atom+xml; charset=utf-8");
        }

        // generate cache key
        String cacheKey = null;
        if(isSiteWide) {
            cacheKey = siteWideCache.generateKey(feedRequest);
        } else {
            cacheKey = weblogFeedCache.generateKey(feedRequest);
        }

        // cached content checking
        CachedContent cachedContent = null;
        if(isSiteWide) {
            cachedContent = (CachedContent) siteWideCache.get(cacheKey);
        } else {
            cachedContent = (CachedContent) weblogFeedCache.get(cacheKey, lastModified);
        }

        if(cachedContent != null) {
            log.debug("HIT "+cacheKey);

            response.setContentLength(cachedContent.getContent().length);
            response.getOutputStream().write(cachedContent.getContent());
            return;

        } else {
            log.debug("MISS "+cacheKey);
        }
       
       
        // validation.  make sure that request input makes sense.
        boolean invalid = false;
        if(feedRequest.getLocale() != null) {
           
            // locale view only allowed if weblog has enabled it
            if(!feedRequest.getWeblog().isEnableMultiLang()) {
                invalid = true;
            }
           
        }
        if(feedRequest.getWeblogCategoryName() != null) {
           
            // category specified.  category must exist.
            if(feedRequest.getWeblogCategory() == null) {
                invalid = true;
            }
           
        } else if(feedRequest.getTags() != null && feedRequest.getTags().size() > 0) {
           
            try {
                // tags specified.  make sure they exist.
                WeblogEntryManager wmgr = WebloggerFactory.getWeblogger().getWeblogEntryManager();
                invalid = !wmgr.getTagComboExists(feedRequest.getTags(), (isSiteWide) ? null : weblog);
            } catch (WebloggerException ex) {
                invalid = true;
            }
        }
       
        if(invalid) {
            if(!response.isCommitted()) response.reset();
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
       
       
        // do we need to force a specific locale for the request?
        if(feedRequest.getLocale() == null && !weblog.isShowAllLangs()) {
            feedRequest.setLocale(weblog.getLocale());
        }
       
        // looks like we need to render content
        HashMap model = new HashMap();
        String pageId = null;
        try {
            // determine what template to render with
            boolean siteWide = WebloggerRuntimeConfig.isSiteWideWeblog(weblog.getHandle());
           if (siteWide && "entries".equals(feedRequest.getType()) && feedRequest.getTerm() != null) {
                pageId = "templates/feeds/site-search-atom.vm";

           } else if ("entries".equals(feedRequest.getType()) && feedRequest.getTerm() != null) {
                pageId = "templates/feeds/weblog-search-atom.vm";
View Full Code Here


    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
       
        log.debug("Entering");
       
        Weblog weblog = null;
       
        WeblogPreviewRequest previewRequest = null;
        try {
            previewRequest = new WeblogPreviewRequest(request);
           
            // lookup weblog specified by preview request
            weblog = previewRequest.getWeblog();
            if(weblog == null) {
                throw new WebloggerException("unable to lookup weblog: "+
                        previewRequest.getWeblogHandle());
            }
        } catch (Exception e) {
            // some kind of error parsing the request or getting weblog
            log.debug("error creating preview request", e);
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
       
        Weblog tmpWebsite = weblog;
       
        if (previewRequest.getThemeName() != null) {
            // only create temporary weblog object if theme name was specified
            // in request, which indicates we're doing a theme preview

            // try getting the preview theme
            log.debug("preview theme = "+previewRequest.getThemeName());
            Theme previewTheme = previewRequest.getTheme();

            // construct a temporary Website object for this request
            // and set the EditorTheme to our previewTheme
            tmpWebsite = new Weblog();
            tmpWebsite.setData(weblog);
            if(previewTheme != null && previewTheme.isEnabled()) {
                tmpWebsite.setEditorTheme(previewTheme.getId());
            } else if(WeblogTheme.CUSTOM.equals(previewRequest.getThemeName())) {
                tmpWebsite.setEditorTheme(WeblogTheme.CUSTOM);
            }

            // we've got to set the weblog in our previewRequest because that's
            // the object that gets referenced during rendering operations
            previewRequest.setWeblog(tmpWebsite);
        }
       
        // do we need to force a specific locale for the request?
        if(previewRequest.getLocale() == null && !weblog.isShowAllLangs()) {
            previewRequest.setLocale(weblog.getLocale());
        }
       
        Template page = null;
        if("page".equals(previewRequest.getContext())) {
            page = previewRequest.getWeblogPage();
           
        // If request specified tags section index, then look for custom template
        } else if("tags".equals(previewRequest.getContext()) &&
                previewRequest.getTags() == null) {
            try {
                page = weblog.getTheme().getTemplateByAction(ThemeTemplate.ACTION_TAGSINDEX);
            } catch(Exception e) {
                log.error("Error getting weblog page for action 'tagsIndex'", e);
            }
           
            // if we don't have a custom tags page then 404, we don't let
            // this one fall through to the default template
            if(page == null) {
                if(!response.isCommitted()) response.reset();
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
                return;
            }
           
        // If this is a permalink then look for a permalink template
        } else if(previewRequest.getWeblogAnchor() != null) {
            try {
                page = weblog.getTheme().getTemplateByAction(ThemeTemplate.ACTION_PERMALINK);
            } catch(Exception e) {
                log.error("Error getting weblog page for action 'permalink'", e);
            }
        }
       
        if(page == null) {
            try {
                page = tmpWebsite.getTheme().getDefaultTemplate();
            } catch(WebloggerException re) {
                log.error("Error getting default page for preview", re);
            }
        }
       
View Full Code Here

                return;
            }
        }


        Weblog weblog = null;
        boolean isSiteWide = false;

        WeblogPageRequest pageRequest = null;
        try {
            pageRequest = new WeblogPageRequest(request);

            weblog = pageRequest.getWeblog();
            if (weblog == null) {
                throw new WebloggerException("unable to lookup weblog: " + pageRequest.getWeblogHandle());
            }

            // is this the site-wide weblog?
            isSiteWide = WebloggerRuntimeConfig.isSiteWideWeblog(pageRequest.getWeblogHandle());
        } catch (Exception e) {
            // some kind of error parsing the request or looking up weblog
            log.debug("error creating page request", e);
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }


        // determine the lastModified date for this content
        long lastModified = System.currentTimeMillis();
        if (isSiteWide) {
            lastModified = siteWideCache.getLastModified().getTime();
        } else if (weblog.getLastModified() != null) {
            lastModified = weblog.getLastModified().getTime();
        }

        // 304 Not Modified handling.
        // We skip this for logged in users to avoid the scenerio where a user
        // views their weblog, logs in, then gets a 304 without the 'edit' links
        if (!pageRequest.isLoggedIn()) {
            if (ModDateHeaderUtil.respondIfNotModified(request, response, lastModified)) {
                return;
            } else {
                // set last-modified date
                ModDateHeaderUtil.setLastModifiedHeader(response, lastModified);
            }
        }


        // generate cache key
        String cacheKey = null;
        if (isSiteWide) {
            cacheKey = siteWideCache.generateKey(pageRequest);
        } else {
            cacheKey = weblogPageCache.generateKey(pageRequest);
        }
       
        // 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 (isSiteWide) {
            siteWideCache.clear();
          } else {
            weblogPageCache.clear();
          }
          I18nMessages.reloadBundle(weblog.getLocaleInstance());
        }

      } catch (Exception ex) {
        log.error("ERROR - reloading theme " + ex);
      }
    }

        // cached content checking
        if ((!this.excludeOwnerPages || !pageRequest.isLoggedIn()) && request.getAttribute("skipCache") == null) {

            CachedContent cachedContent = null;
            if (isSiteWide) {
                cachedContent = (CachedContent) siteWideCache.get(cacheKey);
            } else {
                cachedContent = (CachedContent) weblogPageCache.get(cacheKey, lastModified);
            }

            if (cachedContent != null) {
                log.debug("HIT " + cacheKey);

                // allow for hit counting
                if (!isSiteWide) {
                    this.processHit(weblog, request.getRequestURL().toString(), request.getHeader("referer"));
                }

                response.setContentLength(cachedContent.getContent().length);
                response.setContentType(cachedContent.getContentType());
                response.getOutputStream().write(cachedContent.getContent());
                return;
            } else {
                log.debug("MISS " + cacheKey);
            }
        }

        log.debug("Looking for template to use for rendering");

        // figure out what template to use
        ThemeTemplate page = null;

        // If this is a popup request, then deal with it specially
        // TODO: do we really need to keep supporting this?
        if (request.getParameter("popup") != null) {
            try {
                // Does user have a popupcomments page?
                page = weblog.getTheme().getTemplateByName("_popupcomments");
            } catch (Exception e) {
                // ignored ... considered page not found
            }

            // User doesn't have one so return the default
            if (page == null) {
                page = new StaticThemeTemplate("templates/weblog/popupcomments.vm", "velocity");
            }

            // If request specified the page, then go with that
        } else if ("page".equals(pageRequest.getContext())) {
            page = pageRequest.getWeblogPage();

            // if we don't have this page then 404, we don't let
            // this one fall through to the default template
            if (page == null) {
                if (!response.isCommitted()) {
                    response.reset();
                }
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
                return;
            }

            // If request specified tags section index, then look for custom template
        } else if ("tags".equals(pageRequest.getContext()) && pageRequest.getTags() != null) {
            try {
                page = weblog.getTheme().getTemplateByAction(ThemeTemplate.ACTION_TAGSINDEX);
            } catch (Exception e) {
                log.error("Error getting weblog page for action 'tagsIndex'", e);
            }

            // if we don't have a custom tags page then 404, we don't let
            // this one fall through to the default template
            if (page == null) {
                if (!response.isCommitted()) {
                    response.reset();
                }
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
                return;
            }

            // If this is a permalink then look for a permalink template
        } else if (pageRequest.getWeblogAnchor() != null) {
            try {
                page = weblog.getTheme().getTemplateByAction(ThemeTemplate.ACTION_PERMALINK);
            } catch (Exception e) {
                log.error("Error getting weblog page for action 'permalink'", e);
            }
        }

        // if we haven't found a page yet then try our default page
        if (page == null) {
            try {
                page = weblog.getTheme().getDefaultTemplate();
            } catch (Exception e) {
                log.error("Error getting default page for weblog = " + weblog.getHandle(), e);
            }
        }

        // Still no page?  Then that is a 404
        if (page == null) {
            if (!response.isCommitted()) {
                response.reset();
            }
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }

        log.debug("page found, dealing with it");

        // validation.  make sure that request input makes sense.
        boolean invalid = false;
        if (pageRequest.getWeblogPageName() != null && page.isHidden()) {
            invalid = true;
        }
        if (pageRequest.getLocale() != null) {

            // locale view only allowed if weblog has enabled it
            if (!pageRequest.getWeblog().isEnableMultiLang()) {
                invalid = true;
            }
        }
        if (pageRequest.getWeblogAnchor() != null) {

            // permalink specified.
            // entry must exist, be published before current time, and locale must match
            WeblogEntry entry = pageRequest.getWeblogEntry();
            if (entry == null) {
                invalid = true;
            } else if (pageRequest.getLocale() != null && !entry.getLocale().startsWith(pageRequest.getLocale())) {
                invalid = true;
            } else if (!entry.isPublished()) {
                invalid = true;
            } else if (new Date().before(entry.getPubTime())) {
                invalid = true;
            }
        } else if (pageRequest.getWeblogCategoryName() != null) {

            // category specified.  category must exist.
            if (pageRequest.getWeblogCategory() == null) {
                invalid = true;
            }
        } else if (pageRequest.getTags() != null && pageRequest.getTags().size() > 0) {

            try {
                // tags specified.  make sure they exist.
                WeblogEntryManager wmgr = WebloggerFactory.getWeblogger().getWeblogEntryManager();
                invalid = !wmgr.getTagComboExists(pageRequest.getTags(), (isSiteWide) ? null : weblog);
            } catch (WebloggerException ex) {
                invalid = true;
            }
        }


        if (invalid) {
            log.debug("page failed validation, bailing out");
            if (!response.isCommitted()) {
                response.reset();
            }
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }


        // do we need to force a specific locale for the request?
        if (pageRequest.getLocale() == null && !weblog.isShowAllLangs()) {
            pageRequest.setLocale(weblog.getLocale());
        }


        // allow for hit counting
        if (!isSiteWide) {
            this.processHit(weblog, request.getRequestURL().toString(), request.getHeader("referer"));
        }


        // looks like we need to render content
        // set the content type
        String contentType = "text/html; charset=utf-8";
        if (StringUtils.isNotEmpty(page.getOutputContentType())) {
            contentType = page.getOutputContentType() + "; charset=utf-8";
        } else {
            String mimeType = RollerContext.getServletContext().getMimeType(page.getLink());
            if (mimeType != null) {
                // we found a match ... set the content type
                contentType = mimeType + "; charset=utf-8";
            } else {
                contentType = "text/html; charset=utf-8";
            }
        }

        HashMap model = new HashMap();
        try {
            PageContext pageContext = JspFactory.getDefaultFactory().getPageContext(this, request, response, "", false, 8192, true);

            // special hack for menu tag
            request.setAttribute("pageRequest", pageRequest);

            // populate the rendering model
            Map initData = new HashMap();
            initData.put("requestParameters", request.getParameterMap());
            initData.put("parsedRequest", pageRequest);
            initData.put("pageContext", pageContext);

            // define url strategy
            initData.put("urlStrategy", WebloggerFactory.getWeblogger().getUrlStrategy());

            // if this was a comment posting, check for comment form
            WeblogEntryCommentForm commentForm = (WeblogEntryCommentForm) request.getAttribute("commentForm");
            if (commentForm != null) {
                initData.put("commentForm", commentForm);
            }

            // Load models for pages
            String pageModels = WebloggerConfig.getProperty("rendering.pageModels");
            ModelLoader.loadModels(pageModels, 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
View Full Code Here

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
       
        log.debug("Entering");
       
        Weblog weblog = null;
       
        WeblogRequest weblogRequest = null;
        try {
            weblogRequest = new WeblogRequest(request);
           
            // now make sure the specified weblog really exists
            weblog = weblogRequest.getWeblog();
            if(weblog == null) {
                throw new WebloggerException("Unable to lookup weblog: "+
                        weblogRequest.getWeblogHandle());
            }
           
        } catch(Exception e) {
            // invalid rsd request format or weblog doesn't exist
            log.debug("error creating weblog request", e);
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
       
       

        // Respond with 304 Not Modified if it is not modified.
        long lastModified = System.currentTimeMillis();
        if (weblog.getLastModified() != null) {
            lastModified = weblog.getLastModified().getTime();
        }
        if (ModDateHeaderUtil.respondIfNotModified(request,response,lastModified)) {
            return;
        }
View Full Code Here

    public List getWeblogsUsers(String handle) {
        List results = new ArrayList();
        try {           
            Weblogger roller = WebloggerFactory.getWeblogger();
            UserManager umgr = roller.getUserManager();
            Weblog website = WebloggerFactory.getWeblogger().getWeblogManager().getWeblogByHandle(handle);
            List<WeblogPermission> perms = umgr.getWeblogPermissions(website);
            for (WeblogPermission perm : perms) {
                results.add(UserWrapper.wrap(perm.getUser()));
            }
        } catch (Exception e) {
View Full Code Here

   
    /** Get Website object by handle */
    public WeblogWrapper getWeblog(String handle) {
        WeblogWrapper wrappedWebsite = null;
        try {           
            Weblog website = WebloggerFactory.getWeblogger().getWeblogManager().getWeblogByHandle(handle);
            wrappedWebsite = WeblogWrapper.wrap(website, urlStrategy);
        } catch (Exception e) {
            log.error("ERROR: fetching users by letter", e);
        }
        return wrappedWebsite;
View Full Code Here

        Date startDate = cal.getTime();
        try {           
            List weblogs = WebloggerFactory.getWeblogger().getWeblogManager().getWeblogs(
                Boolean.TRUE, Boolean.TRUE, startDate, null, 0, length);
            for (Iterator it = weblogs.iterator(); it.hasNext();) {
                Weblog website = (Weblog) it.next();
                results.add(WeblogWrapper.wrap(website, urlStrategy));
            }
        } catch (Exception e) {
            log.error("ERROR: fetching weblog list", e);
        }
View Full Code Here

    public WeblogBookmark getBookmark(String id) throws WebloggerException {
        return (WeblogBookmark) strategy.load(WeblogBookmark.class, id);
    }

    public void removeBookmark(WeblogBookmark bookmark) throws WebloggerException {
        Weblog weblog = bookmark.getWebsite();
       
        //Remove the bookmark from its parent folder
        bookmark.getFolder().getBookmarks().remove(bookmark);
       
        // Now remove it from database
View Full Code Here

        }
        String websiteid = folder.getWebsite().getId();
        this.strategy.remove(folder);

        // update weblog last modified date.  date updated by saveWebsite()
        Weblog weblog = roller.getWeblogManager().getWeblog(websiteid);
        roller.getWeblogManager().saveWeblog(weblog);
    }
View Full Code Here

            WeblogEntryManager emgr = WebloggerFactory.getWeblogger().getWeblogEntryManager();       
            UserManager umgr = WebloggerFactory.getWeblogger().getUserManager();

            // first make sure we can delete an entry with comments
            User user = TestUtils.setupUser("commentParentDeleteUser");
            Weblog weblog = TestUtils.setupWeblog("commentParentDelete", user);
            WeblogEntry entry = TestUtils.setupWeblogEntry("CommentParentDeletes1",
                    weblog.getDefaultCategory(), weblog, user);
            TestUtils.endSession(true);

            entry = TestUtils.getManagedWeblogEntry(entry);
            TestUtils.setupComment("comment1", entry);
            TestUtils.setupComment("comment2", entry);
            TestUtils.setupComment("comment3", entry);
            TestUtils.endSession(true);

            // now deleting the entry should succeed and delete all comments
            Exception ex = null;
            try {
                emgr.removeWeblogEntry(TestUtils.getManagedWeblogEntry(entry));
                TestUtils.endSession(true);
            } catch (WebloggerException e) {
                ex = e;
            }
            assertNull(ex);

            // now make sure we can delete a weblog with comments
            weblog = TestUtils.getManagedWebsite(weblog);
            user = TestUtils.getManagedUser(user);
            entry = TestUtils.setupWeblogEntry("CommentParentDeletes2",
                    weblog.getDefaultCategory(), weblog, user);
            TestUtils.endSession(true);

            entry = TestUtils.getManagedWeblogEntry(entry);
            TestUtils.setupComment("comment1", entry);
            TestUtils.setupComment("comment2", entry);
View Full Code Here

TOP

Related Classes of org.apache.roller.weblogger.pojos.Weblog

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.