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

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

started cleaning up code, adding inline-documentation;
also changes to output method in xsl (xhtml)

File size: 3.5 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 * Proxy to the Metadata Repository. 
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        /**
47         * Override of the basic method provided by the super-class
48         */     
49        @Override       
50        public String getBaseURI() {           
51                String uri = getRepositoryPath();               
52                return uri;
53        }
54       
55        @Override
56        public void setFormat(String format) {
57                super.setFormat(format);               
58        }
59       
60        @Override
61        public String getProxyKey() {
62                return proxy_key;
63        }
64       
65        /**
66         * A mapping between the actionkeys in the request and the operation-parameter expected by the MDRepository
67         */
68        private final static HashMap<String,String> urls = new HashMap<String,String>();
69         static
70         {       urls.put("collection", "?operation=getCollections&collection=");
71                 urls.put("model", "?operation=queryModel&q=");
72                 urls.put("values", "?operation=scanIndex&q=");
73                 urls.put("recordset", "?operation=searchRetrieve&query=");
74                 urls.put("record", "?operation=searchRetrieve&query=");
75         } 
76 
77        /**
78         * uses base_url + url_pattern (parametrized by actionkey) to form a url
79         * @return the URL to the component-file
80         * @throws Exception
81         */
82        public URL getTargetRequest() throws IOException {
83        // URL targetURL =new URL( base_url, compname + ".xml");
84               
85                Admin.notifyUser("MDRPA.getQ:" + getSquery() + " and (" +  getQ() + ")");
86                Admin.notifyUser("MDRPA.getActionkey:" + getActionkey());               
87               
88                Query query = new Query(getSquery(), getQ(),getActionkey());
89
90        // check if the query could get parsed
91                if (query.isStatus(Query.PARSEERROR)) {
92                        Admin.notifyUser("MDRPA.query.PARSEERROR:" + query.getMsg());
93                        // pass this bad news to the client
94                        setUserMsg(query.getMsg());
95                        return null;
96                } else {
97                        query.setMaxdepth(getMaxdepth());               
98                        query.setCollection(getCollection());
99                        query.setColumns(getColumns());
100                        query.setMaximumItems(getMaximumItems());
101                        query.setStartItem(getStartItem());
102                        query.setOptions(getOptions());
103                        query.setSort(getSort());
104               
105                        URL targetURL = null;
106                        targetURL =new URL( getBaseURL(), urls.get(getActionkey()) + query.toURLParam() );
107                        Admin.notifyUser("MDRPA.targetURL.query.toURLParam:" + query.toURLParam());
108                        Admin.notifyUser("MDRPA.targetURL:" + targetURL);
109                return targetURL;
110                }
111        }
112
113
114        @Override
115        public void prepare() throws Exception{
116                super.prepare();
117               
118        }
119}
Note: See TracBrowser for help on using the repository browser.