From a29d3cd8ad35a56bd8222fd8030cdfa29dedd618 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Fri, 14 Oct 2011 09:32:33 +0000 Subject: [PATCH] Start working on injection of IOManager and IOHandler git-svn-id: https://svn.argeo.org/commons/trunk@4840 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../jackrabbit/remote/IOHandlerWrapper.java | 99 +++++++++++++++++++ .../jackrabbit/remote/IOManagerBean.java | 67 +++++++++++++ 2 files changed, 166 insertions(+) create mode 100644 server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/remote/IOHandlerWrapper.java create mode 100644 server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/remote/IOManagerBean.java 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 index 000000000..817895b68 --- /dev/null +++ b/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/remote/IOHandlerWrapper.java @@ -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 index 000000000..72db68fb2 --- /dev/null +++ b/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/remote/IOManagerBean.java @@ -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 ioHandlers = new ArrayList(); + + 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 getIoHandlers() { + return ioHandlers; + } + + public synchronized void setIoHandlers(List ioHandlers) { + this.ioHandlers = ioHandlers; + } + +} -- 2.39.2