jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r897071 - in /jackrabbit/trunk/jackrabbit-standalone/src/main: java/org/apache/jackrabbit/standalone/cli/ext/ java/org/apache/jackrabbit/standalone/cli/fs/ resources/org/apache/jackrabbit/command/ resources/org/apache/jackrabbit/command/cli/
Date Fri, 08 Jan 2010 01:00:03 GMT
Author: jukka
Date: Fri Jan  8 01:00:03 2010
New Revision: 897071

URL: http://svn.apache.org/viewvc?rev=897071&view=rev
Log:
JCR-2457: Command line access to remote repositories

Add missing license headers. Use Tika for file type detection.

Removed:
    jackrabbit/trunk/jackrabbit-standalone/src/main/java/org/apache/jackrabbit/standalone/cli/ext/package.html
    jackrabbit/trunk/jackrabbit-standalone/src/main/java/org/apache/jackrabbit/standalone/cli/fs/mimetypes.properties
Modified:
    jackrabbit/trunk/jackrabbit-standalone/src/main/java/org/apache/jackrabbit/standalone/cli/fs/ImportFileSystem.java
    jackrabbit/trunk/jackrabbit-standalone/src/main/resources/org/apache/jackrabbit/command/cli/command-line-rules.xml
    jackrabbit/trunk/jackrabbit-standalone/src/main/resources/org/apache/jackrabbit/command/cli/command-line.xml
    jackrabbit/trunk/jackrabbit-standalone/src/main/resources/org/apache/jackrabbit/command/cli/command.xml
    jackrabbit/trunk/jackrabbit-standalone/src/main/resources/org/apache/jackrabbit/command/resources.properties

Modified: jackrabbit/trunk/jackrabbit-standalone/src/main/java/org/apache/jackrabbit/standalone/cli/fs/ImportFileSystem.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone/src/main/java/org/apache/jackrabbit/standalone/cli/fs/ImportFileSystem.java?rev=897071&r1=897070&r2=897071&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone/src/main/java/org/apache/jackrabbit/standalone/cli/fs/ImportFileSystem.java
(original)
+++ jackrabbit/trunk/jackrabbit-standalone/src/main/java/org/apache/jackrabbit/standalone/cli/fs/ImportFileSystem.java
Fri Jan  8 01:00:03 2010
@@ -19,8 +19,8 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.Calendar;
-import java.util.Properties;
 
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
@@ -29,8 +29,10 @@
 import org.apache.commons.chain.Context;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.commons.JcrUtils;
 import org.apache.jackrabbit.standalone.cli.CommandException;
 import org.apache.jackrabbit.standalone.cli.CommandHelper;
+import org.apache.tika.Tika;
 
 /**
  * Import data from the file system. <br>
@@ -43,18 +45,8 @@
     /** logger */
     private static Log log = LogFactory.getLog(ImportFileSystem.class);
 
-    /** extension to mime type mapping */
-    private static Properties mimeTypes;
-
-    static {
-        try {
-            mimeTypes = new Properties();
-            mimeTypes.load(ImportFileSystem.class
-                .getResourceAsStream("mimetypes.properties"));
-        } catch (Exception e) {
-            log.error("unable to load mime types", e);
-        }
-    }
+    /** Use Apache Tika to detect the media types of imported files */
+    private static Tika tika = new Tika();
 
     // ---------------------------- < keys >
 
