0
|
1 package de.mpiwg.itgroup.escidoc.MPIWGServices.Restlet.services.redirect;
|
|
2
|
|
3 import java.io.IOException;
|
|
4 import java.io.InputStream;
|
|
5 import java.util.Properties;
|
|
6
|
|
7 import org.apache.http.HttpResponse;
|
|
8 import org.jdom.Attribute;
|
|
9 import org.jdom.Document;
|
|
10 import org.jdom.Element;
|
|
11 import org.jdom.JDOMException;
|
|
12 import org.jdom.input.SAXBuilder;
|
|
13 import org.jdom.xpath.XPath;
|
|
14 import org.restlet.data.Status;
|
|
15 import org.restlet.representation.Representation;
|
|
16 import org.restlet.representation.StringRepresentation;
|
|
17 import org.restlet.resource.Get;
|
|
18 import org.restlet.resource.ServerResource;
|
|
19
|
|
20 import de.mpiwg.itgroup.eSciDoc.Tools.EScidocBasicHandler;
|
|
21 import de.mpiwg.itgroup.eSciDoc.Tools.EScidocTools;
|
|
22 import de.mpiwg.itgroup.eSciDoc.echoObjects.ECHORessource;
|
|
23
|
|
24
|
|
25 public class DigilibRedirector extends ServerResource{
|
|
26
|
|
27 private String eScidocServer;
|
|
28 private String eScidocPort;
|
|
29 private String digilibPath;
|
|
30 private String eScidocUser;
|
|
31 private String eScidocUserPW;
|
|
32 public DigilibRedirector() throws IOException{
|
|
33 InputStream is = getClass().getResourceAsStream("/de/mpiwg/itgroup/escidoc/MPIWGServices/Restlet/config/eScidocServer.config");
|
|
34 Properties prop = new Properties();
|
|
35 prop.load(is);
|
|
36 eScidocServer= (String)prop.get("eScidocServer");
|
|
37 eScidocPort=(String)prop.get("eScidocPort");
|
|
38 digilibPath=(String)prop.get("digilibPath");
|
|
39 eScidocUser=(String)prop.get("eScidocUser");
|
|
40 eScidocUserPW=(String)prop.get("eScidocUserPW");
|
|
41
|
|
42 }
|
|
43 @Get("html")
|
|
44 public Representation getHtml()
|
|
45 {
|
|
46 String id = (String)getRequest().getAttributes().get("escidocId");
|
|
47 EScidocBasicHandler handler = null;
|
|
48 if (getContext().getAttributes().containsKey("escidocHandler")){
|
|
49 handler = (EScidocBasicHandler) getContext().getAttributes().get("escidocHandler");
|
|
50 }
|
|
51
|
|
52 if (handler==null){
|
|
53 handler = new EScidocBasicHandler(eScidocServer, Integer.valueOf(eScidocPort),eScidocUser,eScidocUserPW);
|
|
54 }
|
|
55
|
|
56
|
|
57 HttpResponse resp;
|
|
58 try {
|
|
59 resp = handler.eScidocGet("/ir/item/"+id);
|
|
60 } catch (IOException e) {
|
|
61 setStatus(Status.SERVER_ERROR_INTERNAL);
|
|
62 return new StringRepresentation("<html><body>error1</body></html>");
|
|
63 }
|
|
64 int code = resp.getStatusLine().getStatusCode();
|
|
65 if (code!=200){
|
|
66 setStatus(new Status(code));
|
|
67 return new StringRepresentation("<html><body>error2</body></html>");
|
|
68
|
|
69 }
|
|
70
|
|
71 Document doc;
|
|
72 String path;
|
|
73 try {
|
|
74 doc = new SAXBuilder().build(resp.getEntity().getContent());
|
|
75
|
|
76
|
|
77 XPath xp= EScidocTools.getESciDocXpath("//metadataRecords:md-record[@xlink:title='mpiwg-admin']/mpiwg:admin/mpiwg:imageFolder");
|
|
78 Element item = (Element)xp.selectSingleNode(doc);
|
|
79 path = item.getTextTrim();
|
|
80 path= ECHORessource.correct(path); // nur pfad nach online
|
|
81 } catch (Exception e) {
|
|
82 setStatus(Status.SERVER_ERROR_INTERNAL);
|
|
83 return new StringRepresentation("<html><body>error3</body></html>");
|
|
84 }
|
|
85
|
|
86
|
|
87 StringRepresentation repr = new StringRepresentation(digilibPath+path);
|
|
88 getResponse().redirectPermanent(digilibPath+path);
|
|
89 return repr;
|
|
90 }
|
|
91 }
|