Package org.apache.roller.weblogger.pojos

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


     * Flush page cache for weblog.
     */
    public String flushCache() {
       
        try {
            Weblog weblog = getActionWeblog();
           
            // some caches are based on weblog last-modified, so update it
            weblog.setLastModified(new Date());
           
            UserManager umgr = WebloggerFactory.getWeblogger().getUserManager();
            umgr.saveWebsite(weblog);
            WebloggerFactory.getWeblogger().flush();
           
View Full Code Here


    /**
     * Convenience method that creates a weblog and stores it.
     */
    public static Weblog setupWeblog(String handle, User creator) throws Exception {
       
        Weblog testWeblog = new Weblog();
        testWeblog.setName("Test Weblog");
        testWeblog.setDescription("Test Weblog");
        testWeblog.setHandle(handle);
        testWeblog.setEmailAddress("testweblog@dev.null");
        testWeblog.setEditorPage("editor-text.jsp");
        testWeblog.setBlacklist("");
        testWeblog.setEmailFromAddress("");
        testWeblog.setEditorTheme("basic");
        testWeblog.setLocale("en_US");
        testWeblog.setTimeZone("America/Los_Angeles");
        testWeblog.setDateCreated(new java.util.Date());
        testWeblog.setCreator(creator);
       
        // add weblog
        UserManager mgr = WebloggerFactory.getWeblogger().getUserManager();
        mgr.addWebsite(testWeblog);
       
        // flush to db
        WebloggerFactory.getWeblogger().flush();
       
        // query for the new weblog and return it
        Weblog weblog = mgr.getWebsiteByHandle(handle);
       
        if(weblog == null)
            throw new WebloggerException("error setting up weblog");
       
        return weblog;
View Full Code Here

     */
    public static void teardownWeblog(String id) throws Exception {
       
        // lookup the weblog
        UserManager mgr = WebloggerFactory.getWeblogger().getUserManager();
        Weblog weblog = mgr.getWebsite(id);
       
        // remove the weblog
        mgr.removeWebsite(weblog);
       
        // flush to db
View Full Code Here

     */
    private static boolean testComment(WeblogEntryComment c) {
        boolean ret = false;
        List stringRules = new ArrayList();
        List regexRules = new ArrayList();
        Weblog website = c.getWeblogEntry().getWebsite();
        Blacklist.populateSpamRules(
            website.getBlacklist(), stringRules, regexRules,
            WebloggerRuntimeConfig.getProperty("spam.blacklist"));
        Blacklist blacklist = Blacklist.getBlacklist();
        if (   blacklist.isBlacklisted(c.getUrl(),     stringRules, regexRules)
            || blacklist.isBlacklisted(c.getEmail(),   stringRules, regexRules)
            || blacklist.isBlacklisted(c.getName(),    stringRules, regexRules)
View Full Code Here

        log.info("BEGIN");
       
        try {
       
            UserManager mgr = WebloggerFactory.getWeblogger().getUserManager();
            Weblog weblog = null;

            Weblog testWeblog = new Weblog();
            testUser = TestUtils.getManagedUser(testUser);
            testWeblog.setName("Test Weblog");
            testWeblog.setDescription("Test Weblog");
            testWeblog.setHandle("testweblog");
            testWeblog.setEmailAddress("testweblog@dev.null");
            testWeblog.setEditorPage("editor-text.jsp");
            testWeblog.setBlacklist("");
            testWeblog.setEmailFromAddress("");
            testWeblog.setEditorTheme("basic");
            testWeblog.setLocale("en_US");
            testWeblog.setTimeZone("America/Los_Angeles");
            testWeblog.setDateCreated(new java.util.Date());
            testWeblog.setCreator(testUser);

            // make sure test weblog does not exist
            weblog = mgr.getWebsiteByHandle(testWeblog.getHandle());
            assertNull(weblog);

            // add test weblog
            mgr.addWebsite(testWeblog);
            String id = testWeblog.getId();
            TestUtils.endSession(true);

            // make sure test weblog exists
            weblog = null;
            weblog = mgr.getWebsite(id);
View Full Code Here

     * Test lookup mechanisms.
     */
    public void testWeblogLookups() throws Exception {
       
        log.info("BEGIN");
        Weblog testWeblog1 = null;
        Weblog testWeblog2 = null;
        try {
            UserManager mgr = WebloggerFactory.getWeblogger().getUserManager();
            Weblog weblog = null;
           
            // add test weblogs
            testWeblog1 = TestUtils.setupWeblog("testWeblog1", testUser);
            testWeblog2 = TestUtils.setupWeblog("testWeblog2", testUser);
            TestUtils.endSession(true);
           
            // lookup by id
            weblog = mgr.getWebsite(testWeblog1.getId());
            assertNotNull(weblog);
            assertEquals(testWeblog1.getHandle(), weblog.getHandle());
           
            // lookup by weblog handle
            weblog = null;
            weblog = mgr.getWebsiteByHandle(testWeblog1.getHandle());
            assertNotNull(weblog);
            assertEquals(testWeblog1.getHandle(), weblog.getHandle());
           
            // make sure disable weblogs are not returned
            weblog.setEnabled(Boolean.FALSE);
            mgr.saveWebsite(weblog);
            TestUtils.endSession(true);
            weblog = null;
            weblog = mgr.getWebsiteByHandle(testWeblog1.getHandle());
            assertNull(weblog);
           
            // restore enabled state
            weblog = mgr.getWebsiteByHandle(testWeblog1.getHandle(), Boolean.FALSE);
            weblog.setEnabled(Boolean.TRUE);
            mgr.saveWebsite(weblog);
            TestUtils.endSession(true);
            weblog = null;
            weblog = mgr.getWebsiteByHandle(testWeblog1.getHandle());
            assertNotNull(weblog);
           
            // get all weblogs for user
            weblog = null;
            List weblogs1 = mgr.getWebsites(TestUtils.getManagedUser(testUser), Boolean.TRUE, Boolean.TRUE, null, null, 0, -1);
            assertEquals(2, weblogs1.size());
            weblog = (Weblog) weblogs1.get(0);
            assertNotNull(weblog);
           
            // testing paging
            List weblogs11 = mgr.getWebsites(TestUtils.getManagedUser(testUser), Boolean.TRUE, Boolean.TRUE, null, null, 0, 1);
            assertEquals(1, weblogs11.size());
            List weblogs12 = mgr.getWebsites(TestUtils.getManagedUser(testUser), Boolean.TRUE, Boolean.TRUE, null, null, 1, 1);
            assertEquals(1, weblogs12.size());
           
            // make sure disabled weblogs are not returned
            weblog.setEnabled(Boolean.FALSE);
            mgr.saveWebsite(weblog);
            TestUtils.endSession(true);
            List weblogs2 = mgr.getWebsites(TestUtils.getManagedUser(testUser), Boolean.TRUE, Boolean.TRUE, null, null, 0, -1);
            assertEquals(1, weblogs2.size());
            weblog = (Weblog) weblogs2.get(0);
            assertNotNull(weblog);
           
            // make sure inactive weblogs are not returned
            weblog.setActive(Boolean.FALSE);
            mgr.saveWebsite(weblog);
            TestUtils.endSession(true);
            List weblogs3 = mgr.getWebsites(TestUtils.getManagedUser(testUser), Boolean.TRUE, Boolean.TRUE, null, null, 0, -1);
            assertEquals(0, weblogs3.size());
           
View Full Code Here

        if (weblogHandle == null)
            return;

        String selfSiteFragment = "/"+weblogHandle;
        Weblog weblog = null;
        WeblogEntry entry = null;

        // lookup the weblog now
        try {
            UserManager userMgr = roller.getUserManager();
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 (comment.getNotify().booleanValue()) {
                        // only add those with valid email
                        if (comment.getEmail().matches(EMAIL_ADDR_REGEXP)) {
                            subscribers.add(comment.getEmail());
                        }
                    } else {
                        // remove user who doesn't want to be notified
                        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())) {
            msg.append(commentObject.getName() + " "
                    + 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

       
        WeblogManager mgr = WebloggerFactory.getWeblogger().getWeblogManager();

        testWeblog = TestUtils.getManagedWebsite(testWeblog);
        testUser = TestUtils.getManagedUser(testUser);
        Weblog weblog = TestUtils.setupWeblog("tagsExistWeblog1", testUser);
        String wid = weblog.getId();
       
        // setup some test entries to use
        WeblogEntry entry = TestUtils.setupWeblogEntry("tagsExistEntry1",
                testWeblog.getDefaultCategory(), testWeblog, testUser);
        String id1 = entry.getId();
        entry.addTag("blahTag");
        entry.addTag("fooTag");
        mgr.saveWeblogEntry(entry);

        WeblogEntry entry2 = TestUtils.setupWeblogEntry("tagsExistEntry2",
                weblog.getDefaultCategory(), weblog, testUser);
        String id2 = entry2.getId();
        entry2.addTag("aaaTag");
        entry2.addTag("bbbTag");
        mgr.saveWeblogEntry(entry2);
        TestUtils.endSession(true);
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.