roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r189695 [22/67] - in /incubator/roller/trunk: ./ contrib/ contrib/lib/ contrib/plugins/ contrib/plugins/src/ contrib/plugins/src/org/ contrib/plugins/src/org/roller/ contrib/plugins/src/org/roller/presentation/ contrib/plugins/src/org/roller/presentation/velocity/ contrib/plugins/src/org/roller/presentation/velocity/plugins/ contrib/plugins/src/org/roller/presentation/velocity/plugins/acronyms/ contrib/plugins/src/org/roller/presentation/velocity/plugins/bookmarks/ contrib/plugins/src/org/roller/presentation/velocity/plugins/email/ contrib/plugins/src/org/roller/presentation/velocity/plugins/jspwiki/ contrib/plugins/src/org/roller/presentation/velocity/plugins/radeox/ contrib/plugins/src/org/roller/presentation/velocity/plugins/readmore/ contrib/plugins/src/org/roller/presentation/velocity/plugins/smileys/ contrib/plugins/src/org/roller/presentation/velocity/plugins/textile/ contrib/plugins/src/org/roller/presentation/velocity/plugins/topictag/ custom/ custom/src/ custom/web/ docs/ docs/images/ docs/installguide/ docs/installguide/old/ docs/userguide/ docs/userguide/images/ docs/userguide/old/ metadata/ metadata/database/ metadata/database/hibernate/ metadata/xdoclet/ nbproject/ personal/ personal/eclipse/ personal/testing/ sandbox/ sandbox/planetroller/ sandbox/planetroller/metadata/ sandbox/planetroller/metadata/database/ sandbox/planetroller/src/ sandbox/planetroller/src/org/ sandbox/planetroller/src/org/roller/ sandbox/planetroller/src/org/roller/tools/ sandbox/planetroller/src/org/roller/tools/planet/ sandbox/planetroller/templates/ sandbox/planetroller/test/ sandbox/planetroller/test/org/ sandbox/planetroller/test/org/roller/ sandbox/planetroller/test/org/roller/model/ sandbox/planetroller/test/org/roller/tools/ sandbox/planetroller/test/org/roller/tools/planet/ sandbox/planetroller/testdata/ sandbox/planetroller/testdata/cache/ sandbox/planetroller/testdata/output/ sandbox/standalone/ sandbox/standalone/jspwiki/ sandbox/standalone/jspwiki/default/ sandbox/standalone/jspwiki/default/images/ sandbox/standalone/lib/ sandbox/standalone/src/ sandbox/standalone/src/org/ sandbox/standalone/src/org/roller/ sandbox/standalone/src/org/roller/jspwiki/ sandbox/standalone/src/org/roller/tomcat/ sandbox/standalone/src/org/roller/util/ sandbox/standalone/tests/ sandbox/standalone/tests/org/ sandbox/standalone/tests/org/roller/ sandbox/standalone/tests/org/roller/util/ sandbox/standalone/tomcat/ src/ src/org/ src/org/roller/ src/org/roller/business/ src/org/roller/business/hibernate/ src/org/roller/business/search/ src/org/roller/business/search/operations/ src/org/roller/business/utils/ src/org/roller/config/ src/org/roller/config/runtime/ src/org/roller/model/ src/org/roller/pojos/ src/org/roller/presentation/ src/org/roller/presentation/atomapi/ src/org/roller/presentation/bookmarks/ src/org/roller/presentation/bookmarks/actions/ src/org/roller/presentation/bookmarks/formbeans/ src/org/roller/presentation/bookmarks/tags/ src/org/roller/presentation/filters/ src/org/roller/presentation/forms/ src/org/roller/presentation/newsfeeds/ src/org/roller/presentation/pagecache/ src/org/roller/presentation/pagecache/rollercache/ src/org/roller/presentation/pings/ src/org/roller/presentation/planet/ src/org/roller/presentation/tags/ src/org/roller/presentation/tags/calendar/ src/org/roller/presentation/tags/menu/ src/org/roller/presentation/util/ src/org/roller/presentation/velocity/ src/org/roller/presentation/weblog/ src/org/roller/presentation/weblog/actions/ src/org/roller/presentation/weblog/formbeans/ src/org/roller/presentation/weblog/tags/ src/org/roller/presentation/website/ src/org/roller/presentation/website/actions/ src/org/roller/presentation/website/formbeans/ src/org/roller/presentation/website/tags/ src/org/roller/presentation/xmlrpc/ src/org/roller/util/ src/org/roller/util/rome/ tests/ tests/org/ tests/org/roller/ tests/org/roller/ant/ tests/org/roller/business/ tests/org/roller/presentation/ tests/org/roller/presentation/atomapi/ tests/org/roller/presentation/bookmarks/ tests/org/roller/presentation/filters/ tests/org/roller/presentation/velocity/ tests/org/roller/presentation/velocity/plugins/ tests/org/roller/presentation/velocity/plugins/smileys/ tests/org/roller/presentation/velocity/plugins/textile/ tests/org/roller/presentation/weblog/ tests/org/roller/presentation/xmlrpc/ tests/org/roller/util/ tests/org/roller/util/rome/ tools/ tools/buildtime/ tools/buildtime/ant-1.6.2/ tools/buildtime/findbugs/ tools/buildtime/findbugs/lib/ tools/buildtime/findbugs/plugin/ tools/buildtime/mockrunner-0.3/ tools/buildtime/mockrunner-0.3/lib/ tools/buildtime/mockrunner-0.35/ tools/buildtime/mockrunner-0.35/lib/ tools/buildtime/tomcat-4.1.24/ tools/buildtime/xdoclet-1.2/ tools/buildtime/xdoclet-1.2/lib/ tools/hibernate-2.1/ tools/hibernate-2.1/lib/ tools/lib/ tools/standard-1.0.3/ tools/standard-1.0.3/lib/ tools/standard-1.0.3/tld/ tools/struts-1.2.4/ tools/struts-1.2.4/lib/ web/ web/WEB-INF/ web/WEB-INF/classes/ web/WEB-INF/classes/flavors/ web/WEB-INF/classes/themes/ web/bookmarks/ web/editor/ web/editor/images/ web/images/ web/images/editor/ web/images/midas/ web/images/preview/ web/images/smileys/ web/planet/ web/tags/ web/templates/ web/theme/ web/theme/images/ web/theme/lavender/ web/theme/scripts/ web/theme/scripts/classes/ web/themes/ web/themes/basic/ web/themes/berkley/ web/themes/berkley/images/ web/themes/brushedmetal/ web/themes/brushedmetal/images/ web/themes/cheb/ web/themes/cheb/images/ web/themes/cheb/scripts/ web/themes/clean/ web/themes/currency-i18n/ web/themes/currency-i18n/images/ web/themes/currency/ web/themes/currency/images/ web/themes/grey2/ web/themes/moonshine/ web/themes/movablemanila/ web/themes/movablemanila/images/ web/themes/pacifica/ web/themes/robot/ web/themes/rolling/ web/themes/rolling/images/ web/themes/sotto/ web/themes/sotto/images/ web/themes/sotto/styles/ web/themes/sunsets/ web/themes/sunsets/images/ web/themes/sunsets/scripts/ web/themes/sunsets/styles/ web/themes/werner/ web/themes/x2/ web/themes/x2/images/ web/themes/x2/scripts/ web/themes/x2/styles/ web/weblog/ web/website/
Date Thu, 09 Jun 2005 03:19:20 GMT
Added: incubator/roller/trunk/src/org/roller/business/utils/SyncUpgrade098Xto1000.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/utils/SyncUpgrade098Xto1000.java?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/utils/SyncUpgrade098Xto1000.java (added)
+++ incubator/roller/trunk/src/org/roller/business/utils/SyncUpgrade098Xto1000.java Wed Jun  8 20:18:46 2005
@@ -0,0 +1,949 @@
+package org.roller.business.utils;
+
+import java.sql.*;
+import java.util.*;
+import java.io.*;
+
+/**
+ * Synchronize a source 0.9.8.X database with a destination 1.0.0.0 database.
+ */
+public class SyncUpgrade098Xto1000 
+{
+    private Map rootCategoryIds = new Hashtable(); // keyed by website id
+    private static boolean debug = true;
+    
+    public void syncUpgrade(Connection srccon, Connection destcon) 
+    throws Exception
+    {    
+        rootCategoryIds = buildRootCategoryMap(destcon);        
+        
+        syncRolleruserTable(srccon,destcon);
+        syncUserroleTable(srccon,destcon);
+        syncWebsiteTable(srccon,destcon);
+        syncWebpageTable(srccon,destcon);
+        syncWeblogcategoryTable(srccon,destcon);        
+        syncFolderTable(srccon,destcon);
+        syncBookmarkTable(srccon,destcon);
+        syncWeblogentryTable(srccon,destcon);
+        syncCommentTable(srccon,destcon);
+        syncRefererTable(srccon,destcon);
+        
+        ConsistencyCheck.findAndDeleteOrphans(destcon, true, debug);
+    }
+    public Map buildRootCategoryMap(Connection destcon) throws Exception 
+    {        
+        Hashtable map = new Hashtable();
+        Statement destStmt = destcon.createStatement();
+        ResultSet destSet = destStmt.executeQuery(
+           "select c.websiteid,c.id from "
+           +"weblogcategory as c, weblogcategoryassoc as a "
+           +"where c.id=a.categoryid and a.ancestorid is null");
+        while (destSet.next()) 
+        {
+            String websiteid = destSet.getString(1);
+            String categoryid = destSet.getString(2);
+            map.put(websiteid, categoryid);
+        }
+        return map;
+    }
+    private void info(String s) 
+    {
+        System.out.println(s);
+    }
+    private void debug(String s) 
+    {
+        if (debug) System.out.println(s);
+    }
+    private void purgeDeleted(Connection srccon, Connection destcon, String tableName) 
+    throws Exception
+    {
+        PreparedStatement destRows = destcon.prepareStatement(
+            "select id from "+tableName);
+        PreparedStatement deleteRow = destcon.prepareStatement(
+            "delete from "+tableName+" where id=?");
+        PreparedStatement srcExists = srccon.prepareStatement(
+            "select id from "+tableName+" where id=?");
+        ResultSet destSet = destRows.executeQuery();
+        while (destSet.next())
+        {
+            String id = destSet.getString(1);
+            srcExists.clearParameters();
+            srcExists.setString(1, id);
+            ResultSet existsSet = srcExists.executeQuery();
+            if (!existsSet.next() && !id.endsWith("R")) // kludge alert
+            {
+                deleteRow.clearParameters();
+                deleteRow.setString(1, id);
+                deleteRow.executeUpdate();
+                info("Deleting from "+tableName+" id="+id);
+            }
+        }        
+    }
+    private void purgeAssocs(Connection destcon, String assocTable, String mainTable, String fkeyName) 
+    throws Exception
+    {
+        info("--- purgeAssocs --- "+assocTable);
+        PreparedStatement assocRows = destcon.prepareStatement(
+            "select id,"+fkeyName+",ancestorid from "+assocTable);
+        PreparedStatement mainExists = destcon.prepareStatement(
+            "select id from "+mainTable+" where id=?");
+        PreparedStatement deleteMain = destcon.prepareStatement(
+            "delete from "+assocTable+" where "+fkeyName+"=?");
+        PreparedStatement ancestorExists = destcon.prepareStatement(
+            "select id from "+mainTable+" where id=?");
+        PreparedStatement deleteAncestor = destcon.prepareStatement(
+            "delete from "+assocTable+" where ancestorid=?");
+        ResultSet assocSet = assocRows.executeQuery();
+        while (assocSet.next())
+        {
+            String id = assocSet.getString(1);
+            String fkey = assocSet.getString(2);
+            String akey = assocSet.getString(3);
+            mainExists.clearParameters();
+            mainExists.setString(1, fkey);
+            ResultSet existsSet = mainExists.executeQuery();
+            if (!existsSet.next())
+            {
+                deleteMain.clearParameters();
+                deleteMain.setString(1, fkey);
+                deleteMain.executeUpdate();
+                info("Deleting from "+assocTable+" where "+fkeyName+"="+id);
+            }
+            ancestorExists.clearParameters();
+            ancestorExists.setString(1, akey);
+            ResultSet ancestorSet = ancestorExists.executeQuery();
+            if (!ancestorSet.next())
+            {
+                deleteAncestor.clearParameters();
+                deleteAncestor.setString(1, akey);
+                deleteAncestor.executeUpdate();
+                info("Deleting from "+assocTable+" where ancestorid="+id);
+            }
+        }            
+    }
+    private void syncRolleruserTable(Connection srccon, Connection destcon) 
+    throws Exception
+    {
+        info("--- syncRolleruserTable ---");        
+        Set existing = new  TreeSet();         
+        PreparedStatement destExistsStmt = destcon.prepareStatement(
+            "select id from rolleruser where id=?");
+        PreparedStatement destInsert = destcon.prepareStatement(
+            "insert into rolleruser "
+            +"(id,username,passphrase,fullname,emailaddress,datecreated) "
+            +"values (?,?,?,?,?,?)");
+        PreparedStatement destUpdate = destcon.prepareStatement(
+            "update rolleruser set id=?, username=?, passphrase=?, "
+            +"fullname=?, emailaddress=?, datecreated=? where id=?");
+
+        Statement srcStmt = srccon.createStatement();
+        ResultSet srcSet = srcStmt.executeQuery(
+           "select id,username,passphrase,fullname,emailaddress,datecreated "
+           +"from rolleruser");
+        while (srcSet.next()) 
+        {
+            String id = srcSet.getString(1);
+            existing.add(id);
+            destExistsStmt.clearParameters();
+            destExistsStmt.setString(1,id);
+            ResultSet destSet = destExistsStmt.executeQuery();
+            if (!destSet.first())
+            {
+                debug("Inserting rolleruser id="+id);
+                destInsert.clearParameters();
+                destInsert.setString(1, srcSet.getString(1));
+                destInsert.setString(2, srcSet.getString(2));
+                destInsert.setString(3, srcSet.getString(3));
+                destInsert.setString(4, srcSet.getString(4));
+                destInsert.setString(5, srcSet.getString(5));
+                destInsert.setDate(  6, srcSet.getDate(6));
+                destInsert.executeUpdate();
+            }
+            else
+            {
+                debug("Updating rolleruser id="+id);
+                destUpdate.clearParameters();
+                destUpdate.setString(1, srcSet.getString(1));
+                destUpdate.setString(2, srcSet.getString(2));
+                destUpdate.setString(3, srcSet.getString(3));
+                destUpdate.setString(4, srcSet.getString(4));
+                destUpdate.setString(5, srcSet.getString(5));
+                destUpdate.setDate(  6, srcSet.getDate(6));
+                destUpdate.setString(7, srcSet.getString(1));
+                destUpdate.executeUpdate();
+            }                
+        } 
+        purgeDeleted(srccon,destcon,"rolleruser");
+    }
+    private void syncUserroleTable(Connection srccon, Connection destcon) 
+    throws Exception
+    {
+        info("--- syncUserroleTable ---");
+        
+        PreparedStatement destExistsStmt = destcon.prepareStatement(
+            "select id from userrole where id=?");
+        PreparedStatement destInsert = destcon.prepareStatement(
+            "insert into userrole (id,rolename,username,userid) "
+            +"values (?,?,?,?)");
+        PreparedStatement destUpdate = destcon.prepareStatement(
+            "update userrole set id=?, rolename=?, username=?, userid=? "
+            +"where id=?");
+        PreparedStatement parentExistsStmt = destcon.prepareStatement(
+            "select id from rolleruser where id=?");        
+
+        Statement srcStmt = srccon.createStatement();
+        ResultSet srcSet = srcStmt.executeQuery(
+           "select id,rolename,username,userid from userrole");
+        while (srcSet.next()) 
+        {
+            String id = srcSet.getString(1);
+            String userid = srcSet.getString(4);
+            
+            destExistsStmt.clearParameters();
+            destExistsStmt.setString(1, id);
+            ResultSet destSet = destExistsStmt.executeQuery();
+            
+            parentExistsStmt.clearParameters();
+            parentExistsStmt.setString(1, userid);
+            ResultSet parentSet = parentExistsStmt.executeQuery();
+            
+            boolean parentExists = parentSet.first();
+            if (!destSet.first() && parentExists)
+            {
+                debug("Inserting userrole id="+id);
+                destInsert.clearParameters();
+                destInsert.setString(1, srcSet.getString(1));
+                destInsert.setString(2, srcSet.getString(2));
+                destInsert.setString(3, srcSet.getString(3));
+                destInsert.setString(4, srcSet.getString(4));
+                destInsert.executeUpdate();
+            }
+            else if (parentExists)
+            {
+                debug("Updating userrole id="+id);
+                destUpdate.clearParameters();
+                destUpdate.setString(1, srcSet.getString(1));
+                destUpdate.setString(2, srcSet.getString(2));
+                destUpdate.setString(3, srcSet.getString(3));
+                destUpdate.setString(4, srcSet.getString(4));
+                destUpdate.setString(5, srcSet.getString(1));
+                destUpdate.executeUpdate();
+            }                
+            else 
+            {
+                info("Not copying userrole id="+id);
+            }
+        }     
+        purgeDeleted(srccon,destcon,"userrole");
+    }
+    private void syncWebsiteTable(Connection srccon, Connection destcon) 
+    throws Exception
+    {
+        info("--- syncWebsiteTable ---");
+        
+        int id_num=1;
+        int name_num=2;
+        int description_num=3;
+        int userid_num=4;
+        int defaultpageid_num=5; 
+        int weblogdayid_num=6;
+        int ignorewords_num=7;    
+        int enablebloggerapi_num=8; 
+        int editorpage_num=9;    
+        int bloggercatid_num=10;   
+        int allowcomments_num=11; 
+        
+        PreparedStatement destExistsStmt = destcon.prepareStatement(
+            "select id from website where id=?");
+        PreparedStatement destInsert = destcon.prepareStatement(
+            "insert into website (id,name,description,userid,defaultpageid,"
+            +"weblogdayid,ignorewords,enablebloggerapi,editorpage,"
+            +"bloggercatid,allowcomments,defaultcatid) values (?,?,?,?,?,?,?,?,?,?,?,?)");
+        PreparedStatement destUpdate = destcon.prepareStatement(
+        "update website set id=?,name=?,description=?,userid=?,defaultpageid=?,"
+            +"weblogdayid=?,ignorewords=?,enablebloggerapi=?,editorpage=?,"
+            +"bloggercatid=?,allowcomments=? where id=?");
+        PreparedStatement parentExistsStmt = destcon.prepareStatement(
+            "select id from rolleruser where id=?");
+        
+        PreparedStatement insertRootCategory = destcon.prepareStatement(
+            "insert into weblogcategory (id,name,description,websiteid,image) "+
+            "values (?,'root','root',?,NULL)");                        
+        PreparedStatement insertRootCategoryAssoc = destcon.prepareStatement(
+           "insert into weblogcategoryassoc (id,categoryid,ancestorid,relation)"
+            +" values (?,?,NULL,'PARENT')");                        
+        
+        Statement srcStmt = srccon.createStatement();
+        ResultSet srcSet = srcStmt.executeQuery(
+            "select id,name,description,userid,defaultpageid,weblogdayid,"
+           +"ignorewords,enablebloggerapi,editorpage,bloggercatid,allowcomments"
+           +" from website");        
+        while (srcSet.next()) 
+        {
+            String id = srcSet.getString(id_num);
+            String userid = srcSet.getString(userid_num);
+            
+            destExistsStmt.clearParameters();
+            destExistsStmt.setString(id_num, id);            
+            ResultSet destSet = destExistsStmt.executeQuery();
+            
+            parentExistsStmt.clearParameters();
+            parentExistsStmt.setString(id_num, userid);
+            ResultSet parentSet = parentExistsStmt.executeQuery();
+            boolean parentExists = parentSet.first();
+            
+            if (!destSet.first() && parentExists)
+            {
+                debug("Inserting website id="+id);
+                destInsert.clearParameters();
+                destInsert.setString(id_num, srcSet.getString(id_num));
+                destInsert.setString(name_num, srcSet.getString(name_num));
+                destInsert.setString(description_num, srcSet.getString(description_num));
+                destInsert.setString(userid_num, srcSet.getString(userid_num));
+                destInsert.setString(defaultpageid_num, srcSet.getString(defaultpageid_num));
+                destInsert.setString(weblogdayid_num, srcSet.getString(weblogdayid_num));
+                destInsert.setString(ignorewords_num, srcSet.getString(ignorewords_num));
+                destInsert.setBoolean(enablebloggerapi_num, srcSet.getBoolean(enablebloggerapi_num));
+                destInsert.setString(editorpage_num, srcSet.getString(editorpage_num));
+                destInsert.setString(bloggercatid_num, srcSet.getString(bloggercatid_num));
+                destInsert.setBoolean(allowcomments_num, srcSet.getBoolean(allowcomments_num));
+                destInsert.setString(12, id+"R"); // default category
+                destInsert.executeUpdate();
+                
+                // 098 had no root category per website, so create one
+                insertRootCategory.clearParameters();
+                insertRootCategory.setString(1, id+"R");
+                insertRootCategory.setString(2, id);
+                insertRootCategory.executeUpdate();
+                rootCategoryIds.put(id, id+"R"); // and add it to map
+                debug("   Inserting root weblogcategory id="+id+"R");
+                
+                // Create category assoc to go with root category
+                insertRootCategoryAssoc.clearParameters();
+                insertRootCategoryAssoc.setString(1, id+"A");
+                insertRootCategoryAssoc.setString(2, id+"R");
+                insertRootCategoryAssoc.executeUpdate();
+                debug("   Inserting root weblogcategoryassoc id="+id+"A");
+            }
+            else if (parentExists)
+            {
+                debug("Updating website id="+id);
+                destUpdate.clearParameters();
+                destUpdate.setString(id_num, srcSet.getString(id_num));
+                destUpdate.setString(name_num, srcSet.getString(name_num));
+                destUpdate.setString(description_num, srcSet.getString(description_num));
+                destUpdate.setString(userid_num, srcSet.getString(userid_num));
+                destUpdate.setString(defaultpageid_num, srcSet.getString(defaultpageid_num));
+                destUpdate.setString(weblogdayid_num, srcSet.getString(weblogdayid_num));
+                destUpdate.setString(ignorewords_num, srcSet.getString(ignorewords_num));
+                destUpdate.setBoolean(enablebloggerapi_num, srcSet.getBoolean(enablebloggerapi_num));
+                destUpdate.setString(editorpage_num, srcSet.getString(editorpage_num));
+                destUpdate.setString(bloggercatid_num, srcSet.getString(bloggercatid_num));
+                destUpdate.setBoolean(allowcomments_num, srcSet.getBoolean(allowcomments_num));
+                destUpdate.setString(12, srcSet.getString(id_num));
+                destUpdate.executeUpdate();
+            }   
+            else 
+            {
+                info("Not copying website id="+id);
+            }
+        }     
+        purgeDeleted(srccon,destcon,"website");
+    }    
+    private void syncWebpageTable(Connection srccon, Connection destcon) throws Exception
+    {
+        info("--- syncWebpageTable ---");
+        
+        String columns = "id,name,description,link,websiteid,template,updatetime";
+        int id_num=1;
+        int name_num=2;
+        int description_num=3;
+        int link_num=4;
+        int websiteid_num=5;
+        int template_num=6;
+        int updatetime_num=7;
+        
+        PreparedStatement destExistsStmt = destcon.prepareStatement(
+            "select id from webpage where id=?");
+        PreparedStatement destInsert = destcon.prepareStatement(
+            "insert into webpage "+"("+columns+") "+"values (?,?,?,?,?,?,?)");
+        PreparedStatement destUpdate = destcon.prepareStatement(
+            "update webpage set id=?,name=?,description=?,link=?,websiteid=?,"
+            +"template=?,updatetime=? where id=?");
+        PreparedStatement parentExistsStmt = destcon.prepareStatement(
+            "select id from website where id=?");        
+
+        Statement srcStmt = srccon.createStatement();
+        ResultSet srcSet = srcStmt.executeQuery("select "+columns+" from webpage");
+        while (srcSet.next()) 
+        {
+            String id = srcSet.getString(id_num);
+            String userid = srcSet.getString(websiteid_num);
+            
+            destExistsStmt.clearParameters();
+            destExistsStmt.setString(id_num, id);
+            ResultSet destSet = destExistsStmt.executeQuery();
+            
+            parentExistsStmt.clearParameters();
+            parentExistsStmt.setString(id_num, userid);
+            ResultSet parentSet = parentExistsStmt.executeQuery();
+            
+            boolean parentExists = parentSet.first();
+            if (!destSet.first() && parentExists)
+            {
+                debug("Inserting webpage id="+id);
+                destInsert.clearParameters();
+                destInsert.setString(id_num, srcSet.getString(id_num));
+                destInsert.setString(name_num, srcSet.getString(name_num));
+                destInsert.setString(description_num, srcSet.getString(description_num));
+                destInsert.setString(link_num, srcSet.getString(link_num));
+                destInsert.setString(websiteid_num, srcSet.getString(websiteid_num));
+                destInsert.setString(template_num, srcSet.getString(template_num));
+                destInsert.setTimestamp(updatetime_num, srcSet.getTimestamp(updatetime_num));
+                destInsert.executeUpdate();
+            }
+            else if (parentExists)
+            {
+                debug("Updating webpage id="+id);
+                destUpdate.clearParameters();
+                destUpdate.setString(id_num, srcSet.getString(id_num));
+                destUpdate.setString(name_num, srcSet.getString(name_num));
+                destUpdate.setString(description_num, srcSet.getString(description_num));
+                destUpdate.setString(link_num, srcSet.getString(link_num));
+                destUpdate.setString(websiteid_num, srcSet.getString(websiteid_num));
+                destUpdate.setString(template_num, srcSet.getString(template_num));
+                destUpdate.setTimestamp(updatetime_num, srcSet.getTimestamp(updatetime_num));
+                destUpdate.setString(8, srcSet.getString(id_num));
+                destUpdate.executeUpdate();
+            }                
+            else 
+            {
+                info("Not copying webpage id="+id);
+            }
+        }     
+        purgeDeleted(srccon,destcon,"webpage");
+    }
+    private void syncWeblogcategoryTable(Connection srccon, Connection destcon) throws Exception
+    {
+        info("--- syncWeblogcategoryTable ---");
+        
+        String columns = "id,name,description,websiteid,image";
+        int id_num=1;
+        int name_num=2;
+        int description_num=3;
+        int websiteid_num=4;
+        int image_num=5;
+        
+        PreparedStatement destExistsStmt = destcon.prepareStatement(
+            "select id from weblogcategory where id=?");
+        PreparedStatement destInsert = destcon.prepareStatement(
+            "insert into weblogcategory "+"("+columns+") "+"values (?,?,?,?,?)");
+        PreparedStatement destUpdate = destcon.prepareStatement(
+            "update weblogcategory set id=?,name=?,description=?,websiteid=?,"
+            +"image=? where id=?");
+        PreparedStatement parentExistsStmt = destcon.prepareStatement(
+            "select id from website where id=?");        
+
+        PreparedStatement assocInsert = destcon.prepareStatement(
+            "insert into weblogcategoryassoc "
+            +"(id,categoryid,ancestorid,relation) "+"values (?,?,?,'PARENT')");
+
+        Statement srcStmt = srccon.createStatement();
+        ResultSet srcSet = srcStmt.executeQuery("select "+columns+" from weblogcategory");
+        while (srcSet.next()) 
+        {
+            String id = srcSet.getString(id_num);
+            String websiteid = srcSet.getString(websiteid_num);
+            
+            destExistsStmt.clearParameters();
+            destExistsStmt.setString(id_num, id);
+            ResultSet destSet = destExistsStmt.executeQuery();
+            
+            parentExistsStmt.clearParameters();
+            parentExistsStmt.setString(id_num, websiteid);
+            ResultSet parentSet = parentExistsStmt.executeQuery();
+            
+            boolean parentExists = parentSet.first();
+            if (!destSet.first() && parentExists)
+            {
+                debug("Inserting weblogcategory id="+id);
+                destInsert.clearParameters();
+                destInsert.setString(id_num, id);
+                destInsert.setString(name_num, srcSet.getString(name_num));
+                destInsert.setString(description_num, srcSet.getString(description_num));
+                destInsert.setString(websiteid_num, srcSet.getString(websiteid_num));
+                destInsert.setString(image_num, srcSet.getString(image_num));
+                destInsert.executeUpdate();
+                
+                // Create category assoc for new category 
+                assocInsert.clearParameters();
+                assocInsert.setString(1, id+"A");
+                assocInsert.setString(2, id);
+                assocInsert.setString(3, (String)rootCategoryIds.get(websiteid));
+                assocInsert.executeUpdate();                
+            }
+            else if (parentExists)
+            {
+                debug("Updating weblogcategory id="+id);
+                destUpdate.clearParameters();
+                destUpdate.setString(id_num, id);
+                destUpdate.setString(name_num, srcSet.getString(name_num));
+                destUpdate.setString(description_num, srcSet.getString(description_num));
+                destUpdate.setString(websiteid_num, srcSet.getString(websiteid_num));
+                destUpdate.setString(image_num, srcSet.getString(image_num));
+                destUpdate.setString(6, srcSet.getString(id_num));
+                destUpdate.executeUpdate();
+            }                
+            else 
+            {
+                info("Not copying weblogcategory id="+id);
+            }
+        }     
+        purgeDeleted(srccon,destcon,"weblogcategory");
+        purgeAssocs(destcon,"weblogcategoryassoc","weblogcategory","categoryid");
+    }
+    private void syncFolderTable(Connection srccon, Connection destcon) throws Exception
+    {
+        info("--- syncFolderTable ---");
+        
+        String columns = "id,name,description,parentid,websiteid";
+        int id_num=1;
+        int name_num=2;
+        int description_num=3;
+        int parentid_num=4;
+        int websiteid_num=5;
+        
+        PreparedStatement destExistsStmt = destcon.prepareStatement(
+            "select id from folder where id=?");
+        PreparedStatement destInsert = destcon.prepareStatement(
+            "insert into folder "+"("+columns+") "+"values (?,?,?,?,?)");
+        PreparedStatement destUpdate = destcon.prepareStatement(
+            "update folder set id=?,name=?,description=?,parentid=?,websiteid=?"
+            +" where id=?");
+        PreparedStatement parentExistsStmt = destcon.prepareStatement(
+            "select id from website where id=?");        
+
+        PreparedStatement assocInsert = destcon.prepareStatement(
+            "insert into folderassoc "
+            +"(id,folderid,ancestorid,relation) "+"values (?,?,?,'PARENT')");
+
+        Statement srcStmt = srccon.createStatement();
+        ResultSet srcSet = srcStmt.executeQuery("select "+columns+" from folder");
+        while (srcSet.next()) 
+        {
+            String id = srcSet.getString(id_num);
+            String userid = srcSet.getString(websiteid_num);
+            
+            destExistsStmt.clearParameters();
+            destExistsStmt.setString(id_num, id);
+            ResultSet destSet = destExistsStmt.executeQuery();
+            
+            parentExistsStmt.clearParameters();
+            parentExistsStmt.setString(id_num, userid);
+            ResultSet parentSet = parentExistsStmt.executeQuery();
+            
+            boolean parentExists = parentSet.first();
+            if (!destSet.first() && parentExists)
+            {
+                debug("Inserting folder id="+id);
+                destInsert.clearParameters();
+                destInsert.setString(id_num, id);
+                destInsert.setString(name_num, srcSet.getString(name_num));
+                destInsert.setString(description_num, srcSet.getString(description_num));
+                destInsert.setString(parentid_num, srcSet.getString(parentid_num));
+                destInsert.setString(websiteid_num, srcSet.getString(websiteid_num));
+                destInsert.executeUpdate();
+                
+                // Create folder assoc for new folder 
+                assocInsert.clearParameters();
+                assocInsert.setString(1, id+"A");
+                assocInsert.setString(2, id);
+                assocInsert.setString(3, srcSet.getString(parentid_num));
+                assocInsert.executeUpdate();                
+            }
+            else if (parentExists)
+            {
+                debug("Updating folder id="+id);
+                destUpdate.clearParameters();
+                destUpdate.setString(id_num, id);
+                destUpdate.setString(name_num, srcSet.getString(name_num));
+                destUpdate.setString(description_num, srcSet.getString(description_num));
+                destUpdate.setString(parentid_num, srcSet.getString(parentid_num));
+                destUpdate.setString(websiteid_num, srcSet.getString(websiteid_num));
+                destUpdate.setString(6, srcSet.getString(id_num));
+                destUpdate.executeUpdate();
+            }                
+            else 
+            {
+                info("Not copying folder id="+id);
+            }
+        }     
+        purgeDeleted(srccon,destcon,"folder");
+        purgeAssocs(destcon,"folderassoc","folder","folderid");
+    }
+    private void syncBookmarkTable(Connection srccon, Connection destcon) throws Exception
+    {
+        info("--- syncBookmarkTable ---");
+        
+        String columns = "id,folderid,name,description,url,weight,priority,image,feedurl";
+        int id_num=1;
+        int folderid_num=2;
+        int name_num=3;
+        int description_num=4;
+        int url_num=5;
+        int weight_num=6;
+        int priority_num=7;
+        int image_num=8;
+        int feedurl_num=9;
+        
+        PreparedStatement destExistsStmt = destcon.prepareStatement(
+            "select id from bookmark where id=?");
+        PreparedStatement destInsert = destcon.prepareStatement(
+            "insert into bookmark "+"("+columns+") "+"values (?,?,?,?,?,?,?,?,?)");
+        PreparedStatement destUpdate = destcon.prepareStatement(
+            "update bookmark set id=?,folderid=?,name=?,description=?,url=?,weight=?,priority=?,image=?,feedurl=?"
+            +" where id=?");
+        PreparedStatement parentExistsStmt = destcon.prepareStatement(
+            "select id from folder where id=?");        
+
+        Statement srcStmt = srccon.createStatement();
+        ResultSet srcSet = srcStmt.executeQuery("select "+columns+" from bookmark");
+        while (srcSet.next()) 
+        {
+            String id = srcSet.getString(id_num);
+            String folderid = srcSet.getString(folderid_num);
+            
+            destExistsStmt.clearParameters();
+            destExistsStmt.setString(id_num, id);
+            ResultSet destSet = destExistsStmt.executeQuery();
+            
+            parentExistsStmt.clearParameters();
+            parentExistsStmt.setString(id_num, folderid);
+            ResultSet parentSet = parentExistsStmt.executeQuery();
+            
+            boolean parentExists = parentSet.first();
+            if (!destSet.first() && parentExists)
+            {
+                debug("Inserting bookmark id="+id);
+                destInsert.clearParameters();
+                destInsert.setString(id_num, id);
+                destInsert.setString(folderid_num, srcSet.getString(folderid_num));
+                destInsert.setString(name_num, srcSet.getString(name_num));
+                destInsert.setString(description_num, srcSet.getString(name_num));
+                destInsert.setString(url_num, srcSet.getString(url_num));
+                destInsert.setInt(weight_num, srcSet.getInt(weight_num));
+                destInsert.setInt(priority_num, srcSet.getInt(priority_num));
+                destInsert.setString(image_num, srcSet.getString(image_num));
+                destInsert.setString(feedurl_num, srcSet.getString(feedurl_num));
+                destInsert.executeUpdate();
+            }
+            else if (parentExists)
+            {
+                debug("Updating bookmark id="+id);
+                destUpdate.clearParameters();
+                destUpdate.setString(id_num, id);
+                destUpdate.setString(folderid_num, srcSet.getString(folderid_num));
+                destUpdate.setString(name_num, srcSet.getString(name_num));
+                destUpdate.setString(description_num, srcSet.getString(name_num));
+                destUpdate.setString(url_num, srcSet.getString(url_num));
+                destUpdate.setString(weight_num, srcSet.getString(weight_num));
+                destUpdate.setString(priority_num, srcSet.getString(priority_num));
+                destUpdate.setString(image_num, srcSet.getString(image_num));
+                destUpdate.setString(feedurl_num, srcSet.getString(feedurl_num));
+                destUpdate.setString(10, srcSet.getString(id_num));
+                destUpdate.executeUpdate();
+            }                
+            else 
+            {
+                info("Not copying bookmark id="+id);
+            }
+        }     
+        purgeDeleted(srccon,destcon,"bookmark");
+    }
+    private void syncWeblogentryTable(Connection srccon, Connection destcon) throws Exception
+    {
+        info("--- syncWeblogentryTable ---");
+        
+        String columns = "id,anchor,title,text,pubtime,updatetime,websiteid,categoryid,publishentry";
+        int id_num=1;
+        int anchor_num=2;
+        int title_num=3;
+        int text_num=4;
+        int pubtime_num=5;
+        int updatetime_num=6;
+        int websiteid_num=7;
+        int categoryid_num=8;
+        int publishentry_num=9;
+        
+        PreparedStatement destExistsStmt = destcon.prepareStatement(
+            "select id from weblogentry where id=?");
+        PreparedStatement destInsert = destcon.prepareStatement(
+            "insert into weblogentry "+"("+columns+") "+"values (?,?,?,?,?,?,?,?,?)");
+        PreparedStatement destUpdate = destcon.prepareStatement(
+            "update weblogentry set id=?,anchor=?,title=?,text=?,pubtime=?,"
+            +"updatetime=?,websiteid=?,categoryid=?,publishentry=?"
+            +" where id=?");
+        
+        PreparedStatement parentExistsStmt = destcon.prepareStatement(
+            "select id from website where id=?");        
+        PreparedStatement categoryExistsStmt = destcon.prepareStatement(
+            "select id from weblogcategory where id=?");        
+
+        Statement srcStmt = srccon.createStatement();
+        ResultSet srcSet = srcStmt.executeQuery("select "+columns+" from weblogentry");
+        while (srcSet.next()) 
+        {
+            String id = srcSet.getString(id_num);
+            String websiteid = srcSet.getString(websiteid_num);
+            String categoryid = srcSet.getString(categoryid_num);
+            
+            destExistsStmt.clearParameters();
+            destExistsStmt.setString(id_num, id);
+            ResultSet destSet = destExistsStmt.executeQuery();
+            
+            parentExistsStmt.clearParameters();
+            parentExistsStmt.setString(id_num, websiteid);
+            ResultSet parentSet = parentExistsStmt.executeQuery();
+            boolean parentExists = parentSet.first();
+            
+            categoryExistsStmt.clearParameters();
+            categoryExistsStmt.setString(id_num, categoryid);
+            ResultSet categorySet = categoryExistsStmt.executeQuery();
+            boolean categoryExists = categorySet.first();
+            
+            if (!destSet.first() && parentExists && categoryExists)
+            {
+                debug("Inserting weblogentry id="+id);
+                destInsert.clearParameters();
+                destInsert.setString(id_num, id);
+                destInsert.setString(anchor_num, srcSet.getString(anchor_num));
+                destInsert.setString(title_num, srcSet.getString(title_num));
+                destInsert.setString(text_num, srcSet.getString(text_num));
+                destInsert.setTimestamp(pubtime_num, srcSet.getTimestamp(pubtime_num));
+                destInsert.setTimestamp(updatetime_num, srcSet.getTimestamp(updatetime_num));
+                destInsert.setString(websiteid_num, srcSet.getString(websiteid_num));
+                destInsert.setString(categoryid_num, srcSet.getString(categoryid_num));
+                destInsert.setBoolean(publishentry_num, srcSet.getBoolean(publishentry_num));
+                destInsert.executeUpdate();
+            }
+            else if (parentExists && categoryExists)
+            {
+                debug("Updating weblogentry id="+id);
+                destUpdate.clearParameters();
+                destUpdate.setString(id_num, id);
+                destUpdate.setString(anchor_num, srcSet.getString(anchor_num));
+                destUpdate.setString(title_num, srcSet.getString(title_num));
+                destUpdate.setString(text_num, srcSet.getString(text_num));
+                destUpdate.setTimestamp(pubtime_num, srcSet.getTimestamp(pubtime_num));
+                destUpdate.setTimestamp(updatetime_num, srcSet.getTimestamp(updatetime_num));
+                destUpdate.setString(websiteid_num, srcSet.getString(websiteid_num));
+                destUpdate.setString(categoryid_num, srcSet.getString(categoryid_num));
+                destUpdate.setBoolean(publishentry_num, srcSet.getBoolean(publishentry_num));
+                destUpdate.setString(10, srcSet.getString(id_num));
+                destUpdate.executeUpdate();
+            }                
+            else 
+            {
+                info("Not copying weblogentry id="+id);
+            }
+        }     
+        purgeDeleted(srccon,destcon,"weblogentry");
+    }
+    private void syncCommentTable(Connection srccon, Connection destcon) throws Exception
+    {
+        info("--- syncCommentTable ---");
+        
+        String columns = "id,entryid,name,email,url,content,posttime";
+        int id_num=1;
+        int entryid_num=2;
+        int name_num=3;
+        int email_num=4;
+        int url_num=5;
+        int content_num=6;
+        int posttime_num=7;
+        
+        PreparedStatement destExistsStmt = destcon.prepareStatement(
+            "select id from comment where id=?");
+        PreparedStatement destInsert = destcon.prepareStatement(
+            "insert into comment "+"("+columns+") "+"values (?,?,?,?,?,?,?)");
+        PreparedStatement destUpdate = destcon.prepareStatement(
+            "update comment set id=?,entryid=?,name=?,email=?,url=?,content=?,posttime=?"
+            +" where id=?");
+        
+        PreparedStatement parentExistsStmt = destcon.prepareStatement(
+            "select id from weblogentry where id=?");        
+
+        Statement srcStmt = srccon.createStatement();
+        ResultSet srcSet = srcStmt.executeQuery("select "+columns+" from comment");
+        while (srcSet.next()) 
+        {
+            String id = srcSet.getString(id_num);
+            String entryid = srcSet.getString(entryid_num);
+            
+            destExistsStmt.clearParameters();
+            destExistsStmt.setString(id_num, id);
+            ResultSet destSet = destExistsStmt.executeQuery();
+            
+            parentExistsStmt.clearParameters();
+            parentExistsStmt.setString(id_num, entryid);
+            ResultSet parentSet = parentExistsStmt.executeQuery();
+            boolean parentExists = parentSet.first();
+            
+            if (!destSet.first() && parentExists)
+            {
+                debug("Inserting comment id="+id);
+                destInsert.clearParameters();
+                destInsert.setString(id_num, id);
+                destInsert.setString(entryid_num, srcSet.getString(entryid_num));
+                destInsert.setString(name_num, srcSet.getString(name_num));
+                destInsert.setString(email_num, srcSet.getString(email_num));
+                destInsert.setString(url_num, srcSet.getString(url_num));
+                destInsert.setString(content_num, srcSet.getString(content_num));
+                destInsert.setTimestamp(posttime_num, srcSet.getTimestamp(posttime_num));
+                destInsert.executeUpdate();
+            }
+            else if (parentExists)
+            {
+                debug("Updating comment id="+id);
+                destUpdate.clearParameters();
+                destUpdate.setString(id_num, id);
+                destUpdate.setString(entryid_num, srcSet.getString(entryid_num));
+                destUpdate.setString(name_num, srcSet.getString(name_num));
+                destUpdate.setString(email_num, srcSet.getString(email_num));
+                destUpdate.setString(url_num, srcSet.getString(url_num));
+                destUpdate.setString(content_num, srcSet.getString(content_num));
+                destUpdate.setTimestamp(posttime_num, srcSet.getTimestamp(posttime_num));
+                destUpdate.setString(8, srcSet.getString(id_num));
+                destUpdate.executeUpdate();
+            }                
+            else 
+            {
+                info("Not copying comment id="+id);
+            }
+        }     
+        purgeDeleted(srccon,destcon,"comment");
+    }
+    private void syncRefererTable(Connection srccon, Connection destcon) throws Exception
+    {
+        info("--- syncRefererTable ---");
+        
+        String columns = "id,websiteid,entryid,datestr,refurl,refpermalink,"
+            +"reftime,requrl,title,excerpt,dayhits,totalhits,visible,duplicate";
+        int id_num = 1;
+        int websiteid_num = 2;
+        int entryid_num = 3;
+        int datestr_num = 4;
+        int refurl_num = 5;
+        int refpermalink_num = 6;        
+        int reftime_num = 7;
+        int requrl_num = 8;
+        int title_num = 9;
+        int excerpt_num = 10;
+        int dayhits_num = 11;
+        int totalhits_num = 12;
+        int visible_num = 13;
+        int duplicate_num = 14;
+        
+        PreparedStatement destExistsStmt = destcon.prepareStatement(
+            "select id from referer where id=?");
+        PreparedStatement destInsert = destcon.prepareStatement(
+            "insert into referer "+"("+columns+") "
+            +"values (?,?,?,?,?, ?,?,?,?,?, ?,?,?,?)");
+        PreparedStatement destUpdate = destcon.prepareStatement(
+            "update referer set id=?,websiteid=?,entryid=?,datestr=?,refurl=?,"
+            +"refpermalink=?,reftime=?,requrl=?,title=?,excerpt=?,dayhits=?,"
+            +"totalhits=?,visible=?,duplicate=?"
+            +" where id=?");
+        
+        PreparedStatement parentExistsStmt = destcon.prepareStatement(
+            "select id from website where id=?");        
+        
+        Statement srcStmt = srccon.createStatement();
+        // only sync those with excerpts
+        ResultSet srcSet = srcStmt.executeQuery(
+                "select "+columns+" from referer where excerpt is not null");
+        while (srcSet.next()) 
+        {
+            String id = srcSet.getString(id_num);
+            String entryid = srcSet.getString(entryid_num);
+            String websiteid = srcSet.getString(websiteid_num);
+            
+            destExistsStmt.clearParameters();
+            destExistsStmt.setString(id_num, id);
+            ResultSet destSet = destExistsStmt.executeQuery();
+                        
+            parentExistsStmt.clearParameters();
+            parentExistsStmt.setString(id_num, websiteid);
+            ResultSet parentSet = parentExistsStmt.executeQuery();
+            boolean parentExists = parentSet.first() || websiteid == null;
+
+            if (!destSet.first() && parentExists)
+            {
+                debug("Inserting referer id="+id);
+                destInsert.clearParameters();
+                
+                destInsert.setString(id_num, id);
+                destInsert.setString(websiteid_num, srcSet.getString(websiteid_num));
+                destInsert.setString(entryid_num, srcSet.getString(entryid_num));
+                destInsert.setString(datestr_num, srcSet.getString(datestr_num));
+                destInsert.setString(refurl_num, srcSet.getString(refurl_num));
+                
+                destInsert.setString(refpermalink_num, srcSet.getString(refpermalink_num));
+                destInsert.setString(reftime_num, srcSet.getString(reftime_num));
+                destInsert.setString(requrl_num, srcSet.getString(requrl_num));
+                destInsert.setString(title_num, srcSet.getString(title_num));
+                destInsert.setString(excerpt_num, srcSet.getString(excerpt_num));
+                
+                destInsert.setString(dayhits_num, srcSet.getString(dayhits_num));
+                destInsert.setString(totalhits_num, srcSet.getString(totalhits_num));
+                destInsert.setString(visible_num, srcSet.getString(visible_num));
+                destInsert.setString(duplicate_num, srcSet.getString(duplicate_num));
+                
+                destInsert.executeUpdate();
+            }
+            else if (parentExists)
+            {
+                debug("Updating referer id="+id);
+                destUpdate.clearParameters();
+                
+                destUpdate.setString(id_num, id);
+                destUpdate.setString(websiteid_num, srcSet.getString(websiteid_num));
+                destUpdate.setString(entryid_num, srcSet.getString(entryid_num));
+                destUpdate.setString(datestr_num, srcSet.getString(datestr_num));
+                destUpdate.setString(refurl_num, srcSet.getString(refurl_num));
+                
+                destUpdate.setString(refpermalink_num, srcSet.getString(refpermalink_num));
+                destUpdate.setString(reftime_num, srcSet.getString(reftime_num));
+                destUpdate.setString(requrl_num, srcSet.getString(requrl_num));
+                destUpdate.setString(title_num, srcSet.getString(title_num));
+                destUpdate.setString(excerpt_num, srcSet.getString(excerpt_num));
+                
+                destUpdate.setString(dayhits_num, srcSet.getString(dayhits_num));
+                destUpdate.setString(totalhits_num, srcSet.getString(totalhits_num));
+                destUpdate.setString(visible_num, srcSet.getString(visible_num));
+                destUpdate.setString(duplicate_num, srcSet.getString(duplicate_num));
+                
+                destUpdate.setString(15, srcSet.getString(id_num));
+                destUpdate.executeUpdate();
+            }                
+        }     
+        purgeDeleted(srccon,destcon,"referer");
+    }
+    /** for now... just for testing */
+    public static void main(String[] args) throws Exception 
+    {
+        if (args.length > 0) 
+        {
+            if ("-debug".equals(args[0])) 
+            {
+                debug = true;
+            }
+        }        
+        Properties props = new Properties();
+        props.load(new FileInputStream("rollerdb.properties"));
+        Connection destcon = ConsistencyCheck.createConnection(props,"");
+        Connection srccon = ConsistencyCheck.createConnection(props,"src.");
+        
+        new SyncUpgrade098Xto1000().syncUpgrade(srccon, destcon);
+    }
+}

