Package org.apache.roller.planet.business

Examples of org.apache.roller.planet.business.PlanetManager


     * Convenience method for removing a sub.
     */
    public static void teardownSubscription(String id) throws Exception {
       
        // lookup
        PlanetManager mgr = PlanetFactory.getPlanet().getPlanetManager();
        Subscription sub = mgr.getSubscriptionById(id);
       
        // remove
        mgr.deleteSubscription(sub);
       
        // flush
        PlanetFactory.getPlanet().flush();
    }
View Full Code Here


     * Convenience method that creates an entry and stores it.
     */
    public static SubscriptionEntry setupEntry(Subscription sub, String title)
            throws Exception {
       
        PlanetManager mgr = PlanetFactory.getPlanet().getPlanetManager();
       
        // make sure we are using a persistent object
        Subscription testSub = mgr.getSubscriptionById(sub.getId());
       
        // store
        SubscriptionEntry testEntry = new SubscriptionEntry();
        testEntry.setPermalink(title);
        testEntry.setTitle(title);
        testEntry.setPubTime(new java.sql.Timestamp(System.currentTimeMillis()));
        testEntry.setSubscription(testSub);
        testSub.getEntries().add(testEntry);
        mgr.saveEntry(testEntry);
       
        // flush
        PlanetFactory.getPlanet().flush();
       
        // query to make sure we return the persisted object
        SubscriptionEntry entry = mgr.getEntryById(testEntry.getId());
       
        if(entry == null)
            throw new PlanetException("error inserting new entry");
       
        return entry;
View Full Code Here

     * Convenience method for removing an entry.
     */
    public static void teardownEntry(String id) throws Exception {
       
        // lookup
        PlanetManager mgr = PlanetFactory.getPlanet().getPlanetManager();
        SubscriptionEntry entry = mgr.getEntryById(id);
       
        // remove
        mgr.deleteEntry(entry);
        entry.getSubscription().getEntries().remove(entry);
       
        // flush
        PlanetFactory.getPlanet().flush();
    }
View Full Code Here

   
    /**
     * Load relevant Planet if possible.
     */
    public void prepare() throws Exception {
        PlanetManager pMgr = PlanetFactory.getPlanet().getPlanetManager();
        if(getGroupid() != null && !"".equals(getGroupid())) {
            // load a planet group
            log.debug("Loading Planet Group ...");
           
            group = pMgr.getGroupById(getGroupid());
        } else {
            // new group, must have a planet to add it to
            Planet planet = pMgr.getPlanetById(getPlanetid());
            if(planet != null) {
                group = new PlanetGroup();
                group.setPlanet(planet);
            } else {
                throw new PlanetException("could not determine planet "+getPlanetid());
View Full Code Here

    public String save() {
        // save a group group
        log.debug("Saving Planet Group ...");
       
        try {
            PlanetManager pMgr = PlanetFactory.getPlanet().getPlanetManager();
            pMgr.saveGroup(this.group);
            PlanetFactory.getPlanet().flush();
           
            // call setGroupid() just in case this was a new group with no id yet
            setGroupid(this.group.getId());
        } catch (PlanetException ex) {
View Full Code Here

    // Validation - sub url cannot be null, must be valid url
    public String addSub() {
        // add a planet subscription
        log.debug("Adding Planet Subscription ...");
       
        PlanetManager pMgr = PlanetFactory.getPlanet().getPlanetManager();
        try {
            PlanetGroup group = getGroup();
            if(group == null) {
                setError("PlanetSubscriptionForm.error.groupNull");
                return INPUT;
            }
           
            // check if this subscription already exists before adding it
            Subscription sub = pMgr.getSubscription(getAddSubUrl());
            if(sub == null) {
                // sub doesn't exist yet, so we need to fetch it
                FeedFetcher fetcher = PlanetFactory.getPlanet().getFeedFetcher();
                sub = fetcher.fetchSubscription(getAddSubUrl());
               
                // save new sub
                pMgr.saveSubscription(sub);
            }
           
            // add the sub to the group
            group.getSubscriptions().add(sub);
            sub.getGroups().add(group);
            pMgr.saveGroup(group);
           
            // flush changes
            PlanetFactory.getPlanet().flush();
           
            // clear field after success
View Full Code Here

   
    public String deleteSub() {
        // delete a planet subscription
        log.debug("Deleting Planet Subscription ...");
       
        PlanetManager pmgr = PlanetFactory.getPlanet().getPlanetManager();
        try {
            if(!StringUtils.isEmpty(getSubid())) {
                Subscription sub = pmgr.getSubscriptionById(getSubid());
                if(sub == null) {
                    setError("PlanetGroupForm.error.nullSubscription");
                    return INPUT;
                } else {
                    PlanetGroup group = getGroup();
                    group.getSubscriptions().remove(sub);
                    sub.getGroups().remove(group);
                    pmgr.saveGroup(group);
                    PlanetFactory.getPlanet().flush();
                }
               
                setSuccess("PlanetGroupForm.message.subscriptionDeleteSucceeded", sub.getTitle());
            } else {
View Full Code Here

    public void run() {
       
        int count = 0;
        int errorCount = 0;
        try {
            PlanetManager planet = PlanetFactory.getPlanet().getPlanetManager();
            Technorati technorati = null;
            try {
                String proxyHost = PlanetRuntimeConfig.getProperty("site.proxyhost");
                int proxyPort = PlanetRuntimeConfig.getIntProperty("site.proxyport");
                if (proxyHost != null && proxyPort != -1) {
                    technorati = new Technorati(proxyHost, proxyPort);
                } else {
                    technorati = new Technorati();
                }
            } catch (IOException e) {
                log.error("Aborting collection of Technorati rankings.\n"
                        +"technorati.license not found at root of classpath.\n"
                        +"Get license at http://technorati.com/developers/apikey.html\n"
                        +"Put the license string in a file called technorati.license.\n"
                        +"And place that file at the root of Roller's classpath.\n"
                        +"For example, in the /WEB-INF/classes directory.");
                return;
            }
           
            try {
                int limit = PlanetConfig.getIntProperty(
                        "planet.aggregator.technorati.limit", 500);
                int userCount = planet.getSubscriptionCount();
                int mod = (userCount / limit) + 1;
               
                Calendar cal = Calendar.getInstance();
                cal.setTime(new Date());
                int day = cal.get(Calendar.DAY_OF_YEAR);
               
                int start = (day % mod) * limit;
                int end = start + limit;
                end = end > userCount ? userCount : end;
                log.info("Updating subscriptions ["+start+":"+end+"]");
               
                Iterator subs = planet.getSubscriptions().iterator();
                while (subs.hasNext()) {
                    Subscription sub =
                            (Subscription)subs.next();
                    if (count >= start && count < end) {
                        try {
                            Technorati.Result result =
                                    technorati.getBloginfo(sub.getSiteURL());
                            if (result != null && result.getWeblog() != null) {
                                sub.setInboundblogs(
                                        result.getWeblog().getInboundblogs());
                                sub.setInboundlinks(
                                        result.getWeblog().getInboundlinks());
                                log.debug("Adding rank for "
                                        +sub.getFeedURL()+" ["+count+"|"
                                        +sub.getInboundblogs()+"|"
                                        +sub.getInboundlinks()+"]");
                            } else {
                                log.debug(
                                        "No ranking available for "
                                        +sub.getFeedURL()+" ["+count+"]");
                                sub.setInboundlinks(0);
                                sub.setInboundblogs(0);
                            }
                            planet.saveSubscription(sub);
                        } catch (Exception e) {
                            log.warn("WARN ranking subscription ["
                                    + count + "]: " + e.getMessage());
                            if (errorCount++ > 5) {
                                log.warn(
View Full Code Here

   
   
    public void run() {
        try {           
            Planet planet = PlanetFactory.getPlanet();
            PlanetManager planetManager = planet.getPlanetManager();
                       
            // Ignore values from database
            //String mainPage = planetManager.getConfiguration().getMainPage();
            //String templateDir = planetManager.getConfiguration().getTemplateDir();
            //String outputDir = planetManager.getConfiguration().getMainPage();
View Full Code Here

     */
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        log.debug("Entering");

        PlanetManager planet = PlanetFactory.getPlanet().getPlanetManager();

        PlanetRequest planetRequest = null;
        try {
            planetRequest = new PlanetRequest(request);
        } catch (Exception e) {
            // some kind of error parsing the request
            log.debug("error creating planet request", e);
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }

        // figure planet last modified date
        Date lastModified = planetCache.getLastModified();

        // Respond with 304 Not Modified if it is not modified.
        if (ModDateHeaderUtil.respondIfNotModified(request, response, lastModified.getTime())) {
            return;
        }

        // set content type
        String accepts = request.getHeader("Accept");
        String userAgent = request.getHeader("User-Agent");
        if (accepts != null && userAgent != null && accepts.indexOf("*/*") != -1 && userAgent.startsWith("Mozilla")) {
            // client is a browser and now that we offer styled feeds we want
            // browsers to load the page rather than popping up the download
            // dialog, so we provide a content-type that browsers will display
            response.setContentType("text/xml");
        } else {
            response.setContentType("application/rss+xml; charset=utf-8");
        }

        // set last-modified date
        ModDateHeaderUtil.setLastModifiedHeader(response, lastModified.getTime());

        // cached content checking
        String cacheKey = PlanetCache.CACHE_ID + ":" + this.generateKey(planetRequest);
        CachedContent entry = (CachedContent) planetCache.get(cacheKey);
        if (entry != null) {
            response.setContentLength(entry.getContent().length);
            response.getOutputStream().write(entry.getContent());
            return;
        }


        // looks like we need to render content
        @SuppressWarnings("unchecked")
        HashMap<String, Object> model = new HashMap();
        try {
            // populate the rendering model
            if (request.getParameter("group") != null) {
                Planet planetObject = planet.getPlanet("default");
                model.put("group", planet.getGroup(planetObject, request.getParameter("group")));
            }
            model.put("planet", planet);
            model.put("date", new Date());
            model.put("utils", new UtilitiesModel());
            model.put("siteName", PlanetRuntimeConfig.getProperty("site.name"));
View Full Code Here

TOP

Related Classes of org.apache.roller.planet.business.PlanetManager

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.