jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1091847 - in /jackrabbit/sandbox/jcrutil: pom.xml src/main/java/org/jcrutil/JcrFileObject.java src/main/java/org/jcrutil/S3DataStore.java src/test/java/org/jcrutil/S3DataStoreTest.java
Date Wed, 13 Apr 2011 16:47:27 GMT
Author: jukka
Date: Wed Apr 13 16:47:27 2011
New Revision: 1091847

URL: http://svn.apache.org/viewvc?rev=1091847&view=rev
Log:
JCR-2805: Jackrabbit Utilites upgrade to Jackrabbit 2.1.0

Patch by James Smitley.

Modified:
    jackrabbit/sandbox/jcrutil/pom.xml
    jackrabbit/sandbox/jcrutil/src/main/java/org/jcrutil/JcrFileObject.java
    jackrabbit/sandbox/jcrutil/src/main/java/org/jcrutil/S3DataStore.java
    jackrabbit/sandbox/jcrutil/src/test/java/org/jcrutil/S3DataStoreTest.java

Modified: jackrabbit/sandbox/jcrutil/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jcrutil/pom.xml?rev=1091847&r1=1091846&r2=1091847&view=diff
==============================================================================
--- jackrabbit/sandbox/jcrutil/pom.xml (original)
+++ jackrabbit/sandbox/jcrutil/pom.xml Wed Apr 13 16:47:27 2011
@@ -6,7 +6,7 @@
   <groupId>org.jcrutil</groupId>
   <artifactId>jcrutil</artifactId>
   <packaging>jar</packaging>
-  <version>1.0-SNAPSHOT</version>
+  <version>1.1-SNAPSHOT</version>
   <name>jcrutil</name>
   
   <repositories>
@@ -60,7 +60,7 @@
     <dependency>
       <groupId>javax.jcr</groupId>
       <artifactId>jcr</artifactId>
-      <version>1.0</version>
+      <version>2.0</version>
     </dependency>
     <dependency>
       <groupId>commons-vfs</groupId>
@@ -70,7 +70,7 @@
     <dependency>
       <groupId>net.java.dev.jets3t</groupId>
       <artifactId>jets3t</artifactId>
-      <version>0.6.1</version>
+      <version>0.7.3</version>
     </dependency>
     <dependency>
       <groupId>net.sf.ehcache</groupId>
@@ -80,37 +80,32 @@
     <dependency>
       <groupId>org.apache.jackrabbit</groupId>
       <artifactId>jackrabbit-api</artifactId>
-      <version>1.5-SNAPSHOT</version>
+      <version>2.1.0</version>
     </dependency>
     <dependency>
       <groupId>org.apache.jackrabbit</groupId>
       <artifactId>jackrabbit-core</artifactId>
-      <version>1.5-SNAPSHOT</version>
+      <version>2.1.0</version>
     </dependency>
     <dependency>
       <groupId>org.apache.jackrabbit</groupId>
       <artifactId>jackrabbit-jcr-commons</artifactId>
-      <version>1.5-SNAPSHOT</version>
+      <version>2.1.0</version>
     </dependency>
     <dependency>
       <groupId>org.apache.jackrabbit</groupId>
       <artifactId>jackrabbit-spi</artifactId>
-      <version>1.5-SNAPSHOT</version>
+      <version>2.1.0</version>
     </dependency>
     <dependency>
       <groupId>org.apache.jackrabbit</groupId>
       <artifactId>jackrabbit-spi-commons</artifactId>
-      <version>1.5-SNAPSHOT</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.jackrabbit</groupId>
-      <artifactId>jackrabbit-text-extractors</artifactId>
-      <version>1.5-SNAPSHOT</version>
+      <version>2.1.0</version>
     </dependency>
     <dependency>
       <groupId>org.apache.jackrabbit</groupId>
       <artifactId>jackrabbit-jcr-server</artifactId>
-      <version>1.5-SNAPSHOT</version>
+      <version>2.1.0</version>
     </dependency>
   </dependencies>
 </project>

