source: MDService2/branches/MDService_simple/src/eu/clarin/cmdi/mdservice/action/RepoProxyAction.java @ 1510

Last change on this file since 1510 was 1510, checked in by vronk, 13 years ago

now, it at least compiles

File size: 6.1 KB
Line 
1package eu.clarin.cmdi.mdservice.action;
2
3import java.io.File;
4import java.io.IOException;
5import java.io.InputStream;
6import java.io.StringReader;
7import java.io.StringWriter;
8import java.net.MalformedURLException;
9import java.net.URISyntaxException;
10import java.net.URL;
11import java.util.HashMap;
12import java.io.ByteArrayInputStream;
13
14import javax.xml.parsers.DocumentBuilder;
15import javax.xml.parsers.DocumentBuilderFactory;
16import javax.xml.transform.OutputKeys;
17import javax.xml.transform.Transformer;
18import javax.xml.transform.TransformerException;
19import javax.xml.transform.TransformerFactory;
20import javax.xml.transform.dom.DOMSource;
21import javax.xml.transform.stream.StreamResult;
22
23import org.w3c.dom.Document;
24import org.w3c.dom.Node;
25import org.w3c.dom.NodeList;
26import org.xml.sax.InputSource;
27
28import eu.clarin.cmdi.mdservice.model.Query;
29import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
30
31/**
32 * Main Struts 2 controller
33 * responds to requests (collections, model, recordset)
34 * by dispatching the requests to appropriate internal methods and filling the inputStream with the result
35 *
36 * It is possible to switch target-repository dynamically  (on every request). I.e. the client explicitly selects one of the repositories.
37 * 
38 * @author vronk
39 *
40 */
41public class RepoProxyAction extends GenericProxyAction {
42
43        private static final long serialVersionUID = 1L;
44
45        private String proxy_key = "repository";
46        private RepoProxyAction target_proxy;
47        private RepoProxyAction source_action;
48       
49/**
50 * Based on the repository type - we create a typed Proxy, that will do the work.
51 * If the type is not recognized <this> will be also the target_proxy -
52 * TODO: check if it is sane, to work without a typed target_proxy   
53 */
54        protected void  initialize(){
55               
56                switch (WorkspaceProfile.RepositoryType.toRepositoryType(WorkspaceProfile.getRepositoryType(getRepository())))
57                {               
58                    case PAZPAR: 
59                        target_proxy = new Pz2ProxyAction();
60                    case SRU:
61                        target_proxy = new SRUProxyAction();
62                    case MD:
63                        target_proxy = new MDRepoProxyAction();
64                    default:
65                        target_proxy = this;
66                }
67                target_proxy.setSourceAction(this);
68               
69        }
70       
71        public RepoProxyAction getTargetProxy() {
72                return target_proxy;
73        }
74
75        public RepoProxyAction getSourceAction() {
76                return source_action;
77        }
78       
79        public void setSourceAction(RepoProxyAction p_source_action) {
80                source_action = p_source_action;
81        }
82       
83/**
84 * Pass the proxy_key of the actual target_proxy,
85 * or the basic "repository" if the target_proxy is identical 
86 */
87        @Override
88        public String getProxyKey() {
89                if (target_proxy.equals(this)) {
90                  return proxy_key;
91                } else {               
92                        return getTargetProxy().getProxyKey();
93                }
94        }
95
96        /**
97         * Override of the basic method provided by the super-class
98         * Reading the repository-uri from the WorkspaceProfile based on the repository-parameter
99         */     
100        @Override       
101        public String getBaseURI() {           
102                String uri = WorkspaceProfile.getRepositoryPath(getRepository());               
103                return uri;
104        }
105       
106        //TODO remove - just for tests
107        @Override
108        public String getCache() {
109                switch (WorkspaceProfile.RepositoryType.toRepositoryType(WorkspaceProfile.getRepositoryType(getRepository())))
110                {
111                    case PAZPAR: 
112                        return Cache.SKIP;
113                    case SRU:
114                        return Cache.SKIP;
115                    case MD:
116                        return super.getCache();
117                    default:
118                        return super.getCache();
119                }
120        }
121       
122        //TODO remove after xsl update
123        @Override
124        public String getFullFormat() {         
125                switch (WorkspaceProfile.RepositoryType.toRepositoryType(WorkspaceProfile.getRepositoryType(getRepository())))
126                {
127                    case PAZPAR: 
128                        return "pazpar22" + this.getFormat();
129                    case SRU:
130                        return "sru2" + this.getFormat();
131                    case MD:
132                        return super.getFullFormat();
133                    default:
134                        return super.getFullFormat();
135                }
136        }
137       
138        @Override
139        public InputStream getSourceStream() throws IOException, NoStylesheetException {
140       
141                return getTargetProxy().getSourceStream();
142                /*
143                switch (WorkspaceProfile.RepositoryType.toRepositoryType(WorkspaceProfile.getRepositoryType(getRepository())))
144                {
145                    case PAZPAR:
146                        try {
147                                        return getSourcePz2();
148                                } catch (Exception e) {
149                                        // TODO Auto-,generated catch block
150                                        e.printStackTrace();
151                                }
152                    case SRU:
153                        return super.getSourceStream();//getSourceSRU();
154                    case MD:
155                        return super.getSourceStream();
156                    default:
157                        return super.getSourceStream();
158                }
159                */
160        }
161 
162         public String fullQueryString(){
163                String full_query_string= this.getQ();
164                       
165                if (!getSquery().equals("") && !this.getQ().equals("")){
166                                full_query_string = "(" + this.getSquery() + " ) and (" + this.getQ() + ")";
167                        } else if (!this.getSquery().equals("")) {
168                                full_query_string = this.getSquery();
169                        } else if (!this.getQ().equals("")){
170                                full_query_string = this.getQ();
171                        } else {
172                                full_query_string = "";
173                        }
174               
175                return full_query_string;
176         }
177         
178
179        /**
180         * uses base_url + url_pattern (parametrized by actionkey) to form a url
181         * @return the URL to the component-file
182         * @throws Exception
183         */
184         @Override
185        public URL getTargetRequest() throws IOException {
186        // URL targetURL =new URL( base_url, compname + ".xml");
187               
188                Admin.notifyUser("RPA.getQ:" + getSquery() + " and (" +  getQ() + ")");
189                Admin.notifyUser("RPA.getActionkey:" + getActionkey());         
190               
191               
192//              Query query = new Query(getSquery(), getQ(),getActionkey());
193
194                 
195                        URL targetURL = getTargetProxy().getTargetRequest();
196                        // targetURL =new URL( getBaseURL(), urls.get(getActionkey()) + query.toURLParam() );
197                       
198                        //Admin.notifyUser("RPA.targetURL.query.toURLParam:" + query.toURLParam());
199                        Admin.notifyUser("RPA.targetURL:" + targetURL);
200                return targetURL;
201               
202        }
203
204
205
206/*      @Override
207        public URL getTargetRequest() throws IOException {
208 
209                switch (WorkspaceProfile.RepositoryType.toRepositoryType(WorkspaceProfile.getRepositoryType(getRepository())))
210                {
211                    case PAZPAR:
212                        return base_url;
213                    case SRU:
214                                try {
215                                        return getTargetRequestSRU();
216                                } catch (NoStylesheetException e) {
217                                        // TODO Auto-generated catch block
218                                        e.printStackTrace();
219                                }
220                    case MD:
221                        return super.getTargetRequest();
222                    default:
223                        return super.getTargetRequest();
224                }
225        }
226        */
227}       
Note: See TracBrowser for help on using the repository browser.