You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by ag...@apache.org on 2006/04/19 22:53:20 UTC

svn commit: r395393 [2/10] - in /incubator/roller/trunk: ./ contrib/plugins/src/org/roller/presentation/velocity/plugins/topictag/ metadata/database/hibernate/ sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/ sandbox/atomprotocol/src...

Modified: incubator/roller/trunk/src/org/roller/business/hibernate/HibernateBookmarkManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/hibernate/HibernateBookmarkManagerImpl.java?rev=395393&r1=395392&r2=395393&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/hibernate/HibernateBookmarkManagerImpl.java (original)
+++ incubator/roller/trunk/src/org/roller/business/hibernate/HibernateBookmarkManagerImpl.java Wed Apr 19 13:53:01 2006
@@ -2,13 +2,14 @@
  * Created on Jun 18, 2004
  */
 package org.roller.business.hibernate;
+
+import java.io.IOException;
+import java.io.StringReader;
 import org.hibernate.Criteria;
 import org.hibernate.HibernateException;
 import org.hibernate.Session;
 import org.hibernate.criterion.Expression;
 import org.roller.RollerException;
-import org.roller.business.BookmarkManagerImpl;
-import org.roller.business.PersistenceStrategy;
 import org.roller.pojos.Assoc;
 import org.roller.pojos.BookmarkData;
 import org.roller.pojos.FolderAssoc;
@@ -19,162 +20,390 @@
 import java.util.List;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+import org.roller.model.BookmarkManager;
+import org.roller.util.Utilities;
+
 
 /**
- * Hibernate queries.
- * 
- * @author David M Johnson
+ * Hibernate implementation of the BookmarkManager.
  */