Modified: jackrabbit/sandbox/jcrutil/src/main/java/org/jcrutil/JcrFileObject.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jcrutil/src/main/java/org/jcrutil/JcrFileObject.java?rev=1091847&r1=1091846&r2=1091847&view=diff
==============================================================================
--- jackrabbit/sandbox/jcrutil/src/main/java/org/jcrutil/JcrFileObject.java (original)
+++ jackrabbit/sandbox/jcrutil/src/main/java/org/jcrutil/JcrFileObject.java Wed Apr 13 16:47:27
2011
@@ -19,9 +19,12 @@ import javax.jcr.NodeIterator;
 import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.security.AccessControlManager;
+import javax.jcr.security.Privilege;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.commons.vfs.FileContent;
 import org.apache.commons.vfs.FileObject;
 import org.apache.commons.vfs.FileSystemException;
 import org.apache.commons.vfs.FileType;
@@ -29,11 +32,10 @@ import org.apache.commons.vfs.provider.A
 import org.apache.commons.vfs.provider.GenericFileName;
 import org.apache.commons.vfs.provider.URLFileName;
 import org.apache.commons.vfs.util.MonitorOutputStream;
-import org.apache.jackrabbit.api.jsr283.security.AccessControlManager;
-import org.apache.jackrabbit.api.jsr283.security.Privilege;
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.security.authorization.PrivilegeRegistry;
-import org.apache.jackrabbit.server.io.MimeResolver;
+import org.apache.tika.config.TikaConfig;
+import org.apache.tika.mime.MimeTypes;
 
 /**
  * A JCR base FileObject for VFS
@@ -44,8 +46,8 @@ public class JcrFileObject extends Abstr
     /** The Log */
     private static Log log = LogFactory.getLog(JcrFileObject.class);
 
-    /** The MimeResolver */
-    private static MimeResolver MIME_RESOLVER = new MimeResolver();
+    /** The MimeTypes */
+    private static MimeTypes MIME_TYPES = TikaConfig.getDefaultConfig().getMimeRepository();
     
     /** The FileSystem */
     private JcrFileSystem jcrFs;
@@ -56,7 +58,7 @@ public class JcrFileObject extends Abstr
     /** The Node represented by this FileObject */
     private Node node;
 
-    /**
+  /**
      * Create a new FileObject
      * 
      * @param node
@@ -294,7 +296,8 @@ public class JcrFileObject extends Abstr
         SessionImpl sess = (SessionImpl) jcrFs.getSession();
         AccessControlManager acm = sess.getAccessControlManager();
         PrivilegeRegistry pr = new PrivilegeRegistry(sess);
-        return acm.hasPrivileges(getName().getPath(), pr.getPrivileges(PrivilegeRegistry.READ));
+        Privilege[] privilegeArray = new Privilege[] { pr.getPrivilege(Privilege.JCR_READ)
};
+        return acm.hasPrivileges(getName().getPath(), privilegeArray);
     }
 
     /**
@@ -306,7 +309,8 @@ public class JcrFileObject extends Abstr
         SessionImpl sess = (SessionImpl) jcrFs.getSession();
         AccessControlManager acm = sess.getAccessControlManager();
         PrivilegeRegistry pr = new PrivilegeRegistry(sess);
-        return acm.hasPrivileges(getName().getPath(), pr.getPrivileges(PrivilegeRegistry.WRITE));
+        Privilege[] privilegeArray = new Privilege[] { pr.getPrivilege(Privilege.JCR_WRITE)
};
+        return acm.hasPrivileges(getName().getPath(), privilegeArray);
     }
 
     // get/set
@@ -387,7 +391,7 @@ public class JcrFileObject extends Abstr
                 }
 
                 Calendar lastModified = Calendar.getInstance();
-                resNode.setProperty("jcr:mimeType", MIME_RESOLVER.getMimeType(getName().getBaseName()));
+                resNode.setProperty("jcr:mimeType", getMimeType());
                 resNode.setProperty("jcr:data", new BufferedInputStream(tmpFile.getContent().getInputStream()));
                 resNode.setProperty("jcr:lastModified", lastModified);
                 jcrFs.getSession().save();
@@ -399,6 +403,26 @@ public class JcrFileObject extends Abstr
                 tmpFile.delete();
             }
         }
+
+        private String getMimeType() throws IOException {
+            String mimeType = null;
+            InputStream contentInputStream = null;
+
+            try {
+                contentInputStream = tmpFile.getContent().getInputStream();
+                mimeType = MIME_TYPES.getMimeType(getName().getBaseName(), contentInputStream).toString();
+            } finally {
+                if (mimeType == null) {
+                    mimeType = MIME_TYPES.getMimeType(getName().getBaseName()).toString();
+                }
+
+                if (contentInputStream != null) {
+                    contentInputStream.close();
+                }
+            }
+
+            return mimeType;
+        }
     }
 
 }

Modified: jackrabbit/sandbox/jcrutil/src/main/java/org/jcrutil/S3DataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jcrutil/src/main/java/org/jcrutil/S3DataStore.java?rev=1091847&r1=1091846&r2=1091847&view=diff
==============================================================================
--- jackrabbit/sandbox/jcrutil/src/main/java/org/jcrutil/S3DataStore.java (original)
+++ jackrabbit/sandbox/jcrutil/src/main/java/org/jcrutil/S3DataStore.java Wed Apr 13 16:47:27
2011
@@ -38,28 +38,44 @@ import org.jets3t.service.security.AWSCr
 import org.jets3t.service.utils.Mimetypes;
 
 public class S3DataStore implements DataStore {
-    /** The Log */
+    /**
+     * The Log
+     */
     private static Log LOG = LogFactory.getLog(S3DataStore.class);
 
