Examples of WeblogPreviewResourceRequest


Examples of org.apache.roller.ui.rendering.util.WeblogPreviewResourceRequest

        WebsiteData weblog = null;
        String context = request.getContextPath();
        String servlet = request.getServletPath();
        String reqURI = request.getRequestURI();
       
        WeblogPreviewResourceRequest resourceRequest = null;
        try {
            // parse the incoming request and extract the relevant data
            resourceRequest = new WeblogPreviewResourceRequest(request);

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

        } catch(Exception e) {
            // invalid resource request or weblog doesn't exist
            log.debug("error creating weblog resource request", e);
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
       
        log.debug("Resource requested ["+resourceRequest.getResourcePath()+"]");
       
        long resourceLastMod = 0;
        InputStream resourceStream = null;
       
        // first, see if we have a preview theme to operate from
        if(resourceRequest.getThemeName() != null) {
            Theme theme = resourceRequest.getTheme();
            File resource = theme.getResource(resourceRequest.getResourcePath());
            resourceLastMod = resource.lastModified();
            resourceStream = new FileInputStream(resource);
        }
       
        // second, see if resource comes from weblog's configured shared theme
        if(resourceStream == null && !Theme.CUSTOM.equals(weblog.getEditorTheme())) {
            try {
                ThemeManager themeMgr = RollerFactory.getRoller().getThemeManager();
                Theme weblogTheme = themeMgr.getTheme(weblog.getEditorTheme());
                File resource = weblogTheme.getResource(resourceRequest.getResourcePath());
                if(resource != null) {
                    resourceLastMod = resource.lastModified();
                    resourceStream = new FileInputStream(resource);
                }
            } catch (Exception ex) {
                // hmmm, some kind of error getting theme.  that's an error.
                response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                return;
            }
        }
       
        // if not from theme then see if resource is in weblog's upload dir
        if(resourceStream == null) {
            try {
                FileManager fileMgr = RollerFactory.getRoller().getFileManager();
                WeblogResource resource = fileMgr.getFile(weblog,
                        resourceRequest.getResourcePath());
                resourceLastMod = resource.getLastModified();
                resourceStream = resource.getInputStream();
            } catch (Exception ex) {
                // still not found? then we don't have it, 404.
                log.debug("Unable to get resource", ex);
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
                return;
            }
        }
       
        // Respond with 304 Not Modified if it is not modified.
        if (ModDateHeaderUtil.respondIfNotModified(request, response, resourceLastMod)) {
            return;
        } else {
            // set last-modified date
            ModDateHeaderUtil.setLastModifiedHeader(response, resourceLastMod);
        }
       

        // set the content type based on whatever is in our web.xml mime defs
        response.setContentType(this.context.getMimeType(resourceRequest.getResourcePath()));
       
        OutputStream out = null;
        try {
            // ok, lets serve up the file
            byte[] buf = new byte[8192];
View Full Code Here

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

        Weblog weblog = null;
        String context = request.getContextPath();
        String servlet = request.getServletPath();
        String reqURI = request.getRequestURI();
       
        WeblogPreviewResourceRequest resourceRequest = null;
        try {
            // parse the incoming request and extract the relevant data
            resourceRequest = new WeblogPreviewResourceRequest(request);

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

        } catch(Exception e) {
            // invalid resource request or weblog doesn't exist
            log.debug("error creating weblog resource request", e);
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
       
        log.debug("Resource requested ["+resourceRequest.getResourcePath()+"]");
       
        long resourceLastMod = 0;
        InputStream resourceStream = null;
       
        // first, see if we have a preview theme to operate from
        if(!StringUtils.isEmpty(resourceRequest.getThemeName())) {
            Theme theme = resourceRequest.getTheme();
            ThemeResource resource = theme.getResource(resourceRequest.getResourcePath());
            if(resource != null) {
                resourceLastMod = resource.getLastModified();
                resourceStream = resource.getInputStream();
            }
        }
       
        // second, see if resource comes from weblog's configured shared theme
        if(resourceStream == null) {
            try {
                WeblogTheme weblogTheme = weblog.getTheme();
                if(weblogTheme != null) {
                    ThemeResource resource = weblogTheme.getResource(resourceRequest.getResourcePath());
                    if(resource != null) {
                        resourceLastMod = resource.getLastModified();
                        resourceStream = resource.getInputStream();
                    }
                }
            } catch (Exception ex) {
                // hmmm, some kind of error getting theme.  that's an error.
                response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                return;
            }
        }
       
        // if not from theme then see if resource is in weblog's upload dir
        if(resourceStream == null) {
            try {
                FileManager fileMgr = WebloggerFactory.getWeblogger().getFileManager();
                ThemeResource resource = fileMgr.getFile(weblog,
                        resourceRequest.getResourcePath());
                resourceLastMod = resource.getLastModified();
                resourceStream = resource.getInputStream();
            } catch (Exception ex) {
                // still not found? then we don't have it, 404.
                log.debug("Unable to get resource", ex);
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
                return;
            }
        }
       
        // Respond with 304 Not Modified if it is not modified.
        if (ModDateHeaderUtil.respondIfNotModified(request, response, resourceLastMod)) {
            return;
        } else {
            // set last-modified date
            ModDateHeaderUtil.setLastModifiedHeader(response, resourceLastMod);
        }
       

        // set the content type based on whatever is in our web.xml mime defs
        response.setContentType(this.context.getMimeType(resourceRequest.getResourcePath()));
       
        OutputStream out = null;
        try {
            // ok, lets serve up the file
            byte[] buf = new byte[8192];
View Full Code Here

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

        Weblog weblog = null;
        String ctx = request.getContextPath();
        String servlet = request.getServletPath();
        String reqURI = request.getRequestURI();
       
        WeblogPreviewResourceRequest resourceRequest = null;
        try {
            // parse the incoming request and extract the relevant data
            resourceRequest = new WeblogPreviewResourceRequest(request);

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

        } catch(Exception e) {
            // invalid resource request or weblog doesn't exist
            log.debug("error creating weblog resource request", e);
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
       
        log.debug("Resource requested ["+resourceRequest.getResourcePath()+"]");
       
        long resourceLastMod = 0;
        InputStream resourceStream = null;
       
        // first, see if we have a preview theme to operate from
        if(!StringUtils.isEmpty(resourceRequest.getThemeName())) {
            Theme theme = resourceRequest.getTheme();
            ThemeResource resource = theme.getResource(resourceRequest.getResourcePath());
            if(resource != null) {
                resourceLastMod = resource.getLastModified();
                resourceStream = resource.getInputStream();
            }
        }
       
        // second, see if resource comes from weblog's configured shared theme
        if(resourceStream == null) {
            try {
                WeblogTheme weblogTheme = weblog.getTheme();
                if(weblogTheme != null) {
                    ThemeResource resource = weblogTheme.getResource(resourceRequest.getResourcePath());
                    if(resource != null) {
                        resourceLastMod = resource.getLastModified();
                        resourceStream = resource.getInputStream();
                    }
                }
            } catch (Exception ex) {
                // hmmm, some kind of error getting theme.  that's an error.
                response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                return;
            }
        }
       
        // if not from theme then see if resource is in weblog's upload dir
        if(resourceStream == null) {
            try {
                MediaFileManager mmgr =
                    WebloggerFactory.getWeblogger().getMediaFileManager();
                MediaFile mf = mmgr.getMediaFileByOriginalPath(
                    weblog, resourceRequest.getResourcePath());
                resourceLastMod = mf.getLastModified();
                resourceStream = mf.getInputStream();

            } catch (Exception ex) {
                // still not found? then we don't have it, 404.
                log.debug("Unable to get resource", ex);
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
                return;
            }
        }
       
        // Respond with 304 Not Modified if it is not modified.
        if (ModDateHeaderUtil.respondIfNotModified(request, response, resourceLastMod)) {
            return;
        } else {
            // set last-modified date
            ModDateHeaderUtil.setLastModifiedHeader(response, resourceLastMod);
        }
       

        // set the content type based on whatever is in our web.xml mime defs
        response.setContentType(this.context.getMimeType(resourceRequest.getResourcePath()));
       
        OutputStream out = null;
        try {
            // ok, lets serve up the file
            byte[] buf = new byte[8192];
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.