@@ -110,23 +102,16 @@
 
     private void importFile(Node parentnode, File file)
             throws RepositoryException, IOException {
-        String mimeType = null;
-        String extension = getExtension(file.getName());
-        if (extension != null) {
-            mimeType = mimeTypes.getProperty(extension);
-        }
-        if (mimeType == null) {
-            mimeType = "application/octet-stream";
-        }
-
-        Node fileNode = parentnode.addNode(file.getName(), "nt:file");
-        Node resNode = fileNode.addNode("jcr:content", "nt:resource");
-        resNode.setProperty("jcr:mimeType", mimeType);
-        resNode.setProperty("jcr:encoding", "");
-        resNode.setProperty("jcr:data", new FileInputStream(file));
-        Calendar lastModified = Calendar.getInstance();
-        lastModified.setTimeInMillis(file.lastModified());
-        resNode.setProperty("jcr:lastModified", lastModified);
+        InputStream stream = new FileInputStream(file);
+        try {
+            Calendar date = Calendar.getInstance();
+            date.setTimeInMillis(file.lastModified());
+            JcrUtils.putFile(
+                    parentnode, file.getName(),
+                    tika.detect(file), stream, date);
+        } finally {
+            stream.close();
+        }
     }
 
     /**
@@ -146,8 +131,8 @@
         for (int i = 0; i < direntries.length; i++) {
             File direntry = direntries[i];
             if (direntry.isDirectory()) {
-                Node childnode = parentnode.addNode(direntry.getName(),
-                    "nt:folder");
+                Node childnode =
+                    JcrUtils.getOrAddFolder(parentnode, direntry.getName());
                 importFolder(childnode, direntry);
             } else {
                 importFile(parentnode, direntry);

Modified: jackrabbit/trunk/jackrabbit-standalone/src/main/resources/org/apache/jackrabbit/command/cli/command-line-rules.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone/src/main/resources/org/apache/jackrabbit/command/cli/command-line-rules.xml?rev=897071&r1=897070&r2=897071&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone/src/main/resources/org/apache/jackrabbit/command/cli/command-line-rules.xml
(original)
+++ jackrabbit/trunk/jackrabbit-standalone/src/main/resources/org/apache/jackrabbit/command/cli/command-line-rules.xml
Fri Jan  8 01:00:03 2010
@@ -1,4 +1,20 @@
 <?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
 <!DOCTYPE digester-rules PUBLIC
  "-//Jakarta Apache //DTD digester-rules XML V1.0//EN"
  "digester-rules.dtd">

Modified: jackrabbit/trunk/jackrabbit-standalone/src/main/resources/org/apache/jackrabbit/command/cli/command-line.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone/src/main/resources/org/apache/jackrabbit/command/cli/command-line.xml?rev=897071&r1=897070&r2=897071&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone/src/main/resources/org/apache/jackrabbit/command/cli/command-line.xml
(original)
+++ jackrabbit/trunk/jackrabbit-standalone/src/main/resources/org/apache/jackrabbit/command/cli/command-line.xml
Fri Jan  8 01:00:03 2010
@@ -1,4 +1,20 @@
 <?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
 <!DOCTYPE commands [
   <!ELEMENT commands (command+)>
 

Modified: jackrabbit/trunk/jackrabbit-standalone/src/main/resources/org/apache/jackrabbit/command/cli/command.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone/src/main/resources/org/apache/jackrabbit/command/cli/command.xml?rev=897071&r1=897070&r2=897071&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone/src/main/resources/org/apache/jackrabbit/command/cli/command.xml
(original)
+++ jackrabbit/trunk/jackrabbit-standalone/src/main/resources/org/apache/jackrabbit/command/cli/command.xml
Fri Jan  8 01:00:03 2010
@@ -1,4 +1,20 @@
 <?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
 <chains>
 	<catalog>
 

Modified: jackrabbit/trunk/jackrabbit-standalone/src/main/resources/org/apache/jackrabbit/command/resources.properties
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-standalone/src/main/resources/org/apache/jackrabbit/command/resources.properties?rev=897071&r1=897070&r2=897071&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-standalone/src/main/resources/org/apache/jackrabbit/command/resources.properties
(original)
+++ jackrabbit/trunk/jackrabbit-standalone/src/main/resources/org/apache/jackrabbit/command/resources.properties
Fri Jan  8 01:00:03 2010
@@ -1,3 +1,17 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
 
 cmd.addlocktoken                   = Add the given Lock token to the current Session
 cmd.addlocktoken.token             = lock token



Mime
View raw message