-    /** Cached credentials */
+    /**
+     * Cached credentials
+     */
     protected AWSCredentials awsCredentials;
 
-    /** Config parameter awsAccessKey */
+    /**
+     * Config parameter awsAccessKey
+     */
     protected String awsAccessKey;
 
-    /** Config parameter awsSecretKey */
+    /**
+     * Config parameter awsSecretKey
+     */
     protected String awsSecretKey;
 
-    /** Config parameter bucketName */
+    /**
+     * Config parameter bucketName
+     */
     protected String bucketName;
 
-    /** Config parameter minModifiedDate */
+    /**
+     * Config parameter minModifiedDate
+     */
     protected long minModifiedDate;
 
-    /** Config parameter minRecordLength */
+    /**
+     * Config parameter minRecordLength
+     */
     protected int minRecordLength;
 
-    /** The S3Service */
+    /**
+     * The S3Service
+     */
     private S3Service s3Service;
 
     /** S3Object cache */
@@ -92,7 +108,7 @@ public class S3DataStore implements Data
 
             File tmp = File.createTempFile("s3-", ".tmp");
             tmp.deleteOnExit();
-            
+
             InputStream in = new BufferedInputStream(stream, 4096);
             OutputStream out = new BufferedOutputStream(new FileOutputStream(tmp), 4096);
             int i = 0;
@@ -100,21 +116,21 @@ public class S3DataStore implements Data
             while ((i = in.read(buf)) != -1) {
                 out.write(buf, 0, i);
             }
-            
+
             out.close();
-            
+
             Cache s3oContentCache = CacheManager.getInstance().getCache("s3oContentCache");
             s3oContentCache.put(new Element(uuid, tmp.getAbsolutePath()));
-            
+
             S3DataTransfer dt = new S3DataTransfer(s3Service, bucketName, uuid, tmp);
             new Thread(dt).start();
-            
+
             S3Bucket s3b = new S3Bucket(bucketName);
             s3o = new S3Object(s3b, uuid);
             s3o.setContentLength(tmp.length());
             s3o.setLastModifiedDate(new Date(tmp.lastModified()));
             s3o.setContentType(Mimetypes.getInstance().getMimetype(tmp));
-            
+
             Cache s3oCache = CacheManager.getInstance().getCache("s3oCache");
             s3oCache.put(new Element(uuid, s3o));
 
