roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r797783 [1/2] - in /roller/trunk/apps/weblogger: ./ nbproject/ src/java/org/apache/roller/weblogger/business/ src/java/org/apache/roller/weblogger/business/jpa/ src/java/org/apache/roller/weblogger/config/ src/java/org/apache/roller/weblogg...
Date Sat, 25 Jul 2009 15:50:26 GMT
Author: snoopdave
Date: Sat Jul 25 15:50:25 2009
New Revision: 797783

URL: http://svn.apache.org/viewvc?rev=797783&view=rev
Log:
Implementation for Media Blogging: migrate old resources to new system
https://issues.apache.org/jira/browse/ROL-1815

Migration is currently turned off because I'm still testing it and not ready to mark this resolved. 

Includes a test and some test data. 

Added:
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java   (contents, props changed)
      - copied, changed from r791290, roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/MediaFileManagerImpl.java
    roller/trunk/apps/weblogger/test/java/hawk.jpg   (with props)
    roller/trunk/apps/weblogger/testdata/WEB-INF/classes/hawk.jpg   (with props)
    roller/trunk/apps/weblogger/testdata/uploadsdir/
    roller/trunk/apps/weblogger/testdata/uploadsdir/testblog1/
    roller/trunk/apps/weblogger/testdata/uploadsdir/testblog1/hawk.jpg   (with props)
    roller/trunk/apps/weblogger/testdata/uploadsdir/testblog1/nasa.jpg   (with props)
    roller/trunk/apps/weblogger/testdata/uploadsdir/testblog1/roller50-prop.png   (with props)
    roller/trunk/apps/weblogger/testdata/uploadsdir/testblog2/
    roller/trunk/apps/weblogger/testdata/uploadsdir/testblog2/amsterdam.jpg   (with props)
    roller/trunk/apps/weblogger/testdata/uploadsdir/testblog2/p47-thunderbolt.jpg   (with props)
    roller/trunk/apps/weblogger/testdata/uploadsdir/testblog2/rollerwiki.png   (with props)
Removed:
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/MediaFileManagerImpl.java
Modified:
    roller/trunk/apps/weblogger/   (props changed)
    roller/trunk/apps/weblogger/build.xml
    roller/trunk/apps/weblogger/nbproject/project.xml
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/FileContentManager.java
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/FileContentManagerImpl.java
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/MediaFileManager.java
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/WebloggerImpl.java
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAWeblogManagerImpl.java
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAWebloggerModule.java
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/config/roller.properties
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/MediaFileDirectory.java
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/util/Utilities.java
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/atomprotocol/MediaCollection.java
    roller/trunk/apps/weblogger/test/java/org/apache/roller/weblogger/business/FileContentManagerTest.java
    roller/trunk/apps/weblogger/test/java/org/apache/roller/weblogger/business/MediaFileTest.java
    roller/trunk/apps/weblogger/testdata/roller-custom.properties

Propchange: roller/trunk/apps/weblogger/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Sat Jul 25 15:50:25 2009
@@ -1,4 +1,6 @@
 velocity.log
+scratch.txt
 done
 build
+derby.log
 dist

Modified: roller/trunk/apps/weblogger/build.xml
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/build.xml?rev=797783&r1=797782&r2=797783&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/build.xml (original)
+++ roller/trunk/apps/weblogger/build.xml Sat Jul 25 15:50:25 2009
@@ -625,7 +625,7 @@
         
         <!-- Copy test resources -->
         <copy todir="${build.compile.tests}">
-            <fileset dir="${ro.tests}" excludes="**/*.java, **/*.html, **/*.png" />
+            <fileset dir="${ro.tests}" excludes="**/*.java, **/*.html" />
         </copy>
         
         <!-- 
@@ -701,7 +701,10 @@
                     
                     <!-- plugins test suite -->
                     <include name="org/apache/roller/weblogger/business/plugins/PluginsTestSuite.class" />
-                    
+
+                    <!-- mediafile test suite -->
+                    <include name="org/apache/roller/weblogger/business/CoreMediaFileServicesTestSuite.class" />
+
                 </fileset>
             </batchtest>
         </junit>
@@ -854,7 +857,6 @@
     </target>
     
     <!-- You can specify testClass using -DtestClass=foo -->
-    <property name="testClass" value="org.apache.roller.business.TaskLockTest"/>
     <target name="test-one" depends="build-tests">
         <java classname="junit.textui.TestRunner" fork="yes" failonerror="false">
             <arg value="${testClass}"/>
@@ -863,7 +865,29 @@
             </classpath>
         </java>
     </target>
-    
+
+    <!-- You can specify testClass using -DtestClass=foo -->
+    <target name="test-one-with-db" depends="build-tests">
+
+        <!-- allow for startup and initialization of test db -->
+        <antcall target="${test.db.startTask}" />
+        <antcall target="${test.db.initTask}" />
+
+        <java classname="junit.textui.TestRunner" dir="${build.tests}" fork="yes" failonerror="false">
+            <arg value="${testClass}"/>
+            <classpath>
+                <path refid="tests.run.path"/>
+            </classpath>
+            <jvmarg value="-Dcatalina.base=${build.tests}"/>
+            <jvmarg value="-Dro.build=${ro.build}"/>
+            <jvmarg value="-Droller.custom.config=${build.tests}/roller-custom.properties"/>
+        </java>
+        
+        <!-- allow for shutdown of test db -->
+        <antcall target="${test.db.stopTask}" />
+
+    </target>
+
     <!-- ********************************************************************* -->
     <!-- EXPERIMENTAL targets -->
     <!-- ********************************************************************* -->
@@ -944,6 +968,7 @@
         <taskdef name="stopdb" classname="org.apache.roller.weblogger.ant.StopDerbyTask" 
                  classpath="${ro.tools}/buildtime/derby.jar;${ro.tools}/buildtime/derbynet.jar;${build.compile.tests}" />
         <stopdb port="3219"/>
+        <delete dir="${build.tests}/derby-system/roller" />
     </target>
     
     <!-- ********************************************************************* -->

Modified: roller/trunk/apps/weblogger/nbproject/project.xml
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/nbproject/project.xml?rev=797783&r1=797782&r2=797783&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/nbproject/project.xml (original)
+++ roller/trunk/apps/weblogger/nbproject/project.xml Sat Jul 25 15:50:25 2009
@@ -132,7 +132,7 @@
                 <package-root>src/java</package-root>
                 <package-root>test/java</package-root>
                 <package-root>docs/examples/plugins/pluginmodel/src</package-root>
-                <classpath mode="compile">../../tools/roller-core/roller-core.jar:../../tools/roller-planet/roller-planet-business.jar:../../tools/buildtime/activation.jar:../../tools/buildtime/mail.jar:../../tools/buildtime/tomcat-5.0.28/jsp-api.jar:../../tools/buildtime/tomcat-5.0.28/servlet-api.jar:../../tools/lib/commons-codec-1.3.jar:../../tools/lib/commons-collections-3.2.jar:../../tools/lib/commons-digester-1.6.jar:../../tools/lib/commons-id-0.1-SNAPSHOT.jar:../../tools/lib/commons-lang-2.1.jar:../../tools/lib/commons-logging-1.0.4.jar:../../tools/lib/concurrent-1.3.2.jar:../../tools/lib/guice-1.0.jar:../../tools/lib/jaxen-full.jar:../../tools/lib/jdom.jar:../../tools/lib/log4j-1.2.11.jar:../../tools/lib/lucene-1.4.3.jar:../../tools/lib/rome-fetcher-0.9.jar:../../tools/lib/saxpath.jar:../../tools/lib/taglibs-string.jar:../../tools/lib/velocity-1.5.jar:../../tools/openjpa-0.9.7/geronimo-j2ee-connector_1.5_spec-1.0.1.jar:../../tools/openjpa-0.9.7/geronimo-jpa_3.0_spec-1
 .0.jar:../../tools/openjpa-0.9.7/geronimo-jta_1.0.1B_spec-1.0.1.jar:../../tools/openjpa-0.9.7/openjpa-0.9.7-incubating.jar:../../tools/openjpa-0.9.7/serp-1.11.0.jar:../../tools/xmlrpc-3.0/lib/ws-commons-util-1.0.1.jar:../../tools/xmlrpc-3.0/lib/xmlrpc-client-3.0.jar:../../tools/xmlrpc-3.0/lib/xmlrpc-common-3.0.jar:../../tools/xmlrpc-3.0/lib/xmlrpc-server-3.0.jar:../../tools/jakarta-taglibs-standard-1.1.2/lib/jstl.jar:../../tools/jakarta-taglibs-standard-1.1.2/lib/serializer.jar:../../tools/jakarta-taglibs-standard-1.1.2/lib/standard.jar:../../tools/jakarta-taglibs-standard-1.1.2/lib/xalan.jar:../../tools/buildtime/junit-4.1.jar:../../tools/buildtime/ant-1.7.0/ant.jar:../../tools/buildtime/derbyclient.jar:../../tools/buildtime/derby.jar:../../tools/buildtime/derbynet.jar:../../tools/buildtime/mockrunner-0.35/lib/mockrunner-servlet.jar:../../tools/buildtime/mockrunner-0.35/lib/mockrunner-struts.jar:../../tools/buildtime/mockrunner-0.35/lib/mockrunner.jar:../../tools/buildtime/
 mockrunner-0.35/lib/nekohtml.jar:../../tools/struts-2.0.9/lib/antlr-2.7.2.jar:../../tools/struts-2.0.9/lib/commons-beanutils-1.6.jar:../../tools/struts-2.0.9/lib/commons-chain-1.1.jar:../../tools/struts-2.0.9/lib/commons-fileupload-1.2.jar:../../tools/struts-2.0.9/lib/commons-io-1.3.1.jar:../../tools/struts-2.0.9/lib/commons-validator-1.3.0.jar:../../tools/struts-2.0.9/lib/freemarker-2.3.8.jar:../../tools/struts-2.0.9/lib/ognl-2.6.11.jar:../../tools/struts-2.0.9/lib/oro-2.0.8.jar:../../tools/struts-2.0.9/lib/struts2-core-2.0.9.jar:../../tools/struts-2.0.9/lib/struts2-spring-plugin-2.0.9.jar:../../tools/struts-2.0.9/lib/struts2-tiles-plugin-2.0.9.jar:../../tools/struts-2.0.9/lib/tiles-api-2.0.4.jar:../../tools/struts-2.0.9/lib/tiles-core-2.0.4.jar:../../tools/struts-2.0.9/lib/tiles-jsp-2.0.4.jar:../../tools/struts-2.0.9/lib/xwork-2.0.4.jar:../../tools/lib/commons-httpclient-3.0.1.jar:../../tools/lib/dom3-xercesImpl.jar:../../tools/lib/nekohtml.jar:../../tools/lib/openxri-synt
 ax.jar:../../tools/lib/apache-xml-security.jar:../../tools/lib/dom3-xml-apis.jar:../../tools/lib/openxri-client.jar:../../tools/spring-2.5/spring-2.5.4.jar:../../tools/spring-2.5/spring-security-openid-2.0.3.jar:../../tools/spring-2.5/spring-ldap-1.2.1.jar:../../tools/spring-2.5/spring-security-taglibs-2.0.3.jar:../../tools/spring-2.5/spring-security-acl-2.0.3.jar:../../tools/spring-2.5/spring-web-2.5.4.jar:../../tools/spring-2.5/spring-security-core-2.0.3.jar:../../tools/oauth/commons-httpclient-3.1.jar:../../tools/oauth/httpclient-4.0-beta1.jar:../../tools/oauth/httpcore-4.0-beta2.jar:../../tools/oauth/oauth-core-20090121.jar:../../tools/lib/rome-1.0.jar:../../tools/lib/rome-fetcher-1.0.jar:../../tools/lib/rome-propono-1.0.jar</classpath>
