Package org.apache.roller.planet.pojos

Examples of org.apache.roller.planet.pojos.Subscription


       
        log.debug("updating feed: "+sub.getFeedURL());
       
        long subStartTime = System.currentTimeMillis();
       
        Subscription updatedSub;
        try {
            // fetch the latest version of the subscription
            FeedFetcher fetcher = PlanetFactory.getPlanet().getFeedFetcher();
            updatedSub = fetcher.fetchSubscription(sub.getFeedURL(), sub.getLastUpdated());
        } catch (FetcherException ex) {
            throw new UpdaterException("Error fetching updated subscription", ex);
        }
       
        // if sub was unchanged then we are done
        if(updatedSub == null) {
            return;
        }
       
        // if this subscription hasn't changed since last update then we're done
        if(sub.getLastUpdated() != null && updatedSub.getLastUpdated() != null &&
                !updatedSub.getLastUpdated().after(sub.getLastUpdated())) {
            log.debug("Skipping update, feed hasn't changed - "+sub.getFeedURL());
        }
       
        // update subscription attributes
        sub.setSiteURL(updatedSub.getSiteURL());
        sub.setTitle(updatedSub.getTitle());
        sub.setAuthor(updatedSub.getAuthor());
        sub.setLastUpdated(updatedSub.getLastUpdated());
       
        // update subscription entries
        int entries = 0;
        Set<SubscriptionEntry> newEntries = updatedSub.getEntries();
        if(newEntries.size() > 0) try {
            PlanetManager pmgr = PlanetFactory.getPlanet().getPlanetManager();
           
            // clear out old entries
            pmgr.deleteEntries(sub);
View Full Code Here


       
        PlanetManager pmgr = PlanetFactory.getPlanet().getPlanetManager();
       
        Iterator subs = subscriptions.iterator();
        while (subs.hasNext()) {
            Subscription sub = (Subscription)subs.next();
           
            try {
                // reattach sub.  sub gets detached as we iterate
                sub = pmgr.getSubscriptionById(sub.getId());
            } catch (PlanetException ex) {
                log.warn("Subscription went missing while doing update: "+ex.getMessage());
            }
           
            // this updates and saves
            try {
                updateSubscription(sub);
            } catch(UpdaterException ex) {
                // do a little work to get at the source of the problem
                Throwable cause = ex;
                if(ex.getRootCause() != null) {
                    cause = ex.getRootCause();
                }
                if(cause.getCause() != null) {
                    cause = cause.getCause();
                }
               
                log.warn("Error updating subscription - "+sub.getFeedURL(), cause);
               
            } catch(Exception ex) {
                log.warn("Error updating subscription - "+sub.getFeedURL(), ex);
            }
        }
    }
View Full Code Here

        }
       
        log.debug("Feed pulled, extracting data into Subscription");
       
        // build planet subscription from fetched feed
        Subscription newSub = new Subscription();
        newSub.setFeedURL(feedURL);
        newSub.setSiteURL(feed.getLink());
        newSub.setTitle(feed.getTitle());
        newSub.setAuthor(feed.getAuthor());
        newSub.setLastUpdated(feed.getPublishedDate());
       
       
        // normalize any data that couldn't be properly extracted
        if(newSub.getSiteURL() == null) {
            // set the site url to the feed url then
            newSub.setSiteURL(newSub.getFeedURL());
        }
        if(newSub.getAuthor() == null) {
            // set the author to the title
            newSub.setAuthor(newSub.getTitle());
        }
        if(newSub.getLastUpdated() == null) {
            // no update time specified in feed, so try consulting feed info cache
            FeedFetcherCache feedCache = getRomeFetcherCache();
            try {
                SyndFeedInfo feedInfo = feedCache.getFeedInfo(new URL(newSub.getFeedURL()));
                if(feedInfo.getLastModified() != null) {
                    long lastUpdatedLong = ((Long)feedInfo.getLastModified()).longValue();
                    if (lastUpdatedLong != 0) {
                        newSub.setLastUpdated(new Date(lastUpdatedLong));
                    }
                }
            } catch (MalformedURLException ex) {
                // should never happen since we check this above
            }
        }
       
        // check if feed is unchanged and bail now if so
        if(lastModified != null && newSub.getLastUpdated() != null &&
                !newSub.getLastUpdated().after(lastModified)) {
            return null;
        }
       
        if(log.isDebugEnabled()) {
            log.debug("Subscription is: "+newSub.toString());
        }
       
       
        // some kludge to deal with feeds w/ no entry dates
        // we assign arbitrary dates chronologically by entry starting either
        // from the current time or the last update time of the subscription
        Calendar cal = Calendar.getInstance();
        if (newSub.getLastUpdated() != null) {
            cal.setTime(newSub.getLastUpdated());
        } else {
            cal.setTime(new Date());
            cal.add(Calendar.DATE, -1);
        }
       
        // add entries
        List<SyndEntry> feedEntries = feed.getEntries();
        for( SyndEntry feedEntry : feedEntries ) {
            SubscriptionEntry newEntry = buildEntry(feedEntry);
           
            // some kludge to handle feeds with no entry dates
            if (newEntry.getPubTime() == null) {
                log.debug("No published date, assigning fake date for "+feedURL);
                newEntry.setPubTime(new Timestamp(cal.getTimeInMillis()));
                cal.add(Calendar.DATE, -1);
            }
           
            if(newEntry != null) {
                newSub.addEntry(newEntry);
            }
        }
       
        log.debug(feedEntries.size()+" entries included");
       
