changeset 3:498b68667ff3

Neuer Mechanismus zum umleiten der Quellen.
author dwinter
date Fri, 20 Apr 2012 15:55:51 +0200
parents ffeb8be0bded
children 938e45fabd7c
files .classpath .settings/org.eclipse.wst.common.component libs/commons-io-1.3.2.jar src/de/mpiwg/itgroup/escidoc/MPIWGServices/Restlet/RestServer.java src/de/mpiwg/itgroup/escidoc/MPIWGServices/Restlet/config/viewer.config src/de/mpiwg/itgroup/escidoc/MPIWGServices/Restlet/services/redirect/ComponentURLRedirector.java src/de/mpiwg/itgroup/escidoc/MPIWGServices/Restlet/services/redirect/DocuviewerRedirector.java src/de/mpiwg/itgroup/escidoc/MPIWGServices/Restlet/services/redirect/EScidocRedirector.java src/de/mpiwg/itgroup/escidoc/MPIWGServices/Restlet/services/redirect/OrigRefRedirector.java
diffstat 9 files changed, 302 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/.classpath	Mon Dec 13 11:13:02 2010 +0100
+++ b/.classpath	Fri Apr 20 15:55:51 2012 +0200
@@ -20,6 +20,7 @@
 	<classpathentry kind="lib" path="libs/httpcore-4.0.1.jar"/>
 	<classpathentry kind="lib" path="libs/jaxen-1.1.1.jar"/>
 	<classpathentry kind="lib" path="libs/jdom-1.0.jar"/>
+	<classpathentry kind="lib" path="libs/commons-io-1.3.2.jar"/>
 	<classpathentry combineaccessrules="false" kind="src" path="/eSciDocImport"/>
 	<classpathentry combineaccessrules="false" kind="src" path="/eSciDocTools"/>
 	<classpathentry kind="output" path="build/classes"/>
--- a/.settings/org.eclipse.wst.common.component	Mon Dec 13 11:13:02 2010 +0100
+++ b/.settings/org.eclipse.wst.common.component	Fri Apr 20 15:55:51 2012 +0200
@@ -42,6 +42,9 @@
         <dependent-module archiveName="org.apache.commons.logging.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/eSciDocMPIWGServicesRestlet/libs/org.apache.commons.logging_1.1/org.apache.commons.logging.jar">
             <dependency-type>uses</dependency-type>
         </dependent-module>
+        <dependent-module archiveName="xercesImpl.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/MetaDataManager/libs/xercesImpl.jar">
+            <dependency-type>uses</dependency-type>
+        </dependent-module>
         <property name="java-output-path" value="/eScidocMPIWGServicesRestlet/build/classes"/>
         <property name="context-root" value="eScidocMPIWGServicesRestlet"/>
     </wb-module>
Binary file libs/commons-io-1.3.2.jar has changed
--- a/src/de/mpiwg/itgroup/escidoc/MPIWGServices/Restlet/RestServer.java	Mon Dec 13 11:13:02 2010 +0100
+++ b/src/de/mpiwg/itgroup/escidoc/MPIWGServices/Restlet/RestServer.java	Fri Apr 20 15:55:51 2012 +0200
@@ -13,7 +13,9 @@
 import de.mpiwg.itgroup.escidoc.MPIWGServices.Restlet.services.display.DisplayContainer;
 import de.mpiwg.itgroup.escidoc.MPIWGServices.Restlet.services.redirect.DigilibRedirector;
 import de.mpiwg.itgroup.escidoc.MPIWGServices.Restlet.services.redirect.DisplayRedirector;
+import de.mpiwg.itgroup.escidoc.MPIWGServices.Restlet.services.redirect.DocuviewerRedirector;
 import de.mpiwg.itgroup.escidoc.MPIWGServices.Restlet.services.redirect.ECHORedirector;
