public Feed getCollection()

in app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/EntryCollection.java [155:241]


    public Feed getCollection(AtomRequest areq) throws AtomException {
        log.debug("Entering");
        String[] pathInfo = StringUtils.split(areq.getPathInfo(),"/");
        try {
            int start = 0;
            int max = MAX_ENTRIES;
            if (pathInfo.length > 2) {
                try {
                    String s = pathInfo[2].trim();
                    start = Integer.parseInt(s);
                } catch (Exception e) {
                    log.warn("Unparsable range: " + pathInfo[2]);
                }
            }        
            String handle = pathInfo[0];
            String absUrl = WebloggerRuntimeConfig.getAbsoluteContextURL();
            Weblog website = roller.getWeblogManager().getWeblogByHandle(handle);
            if (website == null) {
                throw new AtomNotFoundException("Cannot find specified weblog");
            }
            if (!RollerAtomHandler.canView(user, website)) {
                throw new AtomNotAuthorizedException("Not authorized to access website: " + handle);
            }
            WeblogEntrySearchCriteria wesc = new WeblogEntrySearchCriteria();
            wesc.setWeblog(website);
            wesc.setSortBy(WeblogEntrySearchCriteria.SortBy.UPDATE_TIME);
            wesc.setOffset(start);
            wesc.setMaxResults(max + 1);
            List<WeblogEntry> entries = roller.getWeblogEntryManager().getWeblogEntries(wesc);
            Feed feed = new Feed();
            feed.setId(atomURL
                +"/"+website.getHandle() + "/entries/" + start);
            feed.setTitle(website.getName());

            Link link = new Link();
            link.setHref(absUrl + "/" + website.getHandle());
            link.setRel("alternate");
            link.setType("text/html");
            feed.setAlternateLinks(Collections.singletonList(link));

            List<Entry> atomEntries = new ArrayList<>();
            int count = 0;
            for (WeblogEntry rollerEntry : entries) {
                if (count++ >= MAX_ENTRIES) {
                    break;
                }
                Entry entry = createAtomEntry(rollerEntry);
                atomEntries.add(entry);
                if (count == 1) {
                    // first entry is most recent
                    feed.setUpdated(entry.getUpdated());
                }
            }
            List<Link> links = new ArrayList<>();
            if (entries.size() > max) {
                // add next link
                int nextOffset = start + max;
                String url = atomURL+"/"
                        + website.getHandle() + "/entries/" + nextOffset;
                Link nextLink = new Link();
                nextLink.setRel("next");
                nextLink.setHref(url);
                links.add(nextLink);
            }
            if (start > 0) {
                // add previous link
                int prevOffset = start > max ? start - max : 0;
                String url = atomURL+"/"
                        +website.getHandle() + "/entries/" + prevOffset;
                Link prevLink = new Link();
                prevLink.setRel("previous");
                prevLink.setHref(url);
                links.add(prevLink);
            }
            if (!links.isEmpty()) {
                feed.setOtherLinks(links);
            }
            // Use collection URI as id
            feed.setEntries(atomEntries);
            
            log.debug("Exiting");
            return feed;
        
        } catch (WebloggerException re) {
            throw new AtomException("Getting entry collection");
        }
    }