Added: incubator/roller/trunk/src/org/roller/business/utils/UpgradeDatabase.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/utils/UpgradeDatabase.java?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/utils/UpgradeDatabase.java (added)
+++ incubator/roller/trunk/src/org/roller/business/utils/UpgradeDatabase.java Wed Jun  8 20:18:46 2005
@@ -0,0 +1,171 @@
+package org.roller.business.utils;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.roller.RollerException;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+/**
+ * Upgrade Roller database from 0.9.8 to 1.0.
+ * 
+ * Creates root Category for each Website and associations for each Category.
+ * Sets each Website's default Category and default Blogger.com Category
+ * Creates associations for each Folder.
+ */
+public class UpgradeDatabase
+{
+    private static Log mLogger = 
+        LogFactory.getFactory().getInstance(UpgradeDatabase.class);
+
+    public static void upgradeDatabase(Connection con) throws RollerException
+    {       
+        // get the db version first
+        try
+        {
+            Statement versionStatement = con.createStatement();
+            ResultSet versionResultSet = 
+              versionStatement.executeQuery("select dbversion from rollerconfig");
+            versionResultSet.next();
+            String dbversion = versionResultSet.getString(1);
+            if (dbversion != null) return;
+            
+        } catch(Exception e) {
+            // assume this is a new db using the roller_properties table
+            return;
+        }
+        
+        
+        try
+        {   
+            // Prepated statements for all queries in the loop
+            
+            PreparedStatement rootCatStatement = con.prepareStatement(
+               "select a.id from weblogcategoryassoc as a, weblogcategory as c "+
+               "where c.websiteid=? and a.categoryid=c.id and a.ancestorid is null and a.relation='PARENT'");                        
+            
+            PreparedStatement rootCatCreateStatement = con.prepareStatement(
+               "insert into weblogcategory (id,name,description,websiteid,image) "+
+               "values (?,'root','root',?,NULL)");                        
+            
+            PreparedStatement updateWebsiteStatement = con.prepareStatement(
+               "update website set bloggercatid=?, defaultcatid=? where id=?");                        
+            
+            PreparedStatement catsStatement = con.prepareStatement(
+               "select id from weblogcategory where websiteid=? and id<>?");                        
+            
+            PreparedStatement assocCreateStatement = con.prepareStatement(
+               "insert into weblogcategoryassoc (id,categoryid,ancestorid,relation) "+
+               "values (?,?,?,'PARENT')");                        
+
+            PreparedStatement rootFolderStatement = con.prepareStatement(
+                "select id from folder where websiteid=? and parentid is null");                        
+      
+            PreparedStatement foldersStatement = con.prepareStatement(
+                "select id,parentid from folder where websiteid=?");                        
+      
+            PreparedStatement folderAssocCreateStatement = con.prepareStatement(
+                "insert into folderassoc (id,folderid,ancestorid,relation) "+
+                "values (?,?,?,'PARENT')");                        
+
+            // loop through all websites
+            Statement websitesStatement = con.createStatement();
+            ResultSet websitesResultSet = 
+                websitesStatement.executeQuery("select id from website");
+            while (websitesResultSet.next()) 
+            {
+                String websiteId = websitesResultSet.getString(1);
+                mLogger.info("Upgrading website id="+websiteId);
+                
+                rootCatStatement.clearParameters();
+                rootCatStatement.setString(1, websiteId);
+                ResultSet rootCatResultSet = rootCatStatement.executeQuery();
+                
+                
+                if (!rootCatResultSet.first()) // if website has no root cat
+                {
+                    // then create one
+                    rootCatCreateStatement.clearParameters();
+                    rootCatCreateStatement.setString(1, websiteId+"R");
+                    rootCatCreateStatement.setString(2, websiteId);
+                    rootCatCreateStatement.executeUpdate();
+                    
+                    // and make it the default one for the website
+                    updateWebsiteStatement.clearParameters();
+                    updateWebsiteStatement.setString(1, websiteId+"R");
+                    updateWebsiteStatement.setString(2, websiteId+"R");
+                    updateWebsiteStatement.setString(3, websiteId);
+                    updateWebsiteStatement.executeUpdate();
+                    
+                    // and create an association for it
+                    assocCreateStatement.clearParameters();
+                    assocCreateStatement.setString(1, websiteId+"A0");
+                    assocCreateStatement.setString(2, websiteId+"R");
+                    assocCreateStatement.setString(3, null);
+                    assocCreateStatement.executeUpdate();
+
+                    // and create associations for all of it's children
+                    catsStatement.clearParameters();
+                    catsStatement.setString(1, websiteId);
+                    catsStatement.setString(2, websiteId+"R");
+                    ResultSet cats = catsStatement.executeQuery();
+                    int count = 1;
+                    while (cats.next())
+                    {
+                        String catid = cats.getString(1);
+                        assocCreateStatement.clearParameters();
+                        assocCreateStatement.setString(1, websiteId+"A"+count++);
+                        assocCreateStatement.setString(2, catid);
+                        assocCreateStatement.setString(3, websiteId+"R");
+                        assocCreateStatement.executeUpdate();
+                    }
+                    mLogger.debug("   Created root categories and associations");
+                    
+                    // determine root bookmark folder of website
+                    rootFolderStatement.clearParameters();
+                    rootFolderStatement.setString(1, websiteId);
+                    ResultSet rootFolderResultSet = rootFolderStatement.executeQuery();
+                    rootFolderResultSet.next();
+                    String rootFolderId = rootFolderResultSet.getString(1);
+                    
+                    // create associations for all children fo root folder
+                    foldersStatement.clearParameters();
+                    foldersStatement.setString(1, websiteId);
+                    ResultSet folders = foldersStatement.executeQuery();
+                    while (folders.next())
+                    {
+                        String id = folders.getString(1);
+                        String parentId = folders.getString(2);
+                        folderAssocCreateStatement.clearParameters();
+                        folderAssocCreateStatement.setString(1, id+"R");
+                        folderAssocCreateStatement.setString(2, id);
+                        if (parentId == null)
+                        {
+                            folderAssocCreateStatement.setString(3, null);
+                        }
+                        else
+                        {
+                            folderAssocCreateStatement.setString(3, rootFolderId);
+                        }
+                        folderAssocCreateStatement.executeUpdate();
+                    }
+                    mLogger.debug("   Created folder associations");
+                }
+            }
+            
+            Statement versionUpdateStatement = con.createStatement();
+            versionUpdateStatement.executeUpdate(
+                "update rollerconfig set dbversion='995'");
+            mLogger.info("Database upgrade complete.");
+        }
+        catch (SQLException e)
+        {
+            mLogger.error("ERROR in database upgrade",e);
+            throw new RollerException("ERROR in database upgrade",e);
+        }
+    }
+}

