Start working on injection of IOManager and IOHandler
authorMathieu Baudier <mbaudier@argeo.org>
Fri, 14 Oct 2011 09:32:33 +0000 (09:32 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Fri, 14 Oct 2011 09:32:33 +0000 (09:32 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@4840 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/remote/IOHandlerWrapper.java [new file with mode: 0644]
server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/remote/IOManagerBean.java [new file with mode: 0644]

diff --git a/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/remote/IOHandlerWrapper.java b/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/remote/IOHandlerWrapper.java
new file mode 100644 (file)
index 0000000..817895b
--- /dev/null
@@ -0,0 +1,99 @@
+package org.argeo.jackrabbit.remote;
+
+import java.io.IOException;
+
+import org.apache.jackrabbit.server.io.ExportContext;
+import org.apache.jackrabbit.server.io.IOHandler;
+import org.apache.jackrabbit.server.io.IOManager;
+import org.apache.jackrabbit.server.io.ImportContext;
+import org.apache.jackrabbit.webdav.DavResource;
+import org.argeo.ArgeoException;
+
+/** Wraps an IOHandler so that it can be injected a posteriori */
+public class IOHandlerWrapper implements IOHandler {
+       private IOManager ioManager = null;
+       private IOHandler ioHandler = null;
+
+       public void setIOHandler(IOHandler ioHandler) {
+               if ((this.ioHandler != null) && (ioHandler != null))
+                       throw new ArgeoException(
+                                       "There is already an IO Handler registered");
+               this.ioHandler = ioHandler;
+               if (ioManager != null && this.ioHandler != null)
+                       ioHandler.setIOManager(ioManager);
+       }
+
+       public IOHandler getIOHandler() {
+               return ioHandler;
+       }
+
+       public IOManager getIOManager() {
+               return ioManager;
+       }
+
+       public void setIOManager(IOManager ioManager) {
+               this.ioManager = ioManager;
+               if (ioHandler != null)
+                       ioHandler.setIOManager(ioManager);
+       }
+
+       public String getName() {
+               if (ioHandler != null)
+                       return ioHandler.getName();
+               else
+                       return "Empty IOHandler Wrapper";
+       }
+
+       public boolean canImport(ImportContext context, boolean isCollection) {
+               if (ioHandler != null)
+                       return ioHandler.canImport(context, isCollection);
+               return false;
+       }
+
+       public boolean canImport(ImportContext context, DavResource resource) {
+               if (ioHandler != null)
+                       return ioHandler.canImport(context, resource);
+               return false;
+       }
+
+       public boolean importContent(ImportContext context, boolean isCollection)
+                       throws IOException {
+               if (ioHandler != null)
+                       ioHandler.importContent(context, isCollection);
+               return false;
+       }
+
+       public boolean importContent(ImportContext context, DavResource resource)
+                       throws IOException {
+               if (ioHandler != null)
+                       ioHandler.importContent(context, resource);
+               return false;
+       }
+
+       public boolean canExport(ExportContext context, boolean isCollection) {
+               if (ioHandler != null)
+                       ioHandler.canExport(context, isCollection);
+               return false;
+       }
+
+       public boolean canExport(ExportContext context, DavResource resource) {
+               if (ioHandler != null)
+                       ioHandler.canExport(context, resource);
+               return false;
+       }
+
+       public boolean exportContent(ExportContext context, boolean isCollection)
+                       throws IOException {
+               if (ioHandler != null)
+                       ioHandler.exportContent(context, isCollection);
+               return false;
+       }
+
+       public boolean exportContent(ExportContext context, DavResource resource)
+                       throws IOException {
+               if (ioHandler != null)
+                       ioHandler.exportContent(context, resource);
+               return false;
+       }
+
+}
diff --git a/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/remote/IOManagerBean.java b/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/remote/IOManagerBean.java
new file mode 100644 (file)
index 0000000..72db68f
--- /dev/null
@@ -0,0 +1,67 @@
+package org.argeo.jackrabbit.remote;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.jackrabbit.server.io.ExportContext;
+import org.apache.jackrabbit.server.io.IOHandler;
+import org.apache.jackrabbit.server.io.IOManager;
+import org.apache.jackrabbit.server.io.ImportContext;
+import org.apache.jackrabbit.webdav.DavResource;
+import org.apache.tika.detect.Detector;
+
+/** {@link IOManager} that can easily be configured as a bean. */
+public class IOManagerBean implements IOManager {
+       private Detector detector = null;
+       private List<IOHandler> ioHandlers = new ArrayList<IOHandler>();
+
+       public boolean importContent(ImportContext context, boolean isCollection)
+                       throws IOException {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       public boolean importContent(ImportContext context, DavResource resource)
+                       throws IOException {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       public boolean exportContent(ExportContext context, boolean isCollection)
+                       throws IOException {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       public boolean exportContent(ExportContext context, DavResource resource)
+                       throws IOException {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       public synchronized void addIOHandler(IOHandler ioHandler) {
+               ioHandlers.add(ioHandler);
+       }
+
+       public synchronized IOHandler[] getIOHandlers() {
+               return ioHandlers.toArray(new IOHandler[ioHandlers.size()]);
+       }
+
+       public Detector getDetector() {
+               return detector;
+       }
+
+       public void setDetector(Detector detector) {
+               this.detector = detector;
+       }
+
+       public synchronized List<IOHandler> getIoHandlers() {
+               return ioHandlers;
+       }
+
+       public synchronized void setIoHandlers(List<IOHandler> ioHandlers) {
+               this.ioHandlers = ioHandlers;
+       }
+
+}