source: MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/MDRepoProxyAction.java @ 466

Last change on this file since 466 was 466, checked in by vronk, 14 years ago

initial import

File size: 3.4 KB
Line 
1package eu.clarin.cmdi.mdservice.action;
2
3import java.io.ByteArrayInputStream;
4import java.io.InputStream;
5import java.net.URL;
6import java.util.HashMap;
7
8import com.opensymphony.xwork2.ActionSupport;
9
10import eu.clarin.cmdi.mdservice.model.Query;
11import eu.clarin.cmdi.mdservice.model.Result;
12
13/**
14 * Main Struts 2 controller
15 * responds to requests (collections, model, recordset)
16 * by dispatching the requests to appropriate internal methods and filling the inputStream with the result
17 * 
18 * @author vronk
19 *
20 */
21public class MDRepoProxyAction extends GenericProxyAction {
22
23        private static final long serialVersionUID = 1L;
24
25        private String proxy_key = "mdrepository";
26       
27        @Override
28        public String getProxyKey() {
29                return proxy_key;
30        }
31       
32        private final static HashMap<String,String> urls = new HashMap<String,String>();
33         static
34         {       urls.put("collection", "?operation=getCollections&collection=");
35                 urls.put("model", "?q=");
36                 urls.put("recordset", "?operation=searchRetrieve&query=");
37         } 
38               
39        /**
40         * uses base_url + url_pattern (parametrized by actionkey) to form a url
41         * @return the URL to the component-file
42         * @throws Exception
43         */
44        public URL getTargetRequest() throws Exception {
45        // URL targetURL =new URL( base_url, compname + ".xml");
46               
47                Admin.notifyUser("MDRPA.getQ:" + getQ());
48                Admin.notifyUser("MDRPA.getActionkey:" + getActionkey());
49                Admin.notifyUser("MDRPA.getMaxdepth:" + getMaxdepth());
50               
51                Query query = new Query(getQ(),getActionkey());
52                if (query.isStatus(Query.PARSEERROR)) {
53                        Admin.notifyUser("MDRPA.query.PARSEERROR:" + query.getMsg());
54                        // pass this bad news to the client
55                        setUserMsg(query.getMsg());
56                        return null;
57                } else {
58                        query.setMaxdepth(getMaxdepth());               
59                        URL targetURL = null;           
60                       
61                        targetURL =new URL( getBaseURL(), urls.get(getActionkey()) + query.toURLParam() );
62                        Admin.notifyUser("MDRPA.targetURL:" + targetURL);
63                return targetURL;
64                }
65        }
66
67       
68/*
69 * FOLLOWING ARE OBSOLETE METHODS
70 * for processing the requests and serving the results
71 * they stay here for reference (as bad examples) temporarily
72 * and can/shall be removed in the near future.
73 */
74       
75/**
76 * serves the collections, passes the Request to MDRepositoryProxy
77 * @return
78 * @throws Exception
79 */
80        /*
81        public String collections() throws Exception {
82       
83                Query query = new Query(getQ(),Query.COLLECTIONS);
84               
85//               inputStream = getMDRepo().getCollections(query);
86                 
87                return SUCCESS;
88        }
89*/
90        /**
91         * serves the model/terms, via Query.execute() and .getResult()
92         * @return
93         * @throws Exception
94         */
95/*
96        public String model() throws Exception {
97               
98                Query query = new Query(getQ(), Query.MODEL, getCollection());
99                        Admin.notifyUser(query.getTargetRequest().toString());
100                        query.setMaxdepth(getMaxdepth());
101                query.execute();                               
102                       
103                //inputStream = query.getResult().getResultStream(format);
104                return SUCCESS;
105        }
106*/
107        /**
108         * the method for actual querying of MDRepository
109         * and getting back the MD-recordset
110         * using Query-object (not asking MDRepository yet)
111         *   
112         * @return
113         * @throws Exception
114         */     
115        /*
116        public String recordset() throws Exception {
117               
118                Query query = new Query(getQ(), Query.RECORDSET, getCollection());
119                       
120                        Admin.notifyUser("recordset_target_uri:" + query.getTargetRequest().toString());               
121                        query.execute();                               
122
123//              String str =query.getResult().getHeader();             
124                 
125//              inputStream = new ByteArrayInputStream(str.getBytes());
126
127//              inputStream = query.getResult().getResultStream(format);
128                return SUCCESS;
129                 
130        }
131        */
132}
Note: See TracBrowser for help on using the repository browser.