View Full Code Here

       
        if(!hasActionErrors()) try {
            PlanetManager pmgr = PlanetFactory.getPlanet().getPlanetManager();
           
            // check if this subscription already exists before adding it
            Subscription sub = pmgr.getSubscription(getSubUrl());
            if(sub == null) {
                log.debug("Adding New Subscription - "+getSubUrl());
               
                // sub doesn't exist yet, so we need to fetch it
                FeedFetcher fetcher = PlanetFactory.getPlanet().getFeedFetcher();
                sub = fetcher.fetchSubscription(getSubUrl());
               
                // save new sub
                pmgr.saveSubscription(sub);
            } else {
                log.debug("Adding Existing Subscription - "+getSubUrl());
               
                // Subscription already exists
                addMessage("planetSubscription.foundExisting", sub.getTitle());
            }
           
            // add the sub to the group
            group.getSubscriptions().add(sub);
            sub.getGroups().add(group);
            pmgr.saveGroup(group);
           
            // flush changes
            PlanetFactory.getPlanet().flush();
           
View Full Code Here

        if(getSubUrl() != null) try {
           
            PlanetManager pmgr = PlanetFactory.getPlanet().getPlanetManager();
           
            // remove subscription
            Subscription sub = pmgr.getSubscription(getSubUrl());
            getGroup().getSubscriptions().remove(sub);
            sub.getGroups().remove(getGroup());
            pmgr.saveGroup(getGroup());
            PlanetFactory.getPlanet().flush();
           
            // clear field after success
            setSubUrl(null);
View Full Code Here

        strategy.store(entry);
    }
   
    public void saveSubscription(Subscription sub)
    throws PlanetException {
        Subscription existing = getSubscription(sub.getFeedURL());
        if (existing == null || (existing.getId().equals(sub.getId()))) {
            strategy.store(sub);
        } else {
            throw new PlanetException("ERROR: duplicate feed URLs not allowed");
        }
    }
View Full Code Here

       
        log.debug("updating feed: "+sub.getFeedURL());
       
        long subStartTime = System.currentTimeMillis();
       
        Subscription updatedSub;
        try {
            // fetch the latest version of the subscription
            log.debug("Getting fetcher");
            FeedFetcher fetcher = PlanetFactory.getPlanet().getFeedFetcher();
            log.debug("Using fetcher class: " + fetcher.getClass().getName());
            updatedSub = fetcher.fetchSubscription(sub.getFeedURL(), sub.getLastUpdated());
           
        } catch (FetcherException ex) {
            throw new UpdaterException("Error fetching updated subscription", ex);
        }
       
        log.debug("Got updatedSub = " + updatedSub);

        // if sub was unchanged then we are done
        if (updatedSub == null) {
            return;
        }
       
        // if this subscription hasn't changed since last update then we're done
        if (sub.getLastUpdated() != null && updatedSub.getLastUpdated() != null &&
                !updatedSub.getLastUpdated().after(sub.getLastUpdated())) {
            log.debug("Skipping update, feed hasn't changed - "+sub.getFeedURL());
        }
       
        // update subscription attributes
        sub.setSiteURL(updatedSub.getSiteURL());
        sub.setTitle(updatedSub.getTitle());
        sub.setAuthor(updatedSub.getAuthor());
        sub.setLastUpdated(updatedSub.getLastUpdated());
       
        // update subscription entries
        int entries = 0;
        Set<SubscriptionEntry> newEntries = updatedSub.getEntries();
        log.debug("newEntries.size() = " + newEntries.size());
        if (newEntries.size() > 0) try {
            PlanetManager pmgr = PlanetFactory.getPlanet().getPlanetManager();
           
            // clear out old entries
View Full Code Here

       
        PlanetManager pmgr = PlanetFactory.getPlanet().getPlanetManager();
       
        Iterator subs = subscriptions.iterator();
        while (subs.hasNext()) {
            Subscription sub = (Subscription)subs.next();
           
            try {
                // reattach sub.  sub gets detached as we iterate
                sub = pmgr.getSubscriptionById(sub.getId());
            } catch (PlanetException ex) {
                log.warn("Subscription went missing while doing update: "+ex.getMessage());
            }
           
            // this updates and saves
            try {
                updateSubscription(sub);
            } catch(UpdaterException ex) {
                // do a little work to get at the source of the problem
                Throwable cause = ex;
                if(ex.getRootCause() != null) {
                    cause = ex.getRootCause();
                }
                if(cause.getCause() != null) {
                    cause = cause.getCause();
                }
               
                if (log.isDebugEnabled()) {
                    log.debug("Error updating subscription - "+sub.getFeedURL(), cause);
                } else {
                    log.warn("Error updating subscription - "+sub.getFeedURL()
                        + " turn on debug logging for more info");
                }
               
            } catch(Exception ex) {
                if (log.isDebugEnabled()) {
                    log.warn("Error updating subscription - "+sub.getFeedURL(), ex);
                } else {
                    log.warn("Error updating subscription - "+sub.getFeedURL()
                        + " turn on debug logging for more info");
                }
            }
        }
    }
View Full Code Here

            // load a planet subscription
            log.debug("Loading Planet Subscription ...");
           
            subscription = pMgr.getSubscriptionById(getSubid());
        } else {
            subscription = new Subscription();
        }
    }
View Full Code Here

                    setError("PlanetSubscriptionForm.error.groupNull");
                    return INPUT;
                }
               
                // check if this subscription already exists before adding it
                Subscription sub = pMgr.getSubscription(this.subscription.getFeedURL());
                if(sub != null) {
                    this.subscription = sub;
                } else {
                    pMgr.saveSubscription(this.subscription);
                   
View Full Code Here

TOP

Related Classes of org.apache.roller.planet.pojos.Subscription

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.