Package org.apache.roller.business

Examples of org.apache.roller.business.BookmarkManager


    private void removeWebsiteContents(WebsiteData website)
    throws HibernateException, RollerException {
       
        Session session = this.strategy.getSession();
       
        BookmarkManager bmgr = RollerFactory.getRoller().getBookmarkManager();
        WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager();
       
        // remove tags
        Criteria tagQuery = session.createCriteria(WeblogEntryTagData.class)
            .add(Expression.eq("weblog.id", website.getId()));
        for(Iterator iter = tagQuery.list().iterator(); iter.hasNext();) {
            WeblogEntryTagData tagData = (WeblogEntryTagData) iter.next();
            this.strategy.remove(tagData);
        }
       
        // remove site tag aggregates
        List tags = wmgr.getTags(website, null, null, -1);
        for(Iterator iter = tags.iterator(); iter.hasNext();) {
            TagStat stat = (TagStat) iter.next();
            Query query = session.createQuery("update WeblogEntryTagAggregateData set total = total - ? where name = ? and weblog is null");
            query.setParameter(0, new Integer(stat.getCount()));
            query.setParameter(1, stat.getName());
            query.executeUpdate();
        }
       
        // delete all weblog tag aggregates
        session.createQuery("delete from WeblogEntryTagAggregateData where weblog = ?")
            .setParameter(0, website).executeUpdate();
       
        // delete all bad counts
        session.createQuery("delete from WeblogEntryTagAggregateData where total <= 0").executeUpdate();      
               
        // Remove the website's ping queue entries
        Criteria criteria = session.createCriteria(PingQueueEntryData.class);
        criteria.add(Expression.eq("website", website));
        List queueEntries = criteria.list();
       
        // Remove the website's auto ping configurations
        AutoPingManager autoPingMgr = RollerFactory.getRoller().getAutopingManager();
        List autopings = autoPingMgr.getAutoPingsByWebsite(website);
        Iterator it = autopings.iterator();
        while(it.hasNext()) {
            this.strategy.remove((AutoPingData) it.next());
        }
       
        // Remove the website's custom ping targets
        PingTargetManager pingTargetMgr = RollerFactory.getRoller().getPingTargetManager();
        List pingtargets = pingTargetMgr.getCustomPingTargets(website);
        it = pingtargets.iterator();
        while(it.hasNext()) {
            this.strategy.remove((PingTargetData) it.next());
        }
       
        // remove entries
        Criteria entryQuery = session.createCriteria(WeblogEntryData.class);
        entryQuery.add(Expression.eq("website", website));
        List entries = entryQuery.list();
        for (Iterator iter = entries.iterator(); iter.hasNext();) {
            WeblogEntryData entry = (WeblogEntryData) iter.next();
           
            this.strategy.remove(entry);
        }
       
        // remove associated referers
        Criteria refererQuery = session.createCriteria(RefererData.class);
        refererQuery.add(Expression.eq("website", website));
        List referers = refererQuery.list();
        for (Iterator iter = referers.iterator(); iter.hasNext();) {
            RefererData referer = (RefererData) iter.next();
            this.strategy.remove(referer);
        }
       
       
        // remove associated pages
        Criteria pageQuery = session.createCriteria(WeblogTemplate.class);
        pageQuery.add(Expression.eq("website", website));
        List pages = pageQuery.list();
        for (Iterator iter = pages.iterator(); iter.hasNext();) {
            WeblogTemplate page = (WeblogTemplate) iter.next();
            this.strategy.remove(page);
        }
       
        // remove folders (including bookmarks)
        FolderData rootFolder = bmgr.getRootFolder(website);
        if (null != rootFolder) {
            this.strategy.remove(rootFolder);
           
            // Still cannot get all Bookmarks cleared!
            Iterator allFolders = bmgr.getAllFolders(website).iterator();
            while (allFolders.hasNext()) {
                FolderData aFolder = (FolderData)allFolders.next();
                bmgr.removeFolderContents(aFolder);
                this.strategy.remove(aFolder);
            }
        }
       
        // remove categories
View Full Code Here


        HttpServletRequest  request,
        HttpServletResponse response)
        throws Exception
    {
        RollerRequest rreq = RollerRequest.getRollerRequest(request);
        BookmarkManager bmgr = RollerFactory.getRoller().getBookmarkManager();
        FolderFormEx form = (FolderFormEx)actionForm;
       
        FolderData parentFolder = null;
        if (null!=rreq.getFolder() && null==request.getParameter("correct"))
        {
            // If request specifies folder and we are not correcting an
            // already submitted form then load that folder into the form.
            request.setAttribute("state","edit");

            FolderData fd = rreq.getFolder();
            form.copyFrom(fd, request.getLocale());
            parentFolder = fd.getParent();
           
            BasePageModel pageModel = new BasePageModel(
                "folderForm.add.title", request, response, mapping);
            pageModel.setWebsite(parentFolder.getWebsite());
            request.setAttribute("model", pageModel);
        }
        else if (null != request.getParameter("correct"))
        {
            // We are correcting a previously submtted form.
            request.setAttribute("state","correcting");
           
            String parentId = request.getParameter(RequestConstants.PARENT_ID);
            parentFolder = bmgr.getFolder(parentId);
           
            BasePageModel pageModel = new BasePageModel(
                "folderForm.correct.title", request, response, mapping);
            pageModel.setWebsite(parentFolder.getWebsite());
            request.setAttribute("model", pageModel);
        }
        else
        {
            // We are adding a new bookmark
            request.setAttribute("state","add");
           
            String parentId = request.getParameter(RequestConstants.PARENT_ID);
            parentFolder = bmgr.getFolder(parentId);
           
            BasePageModel pageModel = new BasePageModel(
                "folderForm.add.title", request, response, mapping);
            pageModel.setWebsite(parentFolder.getWebsite());
            request.setAttribute("model", pageModel);
View Full Code Here

    }
   
   
    public void testAddBookmarkToFolder() throws Exception {
       
        BookmarkManager bmgr = getRoller().getBookmarkManager();
        FolderData folder = null;
        BookmarkData bookmark1 = null, bookmark2 = null;
       
        FolderData root = bmgr.getRootFolder(testWeblog);
       
        folder = new FolderData();
        folder.setName("TestFolder1");
        folder.setDescription("created by testAddBookmarkToFolder()");
        folder.setWebsite(testWeblog);
        folder.setParent(root);
        bmgr.saveFolder(folder);
       
        // Add bookmark by adding to folder
        bookmark1 = new BookmarkData(
                folder,
                "TestBookmark1",
                "created by testAddBookmarkToFolder()",
                "http://www.example.com",
                "http://www.example.com/rss.xml",
                new Integer(1),
                new Integer(12),
                "test.jpg");
        folder.addBookmark(bookmark1);
       
        // Add another bookmark
        bookmark2 = new BookmarkData(
                folder,
                "TestBookmark2",
                "created by testAddBookmarkToFolder()",
                "http://www.example.com",
                "http://www.example.com/rss.xml",
                new Integer(1),
                new Integer(12),
                "test.jpf");
        folder.addBookmark(bookmark2);
       
        TestUtils.endSession(true);
       
        FolderData testFolder = null;
        BookmarkData bookmarkb = null, bookmarka = null;
       
        // See that two bookmarks were stored
        testFolder = bmgr.getFolder(folder.getId());
        assertEquals(2, testFolder.getBookmarks().size());
        bookmarka = (BookmarkData)testFolder.getBookmarks().iterator().next();
        bookmarkb = (BookmarkData)testFolder.getBookmarks().iterator().next();
        // Remove one bookmark
        testFolder.removeBookmark(bookmarka);
        bmgr.removeBookmark(bookmarka);
        TestUtils.endSession(true);
       
        // Folder should now contain one bookmark
        testFolder = bmgr.getFolder(folder.getId());
        assertEquals(1, testFolder.getBookmarks().size());
        TestUtils.endSession(true);
       
        // Remove folder
        testFolder = bmgr.getFolder(folder.getId());
        bmgr.removeFolder(testFolder);
        TestUtils.endSession(true);
       
        // Folder and one remaining bookmark should be gone
        assertNull( bmgr.getBookmark(bookmarkb.getId()) );
        assertNull( bmgr.getFolder(folder.getId()) );
    }
View Full Code Here

     *          f2/
     *             f3/
     */
    public void testMoveFolderContents() throws Exception {
       
        BookmarkManager bmgr = getRoller().getBookmarkManager();
       
        FolderData root = bmgr.getRootFolder(testWeblog);
       
        FolderData dest = new FolderData();
        dest.setName("dest");
        dest.setParent(root);
        dest.setWebsite(testWeblog);
        bmgr.saveFolder(dest);
       
        // create source folder f1
        FolderData f1 = new FolderData();
        f1.setName("f1");
        f1.setParent(root);
        f1.setWebsite(testWeblog);
        bmgr.saveFolder(f1);
       
        // create bookmark b1 inside source folder f1
        BookmarkData b1 = new BookmarkData(
                f1, "b1", "testbookmark",
                "http://example.com", "http://example.com/rss",
                new Integer(1), new Integer(1), "image.gif");
        f1.addBookmark(b1);
       
        // create folder f2 inside f1
        FolderData f2 = new FolderData();
        f2.setName("f2");
        f2.setParent(f1);
        f2.setWebsite(testWeblog);
        bmgr.saveFolder(f2);
       
        // create bookmark b2 inside folder f2
        BookmarkData b2 = new BookmarkData(
                f2, "b2", "testbookmark",
                "http://example.com", "http://example.com/rss",
                new Integer(1), new Integer(1), "image.gif");
        f2.addBookmark(b2);
       
        // create folder f3 inside folder f2
        FolderData f3 = new FolderData();
        f3.setName("f3");
        f3.setParent(f2);
        f3.setWebsite(testWeblog);
        bmgr.saveFolder(f3);
       
        // crete bookmark b3 inside folder f3
        BookmarkData b3 = new BookmarkData(
                f3, "b3", "testbookmark",
                "http://example.com", "http://example.com/rss",
                new Integer(1), new Integer(1), "image.gif");
        f3.addBookmark(b3);
       
        TestUtils.endSession(true);
       
        // test that parent cannot be moved into child
        boolean safe = false;
        try {
           
            // Move folder into one of it's children
            f1 = bmgr.getFolder(f1.getId());
            f3 = bmgr.getFolder(f3.getId());
            bmgr.moveFolderContents(f1, f3);
            //f3.save();
            //f1.save();
            TestUtils.endSession(true);
        } catch (RollerException e) {
            safe = true;
        }
        assertTrue(safe);
       
        // verify number of entries in each folder
        dest = bmgr.getFolder(dest.getId());
        f1 = bmgr.getFolder(f1.getId());
        assertEquals(0, dest.retrieveBookmarks(true).size());
        assertEquals(0, dest.retrieveBookmarks(false).size());
        assertEquals(1, f1.retrieveBookmarks(false).size());
       
        List f1list = f1.retrieveBookmarks(true);
        assertEquals(3, f1list.size());
       
        // move contents of source category c1 to destination catetory dest
        f1.moveContents(dest);
        bmgr.saveFolder(f1);
        bmgr.saveFolder(dest);
        TestUtils.endSession(true);
       
        // after move, verify number of entries in eacch folder
        dest = bmgr.getFolder(dest.getId());
        f1 = bmgr.getFolder(f1.getId());
        assertEquals(3, dest.retrieveBookmarks(true).size());
        assertEquals(3, dest.retrieveBookmarks(false).size());
        assertEquals(0, f1.retrieveBookmarks(true).size());
        assertEquals(0, f1.retrieveBookmarks(false).size());
    }
View Full Code Here

   
   
    /** Test bookmark folder paths. */
    public void testPaths() throws Exception {
       
        BookmarkManager bmgr = getRoller().getBookmarkManager();
       
        try {
            FolderData root = bmgr.getRootFolder(testWeblog);
           
            FolderData f1 = new FolderData();
            f1.setName("f1");
            f1.setParent(root);
            f1.setWebsite(testWeblog);
            bmgr.saveFolder(f1);
           
            FolderData f2 = new FolderData();
            f2.setName("f2");
            f2.setParent(f1);
            f2.setWebsite(testWeblog);
            bmgr.saveFolder(f2);
           
            FolderData f3 = new FolderData();
            f3.setName("f3");
            f3.setParent(f2);
            f3.setWebsite(testWeblog);
            bmgr.saveFolder(f3);
           
            TestUtils.endSession(true);
        } catch (RollerException e) {
            TestUtils.endSession(true);
            log.error(e);
        }
       
        try {
           
            assertEquals("f1",bmgr.getFolderByPath(testWeblog, null, "/f1").getName());
            assertEquals("f2",bmgr.getFolderByPath(testWeblog, null, "/f1/f2").getName());
            assertEquals("f3",bmgr.getFolderByPath(testWeblog, null, "/f1/f2/f3").getName());
           
            FolderData f3 = bmgr.getFolderByPath(testWeblog, null, "/f1/f2/f3");
            String pathString = bmgr.getPath(f3);
            String[] pathArray = Utilities.stringToStringArray(pathString,"/");
            assertEquals("f1", pathArray[0]);
            assertEquals("f2", pathArray[1]);
            assertEquals("f3", pathArray[2]);
           
View Full Code Here

    /** Ensure that duplicate folder name will throw RollerException */
    public void testUniquenessOfFolderNames() throws Exception {
       
        boolean exception = false;
        FolderData f3 = null;
        BookmarkManager bmgr = getRoller().getBookmarkManager();
        try {
            FolderData root = bmgr.getRootFolder(testWeblog);
           
            FolderData f1 = new FolderData();
            f1.setName("f1");
            f1.setParent(root);
            f1.setWebsite(testWeblog);
            bmgr.saveFolder(f1);
           
            // first child folder
            FolderData f2 = new FolderData();
            f2.setName("f2");
            f2.setParent(f1);
            f2.setWebsite(testWeblog);
            bmgr.saveFolder(f2);
           
            TestUtils.endSession(true);
           
            // child folder with same name as first
            f3 = new FolderData();
            f3.setName("f2");
            f3.setParent(f1);
            f3.setWebsite(testWeblog);
            bmgr.saveFolder(f3);
           
            TestUtils.endSession(true);
        } catch (RollerException e) {
            exception = true;
        }
View Full Code Here

   
   
    public String render(WeblogEntryData entry, String str) {
        String text = str;
        try {
            BookmarkManager bMgr = RollerFactory.getRoller().getBookmarkManager();
            FolderData rootFolder = bMgr.getRootFolder(entry.getWebsite());
            text = matchBookmarks(text, rootFolder);
            text = lookInFolders(text, rootFolder.getFolders());
        } catch (RollerException e) {
            // nothing much I can do, go with default "Weblog" value
            // could be RollerException or NullPointerException
View Full Code Here

        {
            mLogger.debug("Init called without website.  Skipping bookmark initialization.");
        }
        else
        {
            BookmarkManager bMgr = RollerFactory.getRoller().getBookmarkManager();
            List bookmarks = bMgr.getBookmarks(bMgr.getRootFolder(website), true);

            for (Iterator i = bookmarks.iterator(); i.hasNext();)
            {
                BookmarkData b = (BookmarkData) i.next();
                bookmarkMap.put(b.getName(), b);
View Full Code Here

TOP

Related Classes of org.apache.roller.business.BookmarkManager

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.