+import de.mpiwg.itgroup.escidoc.MPIWGServices.Restlet.services.redirect.EScidocRedirector;
 import de.mpiwg.itgroup.escidoc.MPIWGServices.Restlet.services.redirect.IndexMetaRedirector;
 import de.mpiwg.itgroup.escidoc.MPIWGServices.Restlet.services.redirect.OrigRefRedirector;
 import de.mpiwg.itgroup.escidoc.MPIWGServices.Restlet.services.search.SimpleSearch;
@@ -37,15 +39,15 @@
 		Router router = new Router(getContext());
 		router.attach("/search",SimpleSearch.class);
 		router.attach("/container/{escidocId}",DisplayContainer.class);
-		router.attach("/resultOverview.css",ResultOverviewCSS.class); // zeigt den image ordner im digilib standard display an
-		router.attach("/{escidocId}",ECHORedirector.class); // redirected zur webseite die in echo angebeben ist
-		router.attach("/{escidocId}/echo",ECHORedirector.class); // redirected zur  ECHO Seite, diese redirected eventuell, direct wieder
-		router.attach("/{escidocId}/display",DisplayRedirector.class); // redirected zur display_url die in ECHO angegeben ist, wenn dort keine steht dann wird der image ordner im generischen viewer angezeigt
+		router.attach("/resultOverview.css",ResultOverviewCSS.class); 
+		router.attach("/docuview/{flavour}/{escidocId}",DocuviewerRedirector.class); // redirected zur  ECHO Seite, diese redirected eventuell, direct wieder
+		router.attach("/echo/{escidocId}",ECHORedirector.class); // redirected zur  ECHO Seite, diese redirected eventuell, direct wieder
+		router.attach("/display/{escidocId}",DisplayRedirector.class); // redirected zur display_url die in ECHO angegeben ist, wenn dort keine steht dann wird der image ordner im generischen viewer angezeigt
+		router.attach("/metadata/{escidocId}",IndexMetaRedirector.class); // zeigt die in ESCIDOC abegespeicherten index_meta an
+		router.attach("/metadata/{escidocId}/origRef",OrigRefRedirector.class); // zeigt die original Quelle der Metadaten an, in der Regel das IndexMeta file auf der Foxridge
+		//router.attach("/{escidocId}",ECHORedirector.class); // redirected zur webseite die in echo angebeben ist
+		router.attach("/{escidocId}",EScidocRedirector.class); // redirected zur webseite die in echo angebeben ist
 		router.attach("/{escidocId}/images",DigilibRedirector.class); // zeigt den image ordner im digilib standard display an