Added: incubator/roller/trunk/src/org/roller/config/PingConfig.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/config/PingConfig.java?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/config/PingConfig.java (added)
+++ incubator/roller/trunk/src/org/roller/config/PingConfig.java Wed Jun  8 20:18:46 2005
@@ -0,0 +1,267 @@
+/*
+ * Copyright (c) 2005
+ * Anil R. Gangolli. All rights reserved.
+ *
+ * Distributed with the Roller Weblogger Project under the terms of the Roller Software
+ * License
+ */
+
+package org.roller.config;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.roller.RollerException;
+import org.roller.model.PingTargetManager;
+import org.roller.model.RollerFactory;
+import org.roller.pojos.PingTargetData;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+// This may need to move to a different package, but it seems appropriate here in the current structure.
+// Previous placement in the presentation.pings package introduced the undesirable dependency of the
+// business package on the presentation package.
+
+/**
+ * Thin wrapper around RollerConfig and RollerRuntimeConfig for centralizing access to the many configurable
+ * settings for pings.
+ */
+public class PingConfig
+{
+    private static final Log logger = LogFactory.getLog(PingConfig.class);
+
+
+    // Inhibit construction
+    private PingConfig()
+    {
+    }
+
+    // Config property for maximim ping attempts.
+    static final String MAX_PING_ATTEMPTS_PROP = "pings.maxPingAttempts";
+    private static final int MAX_PING_ATTEMPTS_DEFAULT = 3;
+    private static final int MAX_PING_ATTEMPTS_MIN = 1;
+    private static final int MAX_PING_ATTEMPTS_MAX = 10;
+
+    // Config property for queue processing interval
+    private static final String QUEUE_PROCESSING_INTERVAL_PROP = "pings.queueProcessingIntervalMins";
+    private static final int QUEUE_PROCESSING_INTERVAL_DEFAULT = 5;
+    private static final int QUEUE_PROCESSING_INTERVAL_MIN = 0;
+    private static final int QUEUE_PROCESSING_INTERVAL_MAX = 120;
+
+    // PingConfig property for logging pings (not actually performing them).  Used for debugging.
+    private static final String PINGS_LOG_ONLY_PROP = "pings.logOnly";
+    private static final boolean PINGS_LOG_ONLY_DEFAULT = false;
+
+    // PingConfig property for controlling whether or not to allow custom ping targets
+    // ("Weblog:Custom Ping Targets" page and actions).  If absent, this defaults to false.
+    // with the enabledProperty behavior in editor-menu.xml.
+    // NOTE: If this property name is changed, editor-menu.xml must also be adjusted.
+    private static final String PINGS_DISALLOW_CUSTOM_TARGETS_PROP = "pings.disallowCustomTargets";
+    private static final boolean PINGS_DISALLOW_CUSTOM_TARGETS_DEFAULT = false;
+
+    // PingConfig property for controlling whether or not to allow usage of pings
+    // ("Weblog:Pings" page and actions).  If absent, this defaults to false
+    // NOTE: If this property name is changed, editor-menu.xml must also be adjusted.
+    private static final String PINGS_DISABLE_PING_USAGE_PROP = "pings.disablePingUsage";
+    private static final boolean PINGS_DISABLE_PING_USAGE_DEFAULT = false;
+
+    // PingConfig property for controlling suspending the processing of pings.  If true,
+    // new auto ping requests are not queued, any existing queued requests are not processed,
+    // and sending a manual ping results in a  message saying pings have been disabled.
+    // NOTE: This is a "runtime" property settable on the Admin:PingConfig page, default is false.
+    private static final String PINGS_SUSPEND_PING_PROCESSING_PROP = "pings.suspendPingProcessing";
+
+    // PingConfig property determining the initial common ping targets.  If the list of common
+    // ping targets is empty on startup, the value of this property is used to populate initial values.
+    // The value takes the form of comma-separated ping targets where each ping target is specified in
+    // the form {{name}{pingurl}}.  If an administrator wants to disable this initialization, in order to
+    // maintain an empty list of common targets, the administrator can disable the initialization by
+    // commenting out this property in the config file.
+    private static final String PINGS_INITIAL_COMMON_TARGETS_PROP = "pings.initialCommonTargets";
+
+    /**
+     * Get the maximum number of ping attempts that should be made for each ping queue entry before we give up. If we
+     * get apparently transient failures while trying to perform the ping, the entry is requeued for processing on later
+     * passes through the queue until this number of attempts has been reached.
+     *
+     * @return the configured (or default) maximum number of ping attempts
+     */
+    public static int getMaxPingAttempts()
+    {
+        return getIntegerProperty(MAX_PING_ATTEMPTS_PROP, MAX_PING_ATTEMPTS_DEFAULT,
+            MAX_PING_ATTEMPTS_MIN, MAX_PING_ATTEMPTS_MAX);
+    }
+
+    /**
+     * Get the ping queue processing interval in minutes.
+     *
+     * @return the configured (or default) queue processing interval in minutes.
+     */
+    public static int getQueueProcessingIntervalMins()
+    {
+        return getIntegerProperty(QUEUE_PROCESSING_INTERVAL_PROP, QUEUE_PROCESSING_INTERVAL_DEFAULT,
+            QUEUE_PROCESSING_INTERVAL_MIN, QUEUE_PROCESSING_INTERVAL_MAX);
+    }
+
+
+    /**
+     * Get the logs only setting.  Get configuration value determining whether pings are to be logged only (not sent).
+     * This configuration setting is used for development and debugging.
+     *
+     * @return the configured (or default) value of the logs only setting.
+     */
+    public static boolean getLogPingsOnly()
+    {
+        return getBooleanProperty(PINGS_LOG_ONLY_PROP, PINGS_LOG_ONLY_DEFAULT);
+    }
+
+    /**
+     * Determine whether the configuration disallows custom ping targets.  If this is true, users are not allowed to
+     * create or edit custom ping targets, and any auto ping configs that use them are ignored.
+     *
+     * @return the configured (or default) value of the "disallow custom targets" setting.
+     */
+    public static boolean getDisallowCustomTargets()
+    {
+        return getBooleanProperty(PINGS_DISALLOW_CUSTOM_TARGETS_PROP, PINGS_DISALLOW_CUSTOM_TARGETS_DEFAULT);
+    }
+
+    /**
+     * Determine whether the configuration disables ping usage (configuration of auto pings and sending of manual
+     * pings).  If this is true, all auto ping configus are removed at startup, the Weblog:Pings UI and the associated
+     * actions are disabled.
+     *
+     * @return the configured (or default) value of the enable ping usage setting.
+     */
+    public static boolean getDisablePingUsage()
+    {
+        return getBooleanProperty(PINGS_DISABLE_PING_USAGE_PROP, PINGS_DISABLE_PING_USAGE_DEFAULT);
+    }
+
+    /**
+     * Determine whether ping processing is suspended.  If this is true, new auto ping requests are not
+     * queued, any existing queued requests are not processed, and sending a manual ping results in a message saying
+     * pings have been disabled.
+     *
+     * @return the configured (or default) value of the suspend ping processing setting.
+     */
+    public static boolean getSuspendPingProcessing()
+    {
+        return RollerRuntimeConfig.getBooleanProperty(PINGS_SUSPEND_PING_PROCESSING_PROP);
+    }
+
+    // Each initial commmon ping target is specified in the format {{name}{url}}
+    private static final Pattern PING_TARGET_SPEC = Pattern.compile("\\{\\{(.*?)\\}\\{(.*?)\\}\\}");
+
+    /**
+     * Initialize the common ping targets from the configuration properties. If the current list of common ping targets
+     * is empty, and the <code>PINGS_INITIAL_COMMON_TARGETS_PROP</code> property is present in the configuration then,
+     * this method will use that value to initialize the common targets.  This is called on each server startup.
+     * <p/>
+     * Note: this is expected to be called during initialization  with transaction demarcation being handled by the
+     * caller.
+     *
+     * @see org.roller.presentation.RollerContext#contextInitialized(javax.servlet.ServletContextEvent)
+     */
+    public static void initializeCommonTargets() throws RollerException
+    {
+        String configuredVal = RollerConfig.getProperty(PINGS_INITIAL_COMMON_TARGETS_PROP);
+        if (configuredVal == null || configuredVal.trim().length() == 0)
+        {
+            if (logger.isDebugEnabled()) logger.debug("No (or empty) value of " + PINGS_INITIAL_COMMON_TARGETS_PROP + " present in the configuration.  Skipping initialization of commmon targets.");
+            return;
+        }
+        PingTargetManager pingTargetMgr = RollerFactory.getRoller().getPingTargetManager();
+        if (!pingTargetMgr.getCommonPingTargets().isEmpty())
+        {
+            if (logger.isDebugEnabled()) logger.debug("Some common ping targets are present in the database already.  Skipping initialization.");
+            return;
+        }
+
+        String[] configuredTargets = configuredVal.trim().split(",");
+        for (int i = 0; i < configuredTargets.length; i++)
+        {
+            // Trim space around the target spec
+            String thisTarget = configuredTargets[i].trim();
+            // skip empty ones
+            if (thisTarget.length() == 0) continue;
+            // parse the ith target and store it
+            Matcher m = PING_TARGET_SPEC.matcher(configuredTargets[i].trim());
+            if (m.matches() && m.groupCount() == 2)
+            {
+                String name = m.group(1);
+                String url = m.group(2);
+                logger.info("Creating common ping target '" + name + "' from configuration properties.");
+                PingTargetData pingTarget = pingTargetMgr.createCommonPingTarget(name, url);
+                pingTargetMgr.storePingTarget(pingTarget);
+            }
+            else
+            {
+                logger.error("Unable to parse configured initial ping target '" + configuredTargets[i] +
+                    "'. Skipping this target. Check your setting of the property " + PINGS_INITIAL_COMMON_TARGETS_PROP);
+            }
+        }
+    }
+
+
+    // TODO: Refactor functionality below to RollerConfig?
+
+    /**
+     * Get the value of an integer configuration property.
+     *
+     * @param propName     the property name
+     * @param defaultValue the default value if the property is not present
+     * @param min          the minimum allowed value
+     * @param max          the maximum allowed value
+     * @return the value as an integer; the default value if no configured value is present or if the configured value
+     *         is out of the specified range.
+     */
+    private static int getIntegerProperty(String propName, int defaultValue, int min, int max)
+    {
+        String configuredVal = RollerConfig.getProperty(propName);
+        if (configuredVal == null)
+        {
+            if (logger.isDebugEnabled()) logger.debug("PingConfig property '" + propName + "' is not present in the configuration.  Using default value: " + defaultValue);
+            return defaultValue;
+        }
+
+        int val;
+        try
+        {
+            val = Integer.parseInt(configuredVal);
+        }
+        catch (NumberFormatException ex)
+        {
+            logger.error("ERROR: PingConfig property '" + propName + "' is not an integer value.  Using default value: " + defaultValue);
+            return defaultValue;
+        }
+
+        if (val < min || val > max)
+        {
+            logger.error("ERROR: PingConfig property '" + propName + "' is outside the required range (" + min + ", " + max + ").  Using default value: " + defaultValue);
+            return defaultValue;
+        }
+
+        return val;
+    }
+
+    /**
+     * Get the value of a boolean property with specified default.
+     *
+     * @param propName     the property name
+     * @param defaultValue the default value if the property is not present
+     * @return the configured value or the default if it the configured value is not present.
+     */
+    private static boolean getBooleanProperty(String propName, boolean defaultValue)
+    {
+        String configuredVal = RollerConfig.getProperty(propName);
+        if (configuredVal == null)
+        {
+            if (logger.isDebugEnabled()) logger.debug("PingConfig property '" + propName + "' is not present in the configuration.  Using default value: " + defaultValue);
+            return defaultValue;
+        }
+        return Boolean.valueOf(configuredVal).booleanValue();
+    }
+
+
+}

