Package org.apache.roller.weblogger.pojos

Examples of org.apache.roller.weblogger.pojos.Weblog


    /**
     * Save new theme configuration.
     */
    public String save() {
       
        Weblog weblog = getActionWeblog();
       
        // we are dealing with a custom theme scenario
        if(WeblogTheme.CUSTOM.equals(getThemeType())) {
           
            // only continue if custom themes are allowed
            if(WebloggerRuntimeConfig.getBooleanProperty("themes.customtheme.allowed")) {
               
                // do theme import if necessary
                SharedTheme importTheme = null;
                if(isImportTheme() && !StringUtils.isEmpty(getImportThemeId())) try {
                    ThemeManager themeMgr = WebloggerFactory.getWeblogger().getThemeManager();
                    importTheme = themeMgr.getTheme(getImportThemeId());
                    themeMgr.importTheme(getActionWeblog(), importTheme);
                } catch(WebloggerException re) {
                    log.error("Error customizing theme for weblog - "+getActionWeblog().getHandle(), re);
                    // TODO: i18n
                    addError("Error importing theme");
                }
               
                if(!hasActionErrors()) try {
                    weblog.setEditorTheme(WeblogTheme.CUSTOM);
                    log.debug("Saving custom theme for weblog "+weblog.getHandle());
                   
                    // save updated weblog and flush
                    UserManager userMgr = WebloggerFactory.getWeblogger().getUserManager();
                    userMgr.saveWebsite(weblog);
                    WebloggerFactory.getWeblogger().flush();
                   
                    // make sure to flush the page cache so ppl can see the change
                    CacheManager.invalidate(weblog);
                   
                    // TODO: i18n
                    addMessage("Successfully set theme to - "+WeblogTheme.CUSTOM);
                    if(importTheme != null) {
                        addMessage("Successfully copied templates from theme - "+importTheme.getName());
                    }
                   
                    // reset import theme options
                    setImportTheme(false);
                    setImportThemeId(null);
                   
                } catch(WebloggerException re) {
                    log.error("Error saving weblog - "+getActionWeblog().getHandle(), re);
                    addError("Error setting theme");
                }
            } else {
                // TODO: i18n
                addError("Sorry, custom themes are not allowed");
            }
           
        // we are dealing with a shared theme scenario
        } else if("shared".equals(getThemeType())) {
           
            // make sure theme is valid and enabled
            Theme newTheme = null;
            if(getThemeId() == null) {
                // TODO: i18n
                addError("No theme specified");
               
            } else {
                try {
                    ThemeManager themeMgr = WebloggerFactory.getWeblogger().getThemeManager();
                    newTheme = themeMgr.getTheme(getThemeId());
                   
                    if(!newTheme.isEnabled()) {
                        // TODO: i18n
                        addError("Theme not enabled");
                    }
                   
                } catch(Exception ex) {
                    log.warn(ex);
                    // TODO: i18n
                    addError("Theme not found");
                }
            }
           
            if(!hasActionErrors()) try {
                weblog.setEditorTheme(getThemeId());
                log.debug("Saving theme "+getThemeId()+" for weblog "+weblog.getHandle());
               
                // save updated weblog and flush
                UserManager userMgr = WebloggerFactory.getWeblogger().getUserManager();
                userMgr.saveWebsite(weblog);
                WebloggerFactory.getWeblogger().flush();
View Full Code Here


               
                // get list of user's enabled websites
                List websites = umgr.getWebsites(user, Boolean.TRUE, null, null, null, 0, -1);
                Iterator iter = websites.iterator();
                while (iter.hasNext()) {
                    Weblog website = (Weblog)iter.next();
                   
                    // only include weblog's that have client API support enabled
                    if (Boolean.TRUE.equals(website.getEnableBloggerApi())) {
                        Hashtable blog = new Hashtable(3);
                        blog.put("url", website.getURL());
                        blog.put("blogid", website.getHandle());
                        blog.put("blogName", website.getName());
                        result.add(blog);
                    }
                }
            } catch (Exception e) {
                String msg = "ERROR in BlooggerAPIHander.getUsersBlogs";
View Full Code Here

        mLogger.debug("     BlogId: " + blogid);
        mLogger.debug("     UserId: " + userid);
        mLogger.debug("    Publish: " + publish);
        mLogger.debug("    Content:\n " + content);
       
        Weblog website = validate(blogid, userid, password);
       
        // extract the title from the content
        String title = "";
       
        if (content.indexOf("<title>") != -1) {
            title =
                    content.substring(content.indexOf("<title>") + 7,
                    content.indexOf("</title>"));
            content = StringUtils.replace(content, "<title>"+title+"</title>", "");
        }
        if (StringUtils.isEmpty(title)) {
            title = Utilities.truncateNicely(content, 15, 15, "...");
        }
       
        try {
            Weblogger roller = WebloggerFactory.getWeblogger();
            WeblogManager weblogMgr = roller.getWeblogManager();
           
            Timestamp current = new Timestamp(System.currentTimeMillis());
           
            WeblogEntry entry = new WeblogEntry();
            entry.setTitle(title);
            entry.setText(content);
            entry.setLocale(website.getLocale());
            entry.setPubTime(current);
            entry.setUpdateTime(current);
            User user = roller.getUserManager().getUserByUserName(userid);
            entry.setCreator(user);
            entry.setWebsite(website);
            entry.setCategory(website.getBloggerCategory());
            entry.setCommentDays(new Integer(website.getDefaultCommentDays()));
            if (Boolean.valueOf(publish).booleanValue()) {
                entry.setStatus(WeblogEntry.PUBLISHED);
            } else {
                entry.setStatus(WeblogEntry.DRAFT);
            }
View Full Code Here

        mLogger.debug("     Appkey: " + appkey);
        mLogger.debug("     BlogId: " + blogid);
        mLogger.debug("     UserId: " + userid);
        mLogger.debug("     Number: " + numposts);
       
        Weblog website = validate(blogid, userid,password);
       
        try {
            Vector results = new Vector();
           
            Weblogger roller = WebloggerFactory.getWeblogger();
View Full Code Here

                                             I18nMessages resources,
                                             boolean notifySubscribers)
            throws MailingException {
       
        WeblogEntry entry = commentObject.getWeblogEntry();
        Weblog weblog = entry.getWebsite();
        User user = entry.getCreator();
       
        // Only send email if email notificaiton is enabled
        boolean notify = WebloggerRuntimeConfig.getBooleanProperty("users.comments.emailnotify");
        if (!notify || !weblog.getEmailComments().booleanValue()) {
            // notifications disabled, just bail
            return;
        }
       
        log.debug("Comment notification enabled ... preparing email");
       
        // Determine message and addressing options from init parameters
        boolean hideCommenterAddrs = WebloggerConfig.getBooleanProperty(
                "comment.notification.hideCommenterAddresses");
       
        // use either the weblog configured from address or the site configured from address
        String from = weblog.getEmailFromAddress();
        if(StringUtils.isEmpty(from)) {
            // TODO: this should not be the users email address
            from = user.getEmailAddress();
        }
       
        // build list of email addresses to send notification to
        Set subscribers = new TreeSet();
       
    // If we are to notify subscribers, then...
    if (notifySubscribers) {
      log.debug("Sending notification email to all subscribers");

      // Get all the subscribers to this comment thread
      List comments = entry.getComments(true, true);
      for (Iterator it = comments.iterator(); it.hasNext();) {
        WeblogEntryComment comment = (WeblogEntryComment) it.next();
        if (!StringUtils.isEmpty(comment.getEmail())) {
          // If user has commented twice,
          // count the most recent notify setting
          if (commentObject.getApproved()) {
            if (comment.getNotify().booleanValue()) {
              // only add those with valid email
              if (comment.getEmail().matches(EMAIL_ADDR_REGEXP)) {
                log.info("Add to subscribers list : " + comment.getEmail());
                subscribers.add(comment.getEmail());
              }
            } else {
              // remove user who doesn't want to be notified
              log.info("Remove from subscribers list : " + comment.getEmail());
              subscribers.remove(comment.getEmail());
            }
          }
        }
      }
    } else {
      log.debug("Sending notification email only to weblog owner");
    }
       
        // Form array of commenter addrs
        String[] commenterAddrs = (String[])subscribers.toArray(new String[0]);
       
        //------------------------------------------
        // --- Form the messages to be sent -
        // Build separate owner and commenter (aka subscriber) messages
       
        // Determine with mime type to use for e-mail
        StringBuffer msg = new StringBuffer();
        StringBuffer ownermsg = new StringBuffer();
        boolean escapeHtml = !WebloggerRuntimeConfig.getBooleanProperty("users.comments.htmlenabled");
       
        // first the commenter message       
        if (!escapeHtml) {
            msg.append("<html><body style=\"background: white; ");
            msg.append(" color: black; font-size: 12px\">");
        }
       
        if (!StringUtils.isEmpty(commentObject.getName())) {
            String emailAddress = StringUtils.isBlank(commentObject.getEmail()) ? " " :
                    " (" + commentObject.getEmail() + ") ";
            msg.append(commentObject.getName() + emailAddress
                    + resources.getString("email.comment.wrote")+": ");
        } else {
            msg.append(resources.getString("email.comment.anonymous")+": ");
        }
       
        msg.append((escapeHtml) ? "\n\n" : "<br /><br />");
       
        msg.append((escapeHtml) ? Utilities.escapeHTML(commentObject.getContent())
        : Utilities.transformToHTMLSubset(Utilities.escapeHTML(commentObject.getContent())));
       
        msg.append((escapeHtml) ? "\n\n----\n"
                : "<br /><br /><hr /><span style=\"font-size: 11px\">");
        msg.append(resources.getString("email.comment.respond") + ": ");
        msg.append((escapeHtml) ? "\n" : "<br />");
       
        // Build link back to comment
        String commentURL = WebloggerFactory.getWeblogger().getUrlStrategy().getWeblogCommentsURL(weblog, null, entry.getAnchor(), true);
       
        if (escapeHtml) {
            msg.append(commentURL);
        } else {
            msg.append("<a href=\""+commentURL+"\">"+commentURL+"</a></span>");
        }
       
        // next the owner message
       
        // First, list any messages from the system that were passed in:
        if (messages.getMessageCount() > 0) {
            ownermsg.append((escapeHtml) ? "" : "<p>");
            ownermsg.append(resources.getString("commentServlet.email.thereAreSystemMessages"));
            ownermsg.append((escapeHtml) ? "\n\n" : "</p>");
            ownermsg.append((escapeHtml) ? "" : "<ul>");
        }
        for (Iterator it = messages.getMessages(); it.hasNext();) {
            RollerMessage rollerMessage = (RollerMessage)it.next();
            ownermsg.append((escapeHtml) ? "" : "<li>");
            ownermsg.append(MessageFormat.format(resources.getString(rollerMessage.getKey()), (Object[])rollerMessage.getArgs()) );
            ownermsg.append((escapeHtml) ? "\n\n" : "</li>");
        }
        if (messages.getMessageCount() > 0) {
            ownermsg.append((escapeHtml) ? "\n\n" : "</ul>");
        }
       
        // Next, list any validation error messages that were passed in:
        if (messages.getErrorCount() > 0) {
            ownermsg.append((escapeHtml) ? "" : "<p>");
            ownermsg.append(resources.getString("commentServlet.email.thereAreErrorMessages"));
            ownermsg.append((escapeHtml) ? "\n\n" : "</p>");
            ownermsg.append((escapeHtml) ? "" : "<ul>");
        }
        for (Iterator it = messages.getErrors(); it.hasNext();) {
            RollerMessage rollerMessage = (RollerMessage)it.next();
            ownermsg.append((escapeHtml) ? "" : "<li>");
            ownermsg.append(MessageFormat.format(resources.getString(rollerMessage.getKey()), (Object[])rollerMessage.getArgs()) );
            ownermsg.append((escapeHtml) ? "\n\n" : "</li>");
        }
        if (messages.getErrorCount() > 0) {
            ownermsg.append((escapeHtml) ? "\n\n" : "</ul>");
        }
       
        ownermsg.append(msg);
       
        // add link to weblog edit page so user can login to manage comments
        ownermsg.append((escapeHtml) ? "\n\n----\n" :
            "<br /><br /><hr /><span style=\"font-size: 11px\">");
        ownermsg.append("Link to comment management page:");
        ownermsg.append((escapeHtml) ? "\n" : "<br />");
       
        Map<String, String> parameters = new HashMap();
        parameters.put("bean.entryId", entry.getId());
        String deleteURL = WebloggerFactory.getWeblogger().getUrlStrategy().getActionURL(
                "comments", "/roller-ui/authoring", weblog.getHandle(), parameters, true);
       
        if (escapeHtml) {
            ownermsg.append(deleteURL);
        } else {
            ownermsg.append(
View Full Code Here

    public static void sendEmailApprovalNotification(WeblogEntryComment cd,
                                                     I18nMessages resources)
            throws MailingException {
       
        WeblogEntry entry = cd.getWeblogEntry();
        Weblog weblog = entry.getWebsite();
        User user = entry.getCreator();
       
        // Only send email if email notificaiton is enabled
        boolean notify = WebloggerRuntimeConfig.getBooleanProperty("users.comments.emailnotify");
        if (!notify || !weblog.getEmailComments().booleanValue()) {
            // notifications disabled, just bail
            return;
        }
       
        log.debug("Comment notification enabled ... preparing email");
       
        // use either the weblog configured from address or the site configured from address
        String from = weblog.getEmailFromAddress();
        if(StringUtils.isEmpty(from)) {
            // TODO: this should not be the users email address
            from = user.getEmailAddress();
        }
       
View Full Code Here

   
    public void testResetHitCounts() throws Exception {
        WeblogManager mgr = WebloggerFactory.getWeblogger().getWeblogManager();
       
        testUser = TestUtils.getManagedUser(testUser);
        Weblog blog1 = TestUtils.setupWeblog("hitCntTest1", testUser);
        Weblog blog2 = TestUtils.setupWeblog("hitCntTest2", testUser);
        Weblog blog3 = TestUtils.setupWeblog("hitCntTest3", testUser);
       
        WeblogHitCount cnt1 = TestUtils.setupHitCount(blog1, 10);
        WeblogHitCount cnt2 = TestUtils.setupHitCount(blog2, 20);
        WeblogHitCount cnt3 = TestUtils.setupHitCount(blog3, 30);
       
        TestUtils.endSession(true);
       
        try {
            // make sure data was properly initialized
            WeblogHitCount testCount = null;
            testCount = mgr.getHitCount(cnt1.getId());
            assertEquals(10, testCount.getDailyHits());
            testCount = mgr.getHitCount(cnt2.getId());
            assertEquals(20, testCount.getDailyHits());
            testCount = mgr.getHitCount(cnt3.getId());
            assertEquals(30, testCount.getDailyHits());

            // reset count for one weblog
            blog1 = TestUtils.getManagedWebsite(blog1);
            mgr.resetHitCount(blog1);
            TestUtils.endSession(true);

            // make sure it reset only one weblog
            testCount = mgr.getHitCount(cnt1.getId());
            assertEquals(0, testCount.getDailyHits());
            testCount = mgr.getHitCount(cnt2.getId());
            assertEquals(20, testCount.getDailyHits());
            testCount = mgr.getHitCount(cnt3.getId());
            assertEquals(30, testCount.getDailyHits());

            // reset all counts
            mgr.resetAllHitCounts();
            TestUtils.endSession(true);

            // make sure it reset all counts
            testCount = mgr.getHitCount(cnt1.getId());
            assertEquals(0, testCount.getDailyHits());
            testCount = mgr.getHitCount(cnt2.getId());
            assertEquals(0, testCount.getDailyHits());
            testCount = mgr.getHitCount(cnt3.getId());
            assertEquals(0, testCount.getDailyHits());
       
        } finally {
            // cleanup
            TestUtils.teardownHitCount(cnt1.getId());
            TestUtils.teardownHitCount(cnt2.getId());
            TestUtils.teardownHitCount(cnt3.getId());
            TestUtils.teardownWeblog(blog1.getId());
            TestUtils.teardownWeblog(blog2.getId());
            TestUtils.teardownWeblog(blog3.getId());
        }
    }
View Full Code Here

    public void testHotWeblogs() throws Exception {
       
        WeblogManager mgr = WebloggerFactory.getWeblogger().getWeblogManager();
       
        testUser = TestUtils.getManagedUser(testUser);
        Weblog blog1 = TestUtils.setupWeblog("hitCntHotTest1", testUser);
        Weblog blog2 = TestUtils.setupWeblog("hitCntHotTest2", testUser);
        Weblog blog3 = TestUtils.setupWeblog("hitCntHotTest3", testUser);
       
        WeblogHitCount cnt1 = TestUtils.setupHitCount(blog1, 10);
        WeblogHitCount cnt2 = TestUtils.setupHitCount(blog2, 20);
        WeblogHitCount cnt3 = TestUtils.setupHitCount(blog3, 30);
       
        TestUtils.endSession(true);
       
        // make sure data was properly initialized
        WeblogHitCount testCount = null;
        testCount = mgr.getHitCount(cnt1.getId());
        assertEquals(10, testCount.getDailyHits());
        testCount = mgr.getHitCount(cnt2.getId());
        assertEquals(20, testCount.getDailyHits());
        testCount = mgr.getHitCount(cnt3.getId());
        assertEquals(30, testCount.getDailyHits());
       
        // get hot weblogs
        List hotBlogs = mgr.getHotWeblogs(1, 0, 5);
        assertNotNull(hotBlogs);
        assertEquals(3, hotBlogs.size());
       
        // also check ordering and values
        WeblogHitCount hitCount = null;
        Iterator it = hotBlogs.iterator();
        for(int i=3; it.hasNext(); i--) {
            hitCount = (WeblogHitCount) it.next();
           
            assertEquals(i*10, hitCount.getDailyHits());
        }
       
        // cleanup
        TestUtils.teardownHitCount(cnt1.getId());
        TestUtils.teardownHitCount(cnt2.getId());
        TestUtils.teardownHitCount(cnt3.getId());
        TestUtils.teardownWeblog(blog1.getId());
        TestUtils.teardownWeblog(blog2.getId());
        TestUtils.teardownWeblog(blog3.getId());
    }
View Full Code Here

            WeblogManager wmgr = WebloggerFactory.getWeblogger().getWeblogManager();       
            UserManager umgr = WebloggerFactory.getWeblogger().getUserManager();

            // first make sure we can delete an entry with comments
            User user = TestUtils.setupUser("commentParentDeleteUser");
            Weblog weblog = TestUtils.setupWeblog("commentParentDelete", user);
            WeblogEntry entry = TestUtils.setupWeblogEntry("CommentParentDeletes1",
                    weblog.getDefaultCategory(), weblog, user);
            TestUtils.endSession(true);

            entry = TestUtils.getManagedWeblogEntry(entry);
            TestUtils.setupComment("comment1", entry);
            TestUtils.setupComment("comment2", entry);
            TestUtils.setupComment("comment3", entry);
            TestUtils.endSession(true);

            // now deleting the entry should succeed and delete all comments
            Exception ex = null;
            try {
                wmgr.removeWeblogEntry(TestUtils.getManagedWeblogEntry(entry));
                TestUtils.endSession(true);
            } catch (WebloggerException e) {
                ex = e;
            }
            assertNull(ex);

            // now make sure we can delete a weblog with comments
            weblog = TestUtils.getManagedWebsite(weblog);
            user = TestUtils.getManagedUser(user);
            entry = TestUtils.setupWeblogEntry("CommentParentDeletes2",
                    weblog.getDefaultCategory(), weblog, user);
            TestUtils.endSession(true);

            entry = TestUtils.getManagedWeblogEntry(entry);
            TestUtils.setupComment("comment1", entry);
            TestUtils.setupComment("comment2", entry);
View Full Code Here

    }
       
    public void testSearch() throws Exception {
        IndexManager imgr = WebloggerFactory.getWeblogger().getIndexManager();

        Weblog website = new Weblog();
        website.setHandle("trekker");

        User user = new User();
        user.setUserName("nimoy");

        WeblogEntry wd1 = new WeblogEntry();           
View Full Code Here

TOP

Related Classes of org.apache.roller.weblogger.pojos.Weblog

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.