-		router.attach("/{escidocId}/indexMeta",IndexMetaRedirector.class); // zeigt die in ESCIDOC abegespeicherten index_meta an
-		router.attach("/{escidocId}/origRef",OrigRefRedirector.class); // zeigt die original Quelle der Metadaten an, in der Regel das IndexMeta file auf der Foxridge
-		
-		
 		return router;
 	}
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/de/mpiwg/itgroup/escidoc/MPIWGServices/Restlet/config/viewer.config	Fri Apr 20 15:55:51 2012 +0200
@@ -0,0 +1,3 @@
+echo,http://echo.mpiwg-berlin.mpg.de/ECHOdocuViewfull?url=%s,http://echo.mpiwg-berlin.mpg.de/ECHOdocuViewfull?mode=imagepath&url=%s&viewMode=images
+libcoll,,http://libcoll.mpiwg-berlin.mpg.de/libview?url=%s&mode=imagepath
+digilib,,http://digilib.mpiwg-berlin.mpg.de/digitallibrary/jquery/digilib.html?fn=%s
--- a/src/de/mpiwg/itgroup/escidoc/MPIWGServices/Restlet/services/redirect/ComponentURLRedirector.java	Mon Dec 13 11:13:02 2010 +0100
+++ b/src/de/mpiwg/itgroup/escidoc/MPIWGServices/Restlet/services/redirect/ComponentURLRedirector.java	Fri Apr 20 15:55:51 2012 +0200
@@ -81,7 +81,7 @@
 		
 		} catch (Exception e) {
 			
-			if (content_cat.equals("display_url")) // wemm display und error dann versuche genrische anzeige der bilder
+			if (content_cat.equals("display_url")) // wenn display und error dann versuche genrische anzeige der bilder
 				{
 				url="./images";
 				StringRepresentation repr = new StringRepresentation(url);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/de/mpiwg/itgroup/escidoc/MPIWGServices/Restlet/services/redirect/DocuviewerRedirector.java	Fri Apr 20 15:55:51 2012 +0200
@@ -0,0 +1,206 @@
+package de.mpiwg.itgroup.escidoc.MPIWGServices.Restlet.services.redirect;
+
+
+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.http.HttpResponse;
+import org.jdom.Attribute;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+import org.jdom.xpath.XPath;
+import org.restlet.data.Status;
+import org.restlet.representation.Representation;
+import org.restlet.representation.StringRepresentation;
+import org.restlet.resource.Get;
+import org.restlet.resource.ServerResource;
+
+import de.mpiwg.itgroup.eSciDoc.Tools.EScidocBasicHandler;
+import de.mpiwg.itgroup.eSciDoc.Tools.EScidocTools;
+import de.mpiwg.itgroup.eSciDoc.echoObjects.ECHORessource;
+
+//http://127.0.0.1:8280/eScidocMPIWGServicesRestlet/docuview/escidoc:35464:2
+
+public class DocuviewerRedirector extends ServerResource{
+
+	private String eScidocServer;
+	private String eScidocPort;
+	private String eScidocUser;
+	private String eScidocUserPW;
+	
+	private String viewerWithIndexMetaFormatString;//="http://echo.mpiwg-berlin.mpg.de/ECHOdocuViewfull?url=%s"; // Formatstring fuer URLS, die die Daten anzeigen, falls ein IndexMeta vorhanden ist.
+	private String viewerWithImagePathFormatString;//="http://echo.mpiwg-berlin.mpg.de/ECHOdocuViewfull?mode=imagepath&url=%s&viewMode=images"; // Formatstring fuer URLS, die die Daten anzeigen, falls ein ImagePath vorhanden ist.
+	
+	private Map<String,List<String>> viewers;
+	
+	public DocuviewerRedirector() throws IOException{
+		InputStream is = getClass().getResourceAsStream("/de/mpiwg/itgroup/escidoc/MPIWGServices/Restlet/config/eScidocServer.config");
+		Properties prop = new Properties();
+		prop.load(is);
+		
+		eScidocServer= (String)prop.get("eScidocServer");
+		eScidocPort=(String)prop.get("eScidocPort");
+		eScidocUser = (String)prop.get("eScidocUser");
+		eScidocUserPW=(String)prop.get("eScidocUserPW");
+		
+		InputStream viewerConf = getClass().getResourceAsStream("/de/mpiwg/itgroup/escidoc/MPIWGServices/Restlet/config/viewer.config");
+		
+		BufferedReader br = new BufferedReader(new InputStreamReader(new DataInputStream(viewerConf)));
+		
+		String strLine;
+		viewers = new HashMap<String, List<String>>();
+		
+		while ((strLine = br.readLine()) != null)   {
+			String[] splitted = strLine.split(",");
+			
+			List<String> list =new ArrayList<String>();
+			
+			if (splitted[1].equals(""))
+				list.add(null); // index.meta koennen nicht interpretiert werden.
+			else	
+				list.add(splitted[1]); // add url for index.meta
+		
+			
+			if (splitted.length>1)
+				if (splitted[2].equals(""))
+					list.add(null);
+				else	
+					list.add(splitted[2]); // add url for images
+			else 
+				list.add(null); // null wenn keiner konfiguriert wird. TODO: handle this
+			
+			viewers.put(splitted[0], list);
+		}
+		
+		
+	}
+	@Get("html")
+	public Representation getHtml()
+	{
+		String id = (String)getRequest().getAttributes().get("escidocId");
+		String flavour = (String)getRequest().getAttributes().get("flavour");
+		
+		if (!viewers.containsKey(flavour)){
+			setStatus(Status.CLIENT_ERROR_NOT_FOUND);
+			return new StringRepresentation("no viewer configured for flavour:"+flavour+"! Check /de/mpiwg/itgroup/escidoc/MPIWGServices/Restlet/config/viewer.config");
+		}
+		
+		List<String> formats = viewers.get(flavour);
+		
+		viewerWithIndexMetaFormatString =  formats.get(0);
+		viewerWithImagePathFormatString = formats.get(1);
+		
+		EScidocBasicHandler handler = null;
+		if (getContext().getAttributes().containsKey("escidocHandler")){
+			handler = (EScidocBasicHandler) getContext().getAttributes().get("escidocHandler");
+		}
+		
+		if (handler==null){
+			handler = new EScidocBasicHandler(eScidocServer, Integer.valueOf(eScidocPort),eScidocUser,eScidocUserPW);
+		}
+		
+		
+		HttpResponse resp;
+		try {
+			resp = handler.eScidocGet("/ir/item/"+id);
+		} catch (IOException e) {
+			setStatus(Status.SERVER_ERROR_INTERNAL);
+			return new StringRepresentation("<html><body>error1</body></html>");
+		}
+		int code = resp.getStatusLine().getStatusCode();
+		if (code!=200){
+			setStatus(new Status(code));
+			return new StringRepresentation("<html><body>error2</body></html>");
+			
+		}
+		
+		Document doc;
+		String url;
+		try {
+			doc = new SAXBuilder().build(resp.getEntity().getContent());
+	
+	
+		//XPath xp= EScidocTools.getESciDocXpath("//escidocComponents:component[escidocComponents:properties/prop:content-category[text()='index_meta']]/escidocComponents:content/@xlink:href");
+			
+		XPath xp= EScidocTools.getESciDocXpath("//metadataRecords:md-record[@xlink:title='mpiwg-admin']/mpiwg:admin/mpiwg:orig-ref/@xlink:href");
+			Attribute item = (Attribute)xp.selectSingleNode(doc);	
+		url = item.getValue();
+		
+		} catch (Exception e) {
+			setStatus(Status.SERVER_ERROR_INTERNAL);
+			return new StringRepresentation("<html><body>error3a</body></html>");
+			
+		}
+		
+		
+		if (!url.startsWith("http")) { // relative url 
+			url="http://"+eScidocServer+":"+eScidocPort+url;
+		}
+			
+		
+		
+		String viewerUrl;
+		if (checkIndexMeta(url) && (viewerWithIndexMetaFormatString!=null)){ // index meta enthaelt texttool und viewer kann index meta interpretieren.
+			viewerUrl=String.format(viewerWithIndexMetaFormatString, url);
+		} else { // andernfalls hole den pfad auf die bilder
+			
+			try {
+			XPath xp= EScidocTools.getESciDocXpath("//metadataRecords:md-record[@xlink:title='mpiwg-admin']/mpiwg:admin/mpiwg:imageFolder");
+			Element item = (Element)xp.selectSingleNode(doc);	
+			String path = item.getTextTrim();
+			path= ECHORessource.correct(path); // nur pfad nach online
+			viewerUrl=String.format(viewerWithImagePathFormatString, path);
+			} catch (Exception e) {
+				setStatus(Status.SERVER_ERROR_INTERNAL);
+				return new StringRepresentation("<html><body>error3</body></html>");
+			}
+			
+			
+			
+		}
+		StringRepresentation repr = new StringRepresentation(viewerUrl);
+		getResponse().redirectPermanent(viewerUrl);
+		return repr;
+	}
+
+	
+	
+	private boolean checkIndexMeta(String url) {
+		try {
+			Document doc = new SAXBuilder().build(new URL(url));
+			XPath xp = XPath.newInstance("//texttool");
+			
+			Object item = xp.selectSingleNode(doc);
+			if (item!=null)
+				return true;
+			
+		} catch (MalformedURLException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		} catch (JDOMException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		
+		return false;
+	}
+		
+		
+		
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/de/mpiwg/itgroup/escidoc/MPIWGServices/Restlet/services/redirect/EScidocRedirector.java	Fri Apr 20 15:55:51 2012 +0200
@@ -0,0 +1,77 @@
+package de.mpiwg.itgroup.escidoc.MPIWGServices.Restlet.services.redirect;
+
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+import org.apache.http.HttpResponse;
+import org.jdom.Attribute;
+import org.jdom.Document;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+import org.jdom.xpath.XPath;
+import org.restlet.data.Status;
+import org.restlet.representation.Representation;
+import org.restlet.representation.StringRepresentation;
+import org.restlet.resource.Get;
+import org.restlet.resource.ServerResource;
+
+import de.mpiwg.itgroup.eSciDoc.Tools.EScidocBasicHandler;
+import de.mpiwg.itgroup.eSciDoc.Tools.EScidocTools;
+
+
+public class EScidocRedirector extends ServerResource{
+
+	private String eScidocServer;
+	private String eScidocPort;
+	private String content_cat;
+	private String eScidocUser;
+	private String eScidocUserPW;
+	
+	public EScidocRedirector() throws IOException{
+		
+		InputStream is = getClass().getResourceAsStream("/de/mpiwg/itgroup/escidoc/MPIWGServices/Restlet/config/eScidocServer.config");
+		Properties prop = new Properties();
+		prop.load(is);
+		
+		eScidocServer= (String)prop.get("eScidocServer");
+		eScidocPort=(String)prop.get("eScidocPort");
+		eScidocUser = (String)prop.get("eScidocUser");
+		eScidocUserPW=(String)prop.get("eScidocUserPW");
+		
+	}
+	@Get("html")
+	public Representation getHtml()
+	{
+		String id = (String)getRequest().getAttributes().get("escidocId");
+		EScidocBasicHandler handler = null;
+		if (getContext().getAttributes().containsKey("escidocHandler")){
+			handler = (EScidocBasicHandler) getContext().getAttributes().get("escidocHandler");
+		}
+		
+		if (handler==null){
+			handler = new EScidocBasicHandler(eScidocServer, Integer.valueOf(eScidocPort),eScidocUser,eScidocUserPW);
+		}
+		
+		
+		HttpResponse resp;
+		try {
+			resp = handler.eScidocGet("/ir/item/"+id);
+		} catch (IOException e) {
+			setStatus(Status.SERVER_ERROR_INTERNAL);
+			return new StringRepresentation("<html><body>error1</body></html>");
+		}
+		int code = resp.getStatusLine().getStatusCode();
+		if (code!=200){
+			setStatus(new Status(code));
+			return new StringRepresentation("<html><body>error2</body></html>");
+			
+		}
+		
+		String url = handler.eScidocUrl+"/ir/item/"+id;
+		StringRepresentation repr = new StringRepresentation(url);
+		getResponse().redirectPermanent(url);
+		return repr;
+	}
+}
--- a/src/de/mpiwg/itgroup/escidoc/MPIWGServices/Restlet/services/redirect/OrigRefRedirector.java	Mon Dec 13 11:13:02 2010 +0100
+++ b/src/de/mpiwg/itgroup/escidoc/MPIWGServices/Restlet/services/redirect/OrigRefRedirector.java	Fri Apr 20 15:55:51 2012 +0200
@@ -92,7 +92,7 @@
 			doc = new SAXBuilder().build(resp.getEntity().getContent());
 	
 	
-		XPath xp= EScidocTools.getESciDocXpath("//metadataRecords:md-record[@xlink:title='mpiwg-admin']/mpiwg:admin/mpiwg:orig-ref/@xlink:href");
+			XPath xp= EScidocTools.getESciDocXpath("//metadataRecords:md-record[@xlink:title='mpiwg-admin']/mpiwg:admin/mpiwg:orig-ref/@xlink:href");
 		Attribute item = (Attribute)xp.selectSingleNode(doc);	
 		path = item.getValue();
 		} catch (Exception e) {