+                <classpath mode="compile">../../tools/roller-core/roller-core.jar:../../tools/roller-planet/roller-planet-business.jar:../../tools/buildtime/activation.jar:../../tools/buildtime/mail.jar:../../tools/buildtime/tomcat-5.0.28/jsp-api.jar:../../tools/buildtime/tomcat-5.0.28/servlet-api.jar:../../tools/lib/commons-codec-1.3.jar:../../tools/lib/commons-collections-3.2.jar:../../tools/lib/commons-digester-1.6.jar:../../tools/lib/commons-id-0.1-SNAPSHOT.jar:../../tools/lib/commons-lang-2.1.jar:../../tools/lib/commons-logging-1.0.4.jar:../../tools/lib/concurrent-1.3.2.jar:../../tools/lib/guice-1.0.jar:../../tools/lib/jaxen-full.jar:../../tools/lib/jdom.jar:../../tools/lib/log4j-1.2.11.jar:../../tools/lib/lucene-1.4.3.jar:../../tools/lib/rome-fetcher-0.9.jar:../../tools/lib/saxpath.jar:../../tools/lib/taglibs-string.jar:../../tools/lib/velocity-1.5.jar:../../tools/xmlrpc-3.0/lib/ws-commons-util-1.0.1.jar:../../tools/xmlrpc-3.0/lib/xmlrpc-client-3.0.jar:../../tools/xmlr
 pc-3.0/lib/xmlrpc-common-3.0.jar:../../tools/xmlrpc-3.0/lib/xmlrpc-server-3.0.jar:../../tools/jakarta-taglibs-standard-1.1.2/lib/jstl.jar:../../tools/jakarta-taglibs-standard-1.1.2/lib/serializer.jar:../../tools/jakarta-taglibs-standard-1.1.2/lib/standard.jar:../../tools/jakarta-taglibs-standard-1.1.2/lib/xalan.jar:../../tools/buildtime/junit-4.1.jar:../../tools/buildtime/ant-1.7.0/ant.jar:../../tools/buildtime/derbyclient.jar:../../tools/buildtime/derby.jar:../../tools/buildtime/derbynet.jar:../../tools/buildtime/mockrunner-0.35/lib/mockrunner-servlet.jar:../../tools/buildtime/mockrunner-0.35/lib/mockrunner-struts.jar:../../tools/buildtime/mockrunner-0.35/lib/mockrunner.jar:../../tools/buildtime/mockrunner-0.35/lib/nekohtml.jar:../../tools/struts-2.0.9/lib/antlr-2.7.2.jar:../../tools/struts-2.0.9/lib/commons-beanutils-1.6.jar:../../tools/struts-2.0.9/lib/commons-chain-1.1.jar:../../tools/struts-2.0.9/lib/commons-fileupload-1.2.jar:../../tools/struts-2.0.9/lib/commons-io-1.3
 .1.jar:../../tools/struts-2.0.9/lib/commons-validator-1.3.0.jar:../../tools/struts-2.0.9/lib/freemarker-2.3.8.jar:../../tools/struts-2.0.9/lib/ognl-2.6.11.jar:../../tools/struts-2.0.9/lib/oro-2.0.8.jar:../../tools/struts-2.0.9/lib/struts2-core-2.0.9.jar:../../tools/struts-2.0.9/lib/struts2-spring-plugin-2.0.9.jar:../../tools/struts-2.0.9/lib/struts2-tiles-plugin-2.0.9.jar:../../tools/struts-2.0.9/lib/tiles-api-2.0.4.jar:../../tools/struts-2.0.9/lib/tiles-core-2.0.4.jar:../../tools/struts-2.0.9/lib/tiles-jsp-2.0.4.jar:../../tools/struts-2.0.9/lib/xwork-2.0.4.jar:../../tools/lib/commons-httpclient-3.0.1.jar:../../tools/lib/dom3-xercesImpl.jar:../../tools/lib/nekohtml.jar:../../tools/lib/openxri-syntax.jar:../../tools/lib/apache-xml-security.jar:../../tools/lib/dom3-xml-apis.jar:../../tools/lib/openxri-client.jar:../../tools/spring-2.5/spring-2.5.4.jar:../../tools/spring-2.5/spring-security-openid-2.0.3.jar:../../tools/spring-2.5/spring-ldap-1.2.1.jar:../../tools/spring-2.5/spr
 ing-security-taglibs-2.0.3.jar:../../tools/spring-2.5/spring-security-acl-2.0.3.jar:../../tools/spring-2.5/spring-web-2.5.4.jar:../../tools/spring-2.5/spring-security-core-2.0.3.jar:../../tools/oauth/commons-httpclient-3.1.jar:../../tools/oauth/httpclient-4.0-beta1.jar:../../tools/oauth/httpcore-4.0-beta2.jar:../../tools/oauth/oauth-core-20090121.jar:../../tools/lib/rome-1.0.jar:../../tools/lib/rome-fetcher-1.0.jar:../../tools/lib/rome-propono-1.0.jar:../../tools/openjpa-1.2.1/geronimo-jpa_3.0_spec-1.0.jar</classpath>
                 <source-level>1.5</source-level>
             </compilation-unit>
         </java-data>

Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/FileContentManager.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/FileContentManager.java?rev=797783&r1=797782&r2=797783&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/FileContentManager.java (original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/FileContentManager.java Sat Jul 25 15:50:25 2009
@@ -15,7 +15,6 @@
  * copyright in this work, please see the NOTICE file in the top level
  * directory of this distribution.
  */
-
 package org.apache.roller.weblogger.business;
 
 import java.io.InputStream;
@@ -24,12 +23,11 @@
 import org.apache.roller.weblogger.pojos.Weblog;
 import org.apache.roller.weblogger.util.RollerMessages;
 
-
 /**
  * Interface for managing contents of the files uploaded to Roller.
  */
 public interface FileContentManager {
-    
+
     /**
      * Get a reference to the content of a specific file in a weblog's uploads area.
      * 
@@ -42,10 +40,9 @@
      * @throws FileNotFoundException If path does not exist.
      * @throws FilePathException If path is invalid, or can't be read.
      */
-    public FileContent getFileContent(Weblog weblog, String fileId) 
-    throws FileNotFoundException, FilePathException;
-    
-    
+    public FileContent getFileContent(Weblog weblog, String fileId)
+            throws FileNotFoundException, FilePathException;
+
     /**
      * Save a file's content to weblog's uploads area.
      * 
@@ -57,12 +54,11 @@
      * @throws FilePathException If path is invalid, is not a directory, or can't be read.
      * @throws FileIOException If there is an unexpected error during the save.
      */
-    public void saveFileContent(Weblog weblog, 
+    public void saveFileContent(Weblog weblog,
             String fileId,
-            InputStream is) 
-    throws FileNotFoundException, FilePathException, FileIOException;
-    
-    
+            InputStream is)
+            throws FileNotFoundException, FilePathException, FileIOException;
+
     /**
      * Delete file content from weblog's uploads area.
      * 
@@ -73,10 +69,9 @@
      * @throws FilePathException If path is invalid, or can't be read.
      * @throws FileIOException If there is an unexpected error during the delete.
      */
-    public void deleteFile(Weblog weblog, String fileId) 
-        throws FileNotFoundException, FilePathException, FileIOException;
-    
-    
+    public void deleteFile(Weblog weblog, String fileId)
+            throws FileNotFoundException, FilePathException, FileIOException;
+
     /**
      * Delete all files associated with a given weblog.
      *
@@ -86,9 +81,8 @@
      * @throws FileIOException If there is an unexpected error during the delete.
      */
     public void deleteAllFiles(Weblog weblog)
-        throws FileIOException;
-    
-    
+            throws FileIOException;
+
     /** 
      * Is the given weblog over the file-upload quota limit?
      *
@@ -96,7 +90,7 @@
      * @return True if weblog is over set quota, False otherwise.
      */
     public boolean overQuota(Weblog weblog);
-    
+
     /**
      * Determine if file can be saved given current WebloggerConfig settings.
      * 
@@ -108,14 +102,14 @@
      * @return true if the file can be saved, false otherwise. 
      */
     public boolean canSave(Weblog weblog,
-    		               String fileName,
-                           String contentType,
-                           long size, 
-                           RollerMessages messages);
-    
+            String fileName,
+            String contentType,
+            long size,
+            RollerMessages messages);
+
     /**
      * Release all resources associated with Roller session.
      */
     public void release();
-    
+
 }

Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/FileContentManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/FileContentManagerImpl.java?rev=797783&r1=797782&r2=797783&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/FileContentManagerImpl.java (original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/FileContentManagerImpl.java Sat Jul 25 15:50:25 2009
@@ -44,27 +44,33 @@
 	
     private static Log log = LogFactory.getLog(FileContentManagerImpl.class);
     
-    private String upload_dir = null;
-    
-    
+    private String storage_dir = null;
+
     /**
      * Create file content manager.
      */
     public FileContentManagerImpl() {
-        String uploaddir = WebloggerConfig.getProperty("uploads.dir");
+        
+        String storagedir = WebloggerConfig.getProperty("mediafiles.storage.dir");
         
         // Note: System property expansion is now handled by WebloggerConfig.
         
-        if(uploaddir == null || uploaddir.trim().length() < 1)
-            uploaddir = System.getProperty("user.home") + File.separator+"roller_data"+File.separator+"uploads";
+        if (storagedir == null || storagedir.trim().length() < 1)
+            storagedir = System.getProperty("user.home")
+                + File.separator+"roller_data"+File.separator+"mediafiles";
         
-        if( ! uploaddir.endsWith(File.separator))
-            uploaddir += File.separator;
+        if (! storagedir.endsWith(File.separator))
+            storagedir += File.separator;
         
-        this.upload_dir = uploaddir.replace('/',File.separatorChar);
+        this.storage_dir = storagedir.replace('/',File.separatorChar);
     }
     
-    
+    public void initialize() {
+
+    }
+
+
+
     /**
      * @see org.apache.roller.weblogger.model.FileContentManager#getFileContent(weblog, java.lang.String)
      */
@@ -106,8 +112,7 @@
             bos = new FileOutputStream(saveFile);
             while ((bytesRead = is.read(buffer, 0, 8192)) != -1) {
                 bos.write(buffer, 0, bytesRead);
-            }
-            
+            }            
             log.debug("The file has been written to ["+saveFile.getAbsolutePath()+"]");
         } catch (Exception e) {
             throw new FileIOException("ERROR uploading file", e);
@@ -157,8 +162,8 @@
         long maxDirBytes = (long)(1024000 * maxDirSize.doubleValue());
         
         try {
-            File uploadsDir = this.getRealFile(weblog, null);
-            long weblogDirSize = this.getDirSize(uploadsDir, true);
+            File storageDir = this.getRealFile(weblog, null);
+            long weblogDirSize = this.getDirSize(storageDir, true);
             
             return weblogDirSize > maxDirBytes;
         } catch (Exception ex) {
@@ -205,8 +210,8 @@
                 WebloggerRuntimeConfig.getProperty("uploads.dir.maxsize"));
         long maxDirBytes = (long)(1024000 * maxDirMB.doubleValue());
         try {
-            File uploadsDir = this.getRealFile(weblog, null);
-            long userDirSize = getDirSize(uploadsDir, true);
+            File storageDir = this.getRealFile(weblog, null);
+            long userDirSize = getDirSize(storageDir, true);
             if (userDirSize + size > maxDirBytes) {
                 messages.addError("error.upload.dirmax", maxDirMB.toString());
                 return false;
@@ -366,7 +371,7 @@
             throws FileNotFoundException, FilePathException {
         
         // make sure uploads area exists for this weblog
-        File weblogDir = new File(this.upload_dir + weblog.getHandle());
+        File weblogDir = new File(this.storage_dir + weblog.getHandle());
         if(!weblogDir.exists()) {
             weblogDir.mkdirs();
         }
@@ -400,5 +405,5 @@
         
         return file;
     }
-    
+
 }

Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/MediaFileManager.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/MediaFileManager.java?rev=797783&r1=797782&r2=797783&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/MediaFileManager.java (original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/MediaFileManager.java Sat Jul 25 15:50:25 2009
@@ -15,7 +15,6 @@
  * copyright in this work, please see the NOTICE file in the top level
  * directory of this distribution.
  */
-
 package org.apache.roller.weblogger.business;
 
 import java.util.Collection;
@@ -33,92 +32,116 @@
 public interface MediaFileManager {
 
     /**
+     * Initialization; deal with upgrade migrations, etc.
+     */
+    public void initialize();
+
+    /**
+     * Release all resources associated with Roller session.
+     */
+    public void release();
+
+    /**
      * Create a media file
      */
-	public void createMediaFile(Weblog weblog, MediaFile mediaFile) throws WebloggerException ;
+    public void createMediaFile(Weblog weblog, MediaFile mediaFile)
+            throws WebloggerException;
 
     /**
      * Update metadata for a media file
      */
-	public void updateMediaFile(Weblog weblog, MediaFile mediaFile) throws WebloggerException ;
+    public void updateMediaFile(Weblog weblog, MediaFile mediaFile)
+            throws WebloggerException;
 
     /**
      * Get media file metadata by file id
      */
-	public MediaFile getMediaFile(String id) throws WebloggerException;
+    public MediaFile getMediaFile(String id) throws WebloggerException;
 
     /**
      * Get media file metadata optionally including the actual content
      */
-	public MediaFile getMediaFile(String id, boolean includeContent) throws WebloggerException;
+    public MediaFile getMediaFile(String id, boolean includeContent)
+            throws WebloggerException;
 
     /**
      * Delete a media file
      */
-	public void removeMediaFile(Weblog weblog, MediaFile mediaFile) throws WebloggerException;
+    public void removeMediaFile(Weblog weblog, MediaFile mediaFile)
+            throws WebloggerException;
 
     /**
      * Search for media files based on the filter criteria
      */
-	public List<MediaFile> searchMediaFiles(Weblog weblog, MediaFileFilter filter) throws WebloggerException;
+    public List<MediaFile> searchMediaFiles(Weblog weblog, MediaFileFilter filter)
+            throws WebloggerException;
 
     /**
      * Create root directory for media files in a weblog.
      */
-	public MediaFileDirectory createRootMediaFileDirectory(Weblog weblog) throws WebloggerException;
+    public MediaFileDirectory createRootMediaFileDirectory(Weblog weblog)
+            throws WebloggerException;
 
     /**
      * Create a media file directory with the given name
      */
-	public MediaFileDirectory createMediaFileDirectory(MediaFileDirectory parentDirectory, String newDirName) throws WebloggerException;
+    public MediaFileDirectory createMediaFileDirectory(
+            MediaFileDirectory parentDirectory, String newDirName)
+            throws WebloggerException;
 
     /**
      * Create a media file directory
      */
-	public void createMediaFileDirectory(MediaFileDirectory directory) throws WebloggerException;
+    public void createMediaFileDirectory(MediaFileDirectory directory)
+            throws WebloggerException;
 
     /**
      * Create a media file directory given its path
      */
-	public MediaFileDirectory createMediaFileDirectoryByPath(Weblog weblog, String path) throws WebloggerException; 
+    public MediaFileDirectory createMediaFileDirectoryByPath(
+            Weblog weblog, String path) throws WebloggerException;
 
     /**
      * Get media file directory by id
      */
-	public MediaFileDirectory getMediaFileDirectory(String id) throws WebloggerException;
+    public MediaFileDirectory getMediaFileDirectory(String id)
+            throws WebloggerException;
 
     /**
      * Get media file directory by its path
      */
-	public MediaFileDirectory getMediaFileDirectoryByPath(Weblog weblog, String path) throws WebloggerException; 
+    public MediaFileDirectory getMediaFileDirectoryByPath(
+            Weblog weblog, String path) throws WebloggerException;
 
     /**
      * Get the list of media file directories for the given weblog.
      */
-	public List<MediaFileDirectory> getMediaFileDirectories(Weblog weblog) throws WebloggerException;
+    public List<MediaFileDirectory> getMediaFileDirectories(Weblog weblog)
+            throws WebloggerException;
 
     /**
      * Get the root directory for media files for the given weblog.
      */
-	public MediaFileDirectory getMediaFileRootDirectory(Weblog weblog) throws WebloggerException;
-    
+    public MediaFileDirectory getMediaFileRootDirectory(Weblog weblog)
+            throws WebloggerException;
+
     /**
      * Move a set of media files to a new directory.
      */
-    public void moveMediaFiles(Collection<MediaFile> mediaFiles, MediaFileDirectory directory) throws WebloggerException;
+    public void moveMediaFiles(
+            Collection<MediaFile> mediaFiles, MediaFileDirectory directory)
+            throws WebloggerException;
 
     /**
      * Move one media file to a new directory.
      */
-    public void moveMediaFile(MediaFile mediaFile, MediaFileDirectory directory) throws WebloggerException;
+    public void moveMediaFile(
+            MediaFile mediaFile, MediaFileDirectory directory)
+            throws WebloggerException;
 
     /**
      * Return recently added media files that are public.
      */
- 	public List<MediaFile> fetchRecentPublicMediaFiles(int length) throws WebloggerException;
-
-    /**
-     * Release all resources.
-     */
- 	public void release();
+    public List<MediaFile> fetchRecentPublicMediaFiles(int length)
+            throws WebloggerException;
 }

Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/WebloggerImpl.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/WebloggerImpl.java?rev=797783&r1=797782&r2=797783&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/WebloggerImpl.java (original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/WebloggerImpl.java Sat Jul 25 15:50:25 2009
@@ -353,6 +353,7 @@
         getThemeManager().initialize();
         getThreadManager().initialize();
         getIndexManager().initialize();
+        getMediaFileManager().initialize();
         
         try {
             // Initialize ping systems

Copied: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java (from r791290, roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/MediaFileManagerImpl.java)
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java?p2=roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java&p1=roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/MediaFileManagerImpl.java&r1=791290&r2=797783&rev=797783&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/MediaFileManagerImpl.java (original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java Sat Jul 25 15:50:25 2009
@@ -15,15 +15,20 @@
  * copyright in this work, please see the NOTICE file in the top level
  * directory of this distribution.
  */
+package org.apache.roller.weblogger.business.jpa;
 
-package org.apache.roller.weblogger.business;
-
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import org.apache.roller.weblogger.business.*;
 import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 
+import java.util.Properties;
 import javax.persistence.NoResultException;
 import javax.persistence.Query;
 
@@ -31,156 +36,169 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.roller.weblogger.WebloggerException;
-import org.apache.roller.weblogger.business.jpa.JPAPersistenceStrategy;
+import org.apache.roller.weblogger.config.WebloggerConfig;
 import org.apache.roller.weblogger.pojos.FileContent;
 import org.apache.roller.weblogger.pojos.MediaFile;
 import org.apache.roller.weblogger.pojos.MediaFileDirectory;
 import org.apache.roller.weblogger.pojos.MediaFileFilter;
 import org.apache.roller.weblogger.pojos.MediaFileType;
+import org.apache.roller.weblogger.pojos.User;
 import org.apache.roller.weblogger.pojos.Weblog;
 import org.apache.roller.weblogger.util.RollerMessages;
+import org.apache.roller.weblogger.util.Utilities;
 
 @com.google.inject.Singleton
-public class MediaFileManagerImpl implements MediaFileManager {
-	
+public class JPAMediaFileManagerImpl implements MediaFileManager {
+
     private final Weblogger roller;
     private final JPAPersistenceStrategy persistenceStrategy;
-    
+    private static Log log =
+        LogFactory.getFactory().getInstance(JPAMediaFileManagerImpl.class);
+
+    public static final String
+        MIGRATIION_STATUS_FILENAME = "migration-status.properties";
+
+
     /**
      * Creates a new instance of MediaFileManagerImpl
      */
-   @com.google.inject.Inject
-	protected MediaFileManagerImpl(Weblogger roller, JPAPersistenceStrategy persistenceStrategy) {
-	   this.roller = roller;
-	   this.persistenceStrategy = persistenceStrategy;
-    }
-	
-	/**
-     * The logger instance for this class.
-     */
-    private static Log log = LogFactory
-            .getFactory().getInstance(MediaFileManagerImpl.class);
-
-	public void release() {
-		
-	}
-	
-	/**
-	 * {@inheritDoc}
-	 */
-	public void moveMediaFiles(Collection<MediaFile> mediaFiles, MediaFileDirectory targetDirectory) 
-        throws WebloggerException {
-    	for (MediaFile mediaFile: mediaFiles) {
-    		mediaFile.setDirectory(targetDirectory);
-    		this.persistenceStrategy.store(mediaFile);
-    	}
+    @com.google.inject.Inject
+    protected JPAMediaFileManagerImpl(Weblogger roller, JPAPersistenceStrategy persistenceStrategy) {
+        this.roller = roller;
+        this.persistenceStrategy = persistenceStrategy;
+    }
+
+    /**
+     * Initialize manager; deal with upgrade/migration if 'uploads.migrate.auto' is true.
+     */
+    public void initialize() {
+        boolean autoUpgrade = WebloggerConfig.getBooleanProperty("uploads.migrate.auto");
+        if (autoUpgrade && this.isFileStorageUpgradeRequired()) {
+            this.upgradeFileStorage();
+        }
+    }
+
+    /**
+     * Release resources; currently a no-op.
+     */
+    public void release() {
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void moveMediaFiles(Collection<MediaFile> mediaFiles, MediaFileDirectory targetDirectory)
+            throws WebloggerException {
+        for (MediaFile mediaFile : mediaFiles) {
+            mediaFile.setDirectory(targetDirectory);
+            this.persistenceStrategy.store(mediaFile);
+        }
         // update weblog last modified date.  date updated by saveWebsite()
         roller.getWeblogManager().saveWeblog(targetDirectory.getWeblog());
     }
 
-	/**
-	 * {@inheritDoc}
-	 */
-	public void moveMediaFile(MediaFile mediaFile, MediaFileDirectory targetDirectory) 
-        throws WebloggerException {
-		moveMediaFiles(Arrays.asList(mediaFile), targetDirectory);
-	}
-	
-	/**
-	 * {@inheritDoc}
-	 */
-	public MediaFileDirectory createMediaFileDirectory(MediaFileDirectory parentDirectory, String newDirName) 
-	  throws WebloggerException {
-		
-		if (parentDirectory.hasDirectory(newDirName)) {
+    /**
+     * {@inheritDoc}
+     */
+    public void moveMediaFile(MediaFile mediaFile, MediaFileDirectory targetDirectory)
+            throws WebloggerException {
+        moveMediaFiles(Arrays.asList(mediaFile), targetDirectory);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public MediaFileDirectory createMediaFileDirectory(MediaFileDirectory parentDirectory, String newDirName)
+            throws WebloggerException {
+
+        if (parentDirectory.hasDirectory(newDirName)) {
             throw new WebloggerException("Directory exists");
-		}
-		
-		MediaFileDirectory newDirectory = parentDirectory.createNewDirectory(newDirName);
+        }
+
+        MediaFileDirectory newDirectory = parentDirectory.createNewDirectory(newDirName);
 
-		// update weblog last modified date.  date updated by saveWeblog()
+        // update weblog last modified date.  date updated by saveWeblog()
         roller.getWeblogManager().saveWeblog(newDirectory.getWeblog());
-        
+
         return newDirectory;
-	}
-	
-	/**
-	 * {@inheritDoc}
-	 */
-	public void createMediaFileDirectory(MediaFileDirectory directory) 
-	  throws WebloggerException {
-		this.persistenceStrategy.store(directory);
-        
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void createMediaFileDirectory(MediaFileDirectory directory)
+            throws WebloggerException {
+        this.persistenceStrategy.store(directory);
+
         // update weblog last modified date.  date updated by saveWebsite()
         roller.getWeblogManager().saveWeblog(directory.getWeblog());
-	}
-	
-	/**
-	 * {@inheritDoc}
-	 */
-	public MediaFileDirectory createMediaFileDirectoryByPath(Weblog weblog, String path) 
-	    throws WebloggerException {
-		if (path.startsWith("/")) {
-			path = path.substring(1);
-		}
-		
-		if (path.endsWith("/")) {
-			path = path.substring(0, path.length() - 1);
-		}
-		
-		if (path.equals("")) {
-			/**
-			 * Root cannot be created using this method. Use createRootMediaFileDirectory instead
-			 */
-			throw new WebloggerException("Invalid path!");
-		}
-		
-		int lastPathIndex = path.lastIndexOf("/");
-		
-		MediaFileDirectory parentDirectory;
-		String newDirName;
-		if (lastPathIndex == -1) {
-			//Directory needs to be created under root
-			newDirName = path;
-			parentDirectory = getMediaFileRootDirectory(weblog);
-		}
-		else {
-			String parentPath = path.substring(0, lastPathIndex);
-			newDirName = path.substring(lastPathIndex + 1);
-			parentDirectory = getMediaFileDirectoryByPath(weblog, "/" + parentPath);
-			// Validate whether the parent directory exists
-			if (parentDirectory == null) {
-	            throw new WebloggerException("Parent directory does not exist");
-			}
-		}
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public MediaFileDirectory createMediaFileDirectoryByPath(Weblog weblog, String path)
+            throws WebloggerException {
+        if (path.startsWith("/")) {
+            path = path.substring(1);
+        }
+
+        if (path.endsWith("/")) {
+            path = path.substring(0, path.length() - 1);
+        }
+
+        if (path.equals("")) {
+            /**
+             * Root cannot be created using this method. Use createRootMediaFileDirectory instead
+             */
+            throw new WebloggerException("Invalid path!");
+        }
+
+        int lastPathIndex = path.lastIndexOf("/");
+
+        MediaFileDirectory parentDirectory;
+        String newDirName;
+        if (lastPathIndex == -1) {
+            //Directory needs to be created under root
+            newDirName = path;
+            parentDirectory = getMediaFileRootDirectory(weblog);
+        } else {
+            String parentPath = path.substring(0, lastPathIndex);
+            newDirName = path.substring(lastPathIndex + 1);
+            parentDirectory = getMediaFileDirectoryByPath(weblog, "/" + parentPath);
+            // Validate whether the parent directory exists
+            if (parentDirectory == null) {
+                throw new WebloggerException("Parent directory does not exist");
+            }
+        }
 
-		if (parentDirectory.hasDirectory(newDirName)) {
+        if (parentDirectory.hasDirectory(newDirName)) {
             throw new WebloggerException("Directory exists");
-		}
-		
-		MediaFileDirectory newDirectory = parentDirectory.createNewDirectory(newDirName);
+        }
 
-		// update weblog last modified date.  date updated by saveWeblog()
+        MediaFileDirectory newDirectory = parentDirectory.createNewDirectory(newDirName);
+
+        // update weblog last modified date.  date updated by saveWeblog()
         roller.getWeblogManager().saveWeblog(weblog);
-        
+
         return newDirectory;
-	}
-	
-	/**
-	 * {@inheritDoc}
-	 */
-	public MediaFileDirectory createRootMediaFileDirectory(Weblog weblog) 
-	    throws WebloggerException {
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public MediaFileDirectory createRootMediaFileDirectory(Weblog weblog)
+            throws WebloggerException {
         MediaFileDirectory rootDirectory = new MediaFileDirectory(null, "root", "root directory", weblog);
-		createMediaFileDirectory(rootDirectory);
-		return rootDirectory;
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	public void createMediaFile(Weblog weblog, MediaFile mediaFile) throws WebloggerException {
-		
+        createMediaFileDirectory(rootDirectory);
+        return rootDirectory;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void createMediaFile(Weblog weblog, MediaFile mediaFile) throws WebloggerException {
+
         FileContentManager cmgr = WebloggerFactory.getWeblogger().getFileContentManager();
         RollerMessages msgs = new RollerMessages();
         if (!cmgr.canSave(weblog, mediaFile.getName(), mediaFile.getContentType(), mediaFile.getLength(), msgs)) {
@@ -189,96 +207,96 @@
 
         mediaFile.setDateUploaded(new Timestamp(System.currentTimeMillis()));
         mediaFile.setLastUpdated(mediaFile.getDateUploaded());
-		persistenceStrategy.store(mediaFile);
+        persistenceStrategy.store(mediaFile);
         // update weblog last modified date.  date updated by saveWeblog()
         roller.getWeblogManager().saveWeblog(weblog);
-        
+
         cmgr.saveFileContent(weblog, mediaFile.getId(), mediaFile.getInputStream());
-	}
-	
-	/**
-	 * {@inheritDoc}
-	 */
-	public void updateMediaFile(Weblog weblog, MediaFile mediaFile) throws WebloggerException {
-		mediaFile.setLastUpdated(new Timestamp(System.currentTimeMillis()));
-		persistenceStrategy.store(mediaFile);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void updateMediaFile(Weblog weblog, MediaFile mediaFile) throws WebloggerException {
+        mediaFile.setLastUpdated(new Timestamp(System.currentTimeMillis()));
+        persistenceStrategy.store(mediaFile);
         // update weblog last modified date.  date updated by saveWeblog()
         roller.getWeblogManager().saveWeblog(weblog);
-	}
+    }
 
-	/**
-	 * {@inheritDoc}
-	 */
-	public MediaFile getMediaFile(String id) throws WebloggerException {
+    /**
+     * {@inheritDoc}
+     */
+    public MediaFile getMediaFile(String id) throws WebloggerException {
         return getMediaFile(id, false);
-	}
+    }
 
-	/**
-	 * {@inheritDoc}
-	 */
-	public MediaFile getMediaFile(String id, boolean includeContent) throws WebloggerException {
-		MediaFile mediaFile = (MediaFile) this.persistenceStrategy.load(MediaFile.class, id);
-		if (includeContent) {
-	        FileContentManager cmgr = WebloggerFactory.getWeblogger().getFileContentManager();
-	        FileContent content = cmgr.getFileContent(mediaFile.getDirectory().getWeblog(), id);
-	        mediaFile.setContent(content);
-		}
+    /**
+     * {@inheritDoc}
+     */
+    public MediaFile getMediaFile(String id, boolean includeContent) throws WebloggerException {
+        MediaFile mediaFile = (MediaFile) this.persistenceStrategy.load(MediaFile.class, id);
+        if (includeContent) {
+            FileContentManager cmgr = WebloggerFactory.getWeblogger().getFileContentManager();
+            FileContent content = cmgr.getFileContent(mediaFile.getDirectory().getWeblog(), id);
+            mediaFile.setContent(content);
+        }
         return mediaFile;
-	}
+    }
 
-	/**
-	 * {@inheritDoc}
-	 */
-	public MediaFileDirectory getMediaFileDirectoryByPath(Weblog weblog, String path) 
-      throws WebloggerException {
+    /**
+     * {@inheritDoc}
+     */
+    public MediaFileDirectory getMediaFileDirectoryByPath(Weblog weblog, String path)
+            throws WebloggerException {
         Query q = this.persistenceStrategy.getNamedQuery("MediaFileDirectory.getByWeblogAndPath");
         q.setParameter(1, weblog);
         q.setParameter(2, path);
         try {
-            return (MediaFileDirectory)q.getSingleResult();
+            return (MediaFileDirectory) q.getSingleResult();
         } catch (NoResultException e) {
             return null;
         }
     }
 
-	/**
-	 * {@inheritDoc}
-	 */
-	public MediaFileDirectory getMediaFileDirectory(String id) 
-	    throws WebloggerException {
-		return (MediaFileDirectory) this.persistenceStrategy.load(MediaFileDirectory.class, id);
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	public MediaFileDirectory getMediaFileRootDirectory(Weblog weblog) 
-      throws WebloggerException {
+    /**
+     * {@inheritDoc}
+     */
+    public MediaFileDirectory getMediaFileDirectory(String id)
+            throws WebloggerException {
+        return (MediaFileDirectory) this.persistenceStrategy.load(MediaFileDirectory.class, id);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public MediaFileDirectory getMediaFileRootDirectory(Weblog weblog)
+            throws WebloggerException {
         Query q = this.persistenceStrategy.getNamedQuery("MediaFileDirectory.getByWeblogAndNoParent");
         q.setParameter(1, weblog);
         try {
-            return (MediaFileDirectory)q.getSingleResult();
+            return (MediaFileDirectory) q.getSingleResult();
         } catch (NoResultException e) {
             return null;
         }
-	}
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public List<MediaFileDirectory> getMediaFileDirectories(Weblog weblog)
+            throws WebloggerException {
 
-	/**
-	 * {@inheritDoc}
-	 */
-	public List<MediaFileDirectory> getMediaFileDirectories(Weblog weblog) 
-	    throws WebloggerException {
-        
         Query q = this.persistenceStrategy.getNamedQuery("MediaFileDirectory.getByWeblog");
         q.setParameter(1, weblog);
         return q.getResultList();
-	}
-	
-	/**
-	 * {@inheritDoc}
-	 */
-	public void removeMediaFile(Weblog weblog, MediaFile mediaFile) 
-	    throws WebloggerException {
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void removeMediaFile(Weblog weblog, MediaFile mediaFile)
+            throws WebloggerException {
         FileContentManager cmgr = WebloggerFactory.getWeblogger().getFileContentManager();
 
         this.persistenceStrategy.remove(mediaFile);
@@ -287,116 +305,294 @@
 
         try {
             cmgr.deleteFile(weblog, mediaFile.getId());
-        }
-        catch (FileNotFoundException e) {
+        } catch (FileNotFoundException e) {
             log.debug("File to be deleted already unavailable in the file store");
         }
-	}
-	
-	/**
-	 * {@inheritDoc}
-	 */
- 	public List<MediaFile> fetchRecentPublicMediaFiles(int length) 
- 	    throws WebloggerException {
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public List<MediaFile> fetchRecentPublicMediaFiles(int length)
+            throws WebloggerException {
 
- 		List<Object> params = new ArrayList<Object>();
+        List<Object> params = new ArrayList<Object>();
         int size = 0;
         StringBuffer queryString = new StringBuffer();
-        
+
         queryString.append("SELECT m FROM MediaFile m WHERE m.sharedForGallery = true");
         queryString.append(" order by m.dateUploaded");
         Query query = persistenceStrategy.getDynamicQuery(queryString.toString());
         query.setFirstResult(0);
         query.setMaxResults(length);
         return query.getResultList();
- 	}
- 	
-	/**
-	 * {@inheritDoc}
-	 */
-	public List<MediaFile> searchMediaFiles(Weblog weblog, MediaFileFilter filter) 
-	     throws WebloggerException {
-        
-		List<Object> params = new ArrayList<Object>();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public List<MediaFile> searchMediaFiles(Weblog weblog, MediaFileFilter filter)
+            throws WebloggerException {
+
+        List<Object> params = new ArrayList<Object>();
         int size = 0;
         StringBuffer queryString = new StringBuffer();
         StringBuffer whereClause = new StringBuffer();
         StringBuffer orderBy = new StringBuffer();
-        
+
         queryString.append("SELECT m FROM MediaFile m WHERE ");
-        
-        params.add(size ++, weblog);
+
+        params.add(size++, weblog);
         whereClause.append("m.directory.weblog = ?" + size);
-        
+
         if (!StringUtils.isEmpty(filter.getName())) {
-        	String nameFilter = filter.getName();
-        	nameFilter = nameFilter.trim();
-        	if (!nameFilter.endsWith("%")) {
-        		nameFilter = nameFilter + "%";
-        	}
-        	params.add(size ++, nameFilter);
-        	whereClause.append(" AND m.name like ?" + size);
+            String nameFilter = filter.getName();
+            nameFilter = nameFilter.trim();
+            if (!nameFilter.endsWith("%")) {
+                nameFilter = nameFilter + "%";
+            }
+            params.add(size++, nameFilter);
+            whereClause.append(" AND m.name like ?" + size);
         }
 
         if (filter.getSize() > 0) {
-        	params.add(size ++, filter.getSize());
-        	whereClause.append(" AND m.length ");
-        	switch (filter.getSizeFilterType()) {
-            	case GT: whereClause.append(">");break;
-            	case GTE: whereClause.append(">=");break;
-            	case EQ: whereClause.append("=");break;
-        	    case LT: whereClause.append("<");break;
-        	    case LTE: whereClause.append("<=");break;
-        	    default: whereClause.append("=");break;
-        	}
-        	whereClause.append(" ?" + size);
+            params.add(size++, filter.getSize());
+            whereClause.append(" AND m.length ");
+            switch (filter.getSizeFilterType()) {
+                case GT:
+                    whereClause.append(">");
+                    break;
+                case GTE:
+                    whereClause.append(">=");
+                    break;
+                case EQ:
+                    whereClause.append("=");
+                    break;
+                case LT:
+                    whereClause.append("<");
+                    break;
+                case LTE:
+                    whereClause.append("<=");
+                    break;
+                default:
+                    whereClause.append("=");
+                    break;
+            }
+            whereClause.append(" ?" + size);
         }
-        
+
         if (filter.getTags() != null) {
-        	whereClause.append(" AND EXISTS (SELECT t FROM MediaFileTag t WHERE t.mediaFile = m and t.name IN (");
-        	for (String tag: filter.getTags()) {
-        	    params.add(size ++, tag);
-        	    whereClause.append("?").append(size).append(",");
-        	}
-        	whereClause.deleteCharAt(whereClause.lastIndexOf(","));
-        	whereClause.append("))");
+            whereClause.append(" AND EXISTS (SELECT t FROM MediaFileTag t WHERE t.mediaFile = m and t.name IN (");
+            for (String tag : filter.getTags()) {
+                params.add(size++, tag);
+                whereClause.append("?").append(size).append(",");
+            }
+            whereClause.deleteCharAt(whereClause.lastIndexOf(","));
+            whereClause.append("))");
         }
-        
+
         if (filter.getType() != null) {
-        	if (filter.getType() == MediaFileType.OTHERS) {
-        		for (MediaFileType type: MediaFileType.values()) {
-        			if (type != MediaFileType.OTHERS) {
-                    	params.add(size ++, type.getContentTypePrefix() + "%");
-                    	whereClause.append(" AND m.contentType not like ?" + size);
-        			}
-        		}
-        	}
-        	else {
-            	params.add(size ++, filter.getType().getContentTypePrefix() + "%");
-            	whereClause.append(" AND m.contentType like ?" + size);
-        	}
+            if (filter.getType() == MediaFileType.OTHERS) {
+                for (MediaFileType type : MediaFileType.values()) {
+                    if (type != MediaFileType.OTHERS) {
+                        params.add(size++, type.getContentTypePrefix() + "%");
+                        whereClause.append(" AND m.contentType not like ?" + size);
+                    }
+                }
+            } else {
+                params.add(size++, filter.getType().getContentTypePrefix() + "%");
+                whereClause.append(" AND m.contentType like ?" + size);
+            }
         }
-        
+
         if (filter.getOrder() != null) {
-            switch(filter.getOrder()) {
-            case NAME: orderBy.append(" order by m.name");break;
-            case DATE_UPLOADED: orderBy.append(" order by m.dateUploaded");break;
-            case TYPE: orderBy.append(" order by m.contentType");break;
-            default:
+            switch (filter.getOrder()) {
+                case NAME:
+                    orderBy.append(" order by m.name");
+                    break;
+                case DATE_UPLOADED:
+                    orderBy.append(" order by m.dateUploaded");
+                    break;
+                case TYPE:
+                    orderBy.append(" order by m.contentType");
+                    break;
+                default:
             }
         }
 
         Query query = persistenceStrategy.getDynamicQuery(queryString.toString() + whereClause.toString() + orderBy.toString());
-        for (int i=0; i<params.size(); i++) {
-            query.setParameter(i+1, params.get(i));
+        for (int i = 0; i < params.size(); i++) {
+            query.setParameter(i + 1, params.get(i));
         }
-        
+
         if (filter.getStartIndex() >= 0) {
             query.setFirstResult(filter.getStartIndex());
             query.setMaxResults(filter.getLength());
         }
-        
+
         return query.getResultList();
-	}
-	
+    }
+
+    /**
+     * Does mediafile storage require any upgrading;
+     * checks for existance of migration status file.
+     */
+    public boolean isFileStorageUpgradeRequired() {
+        String uploadsDirName = WebloggerConfig.getProperty("uploads.dir");
+        if (uploadsDirName != null) {
+            File uploadsDir = new File(uploadsDirName);
+            if (uploadsDir.exists() && uploadsDir.isDirectory()) {
+                Properties props = new Properties();
+                try {
+                    props.load(new FileReader(uploadsDirName
+                        + File.separator + MIGRATIION_STATUS_FILENAME));
+                } catch (Exception ignored) {}
+                if (props.getProperty("complete") != null) {
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
+
+    /**
+     * Run mediafile storage upgrade, copying files to new storage system;
+     * creates migration status file only when work is complete.
+     */
+    public List<String> upgradeFileStorage() {
+        List<String> msgs = new ArrayList<String>();
+        String oldDirName = WebloggerConfig.getProperty("uploads.dir");
+        String FS = File.separator;
+
+        if (oldDirName != null) {
+            try {
+
+                // loop through weblogs found in uploads directory
+                File uploadsDir = new File(oldDirName);
+                File[] dirs = uploadsDir.listFiles();
+                for (int i=0; i<dirs.length; i++) {
+
+                    if (dirs[i].isDirectory()) {
+                        WeblogManager wmgr = this.roller.getWeblogManager(); 
+                        Weblog weblog = wmgr.getWeblogByHandle(dirs[i].getName(), null);
+                        if (weblog != null) {
+
+                            log.info("Migrating weblog: " + weblog.getHandle());
+                            
+                            // use 1st admin user found as file creator
+                            List<User> users = wmgr.getWeblogUsers(weblog, true);
+                            User chosenUser = users.get(0);
+                            for (User user: users) {
+                                chosenUser = user;
+                                if (user.hasGlobalPermission("admin")) {
+                                    break;
+                                }
+                            }
+
+                            try {
+                                // create weblog's mediafile directory if needed
+                                MediaFileDirectory root =
+                                    this.getMediaFileRootDirectory(weblog);
+                                if (root == null) {
+                                    root = this.createRootMediaFileDirectory(weblog);
+                                    roller.flush();
+                                }
+
+                                // upgrade!
+                                upgradeUploadsDir(weblog, chosenUser,
+                                  new File(oldDirName + FS + dirs[i].getName()),
+                                  root);
+
+                            } catch (Throwable t) {
+                                log.error("ERROR upgading weblog", t);
+                            }
+                        }
+                    }
+                }
+
+                Properties props = new Properties();
+                props.setProperty("complete", "true");
+                props.store(new FileOutputStream(oldDirName
+                    + File.separator + MIGRATIION_STATUS_FILENAME),
+                    "Migration is complete!");
+
+            } catch (Exception ioex) {}
+        }
+        msgs.add("Migration complete!");
+        return msgs;
+    }
+
+    private void upgradeUploadsDir(Weblog weblog, User user, File oldDir, MediaFileDirectory newDir) {
+        log.debug("Upgrading dir: " + oldDir.getAbsolutePath());
+        if (newDir == null) {
+            log.error("newDir cannot be null");
+            return;
+        }
+
+        // loop through files and directories
+        File[] files = oldDir.listFiles();
+        for (int i=0; i<files.length; i++) {
+
+            // a directory: go recursive
+            if (files[i].isDirectory()) {
+
+                if (newDir.hasDirectory(files[i].getName())) {
+                    // already have a mediafile directory for that
+                    upgradeUploadsDir(weblog, user, files[i],
+                        newDir.getChildDirectory(files[i].getName()));
+
+                } else {
+                    // need to create a new mediafile directory
+                    MediaFileDirectory subDir = null;
+                    try {
+                        subDir = newDir.createNewDirectory(files[i].getName());
+                        roller.getMediaFileManager().createMediaFileDirectory(subDir);
+                        roller.flush();
+
+                    } catch (WebloggerException ex) {
+                        log.error("ERROR creating directory: "
+                            + newDir.getPath() + "/" + files[i].getName());
+                    }
+                    upgradeUploadsDir(weblog, user, files[i], subDir);
+                }
+
+            } else { // a file: create a database record for it
+
+                log.debug("    Upgrade file: " + files[i].getAbsolutePath());
+                MediaFile mf = new MediaFile();
+                try {
+                    mf.setName(files[i].getName());
+                    mf.setDescription(files[i].getName());
+
+                    mf.setDateUploaded(new Timestamp(files[i].lastModified()));
+                    mf.setLastUpdated(new Timestamp(files[i].lastModified()));
+
+                    mf.setDirectory(newDir);
+                    mf.setCreatorUserName(user.getUserName());
+                    mf.setSharedForGallery(Boolean.FALSE);
+
+                    mf.setLength(files[i].length());
+                    mf.setInputStream(new FileInputStream(files[i]));
+                    mf.setContentType(Utilities.getContentTypeFromFileName(files[i].getName()));
+
+                    this.roller.getMediaFileManager().createMediaFile(weblog, mf);
+
+                } catch (WebloggerException ex) {
+                    log.error("ERROR writing file to new storage system: "
+                            + files[i].getAbsolutePath(), ex);
+                    
+                } catch (java.io.FileNotFoundException ex) {
+                    log.error("ERROR reading file from old storage system: "
+                            + files[i].getAbsolutePath(), ex);
+                }
+            }
+        }
+
+        try { // flush changes to this directory
+            roller.flush();
+        } catch (WebloggerException ex) {
+            log.error("ERROR flushing changes to dir: " + newDir.getPath(), ex);
+        }
+    }
+
 }

Propchange: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAMediaFileManagerImpl.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAWeblogManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAWeblogManagerImpl.java?rev=797783&r1=797782&r2=797783&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAWeblogManagerImpl.java (original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAWeblogManagerImpl.java Sat Jul 25 15:50:25 2009
@@ -31,12 +31,14 @@
 import javax.persistence.NoResultException;
 import javax.persistence.Query;
 
+import javax.persistence.Query;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import org.apache.roller.weblogger.WebloggerException;
 import org.apache.roller.weblogger.business.BookmarkManager;
 import org.apache.roller.weblogger.business.FileManager;
+import org.apache.roller.weblogger.business.MediaFileManager;
 import org.apache.roller.weblogger.business.UserManager;
 import org.apache.roller.weblogger.business.WeblogEntryManager;
 import org.apache.roller.weblogger.business.WeblogManager;
@@ -46,6 +48,7 @@
 import org.apache.roller.weblogger.business.pings.PingTargetManager;
 import org.apache.roller.weblogger.config.WebloggerConfig;
 import org.apache.roller.weblogger.pojos.AutoPing;
+import org.apache.roller.weblogger.pojos.MediaFileDirectory;
 import org.apache.roller.weblogger.pojos.PingQueueEntry;
 import org.apache.roller.weblogger.pojos.PingTarget;
 import org.apache.roller.weblogger.pojos.WeblogReferrer;
@@ -128,6 +131,7 @@
         WeblogManager      wmgr = roller.getWeblogManager();
         WeblogEntryManager emgr = roller.getWeblogEntryManager();
         BookmarkManager    bmgr = roller.getBookmarkManager();
+        MediaFileManager   mmgr = roller.getMediaFileManager();
         
         // remove tags
         Query tagQuery = strategy.getNamedQuery("WeblogEntryTag.getByWeblog");
@@ -209,6 +213,13 @@
         }
         this.strategy.flush();
 
+        // remove mediafile metadata
+        List<MediaFileDirectory> dirs = mmgr.getMediaFileDirectories(website);
+        for (MediaFileDirectory dir : dirs) {
+            this.strategy.remove(dir);
+        }
+        this.strategy.flush();
+
         // remove entries
         Query refQuery = strategy.getNamedQuery("WeblogEntry.getByWebsite");
         refQuery.setParameter(1, website);

Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAWebloggerModule.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAWebloggerModule.java?rev=797783&r1=797782&r2=797783&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAWebloggerModule.java (original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAWebloggerModule.java Sat Jul 25 15:50:25 2009
@@ -28,7 +28,6 @@
 import org.apache.roller.weblogger.business.FileManager;
 import org.apache.roller.weblogger.business.FileManagerImpl;
 import org.apache.roller.weblogger.business.MediaFileManager;
-import org.apache.roller.weblogger.business.MediaFileManagerImpl;
 import org.apache.roller.weblogger.business.MultiWeblogURLStrategy;
 import org.apache.roller.weblogger.business.OAuthManager;
 import org.apache.roller.weblogger.business.PropertiesManager;
@@ -80,7 +79,7 @@
                 
         binder.bind(ReferrerQueueManager.class).to(ReferrerQueueManagerImpl.class); 
         binder.bind(FileManager.class).to(         FileManagerImpl.class);   
-        binder.bind(MediaFileManager.class).to(    MediaFileManagerImpl.class);
+        binder.bind(MediaFileManager.class).to(    JPAMediaFileManagerImpl.class);
         binder.bind(FileContentManager.class).to(  FileContentManagerImpl.class);
         binder.bind(IndexManager.class).to(        IndexManagerImpl.class);
         binder.bind(PluginManager.class).to(       PluginManagerImpl.class);    

Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/config/roller.properties
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/config/roller.properties?rev=797783&r1=797782&r2=797783&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/config/roller.properties (original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/config/roller.properties Sat Jul 25 15:50:25 2009
@@ -106,11 +106,20 @@
 #-----------------------------------------------------------------------------
 
 # The directory in which Roller will upload files
+mediafiles.storage.dir=${user.home}/roller_data/mediafiles
+
+# The context path under which resoures will be made available
+mediafile.resource.url=/resources
+
+# The directory in which Roller will upload files
 uploads.dir=${user.home}/roller_data/uploads
 
-# The context path under which resoures will be made available 
+# The context path under which resoures will be made available
 uploads.url=/resources
 
+# Upload old file resoures to Roller 5.0 Mediafile Storage automatically
+uploads.migrate.auto=false
+
 # Directory in which search index is to be created 
 # (delete this directory to force Roller to recreate the entire search index)
 search.index.dir=${user.home}/roller_data/search-index

Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/MediaFileDirectory.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/MediaFileDirectory.java?rev=797783&r1=797782&r2=797783&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/MediaFileDirectory.java (original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/pojos/MediaFileDirectory.java Sat Jul 25 15:50:25 2009
@@ -15,7 +15,6 @@
  * copyright in this work, please see the NOTICE file in the top level
  * directory of this distribution.
  */
-
 package org.apache.roller.weblogger.pojos;
 
 import java.util.Set;
@@ -28,38 +27,37 @@
  * 
  */
 public class MediaFileDirectory {
-	
-	String id;
-	String name;
-	String description;
-	MediaFileDirectory parent;
-	Weblog weblog;
-	String path;
-	Set<MediaFileDirectory> childDirectories;
-	Set<MediaFile> mediaFiles;
-	
-	public MediaFileDirectory() {
-    	
+
+    String id;
+    String name;
+    String description;
+    MediaFileDirectory parent;
+    Weblog weblog;
+    String path;
+    Set<MediaFileDirectory> childDirectories;
+    Set<MediaFile> mediaFiles;
+
+    public MediaFileDirectory() {
     }
 
-	public MediaFileDirectory(
+    public MediaFileDirectory(
             MediaFileDirectory parent,
             String name,
             String desc,
             Weblog weblog) {
-        
-    	this.id = UUIDGenerator.generateUUID();
-    	this.name = name;
+
+        this.id = UUIDGenerator.generateUUID();
+        this.name = name;
         this.description = desc;
-        
+
         this.weblog = weblog;
         this.parent = parent;
-        
+
         // calculate path
-        if(parent == null) {
+        if (parent == null) {
             this.path = "/";
-        } else if("/".equals(parent.getPath())) {
-            this.path = "/"+name;
+        } else if ("/".equals(parent.getPath())) {
+            this.path = "/" + name;
         } else {
             this.path = parent.getPath() + "/" + name;
         }
@@ -69,83 +67,82 @@
      * Database surrogate key.
      *
      */
-	public String getId() {
-		return id;
-	}
+    public String getId() {
+        return id;
+    }
 
     /**
      * A short name for this folder.
      *
      */
-	public String getName() {
-		return name;
-	}
-
-	public void setName(String name) {
-		this.name = name;
-	}
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
 
     /**
      * A full description for this folder.
      *
      */
-	public String getDescription() {
-		return description;
-	}
-
-	public void setDescription(String description) {
-		this.description = description;
-	}
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
 
     /**
      * Return parent folder, or null if folder is root of hierarchy.
      *
      */
-	public MediaFileDirectory getParent() {
-		return parent;
-	}
-
-	public void setParent(MediaFileDirectory parent) {
-		this.parent = parent;
-	}
+    public MediaFileDirectory getParent() {
+        return parent;
+    }
+
+    public void setParent(MediaFileDirectory parent) {
+        this.parent = parent;
+    }
 
     /**
      * Get the weblog which owns this folder.
      *
      */
-	public Weblog getWeblog() {
-		return weblog;
-	}
-
-	public void setWeblog(Weblog weblog) {
-		this.weblog = weblog;
-	}
+    public Weblog getWeblog() {
+        return weblog;
+    }
+
+    public void setWeblog(Weblog weblog) {
+        this.weblog = weblog;
+    }
 
     /**
      * The full path to this folder in the hierarchy.
      *
      */
-	public String getPath() {
-		return path;
-	}
-
-	public void setPath(String path) {
-		this.path = path;
-	}
-	
+    public String getPath() {
+        return path;
+    }
+
+    public void setPath(String path) {
+        this.path = path;
+    }
+
     /**
      * The collection of files in this directory
      * 
      */
-	public Set<MediaFile> getMediaFiles() {
-		return mediaFiles;
-	}
-
-	public void setMediaFiles(Set<MediaFile> mediaFiles) {
-		this.mediaFiles = mediaFiles;
-	}
+    public Set<MediaFile> getMediaFiles() {
+        return mediaFiles;
+    }
+
+    public void setMediaFiles(Set<MediaFile> mediaFiles) {
+        this.mediaFiles = mediaFiles;
+    }
 
-	
     /**
      * Get child folders of this folder.
      *
@@ -153,11 +150,11 @@
     public Set<MediaFileDirectory> getChildDirectories() {
         return this.childDirectories;
     }
-    
+
     public void setChildDirectories(Set<MediaFileDirectory> folders) {
         this.childDirectories = folders;
     }
-    
+
     /**
      * Indicates whether this directory contains the specified file.
      * 
@@ -165,17 +162,18 @@
      * @return true if the file is present in the directory, false otherwise.
      */
     public boolean hasMediaFile(String name) {
-    	Set<MediaFile> fileSet = this.getMediaFiles();
-    	if (fileSet == null) 
-    		return false;
-    	for (MediaFile mediaFile: fileSet) {
-    		if (mediaFile.getName().equals(name)) {
-    			return true;
-    		}
-    	}
-    	return false;
+        Set<MediaFile> fileSet = this.getMediaFiles();
+        if (fileSet == null) {
+            return false;
+        }
+        for (MediaFile mediaFile : fileSet) {
+            if (mediaFile.getName().equals(name)) {
+                return true;
+            }
+        }
+        return false;
     }
-    
+
     /**
      * Returns file with the given name, if present in this directory
      * 
@@ -183,17 +181,18 @@
      * @return media file object
      */
     public MediaFile getMediaFile(String name) {
-    	Set<MediaFile> fileSet = this.getMediaFiles();
-    	if (fileSet == null) 
-    		return null;
-    	for (MediaFile mediaFile: fileSet) {
-    		if (mediaFile.getName().equals(name)) {
-    			return mediaFile;
-    		}
-    	}
-    	return null;
+        Set<MediaFile> fileSet = this.getMediaFiles();
+        if (fileSet == null) {
+            return null;
+        }
+        for (MediaFile mediaFile : fileSet) {
+            if (mediaFile.getName().equals(name)) {
+                return mediaFile;
+            }
+        }
+        return null;
     }
-    
+
     /**
      * Indicates whether this directory contains the specified sub-directory.
      * 
@@ -201,15 +200,25 @@
      * @return true if the sub-directory is present, false otherwise.
      */
     public boolean hasDirectory(String name) {
-    	Set<MediaFileDirectory> dirSet = this.getChildDirectories();
-    	for (MediaFileDirectory directory: dirSet) {
-    		if (directory.getName().equals(name)) {
-    			return true;
-    		}
-    	}
-    	return false;
+        Set<MediaFileDirectory> dirSet = this.getChildDirectories();
+        for (MediaFileDirectory directory : dirSet) {
+            if (directory.getName().equals(name)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+   public MediaFileDirectory getChildDirectory(String name) {
+        for (MediaFileDirectory dir : getChildDirectories()) {
+            if (name.equals(dir.getName())) {
+                return dir;
+            }
+        }
+        return null;
     }
-    
+
+
     /**
      * Creates a new sub-directory
      * 
@@ -217,23 +226,24 @@
      * @return reference to the newly created directory.
      */
     public MediaFileDirectory createNewDirectory(String name) {
-    	MediaFileDirectory newDirectory = new MediaFileDirectory(this, name, "", this.getWeblog());
-    	this.getChildDirectories().add(newDirectory);
-    	return newDirectory;
-    }
-    
-	@Override
-	public boolean equals(Object other) {
-        if (other == this) return true;
-        if (other instanceof MediaFileDirectory != true) return false;
-        MediaFileDirectory o = (MediaFileDirectory)other;
-        return new EqualsBuilder()
-            .append(getId(), o.getId()) 
-            .append(getName(), o.getName()) 
-            .append(getDescription(), o.getDescription()) 
-            .append(getPath(), o.getPath()) 
-            .isEquals();
-	}
-    
+        MediaFileDirectory newDirectory = new MediaFileDirectory(this, name, "", this.getWeblog());
+        this.getChildDirectories().add(newDirectory);
+        return newDirectory;
+    }
 
+    @Override
+    public boolean equals(Object other) {
+        if (other == this) {
+            return true;
+        }
+        if (other instanceof MediaFileDirectory != true) {
+            return false;
+        }
+        MediaFileDirectory o = (MediaFileDirectory) other;
+        return new EqualsBuilder()
+                .append(getId(), o.getId())
+                .append(getName(), o.getName())
+                .append(getDescription(), o.getDescription())
+                .append(getPath(), o.getPath()).isEquals();
+    }
 }

Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/util/Utilities.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/util/Utilities.java?rev=797783&r1=797782&r2=797783&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/util/Utilities.java (original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/util/Utilities.java Sat Jul 25 15:50:25 2009
@@ -22,6 +22,8 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import javax.activation.FileTypeMap;
+import javax.activation.MimetypesFileTypeMap;
 import org.apache.commons.lang.StringEscapeUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
@@ -1006,5 +1008,19 @@
         Matcher m = pattern.matcher(string);
         return m.replaceAll(replacement);
     }
+
+    public static String getContentTypeFromFileName(String fileName) {
+
+        FileTypeMap map = FileTypeMap.getDefaultFileTypeMap();
+        
+        // TODO: figure out why PNG is missing from Java MIME types
+        if (map instanceof MimetypesFileTypeMap) {
+            try {
+                ((MimetypesFileTypeMap)map).addMimeTypes("image/png png PNG");
+            } catch (Exception ignored) {}
+        }
+
+        return map.getContentType(fileName);
+    }
     
 }

Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/atomprotocol/MediaCollection.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/atomprotocol/MediaCollection.java?rev=797783&r1=797782&r2=797783&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/atomprotocol/MediaCollection.java (original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/webservices/atomprotocol/MediaCollection.java Sat Jul 25 15:50:25 2009
@@ -433,14 +433,7 @@
         URLStrategy urlStrategy = WebloggerFactory.getWeblogger().getUrlStrategy();
         String viewURI = urlStrategy.getWeblogResourceURL(website, filePath, true);
         
-        FileTypeMap map = FileTypeMap.getDefaultFileTypeMap();
-        // TODO: figure out why PNG is missing from Java MIME types
-        if (map instanceof MimetypesFileTypeMap) {
-            try {
-                ((MimetypesFileTypeMap)map).addMimeTypes("image/png png PNG");
-            } catch (Exception ignored) {}
-        }
-        String contentType = map.getContentType(file.getName());
+        String contentType = Utilities.getContentTypeFromFileName(file.getName());
         
         Entry entry = new Entry();
         entry.setId(editMediaURI);

Added: roller/trunk/apps/weblogger/test/java/hawk.jpg
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/test/java/hawk.jpg?rev=797783&view=auto
==============================================================================
Binary file - no diff available.

Propchange: roller/trunk/apps/weblogger/test/java/hawk.jpg
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: roller/trunk/apps/weblogger/test/java/org/apache/roller/weblogger/business/FileContentManagerTest.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/test/java/org/apache/roller/weblogger/business/FileContentManagerTest.java?rev=797783&r1=797782&r2=797783&view=diff
==============================================================================
--- roller/trunk/apps/weblogger/test/java/org/apache/roller/weblogger/business/FileContentManagerTest.java (original)
+++ roller/trunk/apps/weblogger/test/java/org/apache/roller/weblogger/business/FileContentManagerTest.java Sat Jul 25 15:50:25 2009
@@ -15,7 +15,6 @@
  * copyright in this work, please see the NOTICE file in the top level
  * directory of this distribution.
  */
-
 package org.apache.roller.weblogger.business;
 
 import java.io.InputStream;
@@ -38,57 +37,42 @@
  * Test File Management business layer operations.
  */
 public class FileContentManagerTest extends TestCase {
-    
+
     private static Log log = LogFactory.getLog(FileContentManagerTest.class);
-    
     User testUser = null;
     Weblog testWeblog = null;
-    
-    
+
     public FileContentManagerTest(String name) {
         super(name);
     }
-    
-    
+
     public static Test suite() {
         return new TestSuite(FileContentManagerTest.class);
     }
-    
-    
+
     public void setUp() throws Exception {
-        
+
         // setup weblogger
         TestUtils.setupWeblogger();
-        
+
     }
-    
+
     public void tearDown() throws Exception {
-        
-        /*
-    	try {
-            TestUtils.teardownWeblog(testWeblog.getId());
-            TestUtils.teardownUser(testUser.getUserName());
-            TestUtils.endSession(true);
-        } catch (Exception ex) {
-            log.error(ex);
-        }
-        */
         PropertiesManager pmgr = WebloggerFactory.getWeblogger().getPropertiesManager();
         Map config = config = pmgr.getProperties();
-        ((RuntimeConfigProperty)config.get("uploads.dir.maxsize")).setValue("30000");
-        ((RuntimeConfigProperty)config.get("uploads.types.forbid")).setValue("");
-        ((RuntimeConfigProperty)config.get("uploads.types.allowed")).setValue("");
-        ((RuntimeConfigProperty)config.get("uploads.enabled")).setValue("true");
+        ((RuntimeConfigProperty) config.get("uploads.dir.maxsize")).setValue("30000");
+        ((RuntimeConfigProperty) config.get("uploads.types.forbid")).setValue("");
+        ((RuntimeConfigProperty) config.get("uploads.types.allowed")).setValue("");
+        ((RuntimeConfigProperty) config.get("uploads.enabled")).setValue("true");
         pmgr.saveProperties(config);
         TestUtils.endSession(true);
     }
-    
-    
+
     /**
      * Test simple file save/delete.
      */
     public void testFileCRUD() throws Exception {
-        
+
         try {
             testUser = TestUtils.setupUser("FCMTest_userName1");
             testWeblog = TestUtils.setupWeblog("FCMTest_handle1", testUser);
@@ -100,53 +84,56 @@
         // update roller properties to prepare for test
         PropertiesManager pmgr = WebloggerFactory.getWeblogger().getPropertiesManager();
         Map config = pmgr.getProperties();
-        ((RuntimeConfigProperty)config.get("uploads.enabled")).setValue("true");
-        ((RuntimeConfigProperty)config.get("uploads.types.allowed")).setValue("opml");
-        ((RuntimeConfigProperty)config.get("uploads.dir.maxsize")).setValue("1.00");
+        ((RuntimeConfigProperty) config.get("uploads.enabled")).setValue("true");
+        ((RuntimeConfigProperty) config.get("uploads.types.allowed")).setValue("opml");
+        ((RuntimeConfigProperty) config.get("uploads.dir.maxsize")).setValue("1.00");
         pmgr.saveProperties(config);
         TestUtils.endSession(true);
-        
+
         /* NOTE: upload dir for unit tests is set in
-               roller/testdata/roller-custom.properties */
+        roller/testdata/roller-custom.properties */
         FileContentManager fmgr = WebloggerFactory.getWeblogger().getFileContentManager();
-        
+
         // File should not exist initially
         try {
-			FileContent fileContent = fmgr.getFileContent(testWeblog, "bookmarks-file-id");
-			assertTrue("Non-existant file retrieved without any exception", false);
-		} catch (FileNotFoundException e) {
-			assertTrue("Exception thrown for non-existant file as expected", true);
-		}
-        
+            FileContent fileContent = fmgr.getFileContent(testWeblog, "bookmarks-file-id");
+            assertTrue("Non-existant file retrieved without any exception", false);
+        } catch (FileNotFoundException e) {
+            assertTrue("Exception thrown for non-existant file as expected", true);
+        }
+
         // store a file
         InputStream is = getClass().getResourceAsStream("/bookmarks.opml");
         fmgr.saveFileContent(testWeblog, "bookmarks-file-id", is);
-        
+
         // make sure file was stored successfully
         FileContent fileContent1 = fmgr.getFileContent(testWeblog, "bookmarks-file-id");
         assertEquals("bookmarks-file-id", fileContent1.getFileId());
-        
-        
+
+
         // delete file
         fmgr.deleteFile(testWeblog, "bookmarks-file-id");
-        
+
         // File should not exist after delete
         try {
-			FileContent fileContent = fmgr.getFileContent(testWeblog, "bookmarks-file-id");
-			assertTrue("Non-existant file retrieved without any exception", false);
-		} catch (FileNotFoundException e) {
-			assertTrue("Exception thrown for non-existant file as expected", true);
-		}
+            FileContent fileContent = fmgr.getFileContent(testWeblog, "bookmarks-file-id");
+            assertTrue("Non-existant file retrieved without any exception", false);
+        } catch (FileNotFoundException e) {
+            assertTrue("Exception thrown for non-existant file as expected", true);
+        }
+
+        TestUtils.endSession(true);
+        TestUtils.teardownWeblog(testWeblog.getId());
+        TestUtils.teardownUser(testUser.getUserName());
     }
-    
-    
+
     /**
      * Test FileContentManager.saveFile() checks.
      *
      * This should test all conditions where a save should fail.
      */
     public void testCanSave() throws Exception {
-        
+
         try {
             testUser = TestUtils.setupUser("FCMTest_userName2");
             testWeblog = TestUtils.setupWeblog("FCMTest_handle2", testUser);
@@ -158,42 +145,45 @@
         FileContentManager fmgr = WebloggerFactory.getWeblogger().getFileContentManager();
         PropertiesManager pmgr = WebloggerFactory.getWeblogger().getPropertiesManager();
         Map config = config = pmgr.getProperties();
-        ((RuntimeConfigProperty)config.get("uploads.dir.maxsize")).setValue("1.00");
-        ((RuntimeConfigProperty)config.get("uploads.types.forbid")).setValue("");
-        ((RuntimeConfigProperty)config.get("uploads.types.allowed")).setValue("");
-        ((RuntimeConfigProperty)config.get("uploads.enabled")).setValue("true");
+        ((RuntimeConfigProperty) config.get("uploads.dir.maxsize")).setValue("1.00");
+        ((RuntimeConfigProperty) config.get("uploads.types.forbid")).setValue("");
+        ((RuntimeConfigProperty) config.get("uploads.types.allowed")).setValue("");
+        ((RuntimeConfigProperty) config.get("uploads.enabled")).setValue("true");
         pmgr.saveProperties(config);
         TestUtils.endSession(true);
-        
+
         config = pmgr.getProperties();
-        ((RuntimeConfigProperty)config.get("uploads.dir.maxsize")).setValue("1.00");
+        ((RuntimeConfigProperty) config.get("uploads.dir.maxsize")).setValue("1.00");
         pmgr.saveProperties(config);
         TestUtils.endSession(true);
-        
+
         RollerMessages msgs = new RollerMessages();
         boolean canSave = fmgr.canSave(testWeblog, "test.gif", "text/plain", 2500000, msgs);
         assertFalse(canSave);
-        
+
         config = pmgr.getProperties();
-        ((RuntimeConfigProperty)config.get("uploads.types.forbid")).setValue("gif");
+        ((RuntimeConfigProperty) config.get("uploads.types.forbid")).setValue("gif");
         pmgr.saveProperties(config);
         TestUtils.endSession(true);
-        
+
         // forbidden types check should fail
-    	msgs = new RollerMessages();
-    	fmgr.canSave(testWeblog, "test.gif", "text/plain", 10, msgs);
+        msgs = new RollerMessages();
+        fmgr.canSave(testWeblog, "test.gif", "text/plain", 10, msgs);
         assertFalse(canSave);
-        
-        
+
+
         config = pmgr.getProperties();
-        ((RuntimeConfigProperty)config.get("uploads.enabled")).setValue("false");
+        ((RuntimeConfigProperty) config.get("uploads.enabled")).setValue("false");
         pmgr.saveProperties(config);
         TestUtils.endSession(true);
-        
+
         // uploads disabled should fail
-    	msgs = new RollerMessages();
-    	fmgr.canSave(testWeblog, "test.gif", "text/plain", 10, msgs);
+        msgs = new RollerMessages();
+        fmgr.canSave(testWeblog, "test.gif", "text/plain", 10, msgs);
         assertFalse(canSave);
+
+        TestUtils.endSession(true);
+        TestUtils.teardownWeblog(testWeblog.getId());
+        TestUtils.teardownUser(testUser.getUserName());
     }
-    
 }



Mime
View raw message