Added: incubator/roller/trunk/src/org/roller/config/RollerConfig.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/config/RollerConfig.java?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/config/RollerConfig.java (added)
+++ incubator/roller/trunk/src/org/roller/config/RollerConfig.java Wed Jun  8 20:18:46 2005
@@ -0,0 +1,159 @@
+/*
+ * RollerConfig.java
+ *
+ */
+
+package org.roller.config;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StringWriter;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
+/**
+ * This is the single entry point for accessing configuration properties
+ * in Roller.
+ *
+ * @author Allen Gilliland
+ */
+public class RollerConfig {
+    
+    private static String default_config = "/roller.properties";
+    private static String custom_config = "/roller-custom.properties";
+    private static String custom_jvm_param = "roller.custom.config";
+    private static File custom_config_file = null;
+    
+    private static Properties mConfig;
+    
+    private static Log mLogger =
+            LogFactory.getFactory().getInstance(RollerConfig.class);
+    
+    
+    /*
+     * Static block run once at class loading
+     *
+     * We load the default properties and any custom properties we find
+     */
+    static {
+        mConfig = new Properties();
+        
+        try {
+            // we'll need this to get at our properties files in the classpath
+            Class config_class = Class.forName("org.roller.config.RollerConfig");
+            
+            // first, lets load our default properties
+            InputStream is = config_class.getResourceAsStream(default_config);
+            mConfig.load(is);
+            mLogger.info("successfully loaded default properties.");
+            
+            // now, see if we can find our custom config
+            is = config_class.getResourceAsStream(custom_config);
+            if(is != null) {
+                mConfig.load(is);
+                mLogger.info("successfully loaded custom properties file from classpath");
+            } else {
+                mLogger.info("no custom properties file found in classpath");
+            }
+            
+            // finally, check for an external config file
+            String env_file = System.getProperty(custom_jvm_param);
+            if(env_file != null && env_file.length() > 0) {
+                custom_config_file = new File(env_file);
+                
+                // make sure the file exists, then try and load it
+                if(custom_config_file != null && custom_config_file.exists()) {
+                    is = new FileInputStream(custom_config_file);
+                    mConfig.load(is);
+                    mLogger.info("successfully loaded custom properties from "+
+                            custom_config_file.getAbsolutePath());
+                } else {
+                    mLogger.warn("failed to load custom properties from "+
+                            custom_config_file.getAbsolutePath());
+                }
+                
+            } else {
+                mLogger.info("no custom properties file specified via jvm option");
+            }
+            
+            // some debugging for those that want it
+            if(mLogger.isDebugEnabled()) {
+                mLogger.debug("RollerConfig looks like this ...");
+                
+                String key = null;
+                Enumeration keys = mConfig.keys();
+                while(keys.hasMoreElements()) {
+                    key = (String) keys.nextElement();
+                    mLogger.debug(key+"="+mConfig.getProperty(key));
+                }
+            }
+            
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        
+    }
+    
+    
+    // no, you may not instantiate this class :p
+    private RollerConfig() {}
+    
+    
+    /**
+     * Retrieve a property value
+     *
+     * @param     key Name of the property
+     * @return    String Value of property requested, null if not found
+     **/
+    public static String getProperty(String key) {
+        mLogger.debug("Fetching property ["+key+"="+mConfig.getProperty(key)+"]");
+        return mConfig.getProperty(key);
+    }
+    
+    
+    /**
+     * Retrieve a property as a boolean ... defaults to false if there is an error
+     **/
+    public static boolean getBooleanProperty(String name) {
+        
+        // get the value first, then convert
+        String value = RollerConfig.getProperty(name);
+        
+        if(value == null)
+            return false;
+        
+        return (new Boolean(value)).booleanValue();
+    }
+    
+    
+    /**
+     * Retrieve all property keys
+     *
+     * @return Enumeration A list of all keys
+     **/
+    public static Enumeration keys() {
+        return mConfig.keys();
+    }
+    
+    
+    /**
+     * Set the "uploads.dir" property at runtime.
+     *
+     * Properties are meant to be read-only, but we make this one exception
+     * for now because we know that some people are still writing their
+     * uploads to the webapp context and we can only get that path at runtime.
+     */
+    public static void setUploadsDir(String path) {
+        
+        // only do this if the user wants to use the webapp context
+        if("${webapp.context}".equals(mConfig.getProperty("uploads.dir")))
+            mConfig.setProperty("uploads.dir", path);
+    }
+    
+}

Added: incubator/roller/trunk/src/org/roller/config/RollerRuntimeConfig.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/config/RollerRuntimeConfig.java?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/config/RollerRuntimeConfig.java (added)
+++ incubator/roller/trunk/src/org/roller/config/RollerRuntimeConfig.java Wed Jun  8 20:18:46 2005
@@ -0,0 +1,154 @@
+/*
+ * RollerRuntimeConfig.java
+ *
+ * Created on May 4, 2005, 3:00 PM
+ */
+
+package org.roller.config;
+
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StringWriter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.roller.config.runtime.RuntimeConfigDefs;
+import org.roller.config.runtime.RuntimeConfigDefsParser;
+import org.roller.model.PropertiesManager;
+import org.roller.model.RollerFactory;
+
+/**
+ * This class acts as a convenience gateway for getting property values
+ * via the PropertiesManager.  We do this because most calls to the
+ * PropertiesManager are just to get the value of a specific property and
+ * thus the caller doesn't need the full RollerPropertyData object.
+ *
+ * We also provide some methods for converting to different data types.
+ *
+ * @author Allen Gilliland
+ */
+public class RollerRuntimeConfig {
+    
+    private static String runtime_config = "/rollerRuntimeConfigDefs.xml";
+    private static RuntimeConfigDefs configDefs = null;
+    
+    private static Log mLogger = 
+        LogFactory.getFactory().getInstance(RollerRuntimeConfig.class);
+    
+    
+    // prevent instantiations
+    private RollerRuntimeConfig() {}
+    
+    
+    /**
+     * Retrieve a single property from the PropertiesManager ... returns null
+     * if there is an error
+     **/
+    public static String getProperty(String name) {
+        
+        String value = null;
+        try {
+            PropertiesManager pmgr = RollerFactory.getRoller().getPropertiesManager();
+            value = pmgr.getProperty(name).getValue();
+        } catch(Exception e) {
+            mLogger.warn("Trouble accessing property: "+name, e);
+        }
+        
+        mLogger.debug("fetched property ["+name+"="+value+"]");
+        
+        return value;
+    }
+    
+    
+    /**
+     * Retrieve a property as a boolean ... defaults to false if there is an error
+     **/
+    public static boolean getBooleanProperty(String name) {
+        
+        // get the value first, then convert
+        String value = RollerRuntimeConfig.getProperty(name);
+        
+        if(value == null)
+            return false;
+        
+        return (new Boolean(value)).booleanValue();
+    }
+    
+    
+    /**
+     * Retrieve a property as an int ... defaults to -1 if there is an error
+     **/
+    public static int getIntProperty(String name) {
+        
+        // get the value first, then convert
+        String value = RollerRuntimeConfig.getProperty(name);
+        
+        if(value == null)
+            return -1;
+        
+        int intval = -1;
+        try {
+            intval = Integer.parseInt(value);
+        } catch(Exception e) {
+            mLogger.warn("Trouble converting to int: "+name, e);
+        }
+        
+        return intval;
+    }
+    
+    
+    public static RuntimeConfigDefs getRuntimeConfigDefs() {
+        
+        if(configDefs == null) {
+            
+            // unmarshall the config defs file
+            try {
+                InputStream is = 
+                        RollerConfig.class.getResourceAsStream(runtime_config);
+                
+                RuntimeConfigDefsParser parser = new RuntimeConfigDefsParser();
+                configDefs = parser.unmarshall(is);
+                
+            } catch(Exception e) {
+                // error while parsing :(
+                mLogger.error("Error parsing runtime config defs", e);
+            }
+            
+        }
+        
+        return configDefs;
+    }
+    
+    
+    /**
+     * Get the runtime configuration definitions XML file as a string.
+     *
+     * This is basically a convenience method for accessing this file.
+     * The file itself contains meta-data about what configuration
+     * properties we change at runtime via the UI and how to setup
+     * the display for editing those properties.
+     */
+    public static String getRuntimeConfigDefsAsString() {
+        
+        mLogger.debug("Trying to load runtime config defs file");
+        
+        try {
+            InputStreamReader reader =
+                    new InputStreamReader(RollerConfig.class.getResourceAsStream(runtime_config));
+            StringWriter configString = new StringWriter();
+            
+            char[] buf = new char[8196];
+            int length = 0;
+            while((length = reader.read(buf)) > 0)
+                configString.write(buf, 0, length);
+            
+            reader.close();
+            
+            return configString.toString();
+        } catch(Exception e) {
+            mLogger.error("Error loading runtime config defs file", e);
+        }
+        
+        return "";
+    }
+    
+}

Added: incubator/roller/trunk/src/org/roller/config/runtime/ConfigDef.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/config/runtime/ConfigDef.java?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/config/runtime/ConfigDef.java (added)
+++ incubator/roller/trunk/src/org/roller/config/runtime/ConfigDef.java Wed Jun  8 20:18:46 2005
@@ -0,0 +1,62 @@
+/*
+ * ConfigDef.java
+ *
+ * Created on June 4, 2005, 1:10 PM
+ */
+
+package org.roller.config.runtime;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represents a logic grouping of runtime configuration properties.
+ * Each ConfigDef may contain 0 or more DisplayGroups.
+ *
+ * @author Allen Gilliland
+ */
+public class ConfigDef {
+    
+    private List displayGroups = null;
+    private String name = null;
+    
+    
+    public ConfigDef() {
+        this.displayGroups = new ArrayList();
+    }
+
+    public ConfigDef(List displaygroups) {
+        this.displayGroups = displaygroups;
+    }
+
+    
+    public boolean addDisplayGroup(DisplayGroup group) {
+        return this.displayGroups.add(group);
+    }
+    
+    public boolean removeDisplayGroup(DisplayGroup group) {
+        return this.displayGroups.remove(group);
+    }
+    
+    
+    public String toString() {
+        return name;
+    }
+    
+    public List getDisplayGroups() {
+        return displayGroups;
+    }
+
+    public void setDisplayGroups(List displayGroups) {
+        this.displayGroups = displayGroups;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+    
+}

Added: incubator/roller/trunk/src/org/roller/config/runtime/DisplayGroup.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/config/runtime/DisplayGroup.java?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/config/runtime/DisplayGroup.java (added)
+++ incubator/roller/trunk/src/org/roller/config/runtime/DisplayGroup.java Wed Jun  8 20:18:46 2005
@@ -0,0 +1,72 @@
+/*
+ * DisplayGroup.java
+ *
+ * Created on June 4, 2005, 1:10 PM
+ */
+
+package org.roller.config.runtime;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represents a single DisplayGroup.
+ * Each DisplayGroup may contain 0 or more PropertyDefs.
+ *
+ * @author Allen Gilliland
+ */
+public class DisplayGroup {
+    
+    private List propertyDefs = null;
+    private String name = null;
+    private String key = null;
+    
+    
+    public DisplayGroup() {
+        this.propertyDefs = new ArrayList();
+    }
+    
+    public DisplayGroup(List propdefs) {
+        this.propertyDefs = propdefs;
+    }
+    
+    
+    public boolean addPropertyDef(PropertyDef prop) {
+        return this.propertyDefs.add(prop);
+    }
+    
+    public boolean removePropertyDef(PropertyDef prop) {
+        return this.propertyDefs.remove(prop);
+    }
+    
+
+    public String toString() {
+        return name+","+key;
+    }
+    
+    public List getPropertyDefs() {
+        return propertyDefs;
+    }
+
+    public void setPropertyDefs(List propertyDefs) {
+        this.propertyDefs = propertyDefs;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getKey() {
+        return key;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+    
+    
+}

Added: incubator/roller/trunk/src/org/roller/config/runtime/PropertyDef.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/config/runtime/PropertyDef.java?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/config/runtime/PropertyDef.java (added)
+++ incubator/roller/trunk/src/org/roller/config/runtime/PropertyDef.java Wed Jun  8 20:18:46 2005
@@ -0,0 +1,105 @@
+/*
+ * PropertyDef.java
+ *
+ * Created on June 4, 2005, 1:13 PM
+ */
+
+package org.roller.config.runtime;
+
+/**
+ * Represents the definition of a single runtime property.
+ *
+ * Each property definition may contain these elements
+ *   - name (required)
+ *   - key (required)
+ *   - type (required)
+ *   - default-value (required)
+ *   - rows (optional)
+ *   - cols (options)
+ *
+ * @author Allen Gilliland
+ */
+public class PropertyDef {
+    
+    private String name = null;
+    private String key = null;
+    private String type = null;
+    private String defaultValue = null;
+    private int rows = 5;
+    private int cols = 25;
+    
+    
+    /** Creates a new instance of PropertyDef */
+    public PropertyDef() {}
+
+    public String toString() {
+        return "["+name+","+key+","+type+","+defaultValue+","+rows+","+cols+"]";
+    }
+    
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getKey() {
+        return key;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getDefaultValue() {
+        return defaultValue;
+    }
+
+    public void setDefaultValue(String defaultvalue) {
+        this.defaultValue = defaultvalue;
+    }
+
+    public int getRows() {
+        return rows;
+    }
+
+    public void setRows(int rows) {
+        this.rows = rows;
+    }
+
+    public void setRows(String rows) {
+        //convert to int
+        try {
+            int r = Integer.parseInt(rows);
+            this.rows = r;
+        } catch(Exception e) {
+            // hmmm ... bogus value
+        }
+    }
+    public int getCols() {
+        return cols;
+    }
+
+    public void setCols(int cols) {
+        this.cols = cols;
+    }
+    
+    public void setCols(String cols) {
+        //convert to int
+        try {
+            int c = Integer.parseInt(cols);
+            this.cols = c;
+        } catch(Exception e) {
+            // hmmm ... bogus value
+        }
+    }
+}

Added: incubator/roller/trunk/src/org/roller/config/runtime/RuntimeConfigDefs.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/config/runtime/RuntimeConfigDefs.java?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/config/runtime/RuntimeConfigDefs.java (added)
+++ incubator/roller/trunk/src/org/roller/config/runtime/RuntimeConfigDefs.java Wed Jun  8 20:18:46 2005
@@ -0,0 +1,49 @@
+/*
+ * RuntimeConfigDefs.java
+ *
+ * Created on June 4, 2005, 1:06 PM
+ */
+
+package org.roller.config.runtime;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * Represents the collection of all ConfigDefs.
+ *
+ * @author Allen Gilliland
+ */
+public class RuntimeConfigDefs {
+    
+    private List configDefs = null;
+    
+    
+    public RuntimeConfigDefs() {
+        this.configDefs = new ArrayList();
+    }
+
+    public RuntimeConfigDefs(List configs) {
+        this.configDefs = configs;
+    }
+    
+    
+    public boolean addConfigDef(ConfigDef config) {
+        return this.configDefs.add(config);
+    }
+    
+    public boolean removeConfigDef(ConfigDef config) {
+        return this.configDefs.remove(config);
+    }
+    
+    
+    public List getConfigDefs() {
+        return configDefs;
+    }
+
+    public void setConfigDefs(List configDefs) {
+        this.configDefs = configDefs;
+    }
+    
+}



Mime
View raw message