1 | package eu.clarin.cmdi.mdservice.action; |
---|
2 | |
---|
3 | import java.io.File; |
---|
4 | import java.io.IOException; |
---|
5 | import java.io.InputStream; |
---|
6 | import java.io.StringReader; |
---|
7 | import java.io.StringWriter; |
---|
8 | import java.net.MalformedURLException; |
---|
9 | import java.net.URISyntaxException; |
---|
10 | import java.net.URL; |
---|
11 | import java.util.HashMap; |
---|
12 | import java.io.ByteArrayInputStream; |
---|
13 | |
---|
14 | import javax.xml.parsers.DocumentBuilder; |
---|
15 | import javax.xml.parsers.DocumentBuilderFactory; |
---|
16 | import javax.xml.transform.OutputKeys; |
---|
17 | import javax.xml.transform.Transformer; |
---|
18 | import javax.xml.transform.TransformerException; |
---|
19 | import javax.xml.transform.TransformerFactory; |
---|
20 | import javax.xml.transform.dom.DOMSource; |
---|
21 | import javax.xml.transform.stream.StreamResult; |
---|
22 | |
---|
23 | import org.w3c.dom.Document; |
---|
24 | import org.w3c.dom.Node; |
---|
25 | import org.w3c.dom.NodeList; |
---|
26 | import org.xml.sax.InputSource; |
---|
27 | |
---|
28 | import eu.clarin.cmdi.mdservice.model.Query; |
---|
29 | |
---|
30 | /** |
---|
31 | |
---|
32 | */ |
---|
33 | public class Pz2ProxyAction extends GenericProxyAction { |
---|
34 | |
---|
35 | private static final long serialVersionUID = 1L; |
---|
36 | |
---|
37 | private String proxy_key = "pazpar2"; |
---|
38 | |
---|
39 | private String command; |
---|
40 | private String query; |
---|
41 | private String sessionID; |
---|
42 | private String sort; |
---|
43 | private String block; |
---|
44 | |
---|
45 | public void setCommand(String command) { |
---|
46 | this.command = command; |
---|
47 | } |
---|
48 | public String getCommand() { |
---|
49 | return command; |
---|
50 | } |
---|
51 | public void setQuery(String query) { |
---|
52 | this.query = query; |
---|
53 | } |
---|
54 | public String getQuery() { |
---|
55 | return query; |
---|
56 | } |
---|
57 | public void setSessionID(String sessionID) { |
---|
58 | this.sessionID = sessionID; |
---|
59 | } |
---|
60 | public String getSessionID() { |
---|
61 | return sessionID; |
---|
62 | } |
---|
63 | |
---|
64 | public void setSort(String sort) { |
---|
65 | this.sort = sort; |
---|
66 | } |
---|
67 | public String getSort() { |
---|
68 | return sort; |
---|
69 | } |
---|
70 | public void setBlock(String block) { |
---|
71 | this.block = block; |
---|
72 | } |
---|
73 | public String getBlock() { |
---|
74 | return block; |
---|
75 | } |
---|
76 | //TODO cache after analysis |
---|
77 | @Override |
---|
78 | public String getCache() { |
---|
79 | return Cache.SKIP; |
---|
80 | } |
---|
81 | |
---|
82 | public String createURLParams(){ |
---|
83 | String params = "?"; |
---|
84 | if (!(command == null)){ |
---|
85 | params = params + "command=" + command; |
---|
86 | } |
---|
87 | if (!(sessionID == null)){ |
---|
88 | params = params + "&session=" + sessionID; |
---|
89 | } |
---|
90 | if (!(query == null)){ |
---|
91 | params = params + "&query=" + query; |
---|
92 | } |
---|
93 | if (!(getStartItem() == null)){ |
---|
94 | params = params + "&start=" + getStartItem(); |
---|
95 | } |
---|
96 | if (!(getMaximumItems() == null)){ |
---|
97 | params = params + "&num=" + getMaximumItems(); |
---|
98 | } |
---|
99 | if (!(sort == null)){ |
---|
100 | params = params + "&sort=" + sort; |
---|
101 | if (!(block == null)){ |
---|
102 | params = params + ":" + block; |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | return params; |
---|
107 | } |
---|
108 | @Override |
---|
109 | public String getBaseURI() { |
---|
110 | String uri = getRepositoryPath(); |
---|
111 | return uri; |
---|
112 | } |
---|
113 | |
---|
114 | @Override |
---|
115 | public URL getTargetRequest() throws IOException { |
---|
116 | URL targetURL = null; |
---|
117 | |
---|
118 | targetURL =new URL( getBaseURL(), createURLParams() ); |
---|
119 | Admin.notifyUser("Pz2.targetURL:" + targetURL); |
---|
120 | return targetURL; |
---|
121 | } |
---|
122 | |
---|
123 | } |
---|