public Subscription fetchSubscription()

in app/src/main/java/org/apache/roller/weblogger/planet/business/WebloggerRomeFeedFetcher.java [63:163]


    public Subscription fetchSubscription(String feedURL, Date lastModified)
            throws FetcherException {
        
        if(feedURL == null) {
            throw new IllegalArgumentException("feed url cannot be null");
        }
        
        // we handle special weblogger planet integrated subscriptions which have
        // feedURLs defined as ... weblogger:<blog handle>
        if(!feedURL.startsWith("weblogger:")) {
            log.debug("Feed is remote, letting parent handle it - "+feedURL);            
            return super.fetchSubscription(feedURL, lastModified);
        }
        
        // extract blog handle from our special feed url
        String weblogHandle = null;
        String[] items = feedURL.split(":", 2);
        if(items != null && items.length > 1) {
            weblogHandle = items[1];
        }
        
        log.debug("Handling LOCAL feed - "+feedURL);
        
        Weblog localWeblog;
        try {
            localWeblog = WebloggerFactory.getWeblogger().getWeblogManager()
                    .getWeblogByHandle(weblogHandle);
            if (localWeblog == null) {
                throw new FetcherException("Local feed - "+feedURL+" no longer exists in weblogger");
            }
            
        } catch (WebloggerException ex) {
            throw new FetcherException("Problem looking up local weblog - "+weblogHandle, ex);
        }
        
        // if weblog hasn't changed since last fetch then bail
        if(lastModified != null && !localWeblog.getLastModified().after(lastModified)) {
            log.debug("Skipping unmodified LOCAL weblog");
            return null;
        }
        
        // build planet subscription from weblog
        Subscription newSub = new Subscription();
        newSub.setFeedURL(feedURL);
        newSub.setSiteURL(WebloggerFactory.getWeblogger().getUrlStrategy().getWeblogURL(localWeblog, null, true));
        newSub.setTitle(localWeblog.getName());
        newSub.setAuthor(localWeblog.getName());
        newSub.setLastUpdated(localWeblog.getLastModified());
        
        // must have a last updated time
        if(newSub.getLastUpdated() == null) {
            newSub.setLastUpdated(new Date());
        }
        
        // lookup recent entries from weblog and add them to the subscription
        try {
            int entryCount = WebloggerRuntimeConfig.getIntProperty("site.newsfeeds.defaultEntries");

            if (log.isDebugEnabled()) {
                log.debug("Seeking up to " + entryCount + " entries from " + localWeblog.getHandle());
            }
            
            // grab recent entries for this weblog
            WeblogEntryManager wmgr = WebloggerFactory.getWeblogger().getWeblogEntryManager();
            WeblogEntrySearchCriteria wesc = new WeblogEntrySearchCriteria();
            wesc.setWeblog(localWeblog);
            wesc.setStatus(PubStatus.PUBLISHED);
            wesc.setMaxResults(entryCount);
            List<WeblogEntry> entries = wmgr.getWeblogEntries(wesc);
            log.debug("Found " + entries.size());

            // Populate subscription object with new entries
            PluginManager ppmgr = WebloggerFactory.getWeblogger().getPluginManager();
            Map<String, WeblogEntryPlugin> pagePlugins = ppmgr.getWeblogEntryPlugins(localWeblog);
            for ( WeblogEntry rollerEntry : entries ) {
                SubscriptionEntry entry = new SubscriptionEntry();
                String content;
                if (!StringUtils.isEmpty(rollerEntry.getText())) {
                    content = rollerEntry.getText();
                } else {
                    content = rollerEntry.getSummary();
                }
                content = ppmgr.applyWeblogEntryPlugins(pagePlugins, rollerEntry, content);
                
                entry.setAuthor(rollerEntry.getCreator().getScreenName());
                entry.setTitle(rollerEntry.getTitle());
                entry.setPubTime(rollerEntry.getPubTime());
                entry.setText(content);
                entry.setPermalink(rollerEntry.getPermalink());
                entry.setCategoriesString(rollerEntry.getCategory().getName());
                
                newSub.addEntry(entry);
            }
            
        } catch (WebloggerException ex) {
            throw new FetcherException("Error processing entries for local weblog - "+weblogHandle, ex);
        }
        
        // all done
        return newSub;
    }