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

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

changes in recordset display, query_detail; adding documenting

File size: 5.8 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;
29
30/**
31 * Main Struts 2 controller
32 * responds to requests (collections, model, recordset)
33 * by dispatching the requests to appropriate internal methods and filling the inputStream with the result
34 *
35 * It is possible to switch target-repository dynamically  (on every request). I.e. the client explicitly selects one of the repositories.
36 * 
37 * @author vronk
38 *
39 */
40public class MDRepoProxyAction extends GenericProxyAction {
41
42        private static final long serialVersionUID = 1L;
43
44        private String proxy_key = "mdrepository";
45       
46        @Override
47        public String getBaseURI() {           
48                Admin.notifyUser("MDREPO-property:" + Admin.getConfig().getProperty(getProxyKey() + ".uri"));
49                Admin.notifyUser("MDREPO-profile:" + getRepositoryPath());
50                String uri = getRepositoryPath();//Admin.getConfig().getProperty(getProxyKey() + ".uri");               
51                return uri;
52        }
53       
54        @Override
55        public void setFormat(String format) {
56                super.setFormat(format);               
57        }
58        @Override
59        public String getProxyKey() {
60                return proxy_key;
61        }
62       
63       
64        private final static HashMap<String,String> urls = new HashMap<String,String>();
65         static
66         {       urls.put("collection", "?operation=getCollections&collection=");
67                 urls.put("model", "?operation=queryModel&q=");
68                 urls.put("values", "?operation=scanIndex&q=");
69                 urls.put("recordset", "?operation=searchRetrieve&query=");
70                 urls.put("record", "?operation=searchRetrieve&query=");
71         } 
72        /*
73         @Override
74         public URL getBaseURL() throws MalformedURLException {         
75                        if (base_url == null) {
76                                base_url = new URL(Admin.getConfig().getProperty(getProxyKey() + ".uri"));
77                                try {
78                                        Admin.notifyUser("TEST-URLold:" + base_url.toURI());
79                                } catch (URISyntaxException e) {
80                                        // TODO Auto-generated catch block
81                                        e.printStackTrace();
82                                }
83                                base_url = new URL(getRepository());
84                                try {
85                                        Admin.notifyUser("TEST-URLnew:" + base_url.toURI());
86                                } catch (URISyntaxException e) {
87                                        // TODO Auto-generated catch block
88                                        e.printStackTrace();
89                                }
90                        }
91                        return base_url;
92                }
93         */
94         
95        /**
96         * uses base_url + url_pattern (parametrized by actionkey) to form a url
97         * @return the URL to the component-file
98         * @throws Exception
99         */
100        public URL getTargetRequest() throws IOException {
101        // URL targetURL =new URL( base_url, compname + ".xml");
102               
103                Admin.notifyUser("MDRPA.getQ:" + getSquery() + " and (" +  getQ() + ")");
104                Admin.notifyUser("MDRPA.getActionkey:" + getActionkey());
105                Admin.notifyUser("MDRPA.getMaxdepth:" + getMaxdepth());
106               
107                Query query = new Query(getSquery(), getQ(),getActionkey());
108                if (query.isStatus(Query.PARSEERROR)) {
109                        Admin.notifyUser("MDRPA.query.PARSEERROR:" + query.getMsg());
110                        // pass this bad news to the client
111                        setUserMsg(query.getMsg());
112                        return null;
113                } else {
114                        query.setMaxdepth(getMaxdepth());               
115                        query.setCollection(getCollection());
116                        query.setColumns(getColumns());
117                        query.setMaximumItems(getMaximumItems());
118                        query.setStartItem(getStartItem());
119                        query.setOptions(getOptions());
120                        query.setSort(getSort());
121                        //Admin.notifyUser("MDRPA.records:" + query.getStartRecord());
122                        //Admin.notifyUser("MDRPA.records:" + query.getMaximumRecords());
123                        URL targetURL = null;           
124                       
125                        targetURL =new URL( getBaseURL(), urls.get(getActionkey()) + query.toURLParam() );
126                        Admin.notifyUser("MDRPA.targetURL.query.toURLParam:" + query.toURLParam());
127                        Admin.notifyUser("MDRPA.targetURL:" + targetURL);
128                return targetURL;
129                }
130        }
131
132       
133/*
134 * FOLLOWING ARE OBSOLETE METHODS
135 * for processing the requests and serving the results
136 * they stay here for reference (as bad examples) temporarily
137 * and can/shall be removed in the near future.
138 */
139       
140/**
141 * serves the collections, passes the Request to MDRepositoryProxy
142 * @return
143 * @throws Exception
144 */
145        /*
146        public String collections() throws Exception {
147       
148                Query query = new Query(getQ(),Query.COLLECTIONS);
149               
150//               inputStream = getMDRepo().getCollections(query);
151                 
152                return SUCCESS;
153        }
154*/
155        /**
156         * serves the model/terms, via Query.execute() and .getResult()
157         * @return
158         * @throws Exception
159         */
160/*
161        public String model() throws Exception {
162               
163                Query query = new Query(getQ(), Query.MODEL, getCollection());
164                        Admin.notifyUser(query.getTargetRequest().toString());
165                        query.setMaxdepth(getMaxdepth());
166                query.execute();                               
167                       
168                //inputStream = query.getResult().getResultStream(format);
169                return SUCCESS;
170        }
171*/
172        /**
173         * the method for actual querying of MDRepository
174         * and getting back the MD-recordset
175         * using Query-object (not asking MDRepository yet)
176         *   
177         * @return
178         * @throws Exception
179         * @throws Exception
180         */     
181        /*
182        public String recordset() throws Exception {
183               
184                Query query = new Query(getQ(), Query.RECORDSET, getCollection());
185                       
186                        Admin.notifyUser("recordset_target_uri:" + query.getTargetRequest().toString());               
187                        query.execute();                               
188
189//              String str =query.getResult().getHeader();             
190                 
191//              inputStream = new ByteArrayInputStream(str.getBytes());
192
193//              inputStream = query.getResult().getResultStream(format);
194                return SUCCESS;
195                 
196        }
197        */
198       
199        @Override
200        public void prepare() throws Exception{
201                super.prepare();
202               
203        }
204}
Note: See TracBrowser for help on using the repository browser.