Package org.apache.roller.presentation

Examples of org.apache.roller.presentation.WeblogPageRequest


        }
        String requestUrl = reqsb.toString();
       
        // parse the incoming request and make sure it's a valid page request
        WebsiteData weblog = null;
        WeblogPageRequest pageRequest = null;
        try {
            pageRequest = new WeblogPageRequest(request);
            UserManager userMgr = RollerFactory.getRoller().getUserManager();
            weblog = userMgr.getWebsiteByHandle(pageRequest.getWeblogHandle());
           
            if(weblog == null) {
                throw new Exception("no weblog named "+pageRequest.getWeblogHandle());
            }
           
        } catch(Exception ex) {
            // bad url or couldn't obtain weblog
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
       
        // determine if this request came from a robot
        if (robotPattern != null) {
            // If the pattern is present, we check for whether the User-Agent matches,
            // and set isRobot if so.  Currently, all referral processing, including
            // spam check, is skipped for robots identified in this way.
            String userAgent = request.getHeader("User-Agent");
            isRobot = (userAgent != null && userAgent.length() > 0 && robotPattern.matcher(userAgent).matches());
        }
       
        // validate the referrer
        if (pageRequest != null && pageRequest.getWeblogHandle() != null && !isRobot) {
           
            RollerContext rctx = RollerContext.getRollerContext();
           
            // Base page URLs, with and without www.
            String basePageUrlWWW =
                    rctx.getAbsoluteContextUrl(request)+"/page/"+weblog.getHandle();
            String basePageUrl = basePageUrlWWW;
            if ( basePageUrlWWW.startsWith("http://www.") ) {
                // chop off the http://www.
                basePageUrl = "http://"+basePageUrlWWW.substring(11);
            }
           
            // ignore referrers coming from users own blog
            if (referrerUrl == null ||
                    (!referrerUrl.startsWith(basePageUrl) &&
                    !referrerUrl.startsWith(basePageUrlWWW))) {
               
                String selfSiteFragment = "/page/"+weblog.getHandle();

                // validate the referrer
                if ( referrerUrl != null ) {
                    // ignore a Referrer from the persons own blog
                    if (referrerUrl.indexOf(selfSiteFragment) != -1) {
                        referrerUrl = null;
                        ignoreReferrer = true;
                    } else {
                        // treat editor referral as direct
                        int lastSlash = requestUrl.indexOf("/", 8);
                        if (lastSlash == -1) lastSlash = requestUrl.length();
                        String requestSite = requestUrl.substring(0, lastSlash);
                       
                        if (referrerUrl.matches(requestSite + ".*\\.do.*")) {
                            referrerUrl = null;
                        } else {
                            // If referer URL is blacklisted, throw it out
                            isRefSpammer = SpamChecker.checkReferrer(weblog, referrerUrl);
                        }
                    }
                }
               
            } else {
                mLogger.debug("Ignoring referer = "+referrerUrl);
                ignoreReferrer = true;
            }
        }
       
        // pre-processing complete, let's finish the job
        if (isRefSpammer) {
            // spammers get a 403 Access Denied
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
            return;
           
        } else if(!isRobot && !ignoreReferrer) {
            // referrer is valid, lets record it
            try {
                IncomingReferrer referrer = new IncomingReferrer();
                referrer.setReferrerUrl(referrerUrl);
                referrer.setRequestUrl(requestUrl);
                referrer.setWeblogHandle(pageRequest.getWeblogHandle());
                referrer.setWeblogAnchor(pageRequest.getWeblogAnchor());
                referrer.setWeblogDateString(pageRequest.getWeblogDate());
               
                ReferrerQueueManager refQueue =
                    RollerFactory.getRoller().getReferrerQueueManager();
                refQueue.processReferrer(referrer);
            } catch(Exception e) {
View Full Code Here


        mLogger.debug("entering");
       
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) res;
       
        WeblogPageRequest pageRequest = null;
        try {
            pageRequest = new WeblogPageRequest(request);
        } catch(Exception e) {
            mLogger.error("error creating page request", e);
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
       
        String key = this.CACHE_ID+":"+this.generateKey(pageRequest);
       
        Date updateTime = null;
        try {
            // we need the last expiration time for the given weblog
            long lastExpiration = 0;
            Date lastExpirationDate =
                    (Date) CacheManager.getLastExpiredDate(pageRequest.getWeblogHandle());
            if(lastExpirationDate != null)
                lastExpiration = lastExpirationDate.getTime();
           
            LazyExpiringCacheEntry entry =
                    (LazyExpiringCacheEntry) this.mCache.get(key);
            if(entry != null) {
                updateTime = (Date) entry.getValue(lastExpiration);
               
                if(updateTime == null)
                    mLogger.debug("HIT-INVALID "+key);
            }
           
            if (updateTime == null) {
                mLogger.debug("MISS "+key);
               
                if(pageRequest.getWeblogHandle() != null) {
                    // just set updateTime to now
                    updateTime = new Date();
                    this.mCache.put(key, new LazyExpiringCacheEntry(updateTime));
                }
               
View Full Code Here

        mLogger.debug("entering");
       
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) res;
       
        WeblogPageRequest pageRequest = null;
        try {
            pageRequest = new WeblogPageRequest(request);
        } catch(Exception e) {
            // some kind of error parsing the request
            mLogger.error("error creating page request", e);
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
       
        String key = this.CACHE_ID+":"+this.generateKey(pageRequest);
       
        try {
            ResponseContent respContent = null;
            if(!this.excludeOwnerPages || !pageRequest.isLoggedIn()) {
                // we need the last expiration time for the given weblog
                long lastExpiration = 0;
                Date lastExpirationDate =
                        (Date) CacheManager.getLastExpiredDate(pageRequest.getWeblogHandle());
                if(lastExpirationDate != null)
                    lastExpiration = lastExpirationDate.getTime();
               
                LazyExpiringCacheEntry entry =
                        (LazyExpiringCacheEntry) this.mCache.get(key);
                if(entry != null) {
                    respContent = (ResponseContent) entry.getValue(lastExpiration);
                   
                    if(respContent == null)
                        mLogger.debug("HIT-INVALID "+key);
                }
            }
           
            if (respContent == null) {
               
                mLogger.debug("MISS "+key);
                this.misses++;
               
                CacheHttpServletResponseWrapper cacheResponse =
                        new CacheHttpServletResponseWrapper(response);
               
                chain.doFilter(request, cacheResponse);
               
                cacheResponse.flushBuffer();
               
                // Store as the cache content the result of the response
                // if no exception was noted by content generator.
                if (request.getAttribute("DisplayException") == null) {
                    ResponseContent rc = cacheResponse.getContent();
                   
                    // only cache if this is not a logged in user?
                    if (!this.excludeOwnerPages || !pageRequest.isLoggedIn()) {
                        if (rc != null && rc.getSize() > 0) {
                            this.mCache.put(key, new LazyExpiringCacheEntry(rc));
                        } else {
                            mLogger.debug("Not caching zero length content for key: " + key);
                        }
View Full Code Here

TOP

Related Classes of org.apache.roller.presentation.WeblogPageRequest

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.