-public class HibernateBookmarkManagerImpl extends BookmarkManagerImpl
-{
+public class HibernateBookmarkManagerImpl implements BookmarkManager {
+    
     static final long serialVersionUID = 5286654557062382772L;
-
-    private static Log mLogger =
-        LogFactory.getFactory().getInstance(HibernateBookmarkManagerImpl.class);
+    
+    private static Log log = LogFactory.getLog(HibernateBookmarkManagerImpl.class);
+    
+    private HibernatePersistenceStrategy strategy = null;
+    
     
     /**
      * @param pstrategy
      * @param roller
      */
-    public HibernateBookmarkManagerImpl(PersistenceStrategy pstrategy)
-    {
-        super(pstrategy);
-        mLogger.debug("Instantiating Bookmark Manager");
+    public HibernateBookmarkManagerImpl(HibernatePersistenceStrategy strat) {
+        log.debug("Instantiating Hibernate Bookmark Manager");
+        
+        this.strategy = strat;
     }
-
+    
+    
+    public void saveBookmark(BookmarkData bookmark) throws RollerException {
+        this.strategy.store(bookmark);
+    }
+    
+    
+    public BookmarkData getBookmark(String id) throws RollerException {
+        BookmarkData bd = (BookmarkData)
+        strategy.load(id, BookmarkData.class);
+        // TODO: huh?  why do we do this?
+        if (bd != null) bd.setBookmarkManager(this);
+        return bd;
+    }
+    
+    
+    public void removeBookmark(BookmarkData bookmark) throws RollerException {
+        this.strategy.remove(bookmark);
+    }
+    
+    //------------------------------------------------------------ Folder CRUD
+    
+    
+    public void saveFolder(FolderData folder) throws RollerException {
+        
+        if(isDuplicateFolderName(folder)) {
+            throw new RollerException("Duplicate folder name");
+        }
+        
+        this.strategy.store(folder);
+    }
+    
+    
+    public void removeFolder(FolderData folder) throws RollerException {
+        
+        this.strategy.remove(folder);
+    }
+    
+    
+    /**
+     * Retrieve folder and lazy-load it's sub-folders and bookmarks.
+     */
+    public FolderData getFolder(String id) throws RollerException {
+        return (FolderData)strategy.load(id, FolderData.class);
+    }
+    
+    //------------------------------------------------------------ Operations
+    
+    public void importBookmarks(WebsiteData website, String folderName, String opml)
+            throws RollerException {
+        
+        String msg = "importBookmarks";
+        try {
+            // Build JDOC document OPML string
+            SAXBuilder builder = new SAXBuilder();
+            StringReader reader = new StringReader( opml );
+            Document doc = builder.build( reader );
+            
+            FolderData newFolder = getFolder(website, folderName);
+            if (newFolder == null) {
+                newFolder = new FolderData(
+                        getRootFolder(website), folderName, folderName, website);
+                this.strategy.store(newFolder);
+            }
+            
+            // Iterate through children of OPML body, importing each
+            Element body = doc.getRootElement().getChild("body");
+            Iterator iter = body.getChildren().iterator();
+            while (iter.hasNext()) {
+                Element elem = (Element)iter.next();
+                importOpmlElement( website, elem, newFolder );
+            }
+            
+        } catch (Exception ex) {
+            throw new RollerException(ex);
+        }
+    }
+    
+    // convenience method used when importing bookmarks
+    // NOTE: this method does not commit any changes, that is done by importBookmarks()
+    private void importOpmlElement(
+            WebsiteData website, Element elem, FolderData parent)
+            throws RollerException {
+        String text = elem.getAttributeValue("text");
+        String title = elem.getAttributeValue("title");
+        String desc = elem.getAttributeValue("description");
+        String url = elem.getAttributeValue("url");
+        //String type = elem.getAttributeValue("type");
+        String xmlUrl = elem.getAttributeValue("xmlUrl");
+        String htmlUrl = elem.getAttributeValue("htmlUrl");
+        
+        title =   null!=title ? title : text;
+        desc =    null!=desc ? desc : title;
+        xmlUrl =  null!=xmlUrl ? xmlUrl : url;
+        url =     null!=htmlUrl ? htmlUrl : url;
+        
+        if (elem.getChildren().size()==0) {
+            // Leaf element.  Store a bookmark
+            // Currently bookmarks must have at least a name and HTML url to be stored. Previous logic was
+            // trying to skip invalid ones, but was letting ones with an xml url and no html url through
+            // which could result in a db exception.
+            // TODO: Consider providing error feedback instead of silently skipping the invalid bookmarks here.
+            if (null != title && null != url) {
+                BookmarkData bd = new BookmarkData(parent,
+                        title,
+                        desc,
+                        url,
+                        xmlUrl,
+                        new Integer(0),
+                        new Integer(100),
+                        null);
+                parent.addBookmark(bd);
+                // TODO: maybe this should be saving the folder?
+                this.strategy.store(bd);
+            }
+        } else {
+            // Store a folder
+            FolderData fd = new FolderData(
+                    parent,
+                    title,
+                    desc,
+                    parent.getWebsite());
+            this.strategy.store(fd);
+            
+            // Import folder's children
+            Iterator iter = elem.getChildren("outline").iterator();
+            while ( iter.hasNext() ) {
+                Element subelem = (Element)iter.next();
+                importOpmlElement( website, subelem, fd  );
+            }
+        }
+    }
+    
+    //----------------------------------------------------------------
+    public void moveFolderContents(FolderData src, FolderData dest)
+            throws RollerException {
+        
+        if (dest.descendentOf(src)) {
+            throw new RollerException(
+                    "ERROR cannot move parent folder into it's own child");
+        }
+        
+        try {
+            // Add to destination folder
+            LinkedList deleteList = new LinkedList();
+            Iterator srcBookmarks = src.getBookmarks().iterator();
+            while (srcBookmarks.hasNext()) {
+                BookmarkData bd = (BookmarkData)srcBookmarks.next();
+                deleteList.add(bd);
+                
+                BookmarkData movedBd = new BookmarkData();
+                movedBd.setData(bd);
+                movedBd.setId(null);
+                
+                dest.addBookmark(movedBd);
+                this.strategy.store(movedBd);
+            }
+            
+            // Remove from source folder
+            Iterator deleteIter = deleteList.iterator();
+            while (deleteIter.hasNext()) {
+                BookmarkData bd = (BookmarkData)deleteIter.next();
+                src.removeBookmark(bd);
+                // TODO: this won't conflict with the bookmark we store above right?
+                this.strategy.remove(bd);
+            }
+            
+        } catch (Exception ex) {
+            throw new RollerException(ex);
+        }
+    }
+    
+    //----------------------------------------------------------------
+    public void removeFolderContents(FolderData src) throws RollerException {
+        
+        // just go through the folder and remove each bookmark
+        Iterator srcBookmarks = src.getBookmarks().iterator();
+        while (srcBookmarks.hasNext()) {
+            BookmarkData bd = (BookmarkData)srcBookmarks.next();
+            this.strategy.remove(bd);
+        }
+    }
+    
+    //---------------------------------------------------------------- Queries
+    
+    public FolderData getFolder(WebsiteData website, String folderPath)
+    throws RollerException {
+        return getFolderByPath(website, null, folderPath);
+    }
+    
+    public String getPath(FolderData folder) throws RollerException {
+        if (null == folder.getParent()) {
+            return "/";
+        } else {
+            String parentPath = getPath(folder.getParent());
+            parentPath = "/".equals(parentPath) ? "" : parentPath;
+            return parentPath + "/" + folder.getName();
+        }
+    }
+    
+    public FolderData getFolderByPath(
+            WebsiteData website, FolderData folder, String path)
+            throws RollerException {
+        final Iterator folders;
+        final String[] pathArray = Utilities.stringToStringArray(path, "/");
+        
+        if (folder == null && (null == path || "".equals(path.trim()))) {
+            throw new RollerException("Bad arguments.");
+        }
+        
+        if (path.trim().equals("/")) {
+            return getRootFolder(website);
+        } else if (folder == null || path.trim().startsWith("/")) {
+            folders = getRootFolder(website).getFolders().iterator();
+        } else {
+            folders = folder.getFolders().iterator();
+        }
+        
+        while (folders.hasNext()) {
+            FolderData possibleMatch = (FolderData)folders.next();
+            if (possibleMatch.getName().equals(pathArray[0])) {
+                if (pathArray.length == 1) {
+                    return possibleMatch;
+                } else {
+                    String[] subpath = new String[pathArray.length - 1];
+                    System.arraycopy(pathArray, 1, subpath, 0, subpath.length);
+                    
+                    String pathString= Utilities.stringArrayToString(subpath,"/");
+                    return getFolderByPath(website, possibleMatch, pathString);
+                }
+            }
+        }
+        
+        // The folder did not match and neither did any subfolders
+        return null;
+    }
+    
+    //----------------------------------------------- FolderAssoc CRUD
+    
+    
+    public FolderAssoc retrieveFolderAssoc(String id) throws RollerException {
+        return (FolderAssoc)strategy.load(id, FolderAssoc.class);
+    }
+    
+    public void release() {}
+    
     /**
      * @see org.roller.model.BookmarkManager#retrieveBookmarks(
      *      org.roller.pojos.FolderData, boolean)
      */
-    public List retrieveBookmarks(FolderData folder, boolean subfolders)
-                    throws RollerException
-    {
-        try
-        {
-            Session session = ((HibernateStrategy) mStrategy).getSession();
+    public List getBookmarks(FolderData folder, boolean subfolders)
+    throws RollerException {
+        try {
+            Session session = ((HibernatePersistenceStrategy) strategy).getSession();
             List bookmarks = new LinkedList();
-            if (subfolders)
-            {
+            if (subfolders) {
                 // get bookmarks in subfolders
                 Criteria assocsQuery = session
-                                .createCriteria(FolderAssoc.class);
+                        .createCriteria(FolderAssoc.class);
                 assocsQuery.add(Expression.eq("ancestorFolder", folder));
                 Iterator assocs = assocsQuery.list().iterator();
-                while (assocs.hasNext())
-                {
+                while (assocs.hasNext()) {
                     FolderAssoc assoc = (FolderAssoc) assocs.next();
                     Criteria bookmarksQuery = session
-                                    .createCriteria(BookmarkData.class);
+                            .createCriteria(BookmarkData.class);
                     bookmarksQuery.add(Expression.eq("folder", assoc
-                                    .getFolder()));
+                            .getFolder()));
                     Iterator bookmarkIter = bookmarksQuery.list().iterator();
-                    while (bookmarkIter.hasNext())
-                    {
+                    while (bookmarkIter.hasNext()) {
                         BookmarkData entry = (BookmarkData) bookmarkIter.next();
                         bookmarks.add(entry);
                     }
                 }
             }
+            
             // get bookmarks in folder
             Criteria bookmarksQuery = session
-                            .createCriteria(BookmarkData.class);
+                    .createCriteria(BookmarkData.class);
             bookmarksQuery.add(Expression.eq("folder", folder));
             Iterator bookmarkIter = bookmarksQuery.list().iterator();
-            while (bookmarkIter.hasNext())
-            {
+            while (bookmarkIter.hasNext()) {
                 BookmarkData bookmark = (BookmarkData) bookmarkIter.next();
                 bookmarks.add(bookmark);
             }
             return bookmarks;
-        }
-        catch (HibernateException e)
-        {
+        } catch (HibernateException e) {
             throw new RollerException(e);
         }
     }
-
-    public FolderData getRootFolder(WebsiteData website) throws RollerException
-    {
+    
+    public FolderData getRootFolder(WebsiteData website) throws RollerException {
         if (website == null)
             throw new RollerException("website is null");
-        try
-        {
-            Session session = ((HibernateStrategy) mStrategy).getSession();
+        try {
+            Session session = ((HibernatePersistenceStrategy) strategy).getSession();
             Criteria criteria = session.createCriteria(FolderAssoc.class);
             criteria.createAlias("folder", "f");
             criteria.add(Expression.eq("f.website", website));
             criteria.add(Expression.isNull("ancestorFolder"));
             criteria.add(Expression.eq("relation", FolderAssoc.PARENT));
             List results = criteria.list();
-            if (results.size() > 1)
-            {
+            if (results.size() > 1) {
                 // Should not have more than one root
                 throw new RollerException(
-                                "More than one root folder found for website "
-                                                + website.getId());
-            }
-            else if (results.size() == 1)
-            {
+                        "More than one root folder found for website "
+                        + website.getId());
+            } else if (results.size() == 1) {
                 // Return root
                 return ((FolderAssoc) results.get(0)).getFolder();
             }
             return null;
-        }
-        catch (HibernateException e)
-        {
+        } catch (HibernateException e) {
             throw new RollerException(e);
         }
     }
-
-    public List getAllFolders(WebsiteData website) throws RollerException
-    {
+    
+    public List getAllFolders(WebsiteData website) throws RollerException {
         if (website == null)
             throw new RollerException("Website is null");
         
-        try
-        {
-            Session session = ((HibernateStrategy) mStrategy).getSession();
+        try {
+            Session session = ((HibernatePersistenceStrategy) strategy).getSession();
             Criteria criteria = session.createCriteria(FolderData.class);
-            criteria.add(Expression.eq("website", website));            
+            criteria.add(Expression.eq("website", website));
             return criteria.list();
-        }
-        catch (HibernateException e)
-        {
+        } catch (HibernateException e) {
             throw new RollerException(e);
         }
-
+        
     }
-
-    /** 
+    
+    /**
      * @see org.roller.model.BookmarkManager#isDuplicateFolderName(org.roller.pojos.FolderData)
      */
-    public boolean isDuplicateFolderName(FolderData folder) throws RollerException
-    {
+    public boolean isDuplicateFolderName(FolderData folder) throws RollerException {
         // ensure that no sibling folders share the same name
         boolean isNewFolder = (folder.getId() == null);
         FolderData parent =
-            isNewFolder ? (FolderData)folder.getNewParent() : folder.getParent();
+                isNewFolder ? (FolderData)folder.getNewParent() : folder.getParent();
         
-        if (null != parent)
-        {
+        if (null != parent) {
             List sameNames;
-            try
-            {
-                Session session = ((HibernateStrategy) mStrategy).getSession();
+            try {
+                Session session = ((HibernatePersistenceStrategy) strategy).getSession();
                 Criteria criteria = session.createCriteria(FolderAssoc.class);
                 criteria.createAlias("folder", "f");
                 criteria.add(Expression.eq("f.name", folder.getName()));
                 criteria.add(Expression.eq("ancestorFolder", parent));
                 criteria.add(Expression.eq("relation", Assoc.PARENT));
                 sameNames = criteria.list();
-            }
-            catch (HibernateException e)
-            {
+            } catch (HibernateException e) {
                 throw new RollerException(e);
             }
             // If we got some matches
-            if (sameNames.size() > 0)
-            {
+            if (sameNames.size() > 0) {
                 // if we're saving a new folder, any matches are dups
                 if (isNewFolder) return true;
                 // otherwise it's a dup it isn't the same one (one match with the same id).
@@ -184,143 +413,115 @@
         }
         return false;
     }
-
-    /** 
+    
+    /**
      * @see org.roller.model.BookmarkManager#getFolderParentAssoc(
      * org.roller.pojos.FolderData)
      */
-    public Assoc getFolderParentAssoc(FolderData folder) throws RollerException
-    {
-        try
-        {
-            Session session = ((HibernateStrategy)mStrategy).getSession();
+    public Assoc getFolderParentAssoc(FolderData folder) throws RollerException {
+        try {
+            Session session = ((HibernatePersistenceStrategy)strategy).getSession();
             Criteria criteria = session.createCriteria(FolderAssoc.class);
             criteria.add(Expression.eq("folder", folder));
             criteria.add(Expression.eq("relation", Assoc.PARENT));
             List parents = criteria.list();
-            if (parents.size() > 1)
-            {
+            if (parents.size() > 1) {
                 throw new RollerException("ERROR: more than one parent");
-            }
-            else if (parents.size() == 1)
-            {
+            } else if (parents.size() == 1) {
                 return (Assoc) parents.get(0);
-            }
-            else
-            {
+            } else {
                 return null;
             }
-        }
-        catch (HibernateException e)
-        {
+        } catch (HibernateException e) {
             throw new RollerException(e);
         }
     }
-
-    /** 
+    
+    /**
      * @see org.roller.model.BookmarkManager#getFolderChildAssocs(
      * org.roller.pojos.FolderData)
      */
-    public List getFolderChildAssocs(FolderData folder) throws RollerException
-    {
-        try
-        {
-            Session session = ((HibernateStrategy)mStrategy).getSession();
+    public List getFolderChildAssocs(FolderData folder) throws RollerException {
+        try {
+            Session session = ((HibernatePersistenceStrategy)strategy).getSession();
             Criteria criteria = session.createCriteria(FolderAssoc.class);
             criteria.add(Expression.eq("ancestorFolder", folder));
             criteria.add(Expression.eq("relation", Assoc.PARENT));
             return criteria.list();
-        }
-        catch (HibernateException e)
-        {
+        } catch (HibernateException e) {
             throw new RollerException(e);
         }
     }
-
-    /** 
+    
+    /**
      * @see org.roller.model.BookmarkManager#getAllFolderDecscendentAssocs(
      * org.roller.pojos.FolderData)
      */
-    public List getAllFolderDecscendentAssocs(FolderData folder) throws RollerException
-    {
-        try
-        {
-            Session session = ((HibernateStrategy)mStrategy).getSession();
+    public List getAllFolderDecscendentAssocs(FolderData folder) throws RollerException {
+        try {
+            Session session = ((HibernatePersistenceStrategy)strategy).getSession();
             Criteria criteria = session.createCriteria(FolderAssoc.class);
             criteria.add(Expression.eq("ancestorFolder", folder));
             return criteria.list();
-        }
-        catch (HibernateException e)
-        {
+        } catch (HibernateException e) {
             throw new RollerException(e);
         }
     }
-
-    /** 
+    
+    /**
      * @see org.roller.model.BookmarkManager#getFolderAncestorAssocs(
      * org.roller.pojos.FolderData)
      */
-    public List getFolderAncestorAssocs(FolderData folder) throws RollerException
-    {
-        try
-        {
-            Session session = ((HibernateStrategy)mStrategy).getSession();
+    public List getFolderAncestorAssocs(FolderData folder) throws RollerException {
+        try {
+            Session session = ((HibernatePersistenceStrategy)strategy).getSession();
             Criteria criteria = session.createCriteria(FolderAssoc.class);
             criteria.add(Expression.eq("folder", folder));
             return criteria.list();
-        }
-        catch (HibernateException e)
-        {
+        } catch (HibernateException e) {
             throw new RollerException(e);
         }
     }
-
+    
     /**
      * @see org.roller.model.BookmarkManager#isFolderInUse(org.roller.pojos.FolderData)
      */
-    public boolean isFolderInUse(FolderData folder) throws RollerException
-    {
-        try
-        {
+    public boolean isFolderInUse(FolderData folder) throws RollerException {
+        try {
             // We consider a folder to be "in use" if it contains any bookmarks or has
             // any children.
-
+            
             // We first determine the number of bookmark entries.
             // NOTE: This seems to be an attempt to optimize, rather than just use getBookmarks(),
             // but I'm not sure that this optimization is really worthwhile, and it ignores
             // caching in the case that the (lazy) getBookmarks has been done already. --agangolli
             // TODO: condider changing to just use getBookmarks().size()
-            Session session = ((HibernateStrategy)mStrategy).getSession();
+            
+            Session session = ((HibernatePersistenceStrategy)strategy).getSession();
             Criteria criteria = session.createCriteria(BookmarkData.class);
             criteria.add(Expression.eq("folder", folder));
             criteria.setMaxResults(1);
             int entryCount = criteria.list().size();
-
+            
             // Return true if we have bookmarks or (, failing that, then checking) if we have children
             return (entryCount > 0 || folder.getFolders().size() > 0);
-        }
-        catch (HibernateException e)
-        {
+        } catch (HibernateException e) {
             throw new RollerException(e);
         }
     }
-
+    
     public boolean isDescendentOf(FolderData child, FolderData ancestor)
-        throws RollerException
-    {
+    throws RollerException {
         boolean ret = false;
-        try
-        {
-            Session session = ((HibernateStrategy)mStrategy).getSession();
+        try {
+            Session session = ((HibernatePersistenceStrategy)strategy).getSession();
             Criteria criteria = session.createCriteria(FolderAssoc.class);
             criteria.add(Expression.eq("folder", child));
             criteria.add(Expression.eq("ancestorFolder", ancestor));
             ret = criteria.list().size() > 0;
-        }
-        catch (HibernateException e)
-        {
-            throw new RollerException(e);        
+        } catch (HibernateException e) {
+            throw new RollerException(e);
         }
         return ret;
-    }    
+    }
 }

Modified: incubator/roller/trunk/src/org/roller/business/hibernate/HibernateConfigManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/hibernate/HibernateConfigManagerImpl.java?rev=395393&r1=395392&r2=395393&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/hibernate/HibernateConfigManagerImpl.java (original)
+++ incubator/roller/trunk/src/org/roller/business/hibernate/HibernateConfigManagerImpl.java Wed Apr 19 13:53:01 2006
@@ -6,62 +6,85 @@
 import org.hibernate.Criteria;
 import org.hibernate.HibernateException;
 import org.hibernate.Session;
-
 import org.roller.RollerException;
-import org.roller.business.ConfigManagerImpl;
-import org.roller.business.PersistenceStrategy;
 import org.roller.pojos.RollerConfigData;
-
 import java.util.List;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.roller.model.ConfigManager;
+
 
 /**
- * @author David M Johnson
+ * The *OLD* Roller configuration mechanism.
+ *
+ * This has been replaced by the PropertiesManager and the roller.properties
+ * file.
  */
-public class HibernateConfigManagerImpl extends ConfigManagerImpl
-{
+public class HibernateConfigManagerImpl implements ConfigManager {
+    
     static final long serialVersionUID = -3674252864091781177L;
     
-    private static Log mLogger =
-        LogFactory.getFactory().getInstance(HibernateConfigManagerImpl.class);
+    private static Log log = LogFactory.getLog(HibernateConfigManagerImpl.class);
+    
+    private HibernatePersistenceStrategy strategy = null;
+    
+    
+    public HibernateConfigManagerImpl(HibernatePersistenceStrategy strategy) {
+        log.debug("Instantiating Hibernate Config Manager");
+        
+        this.strategy = strategy;
+    }
+    
     
     /**
-     * @param strategy
-     * @param roller
+     * @see org.roller.model.ConfigManager#storeRollerConfig(org.roller.pojos.RollerConfig)
      */
-    public HibernateConfigManagerImpl(PersistenceStrategy strategy)
-    {
-        super(strategy);
-        mLogger.debug("Instantiating Config Manager");
+    public void storeRollerConfig(RollerConfigData data) throws RollerException {
+        // no longer supported
     }
-
+    
+    
+    /**
+     * This isn't part of the ConfigManager Interface, because really
+     * we shouldn't ever delete the RollerConfig.  This is mostly here
+     * to assist with unit testing.
+     */
+    public void removeRollerConfig(String id) throws RollerException {
+        // no longer supported
+    }
+    
+    
     /**
      * Fetch all RollerConfigs and return the first one, if any.
      * Note: there should only be one!
      * @see org.roller.model.ConfigManager#getRollerConfig()
      */
-    public RollerConfigData getRollerConfig() throws RollerException
-    {
-        mLogger.error("Someone is trying to use the old config!!\n"+
+    public RollerConfigData getRollerConfig() throws RollerException {
+        
+        log.error("Someone is trying to use the old config!!\n"+
                 "This configuration mechanism has been deprecated\n"+
                 "You should see this message only once when you first upgrade\n"+
                 "your installation to roller 1.2\n\n"+
                 "If you continue to see this message please shoot us an email\n"+
-                "at roller-development@lists.sourceforge.net with some output\n"+
+                "at roller-dev@incubator.apache.org with some output\n"+
                 "from your log files.\n");
-        try
-        {
-            Session session = ((HibernateStrategy)mStrategy).getSession();
+        
+        try {
+            Session session = this.strategy.getSession();
             Criteria criteria = session.createCriteria(RollerConfigData.class);
             criteria.setMaxResults(1);
-            List list = criteria.list();
-            return list.size()!=0 ? (RollerConfigData)list.get(0) : null;
-        }
-        catch (HibernateException e)
-        {
+            return (RollerConfigData) criteria.uniqueResult();
+        } catch (HibernateException e) {
             throw new RollerException(e);
         }
     }
-
+    
+    
+    public RollerConfigData readFromFile(String file) {
+        return null;
+    }
+    
+    
+    public void release() {}
+    
 }

Modified: incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePingQueueManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePingQueueManagerImpl.java?rev=395393&r1=395392&r2=395393&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePingQueueManagerImpl.java (original)
+++ incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePingQueueManagerImpl.java Wed Apr 19 13:53:01 2006
@@ -16,123 +16,90 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.roller.RollerException;
-import org.roller.business.PersistenceStrategy;
-import org.roller.business.PingQueueManagerImpl;
 import org.roller.pojos.AutoPingData;
 import org.roller.pojos.PingQueueEntryData;
-import org.roller.pojos.WebsiteData;
-import org.roller.pojos.PingTargetData;
-
 import java.sql.Timestamp;
-import java.util.Iterator;
 import java.util.List;
-import java.util.Collection;
-
-public class HibernatePingQueueManagerImpl extends PingQueueManagerImpl
-{
-    static final long serialVersionUID = -7660638707453106615L;
+import org.roller.model.PingQueueManager;
 
-    private static Log logger = LogFactory.getLog(HibernatePingQueueManagerImpl.class);
-
-    public HibernatePingQueueManagerImpl(PersistenceStrategy persistenceStrategy)
-    {
-        super(persistenceStrategy);
-    }
-
-    public void addQueueEntry(AutoPingData autoPing) throws RollerException
-    {
-        if (logger.isDebugEnabled()) logger.debug("Creating new ping queue entry for auto ping configuration: " + autoPing);
 
+/**
+ * Hibernate implementation of the PingQueueManager.
+ */
+public class HibernatePingQueueManagerImpl implements PingQueueManager {
+    
+    static final long serialVersionUID = -7660638707453106615L;
+    
+    private static Log log = LogFactory.getLog(HibernatePingQueueManagerImpl.class);
+    
+    private HibernatePersistenceStrategy strategy = null;
+    
+    
+    public HibernatePingQueueManagerImpl(HibernatePersistenceStrategy strat) {
+        this.strategy = strat;
+    }
+    
+    
+    public PingQueueEntryData getQueueEntry(String id) throws RollerException {
+        return (PingQueueEntryData) strategy.load(id, PingQueueEntryData.class);
+    }
+    
+    
+    public void saveQueueEntry(PingQueueEntryData pingQueueEntry) throws RollerException {
+        log.debug("Storing ping queue entry: " + pingQueueEntry);
+        strategy.store(pingQueueEntry);
+    }
+    
+    
+    public void removeQueueEntry(PingQueueEntryData pingQueueEntry) throws RollerException {
+        log.debug("Removing ping queue entry: " + pingQueueEntry);
+        strategy.remove(pingQueueEntry);
+    }
+    
+    
+    public void addQueueEntry(AutoPingData autoPing) throws RollerException {
+        log.debug("Creating new ping queue entry for auto ping configuration: " + autoPing);
+        
         // First check if there is an existing ping queue entry for the same target and website
-        if (isAlreadyQueued(autoPing))
-        {
-            if (logger.isDebugEnabled()) logger.debug("A ping queue entry is already present for this ping target and website: " + autoPing);
+        if (isAlreadyQueued(autoPing)) {
+            log.debug("A ping queue entry is already present for this ping target and website: " + autoPing);
             return;
         }
-
+        
         Timestamp now = new Timestamp(System.currentTimeMillis());
         PingQueueEntryData pingQueueEntry =
-            new PingQueueEntryData(null, now, autoPing.getPingTarget(), autoPing.getWebsite(), 0);
-        storeQueueEntry(pingQueueEntry);
-    }
-
-    public void dropQueue() throws RollerException
-    {
-        logger.info("NOTICE Dropping all ping queue entries.");
-        List queueEntries = getAllQueueEntries();
-        removeEntries(queueEntries);
+                new PingQueueEntryData(null, now, autoPing.getPingTarget(), autoPing.getWebsite(), 0);
+        this.saveQueueEntry(pingQueueEntry);
     }
-
-    public List getAllQueueEntries() throws RollerException
-    {
-        Session session = ((HibernateStrategy) persistenceStrategy).getSession();
-        Criteria criteria = session.createCriteria(PingQueueEntryData.class);
-        criteria.addOrder(Order.asc("entryTime"));
-        try
-        {
+    
+    
+    public List getAllQueueEntries() throws RollerException {
+        try {
+            Session session = ((HibernatePersistenceStrategy) strategy).getSession();
+            Criteria criteria = session.createCriteria(PingQueueEntryData.class);
+            criteria.addOrder(Order.asc("entryTime"));
+            
             return criteria.list();
-        }
-        catch (HibernateException e)
-        {
+        } catch (HibernateException e) {
             throw new RollerException("ERROR retrieving queue entries.", e);
         }
     }
-
-    public void removeQueueEntriesByPingTarget(PingTargetData pingTarget) throws RollerException {
-        try
-        {
-            if (logger.isDebugEnabled()) logger.debug("Removing all ping queue entries for ping target " + pingTarget);
-            Session session = ((HibernateStrategy) persistenceStrategy).getSession();
-            Criteria criteria = session.createCriteria(PingQueueEntryData.class);
-            criteria.add(Expression.eq("pingTarget", pingTarget));
-            List queueEntries = criteria.list();
-            removeEntries(queueEntries);
-        }
-        catch (HibernateException e)
-        {
-            throw new RollerException("ERROR removing queue entries for ping target " + pingTarget, e);
-        }
-    }
-
-    public void removeQueueEntriesByWebsite(WebsiteData website) throws RollerException {
-        try
-        {
-            if (logger.isDebugEnabled()) logger.debug("Removing all ping queue entries for website " + website);
-            Session session = ((HibernateStrategy) persistenceStrategy).getSession();
-            Criteria criteria = session.createCriteria(PingQueueEntryData.class);
-            criteria.add(Expression.eq("website", website));
-            List queueEntries = criteria.list();
-            removeEntries(queueEntries);
-        }
-        catch (HibernateException e)
-        {
-            throw new RollerException("ERROR removing queue entries for website " + website, e);
-        }
-    }
-
+    
+    
     // private helper to determine if an has already been queued for the same website and ping target.
-    private boolean isAlreadyQueued(AutoPingData autoPing) throws RollerException
-    {
-        try
-        {
-            Session session = ((HibernateStrategy) persistenceStrategy).getSession();
+    private boolean isAlreadyQueued(AutoPingData autoPing) throws RollerException {
+        try {
+            Session session = ((HibernatePersistenceStrategy) strategy).getSession();
             Criteria criteria = session.createCriteria(PingQueueEntryData.class);
             criteria.add(Expression.eq("pingTarget", autoPing.getPingTarget()));
             criteria.add(Expression.eq("website", autoPing.getWebsite()));
             return !criteria.list().isEmpty();
-        }
-        catch (HibernateException e)
-        {
+        } catch (HibernateException e) {
             throw new RollerException("ERROR determining if preexisting queue entry is present.",e);
         }
     }
-
-    // Private helper to remove a collection of queue entries
-    private void removeEntries(Collection queueEntries) throws RollerException {
-        for (Iterator i = queueEntries.iterator(); i.hasNext();)
-        {
-            PingQueueEntryData pqe = (PingQueueEntryData) i.next();
-            pqe.remove();
-        }
-    }
+    
+    
+    public void release() {}
+    
 }

Modified: incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePingTargetManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePingTargetManagerImpl.java?rev=395393&r1=395392&r2=395393&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePingTargetManagerImpl.java (original)
+++ incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePingTargetManagerImpl.java Wed Apr 19 13:53:01 2006
@@ -8,106 +8,218 @@
 
 package org.roller.business.hibernate;
 
+import java.net.InetAddress;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.UnknownHostException;
 import org.hibernate.Criteria;
 import org.hibernate.HibernateException;
 import org.hibernate.Session;
 import org.hibernate.criterion.Expression;
 import org.hibernate.criterion.Order;
 import org.roller.RollerException;
-import org.roller.business.PersistenceStrategy;
-import org.roller.business.PingTargetManagerImpl;
 import org.roller.pojos.PingTargetData;
 import org.roller.pojos.WebsiteData;
-
 import java.util.Iterator;
 import java.util.List;
 import java.util.Collection;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.roller.model.AutoPingManager;
+import org.roller.model.PingTargetManager;
+import org.roller.model.RollerFactory;
+import org.roller.pojos.AutoPingData;
+import org.roller.pojos.PingQueueEntryData;
 
-public class HibernatePingTargetManagerImpl extends PingTargetManagerImpl
-{
-    static final long serialVersionUID = 121008492583382718L;
 
-    public HibernatePingTargetManagerImpl(PersistenceStrategy persistenceStrategy)
-    {
-        super(persistenceStrategy);
+/**
+ * Hibernate implementation of the PingTargetManager.
+ */
+public class HibernatePingTargetManagerImpl implements PingTargetManager {
+    
+    static final long serialVersionUID = 121008492583382718L;
+    
+    private static Log log = LogFactory.getLog(HibernatePingTargetManagerImpl.class);
+    
+    private HibernatePersistenceStrategy strategy = null;
+    
+    
+    public HibernatePingTargetManagerImpl(HibernatePersistenceStrategy strat) {
+        this.strategy = strat;
+    }
+    
+    
+    public void removePingTarget(String id) throws RollerException {
+        
+        PingTargetData pingTarget = getPingTarget(id);
+        
+        // remove contents and then target
+        this.removePingTargetContents(pingTarget);
+        strategy.remove(pingTarget);
+    }
+    
+    
+    public void removePingTarget(PingTargetData pingTarget) throws RollerException {
+        this.strategy.remove(pingTarget);
     }
-
+    
+    
     /**
-     * @see org.roller.model.PingTargetManager#getCommonPingTargets()
+     * Convenience method which removes any queued pings or auto pings that
+     * reference the given ping target.
      */
-    public List getCommonPingTargets() throws RollerException
-    {
-        try
-        {
-            Session session = ((HibernateStrategy) persistenceStrategy).getSession();
-            Criteria criteria = session.createCriteria(PingTargetData.class);
-            criteria.add(Expression.isNull("website"));
-            criteria.addOrder(Order.asc("name"));
-            return criteria.list();
+    private void removePingTargetContents(PingTargetData ping) 
+            throws RollerException {
+        
+        Session session = this.strategy.getSession();
+        
+        // Remove the website's ping queue entries
+        Criteria criteria = session.createCriteria(PingQueueEntryData.class);
+        criteria.add(Expression.eq("pingTarget", ping));
+        List queueEntries = criteria.list();
+        
+        // Remove the website's auto ping configurations
+        AutoPingManager autoPingMgr = RollerFactory.getRoller().getAutopingManager();
+        List autopings = autoPingMgr.getAutoPingsByTarget(ping);
+        Iterator it = autopings.iterator();
+        while(it.hasNext()) {
+            this.strategy.remove((AutoPingData) it.next());
         }
-        catch (HibernateException e)
-        {
+    }
+    
+    
+    /**
+     * @see org.roller.model.PingTargetManager#removeAllCustomPingTargets()
+     */
+    public void removeAllCustomPingTargets() throws RollerException {
+        
+        try {
+            Session session = strategy.getSession();
+            Criteria criteria = session.createCriteria(PingTargetData.class);
+            criteria.add(Expression.isNotNull("website"));
+            List allCustomTargets = criteria.list();
+            removeTargets(allCustomTargets);
+        } catch (HibernateException e) {
             throw new RollerException(e);
         }
-
     }
-
+    
+    
+    // Private helper to remove a collection of targets.
+    private void removeTargets(Collection customTargets) throws RollerException {
+        
+        // just go through the list and remove each auto ping
+        Iterator targets = customTargets.iterator();
+        while (targets.hasNext()) {
+            this.strategy.remove((PingTargetData) targets.next());
+        }
+    }
+    
+    
+    public void savePingTarget(PingTargetData pingTarget) throws RollerException {
+        strategy.store(pingTarget);
+    }
+    
+    
+    public PingTargetData getPingTarget(String id) throws RollerException {
+        return (PingTargetData) strategy.load(id, PingTargetData.class);
+    }
+
+    
+    public boolean isNameUnique(PingTargetData pingTarget) throws RollerException {
+        String name = pingTarget.getName();
+        if (name == null || name.trim().length() == 0) return false;
+        
+        String id = pingTarget.getId();
+        
+        // Determine the set of "brother" targets (custom or common) among which this name should be unique.
+        List brotherTargets = null;
+        WebsiteData website = pingTarget.getWebsite();
+        if (website == null) {
+            brotherTargets = getCommonPingTargets();
+        } else {
+            brotherTargets = getCustomPingTargets(website);
+        }
+        
+        // Within that set of targets, fail if there is a target with the same name and that target doesn't
+        // have the same id.
+        for (Iterator i = brotherTargets.iterator(); i.hasNext();) {
+            PingTargetData brother = (PingTargetData) i.next();
+            // Fail if it has the same name but not the same id.
+            if (brother.getName().equals(name) && (id == null || !brother.getId().equals(id))) {
+                return false;
+            }
+        }
+        // No conflict found
+        return true;
+    }
+    
+    
+    public boolean isUrlWellFormed(PingTargetData pingTarget) throws RollerException {
+        String url = pingTarget.getPingUrl();
+        if (url == null || url.trim().length() == 0) return false;
+        try {
+            URL parsedUrl = new URL(url);
+            // OK.  If we get here, it parses ok.  Now just check that the protocol is http and there is a host portion.
+            boolean isHttp = parsedUrl.getProtocol().equals("http");
+            boolean hasHost = (parsedUrl.getHost() != null) && (parsedUrl.getHost().trim().length() > 0);
+            return isHttp && hasHost;
+        } catch (MalformedURLException e) {
+            return false;
+        }
+    }
+    
+    
+    public boolean isHostnameKnown(PingTargetData pingTarget) throws RollerException {
+        String url = pingTarget.getPingUrl();
+        if (url == null || url.trim().length() == 0) return false;
+        try {
+            URL parsedUrl = new URL(url);
+            String host = parsedUrl.getHost();
+            if (host == null || host.trim().length() == 0) return false;
+            InetAddress addr = InetAddress.getByName(host);
+            return true;
+        } catch (MalformedURLException e) {
+            return false;
+        } catch (UnknownHostException e) {
+            return false;
+        }
+    }
+    
+    
     /**
-     * @see org.roller.model.PingTargetManager#getCustomPingTargets(org.roller.pojos.WebsiteData)
+     * @see org.roller.model.PingTargetManager#getCommonPingTargets()
      */
-    public List getCustomPingTargets(WebsiteData website) throws RollerException
-    {
-        try
-        {
-            Session session = ((HibernateStrategy) persistenceStrategy).getSession();
+    public List getCommonPingTargets() throws RollerException {
+        try {
+            Session session = ((HibernatePersistenceStrategy) strategy).getSession();
             Criteria criteria = session.createCriteria(PingTargetData.class);
-            criteria.add(Expression.eq("website", website));
+            criteria.add(Expression.isNull("website"));
             criteria.addOrder(Order.asc("name"));
             return criteria.list();
-        }
-        catch (HibernateException e)
-        {
+        } catch (HibernateException e) {
             throw new RollerException(e);
         }
+        
     }
-
-    /**
-     * @see org.roller.model.PingTargetManager#removeCustomPingTargets(org.roller.pojos.WebsiteData) 
-     */
-    public void removeCustomPingTargets(WebsiteData website) throws RollerException
-    {
-        List customTargets = getCustomPingTargets(website);
-        removeTargets(customTargets);
-    }
-
+    
+    
     /**
-     * @see org.roller.model.PingTargetManager#removeAllCustomPingTargets()
+     * @see org.roller.model.PingTargetManager#getCustomPingTargets(org.roller.pojos.WebsiteData)
      */
-    public void removeAllCustomPingTargets() throws RollerException
-    {
-        try
-        {
-            Session session = ((HibernateStrategy) persistenceStrategy).getSession();
+    public List getCustomPingTargets(WebsiteData website) throws RollerException {
+        try {
+            Session session = ((HibernatePersistenceStrategy) strategy).getSession();
             Criteria criteria = session.createCriteria(PingTargetData.class);
-            criteria.add(Expression.isNotNull("website"));
-            List allCustomTargets = criteria.list();
-            removeTargets(allCustomTargets);
-        }
-        catch (HibernateException e)
-        {
+            criteria.add(Expression.eq("website", website));
+            criteria.addOrder(Order.asc("name"));
+            return criteria.list();
+        } catch (HibernateException e) {
             throw new RollerException(e);
         }
     }
-
-    // Private helper to remove a collection of targets.
-    private void removeTargets(Collection customTargets)
-        throws RollerException
-    {
-        for (Iterator i = customTargets.iterator(); i.hasNext();)
-        {
-            PingTargetData pt = (PingTargetData) i.next();
-            pt.remove();
-        }
-    }
-
+    
+    
+    public void release() {}
+    
 }

Modified: incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePlanetManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePlanetManagerImpl.java?rev=395393&r1=395392&r2=395393&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePlanetManagerImpl.java (original)
+++ incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePlanetManagerImpl.java Wed Apr 19 13:53:01 2006
@@ -16,10 +16,17 @@
 
 package org.roller.business.hibernate;
 
+import com.sun.syndication.feed.synd.SyndEntry;
+import com.sun.syndication.feed.synd.SyndFeed;
 import com.sun.syndication.fetcher.FeedFetcher;
 import com.sun.syndication.fetcher.impl.FeedFetcherCache;
+import com.sun.syndication.fetcher.impl.HttpURLFeedFetcher;
+import com.sun.syndication.fetcher.impl.SyndFeedInfo;
+import java.io.File;
+import java.net.URL;
 import java.text.MessageFormat;
 import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -27,83 +34,103 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
-
 import org.hibernate.Criteria;
 import org.hibernate.HibernateException;
 import org.hibernate.Query;
 import org.hibernate.Session;
 import org.hibernate.criterion.Expression;
 import org.hibernate.criterion.Order;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.velocity.VelocityContext;
 import org.roller.RollerException;
-import org.roller.business.PersistenceStrategy;
-import org.roller.business.PlanetManagerImpl;
 import org.roller.config.RollerConfig;
 import org.roller.config.RollerRuntimeConfig;
-import org.roller.model.PagePluginManager;
+import org.roller.model.PlanetManager;
 import org.roller.model.Roller;
-import org.roller.model.UserManager;
-import org.roller.model.WeblogManager;
+import org.roller.model.RollerFactory;
 import org.roller.pojos.PlanetConfigData;
 import org.roller.pojos.PlanetEntryData;
 import org.roller.pojos.PlanetGroupData;
 import org.roller.pojos.PlanetGroupSubscriptionAssoc;
 import org.roller.pojos.PlanetSubscriptionData;
-import org.roller.pojos.WeblogEntryData;
-import org.roller.pojos.WebsiteData;
+import org.roller.util.rome.DiskFeedInfoCache;
+
 
 /**
- * Manages Planet Roller objects and entry aggregations in a database.
- * @author Dave Johnson
+ * Hibernate implementation of the PlanetManager.
  */
-public class HibernatePlanetManagerImpl extends PlanetManagerImpl {
-    protected Map lastUpdatedByGroup = new HashMap();
+public class HibernatePlanetManagerImpl implements PlanetManager {
+    
+    private static Log log = LogFactory.getLog(HibernatePlanetManagerImpl.class);
+    
     protected static final String NO_GROUP = "zzz_nogroup_zzz";
     
-    private static Log logger =
-            LogFactory.getFactory().getInstance(HibernatePlanetManagerImpl.class);
+    private HibernatePersistenceStrategy strategy = null;
+    private String localURL = null;
+    private Map lastUpdatedByGroup = new HashMap();
+    
     
-    public HibernatePlanetManagerImpl(
-            PersistenceStrategy strategy, Roller roller) {
-        super(strategy, roller);
+    public HibernatePlanetManagerImpl(HibernatePersistenceStrategy strat) {
+        
+        this.strategy = strat;
+        
+        // TODO: this is bad.  this property should be in the planet config.
+        localURL = RollerRuntimeConfig.getProperty("site.absoluteurl");
     }
     
-    public void saveConfiguration(PlanetConfigData config)
-    throws RollerException {
-        config.save();
+    
+    public void saveConfiguration(PlanetConfigData config) throws RollerException {
+        strategy.store(config);
     }
     
+    
     public void saveGroup(PlanetGroupData group) throws RollerException {
+        
+        // save each sub assoc first, then the group
         Iterator assocs = group.getGroupSubscriptionAssocs().iterator();
         while (assocs.hasNext()) {
             PlanetGroupSubscriptionAssoc assoc =
                     (PlanetGroupSubscriptionAssoc)assocs.next();
-            assoc.save();
+            strategy.store(assoc);
         }
-        group.save();
+        strategy.store(group);
     }
     
+    
     public void saveEntry(PlanetEntryData entry) throws RollerException {
-        entry.save();
+        strategy.store(entry);
     }
     
-    public void saveSubscription(PlanetSubscriptionData sub)
-    throws RollerException {
+    
+    public void saveSubscription(PlanetSubscriptionData sub) throws RollerException {
         PlanetSubscriptionData existing = getSubscription(sub.getFeedUrl());
         if (existing == null || (existing.getId().equals(sub.getId()))) {
-            sub.save();
+            this.strategy.store(sub);
         } else {
             throw new RollerException("ERROR: duplicate feed URLs not allowed");
         }
     }
     
+    
+    public void deleteEntry(PlanetEntryData entry) throws RollerException {
+        strategy.remove(entry);
+    }
+    
+    
+    public void deleteGroup(PlanetGroupData group) throws RollerException {
+        strategy.remove(group);
+    }
+    
+    
+    public void deleteSubscription(PlanetSubscriptionData sub) throws RollerException {
+        strategy.remove(sub);
+    }
+    
+    
     public PlanetConfigData getConfiguration() throws RollerException {
         PlanetConfigData config = null;
         try {
-            Session session = ((HibernateStrategy)strategy).getSession();
+            Session session = ((HibernatePersistenceStrategy)strategy).getSession();
             Criteria criteria = session.createCriteria(PlanetConfigData.class);
             criteria.setMaxResults(1);
             List list = criteria.list();
@@ -121,77 +148,145 @@
         return config;
     }
     
-    public List getGroups() throws RollerException {
+    
+    public PlanetSubscriptionData getSubscription(String feedUrl) throws RollerException {
         try {
-            Session session = ((HibernateStrategy)strategy).getSession();
-            Criteria criteria = session.createCriteria(PlanetGroupData.class);
-            return criteria.list();
+            Session session = ((HibernatePersistenceStrategy)strategy).getSession();
+            Criteria criteria =
+                    session.createCriteria(PlanetSubscriptionData.class);
+            criteria.setMaxResults(1);
+            criteria.add(Expression.eq("feedUrl", feedUrl));
+            List list = criteria.list();
+            return list.size()!=0 ? (PlanetSubscriptionData)list.get(0) : null;
         } catch (HibernateException e) {
             throw new RollerException(e);
         }
     }
     
-    public List getGroupHandles() throws RollerException {
-        List handles = new ArrayList();
-        Iterator list = getGroups().iterator();
-        while (list.hasNext()) {
-            PlanetGroupData group = (PlanetGroupData)list.next();
-            handles.add(group.getHandle());
-        }
-        return handles;
+    
+    public PlanetSubscriptionData getSubscriptionById(String id) throws RollerException {
+        return (PlanetSubscriptionData) strategy.load(id, PlanetSubscriptionData.class);
     }
     
-    public PlanetSubscriptionData getSubscription(String feedUrl)
-    throws RollerException {
+    
+    public Iterator getAllSubscriptions() {
         try {
-            Session session = ((HibernateStrategy)strategy).getSession();
+            Session session = ((HibernatePersistenceStrategy)strategy).getSession();
             Criteria criteria =
                     session.createCriteria(PlanetSubscriptionData.class);
-            criteria.setMaxResults(1);
-            criteria.add(Expression.eq("feedUrl", feedUrl));
+            criteria.addOrder(Order.asc("feedUrl"));
             List list = criteria.list();
-            return list.size()!=0 ? (PlanetSubscriptionData)list.get(0) : null;
+            return list.iterator();
+        } catch (Throwable e) {
+            throw new RuntimeException(
+                    "ERROR fetching subscription collection", e);
+        }
+    }
+    
+    public int getSubscriptionCount() throws RollerException {
+        try {
+            Session session = ((HibernatePersistenceStrategy)strategy).getSession();
+            Integer count = (Integer)session.createQuery(
+                    "select count(*) from org.roller.pojos.PlanetSubscriptionData").uniqueResult();
+            return count.intValue();
+        } catch (Throwable e) {
+            throw new RuntimeException(
+                    "ERROR fetching subscription count", e);
+        }
+    }
+    
+    public synchronized List getTopSubscriptions(int max) throws RollerException {
+        String groupHandle = NO_GROUP;
+        List ret = null;
+        try {
+            Session session = ((HibernatePersistenceStrategy)strategy).getSession();
+            Criteria criteria =
+                    session.createCriteria(PlanetSubscriptionData.class);
+            criteria.setMaxResults(max);
+            criteria.addOrder(Order.desc("inboundblogs"));
+            ret = criteria.list();
         } catch (HibernateException e) {
             throw new RollerException(e);
         }
+        return ret;
     }
     
-    public PlanetSubscriptionData getSubscriptionById(String id)
-    throws RollerException {
-        return (PlanetSubscriptionData)
-        strategy.load(id, PlanetSubscriptionData.class);
+    public synchronized List getTopSubscriptions(
+            PlanetGroupData group, int max) throws RollerException {
+        String groupHandle = (group == null) ? NO_GROUP : group.getHandle();
+        List ret = null;
+        try {
+            Session session = ((HibernatePersistenceStrategy)strategy).getSession();
+            Query query = session.createQuery(
+                    "select sub from org.roller.pojos.PlanetSubscriptionData sub "
+                    +"join sub.groupSubscriptionAssocs assoc "
+                    +"where "
+                    +"assoc.group.handle=:groupHandle "
+                    +"order by sub.inboundblogs desc");
+            query.setString("groupHandle", group.getHandle());
+            query.setMaxResults(max);
+            ret = query.list();
+        } catch (HibernateException e) {
+            throw new RollerException(e);
+        }
+        return ret;
     }
     
+    
     public PlanetGroupData getGroup(String handle) throws RollerException {
         try {
-            Session session = ((HibernateStrategy)strategy).getSession();
+            Session session = strategy.getSession();
             Criteria criteria = session.createCriteria(PlanetGroupData.class);
             criteria.setMaxResults(1);
             criteria.add(Expression.eq("handle", handle));
-            List list = criteria.list();
-            return list.size()!=0 ? (PlanetGroupData)list.get(0) : null;
+            return (PlanetGroupData) criteria.uniqueResult();
         } catch (HibernateException e) {
             throw new RollerException(e);
         }
     }
     
     public PlanetGroupData getGroupById(String id) throws RollerException {
-        return (PlanetGroupData)
-        strategy.load(id, PlanetGroupData.class);
+        return (PlanetGroupData) strategy.load(id, PlanetGroupData.class);
+    }
+    
+    
+    public List getGroups() throws RollerException {
+        try {
+            Session session = ((HibernatePersistenceStrategy)strategy).getSession();
+            Criteria criteria = session.createCriteria(PlanetGroupData.class);
+            return criteria.list();
+        } catch (HibernateException e) {
+            throw new RollerException(e);
+        }
+    }
+    
+    
+    public List getGroupHandles() throws RollerException {
+        List handles = new ArrayList();
+        Iterator list = getGroups().iterator();
+        while (list.hasNext()) {
+            PlanetGroupData group = (PlanetGroupData)list.next();
+            handles.add(group.getHandle());
+        }
+        return handles;
     }
     
+    
     public synchronized List getAggregation(int maxEntries) throws RollerException {
         return getAggregation(null, maxEntries);
     }
     
+    
     public synchronized List getAggregation(PlanetGroupData group, int maxEntries)
-    throws RollerException {
+            throws RollerException {
+        
         List ret = null;
         try {
             String groupHandle = (group == null) ? NO_GROUP : group.getHandle();
             long startTime = System.currentTimeMillis();
             Session session =
-                    ((HibernateStrategy)strategy).getSession();
+                    ((HibernatePersistenceStrategy)strategy).getSession();
+            
             if (group != null) {
                 Query query = session.createQuery(
                         "select entry from org.roller.pojos.PlanetEntryData entry "
@@ -220,180 +315,219 @@
             lastUpdatedByGroup.put(groupHandle, retLastUpdated);
             
             long endTime = System.currentTimeMillis();
-            logger.info("Generated aggregation in "
+            log.info("Generated aggregation in "
                     +((endTime-startTime)/1000.0)+" seconds");
         } catch (Throwable e) {
-            logger.error("ERROR: building aggregation for: "+group, e);
+            log.error("ERROR: building aggregation for: "+group, e);
             throw new RollerException(e);
         }
         return ret;
     }
     
-    public void deleteEntry(PlanetEntryData entry) throws RollerException {
-        entry.remove();
-    }
     
-    public void deleteGroup(PlanetGroupData group) throws RollerException {
-        group.remove();
+    public synchronized void clearCachedAggregations() {
+        lastUpdatedByGroup.clear();
     }
     
-    public void deleteSubscription(PlanetSubscriptionData sub)
-    throws RollerException {
-        sub.remove();
+    public Date getLastUpdated() {
+        return (Date)lastUpdatedByGroup.get(NO_GROUP);
     }
     
-    public Iterator getAllSubscriptions() {
-        try {
-            Session session = ((HibernateStrategy)strategy).getSession();
-            Criteria criteria =
-                    session.createCriteria(PlanetSubscriptionData.class);
-            criteria.addOrder(Order.asc("feedUrl"));
-            List list = criteria.list();
-            return list.iterator();
-        } catch (Throwable e) {
-            throw new RuntimeException(
-                    "ERROR fetching subscription collection", e);
-        }
+    public Date getLastUpdated(PlanetGroupData group) {
+        return (Date)lastUpdatedByGroup.get(group);
     }
     
-    public int getSubscriptionCount() throws RollerException {
-        try {
-            Session session = ((HibernateStrategy)strategy).getSession();
-            Integer count = (Integer)session.createQuery(
-                    "select count(*) from org.roller.pojos.PlanetSubscriptionData").uniqueResult();
-            return count.intValue();
-        } catch (Throwable e) {
-            throw new RuntimeException(
-                    "ERROR fetching subscription count", e);
-        }
-    }
     
-    public synchronized List getTopSubscriptions(int max) throws RollerException {
-        String groupHandle = NO_GROUP;
-        List ret = null;
-        try {
-            Session session = ((HibernateStrategy)strategy).getSession();
-            Criteria criteria =
-                    session.createCriteria(PlanetSubscriptionData.class);
-            criteria.setMaxResults(max);
-            criteria.addOrder(Order.desc("inboundblogs"));
-            ret = criteria.list();
-        } catch (HibernateException e) {
-            throw new RollerException(e);
+    public void refreshEntries() throws RollerException {
+        
+        Roller roller = RollerFactory.getRoller();
+        
+        Date now = new Date();
+        long startTime = System.currentTimeMillis();
+        PlanetConfigData config = getConfiguration();
+        
+        // can't continue without cache dir
+        if (config == null || config.getCacheDir() == null) {
+            log.warn("Planet cache directory not set, aborting refresh");
+            return;
         }
-        return ret;
-    }
-    
-    public synchronized List getTopSubscriptions(
-            PlanetGroupData group, int max) throws RollerException {
-        String groupHandle = (group == null) ? NO_GROUP : group.getHandle();
-        List ret = null;
+        
+        // allow ${user.home} in cache dir property
+        String cacheDirName = config.getCacheDir().replaceFirst(
+                "\\$\\{user.home}",System.getProperty("user.home"));
+        
+        // allow ${catalina.home} in cache dir property
+        cacheDirName = cacheDirName.replaceFirst(
+                "\\$\\{catalina.home}",System.getProperty("catalina.home"));
+        
+        // create cache  dir if it does not exist
+        File cacheDir = null;
         try {
-            Session session = ((HibernateStrategy)strategy).getSession();
-            Query query = session.createQuery(
-                    "select sub from org.roller.pojos.PlanetSubscriptionData sub "
-                    +"join sub.groupSubscriptionAssocs assoc "
-                    +"where "
-                    +"assoc.group.handle=:groupHandle "
-                    +"order by sub.inboundblogs desc");
-            query.setString("groupHandle", group.getHandle());
-            query.setMaxResults(max);
-            ret = query.list();
-        } catch (HibernateException e) {
-            throw new RollerException(e);
+            cacheDir = new File(cacheDirName);
+            if (!cacheDir.exists()) cacheDir.mkdirs();
+        } catch (Exception e) {
+            log.error("Unable to create planet cache directory");
+            return;
         }
-        return ret;
-    }
-    
-    public synchronized void clearCachedAggregations() {
-        lastUpdatedByGroup.clear();
-    }
-    
-    public Date getLastUpdated() {
-        return (Date)lastUpdatedByGroup.get(NO_GROUP);
+        
+        // abort if cache dir is not writable
+        if (!cacheDir.canWrite()) {
+            log.error("Planet cache directory is not writable");
+            return;
+        }
+        
+        FeedFetcherCache feedInfoCache =
+                new DiskFeedInfoCache(cacheDirName);
+        
+        if (config.getProxyHost()!=null && config.getProxyPort() > 0) {
+            System.setProperty("proxySet", "true");
+            System.setProperty("http.proxyHost", config.getProxyHost());
+            System.setProperty("http.proxyPort",
+                    Integer.toString(config.getProxyPort()));
+        }
+        /** a hack to set 15 sec timeouts for java.net.HttpURLConnection */
+        System.setProperty("sun.net.client.defaultConnectTimeout", "15000");
+        System.setProperty("sun.net.client.defaultReadTimeout", "15000");
+        
+        FeedFetcher feedFetcher = new HttpURLFeedFetcher(feedInfoCache);
+        //FeedFetcher feedFetcher = new HttpClientFeedFetcher(feedInfoCache);
+        feedFetcher.setUsingDeltaEncoding(false);
+        feedFetcher.setUserAgent("RollerPlanetAggregator");
+        
+        // Loop through all subscriptions in the system
+        Iterator subs = getAllSubscriptions();
+        while (subs.hasNext()) {
+            
+            long subStartTime = System.currentTimeMillis();
+            
+            PlanetSubscriptionData sub = (PlanetSubscriptionData)subs.next();
+            
+            // reattach sub.  sub gets detached as we iterate
+            sub = this.getSubscriptionById(sub.getId());
+            
+            // Fetch latest entries for each subscription
+//            Set newEntries = null;
+//            int count = 0;
+//            if (!StringUtils.isEmpty(localURL) && sub.getFeedUrl().startsWith(localURL)) {
+//                newEntries = getNewEntriesLocal(sub, feedFetcher, feedInfoCache);
+//            } else {
+//                newEntries = getNewEntriesRemote(sub, feedFetcher, feedInfoCache);
+//            }
+            Set newEntries = this.getNewEntries(sub, feedFetcher, feedInfoCache);
+            int count = newEntries.size();
+            
+            log.debug("   Entry count: " + count);
+            if (count > 0) {
+                sub.purgeEntries();
+                sub.addEntries(newEntries);
+                this.saveSubscription(sub);
+                if(roller != null) roller.flush();
+            }
+            long subEndTime = System.currentTimeMillis();
+            log.info("   " + count + " - "
+                    + ((subEndTime-subStartTime)/1000.0)
+                    + " seconds to process (" + count + ") entries of "
+                    + sub.getFeedUrl());
+        }
+        // Clear the aggregation cache
+        clearCachedAggregations();
+        
+        long endTime = System.currentTimeMillis();
+        log.info("--- DONE --- Refreshed entries in "
+                + ((endTime-startTime)/1000.0) + " seconds");
     }
     
-    public Date getLastUpdated(PlanetGroupData group) {
-        return (Date)lastUpdatedByGroup.get(group);
-    }
     
-    protected Set getNewEntriesLocal(PlanetSubscriptionData sub,
-            FeedFetcher feedFetcher, FeedFetcherCache feedInfoCache)
+    protected Set getNewEntries(PlanetSubscriptionData sub,
+                                FeedFetcher feedFetcher,
+                                FeedFetcherCache feedInfoCache)
             throws RollerException {
         
         Set newEntries = new TreeSet();
+        SyndFeed feed = null;
+        URL feedUrl = null;
+        Date lastUpdated = new Date();
         try {
-            // for local feeds, sub.author = website.handle
-            if (sub.getAuthor()!=null && sub.getFeedUrl().endsWith(sub.getAuthor())) {
-                
-                logger.debug("Getting LOCAL feed "+sub.getFeedUrl());
+            feedUrl = new URL(sub.getFeedUrl());
+            log.debug("Get feed from cache "+sub.getFeedUrl());
+            feed = feedFetcher.retrieveFeed(feedUrl);
+            SyndFeedInfo feedInfo = feedInfoCache.getFeedInfo(feedUrl);
+            if (feedInfo.getLastModified() != null) {
+                long lastUpdatedLong =
+                        ((Long)feedInfo.getLastModified()).longValue();
+                if (lastUpdatedLong != 0) {
+                    lastUpdated = new Date(lastUpdatedLong);
+                }
+            }
+            Thread.sleep(100); // be nice
+        } catch (Exception e) {
+            log.warn("ERROR parsing " + sub.getFeedUrl()
+            + " : " + e.getClass().getName() + " : " + e.getMessage());
+            log.debug(e);
+            return newEntries; // bail out
+        }
+        if (lastUpdated!=null && sub.getLastUpdated()!=null) {
+            Calendar feedCal = Calendar.getInstance();
+            feedCal.setTime(lastUpdated);
+            
+            Calendar subCal = Calendar.getInstance();
+            subCal.setTime(sub.getLastUpdated());
             
-                // get corresponding website object
-                UserManager usermgr = roller.getUserManager();
-                WebsiteData website = usermgr.getWebsiteByHandle(sub.getAuthor());
-                if (website == null) return newEntries;
-                
-                // figure website last update time
-                WeblogManager blogmgr = roller.getWeblogManager();
-                
-                Date siteUpdated = blogmgr.getWeblogLastPublishTime(website);
-                if (siteUpdated == null) { // Site never updated, skip it
-                    logger.warn("Last-publish time null, skipping local feed ["
-                                 + website.getHandle() + "]");
-                    return newEntries; 
+            if (!feedCal.after(subCal)) {
+                if (log.isDebugEnabled()) {
+                    String msg = MessageFormat.format(
+                            "   Skipping ({0} / {1})",
+                            new Object[] {
+                        lastUpdated, sub.getLastUpdated()});
+                    log.debug(msg);
+                }
+                return newEntries; // bail out
+            }
+        }
+        if (feed.getPublishedDate() != null) {
+            sub.setLastUpdated(feed.getPublishedDate());
+            // saving sub here causes detachment issues, so we save it later
+        }
+        
+        // Kludge for Feeds without entry dates: most recent entry is given
+        // feed's last publish date (or yesterday if none exists) and earler
+        // entries are placed at once day intervals before that.
+        Calendar cal = Calendar.getInstance();
+        if (sub.getLastUpdated() != null) {
+            cal.setTime(sub.getLastUpdated());
+        } else {
+            cal.setTime(new Date());
+            cal.add(Calendar.DATE, -1);
+        }
+        
+        // Populate subscription object with new entries
+        Iterator entries = feed.getEntries().iterator();
+        while (entries.hasNext()) {
+            try {
+                SyndEntry romeEntry = (SyndEntry) entries.next();
+                PlanetEntryData entry =
+                        new PlanetEntryData(feed, romeEntry, sub);
+                if (entry.getPublished() == null) {
+                    log.debug(
+                            "No published date, assigning fake date for "+feedUrl);
+                    entry.setPublished(cal.getTime());
                 }
-                
-                // if website last update time > subsciption last update time
-                List entries = new ArrayList();
-                if (sub.getLastUpdated()==null || siteUpdated.after(sub.getLastUpdated())) {
-                    int entryCount = RollerRuntimeConfig.getIntProperty(
-                        "site.newsfeeds.defaultEntries");    
-                     entries = blogmgr.getWeblogEntries(
-                        website, 
-                        null,                        // startDate
-                        new Date(),                  // endDate
-                        null,                        // catName
-                        WeblogEntryData.PUBLISHED,   // status
-                        null,                        // sortby (null means pubTime)
-                        new Integer(entryCount));    // maxEntries
-                    
-                    sub.setLastUpdated(siteUpdated);
-                    saveSubscription(sub);
-                    
+                if (entry.getPermalink() == null) {
+                    log.warn("No permalink, rejecting entry from "+feedUrl);
                 } else {
-                    if (logger.isDebugEnabled()) {
-                        String msg = MessageFormat.format(
-                            "   Skipping ({0} / {1})", new Object[] {
-                            siteUpdated, sub.getLastUpdated()});
-                            logger.debug(msg);
-                    }
-                }  
-                // Populate subscription object with new entries
-                PagePluginManager ppmgr = roller.getPagePluginManager();
-                Map pagePlugins = ppmgr.createAndInitPagePlugins(
-                    website, 
-                    null,
-                    RollerRuntimeConfig.getProperty("site.absoluteurl"),
-                    new VelocityContext());
-                Iterator entryIter = entries.iterator();
-                while (entryIter.hasNext()) {
-                    try {
-                        WeblogEntryData rollerEntry = 
-                            (WeblogEntryData)entryIter.next();
-                        PlanetEntryData entry =
-                            new PlanetEntryData(rollerEntry, sub, pagePlugins);
-                        saveEntry(entry);
-                        newEntries.add(entry);
-                    } catch (Exception e) {
-                        logger.error("ERROR processing subscription entry", e);
-                    }
+                    newEntries.add(entry);
                 }
-                return newEntries;
+                cal.add(Calendar.DATE, -1);
+            } catch (Exception e) {
+                log.error("ERROR processing subscription entry", e);
             }
-        } catch (Exception e) {
-            logger.warn("Problem reading local feed", e);
         }
-        return getNewEntriesRemote(sub, feedFetcher, feedInfoCache);
+        return newEntries;
     }
+
+    protected String getLocalURL() {
+        return localURL;
+    }
+    
 }