1 | package eu.clarin.cmdi.mdservice.action; |
---|
2 | |
---|
3 | import java.io.IOException; |
---|
4 | import java.io.InputStream; |
---|
5 | import java.net.MalformedURLException; |
---|
6 | import java.net.URL; |
---|
7 | import java.net.URLConnection; |
---|
8 | |
---|
9 | import com.opensymphony.xwork2.ActionSupport; |
---|
10 | |
---|
11 | /** |
---|
12 | * Acts as a Struts 2 controller |
---|
13 | * serves the requests regarding Components |
---|
14 | * it passes them further (Proxy) to the ComponentRegistry. |
---|
15 | * |
---|
16 | * Nested Components are resolved during xsl-transformation. |
---|
17 | * @author vronk |
---|
18 | * |
---|
19 | */ |
---|
20 | public class CompRegistryProxyAction extends GenericProxyAction { |
---|
21 | |
---|
22 | private static final long serialVersionUID = 1L; |
---|
23 | |
---|
24 | private String proxy_key = "compregistry"; |
---|
25 | private String compid; |
---|
26 | |
---|
27 | public String getCompid() { |
---|
28 | return compid; |
---|
29 | } |
---|
30 | |
---|
31 | public void setCompid(String compid) { |
---|
32 | this.compid = compid; |
---|
33 | } |
---|
34 | |
---|
35 | @Override |
---|
36 | public String getFullFormat() { |
---|
37 | if (compid==null || compid.equals("")) { |
---|
38 | return "complist2" + getFormat(); |
---|
39 | } else { |
---|
40 | return "comp2" + getFormat(); |
---|
41 | } |
---|
42 | } |
---|
43 | |
---|
44 | @Override |
---|
45 | public String getProxyKey() { |
---|
46 | return proxy_key; |
---|
47 | } |
---|
48 | |
---|
49 | @Override |
---|
50 | public String getRequestKey() { |
---|
51 | String key=""; |
---|
52 | if (getActionkey()!=null) { |
---|
53 | key += getActionkey() + "-" ; |
---|
54 | } |
---|
55 | if (getCompid()!=null) { |
---|
56 | key += getCompid() + "-" ; |
---|
57 | } |
---|
58 | |
---|
59 | return key; |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | /** |
---|
64 | * uses base_url and (optionally) compid to form a url |
---|
65 | * no compid => list all components/profiles |
---|
66 | * @return the URL to component-registry |
---|
67 | * @throws Exception |
---|
68 | */ |
---|
69 | public URL getTargetRequest() throws IOException { |
---|
70 | // URL targetURL =new URL( base_url, compname + ".xml"); |
---|
71 | URL targetURL = null; |
---|
72 | if (compid==null || compid.equals("")) { |
---|
73 | targetURL =new URL( getBaseURL(), getActionkey() ); |
---|
74 | } else { |
---|
75 | targetURL =new URL( getBaseURL(), getActionkey() + "/clarin.eu:cr1:" + compid); |
---|
76 | } |
---|
77 | Admin.notifyUser("CompReg.targetURL:" + targetURL); |
---|
78 | // URLConnection urlConnection = targetURL.openConnection(); |
---|
79 | // urlConnection.setRequestProperty("Accept", "application/xml"); |
---|
80 | return targetURL; |
---|
81 | } |
---|
82 | |
---|
83 | |
---|
84 | } |
---|