1 | package eu.clarin.cmdi.mdservice.action; |
---|
2 | |
---|
3 | import java.io.BufferedReader; |
---|
4 | import java.io.ByteArrayInputStream; |
---|
5 | import java.io.IOException; |
---|
6 | import java.io.InputStream; |
---|
7 | import java.io.InputStreamReader; |
---|
8 | import java.io.StringWriter; |
---|
9 | import java.io.UnsupportedEncodingException; |
---|
10 | import java.util.HashMap; |
---|
11 | import javax.xml.parsers.ParserConfigurationException; |
---|
12 | import javax.xml.transform.TransformerConfigurationException; |
---|
13 | import javax.xml.transform.TransformerException; |
---|
14 | import javax.xml.transform.TransformerFactory; |
---|
15 | import javax.xml.transform.TransformerFactoryConfigurationError; |
---|
16 | import javax.xml.transform.dom.DOMSource; |
---|
17 | import javax.xml.transform.stream.StreamResult; |
---|
18 | |
---|
19 | import org.w3c.dom.Document; |
---|
20 | import org.w3c.dom.Node; |
---|
21 | |
---|
22 | import eu.clarin.cmdi.mdservice.internal.Cache; |
---|
23 | import eu.clarin.cmdi.mdservice.internal.Utils; |
---|
24 | import eu.clarin.cmdi.mdservice.model.Diagnostic; |
---|
25 | import eu.clarin.cmdi.mdservice.model.Query; |
---|
26 | import eu.clarin.cmdi.mdservice.model.Repositories; |
---|
27 | import eu.clarin.cmdi.mdservice.model.WorkspaceProfile; |
---|
28 | import eu.clarin.cmdi.mdservice.proxy.MDRepoProxy; |
---|
29 | import eu.clarin.cmdi.mdservice.proxy.Pz2Proxy; |
---|
30 | import eu.clarin.cmdi.mdservice.proxy.SRUProxy; |
---|
31 | |
---|
32 | |
---|
33 | |
---|
34 | |
---|
35 | public class SRUAction extends RepoAction |
---|
36 | { |
---|
37 | |
---|
38 | private static final long serialVersionUID = 1L; |
---|
39 | |
---|
40 | /** |
---|
41 | * Properties to be filled by Struts with according request-parameters |
---|
42 | */ |
---|
43 | |
---|
44 | private static int OP_SEARCHRETRIEVE = 1; |
---|
45 | private static int OP_EXPLAIN = 2; |
---|
46 | private static int OP_SCAN = 3; |
---|
47 | |
---|
48 | |
---|
49 | //TODO cache after analysis ? |
---|
50 | /* |
---|
51 | @Override |
---|
52 | public String getCache() { |
---|
53 | return Cache.SKIP; |
---|
54 | } |
---|
55 | */ |
---|
56 | |
---|
57 | @Override |
---|
58 | public String getRepository() { |
---|
59 | if (getParams().get("repository") == null){ |
---|
60 | return getParam("x-cmd-repository"); |
---|
61 | } |
---|
62 | return getParam("repository"); |
---|
63 | } |
---|
64 | |
---|
65 | @Override |
---|
66 | public String getFormat() { |
---|
67 | if (getParams().get("format") == null){ |
---|
68 | if (getParams().get("x-cmd-format") == null){ |
---|
69 | return "xml"; |
---|
70 | } |
---|
71 | return getParam("x-cmd-format"); |
---|
72 | } |
---|
73 | return getParam("format"); |
---|
74 | } |
---|
75 | |
---|
76 | /* |
---|
77 | public String getOperation() { |
---|
78 | if (getParams().get("operation") == null){ |
---|
79 | return "searchRetrieve"; |
---|
80 | } |
---|
81 | return getParam("operation"); |
---|
82 | } |
---|
83 | */ |
---|
84 | protected final static HashMap<String,Integer> operation_code = new HashMap<String,Integer>(); |
---|
85 | static |
---|
86 | { |
---|
87 | operation_code.put("searchRetrieve", OP_SEARCHRETRIEVE); |
---|
88 | operation_code.put("explain", OP_EXPLAIN); |
---|
89 | operation_code.put("scan", OP_SCAN); |
---|
90 | } |
---|
91 | |
---|
92 | /** |
---|
93 | * primitive identification of the target-proxy |
---|
94 | * base for finding the right base_url in the props |
---|
95 | * subclass has to override with its specific proxykey |
---|
96 | * @return |
---|
97 | */ |
---|
98 | public String getProxyKey() { |
---|
99 | return ""; |
---|
100 | } |
---|
101 | |
---|
102 | |
---|
103 | @Override |
---|
104 | public void setTargetProxy(){ |
---|
105 | |
---|
106 | //Query query = new Query(); |
---|
107 | switch (Repositories.RepositoryType.toRepositoryType(Repositories.getRepositories().getRepositoryType(getRepository()))) |
---|
108 | { |
---|
109 | case PAZPAR: |
---|
110 | setTargetProxy(new Pz2Proxy(new Query(getActionkey(), this.getParams()))); |
---|
111 | return; |
---|
112 | case SRU: |
---|
113 | setTargetProxy(new SRUProxy(new Query(Query.SRUEXTERN,getParams()))); |
---|
114 | return; |
---|
115 | case MD: |
---|
116 | setTargetProxy(new MDRepoProxy(new Query(Query.RECORDSET,getParams()))); |
---|
117 | return; |
---|
118 | default: |
---|
119 | //TODO error = bad workspaceProfile configuration |
---|
120 | getDiagnostics().Add(Diagnostic.SYSTEM_ERROR, "Error in workspaceprofile configuration", "repository=" + getRepository() ); |
---|
121 | } |
---|
122 | } |
---|
123 | } |
---|