public WeblogFeedRequest()

in app/src/main/java/org/apache/roller/weblogger/ui/rendering/util/WeblogFeedRequest.java [69:167]


    public WeblogFeedRequest(HttpServletRequest request) 
            throws InvalidRequestException {
        
        // let our parent take care of their business first
        // parent determines weblog handle and locale if specified
        super(request);
        
        String servlet = request.getServletPath();
        
        // we only want the path info left over from after our parents parsing
        String pathInfo = this.getPathInfo();
        
        // parse the request object and figure out what we've got
        log.debug("parsing path "+pathInfo);
        
        // was this request bound for the feed servlet?
        if(servlet == null || !FEED_SERVLET.equals(servlet)) {
            throw new InvalidRequestException("not a weblog feed request, "+
                    request.getRequestURL());
        }
        
        
        /* 
         * parse the path info.
         * 
         * must look like this ...
         *
         * /<type>/<format>
         */
        if(pathInfo != null && pathInfo.trim().length() > 1) {
            
            String[] pathElements = pathInfo.split("/");
            if(pathElements.length == 2
                    && StringUtils.isAlphanumeric(pathElements[0])
                    && StringUtils.isAlphanumeric(pathElements[1])) {
                this.type = pathElements[0];
                this.format = pathElements[1];
            } else {
                throw new InvalidRequestException("invalid feed path info, "+
                        request.getRequestURL());
            }
            
        } else {
            throw new InvalidRequestException("invalid feed path info, "+
                    request.getRequestURL());
        }
        
        
        /* 
         * parse request parameters
         *
         * the only params we currently care about are:
         *   cat - specifies a weblog category
         *   excerpts - specifies the feed should only include excerpts
         *
         */
        if(request.getParameter("cat") != null) {
            // replacing plus sign below with its encoded equivalent (http://stackoverflow.com/a/6926987)
            this.weblogCategoryName =
                    URLUtilities.decode(request.getParameter("cat").replace("+", "%2B"));
        }
        
        if(request.getParameter("tags") != null) {
            this.tags = Utilities.splitStringAsTags(request.getParameter("tags"));                  
            int maxSize = WebloggerConfig.getIntProperty("tags.queries.maxIntersectionSize", 3);
            if (this.tags.size() > maxSize) {
                throw new InvalidRequestException("max number of tags allowed is " + maxSize + ", "
                        + request.getRequestURL());
            }
        }        
        
        if(request.getParameter("excerpts") != null) {
            this.excerpts = Boolean.valueOf(request.getParameter("excerpts"));
        }
        
        if(request.getParameter("page") != null) {
            try {
                this.page = Integer.parseInt(request.getParameter("page"));
            } catch(NumberFormatException e) {
                // 
            }
        }     
        
        if(request.getParameter("q") != null && !request.getParameter("q").isBlank()) {
            this.term = URLUtilities.decode(request.getParameter("q"));
        }        
        
        if(this.tags != null && !this.tags.isEmpty() && this.weblogCategoryName != null) {
            throw new InvalidRequestException("please specify either category or tags but not both, " + request.getRequestURL());            
        }
        
        if(log.isDebugEnabled()) {
            log.debug("type = "+this.type);
            log.debug("format = "+this.format);
            log.debug("weblogCategory = "+this.weblogCategoryName);
            log.debug("tags = "+this.tags);
            log.debug("excerpts = "+this.excerpts);
        }
    }