@@ -176,28 +192,27 @@ public class S3DataStore implements Data
         return minRecordLength;
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public DataRecord getRecord(DataIdentifier identifier) throws DataStoreException {
-        LOG.debug("getRecord: " + identifier);
+    private S3DataRecord getS3DataRecord(DataIdentifier dataIdentifier, boolean checkExistence)
throws S3ServiceException {
+        S3DataRecord s3DataRecord = null;
 
-        try {
-            String ident = identifier.toString();
-            Cache s3oCache = CacheManager.getInstance().getCache("s3oCache");
-            Element elem = s3oCache.get(ident);
+        String ident = dataIdentifier.toString();
+        Cache s3oCache = CacheManager.getInstance().getCache("s3oCache");
+        Element elem = s3oCache.get(ident);
 
-            S3Object s3o = null;
-            if (elem != null) {
-                LOG.debug("getRecord cache hit: " + ident);
-                s3o = (S3Object) elem.getValue();
-            } else {
-                LOG.debug("getRecord adding to cache: " + ident);
+        S3Object s3o = null;
+        if (elem != null) {
+            LOG.debug("getS3Object cache hit: " + ident);
+            s3o = (S3Object) elem.getValue();
+        } else {
+            LOG.debug("getS3Object adding to cache: " + ident);
+            if (!checkExistence || s3Service.isObjectInBucket(bucketName, ident)) {
                 s3o = s3Service.getObjectDetails(new S3Bucket(bucketName), ident);
-                s3oCache.put(new Element(ident, s3o));
             }
+            s3oCache.put(new Element(ident, s3o));
+        }
 
-            usesIdentifier(identifier);
+        if (s3o != null) {
+            usesIdentifier(dataIdentifier);
 
             if (minModifiedDate > 0) {
                 Date lmd = s3o.getLastModifiedDate();
@@ -208,15 +223,36 @@ public class S3DataStore implements Data
                 }
             }
 
-            return new S3DataRecord(this, identifier, s3o);
-        } catch (S3ServiceException se) {
-            throw new DataStoreException(se);
+            s3DataRecord = new S3DataRecord(this, dataIdentifier, s3o);
+        }
+
+        return s3DataRecord;
+    }
+
+    public DataRecord getRecordIfStored(DataIdentifier identifier) throws DataStoreException
{
+        LOG.debug("getRecordIfStored: " + identifier);
+        try {
+            return getS3DataRecord(identifier, true);
+        } catch (S3ServiceException e) {
+            throw new DataStoreException(e);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public DataRecord getRecord(DataIdentifier identifier) throws DataStoreException {
+        LOG.debug("getRecord: " + identifier);
+        try {
+            return getS3DataRecord(identifier, false);
+        } catch (S3ServiceException e) {
+            throw new DataStoreException(e);
         }
     }
 
     /**
      * Delete data record
-     * 
+     *
      * @param identifier The DataIdentifier
      */
     public void deleteRecord(DataIdentifier identifier) throws DataStoreException {
@@ -262,7 +298,7 @@ public class S3DataStore implements Data
 
     /**
      * Add WeakReference to inUse Map
-     * 
+     *
      * @param identifier The DataIdentifier
      */
     private void usesIdentifier(DataIdentifier identifier) {

Modified: jackrabbit/sandbox/jcrutil/src/test/java/org/jcrutil/S3DataStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jcrutil/src/test/java/org/jcrutil/S3DataStoreTest.java?rev=1091847&r1=1091846&r2=1091847&view=diff
==============================================================================
--- jackrabbit/sandbox/jcrutil/src/test/java/org/jcrutil/S3DataStoreTest.java (original)
+++ jackrabbit/sandbox/jcrutil/src/test/java/org/jcrutil/S3DataStoreTest.java Wed Apr 13 16:47:27
2011
@@ -25,7 +25,7 @@ public class S3DataStoreTest extends Tes
         
         try {
             Node root = session.getRootNode();
-
+            
             // Store content
             Node node1 = root.addNode("node1");
             Node node2 = root.addNode("node2");



Mime
View raw message