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

Last change on this file was 1496, checked in by gaba, 13 years ago

repoaction created ,
options + repositories moved to workspaceprofile

File size: 4.3 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 * Proxy to the Metadata Repository. 
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 MDRepoProxyAction extends GenericProxyAction {
42
43        private static final long serialVersionUID = 1L;
44
45        private String proxy_key = "mdrepository";
46       
47        /**
48         * Override of the basic method provided by the super-class
49         */     
50        @Override       
51        public String getBaseURI() {           
52                String uri = WorkspaceProfile.getRepositoryPath(getRepository());               
53                return uri;
54        }
55       
56        @Override
57        public void setFormat(String format) {
58                super.setFormat(format);               
59        }
60       
61        @Override
62        public String getProxyKey() {
63                return proxy_key;
64        }
65       
66        /**
67         * A mapping between the actionkeys in the request and the operation-parameter expected by the MDRepository
68         */
69        private final static HashMap<String,String> urls = new HashMap<String,String>();
70         static
71         {       urls.put("collection", "?operation=getCollections&collection=");
72                 urls.put("model", "?operation=queryModel&q=");
73                 urls.put("values", "?operation=scanIndex&q=");
74                 urls.put("recordset", "?operation=searchRetrieve&query=");
75                 urls.put("record", "?operation=searchRetrieve&query=");
76         } 
77 
78         public String fullQueryString(){
79                String full_query_string= this.getQ();
80                       
81                if (!getSquery().equals("") && !this.getQ().equals("")){
82                                full_query_string = "(" + this.getSquery() + " ) and (" + this.getQ() + ")";
83                        } else if (!this.getSquery().equals("")) {
84                                full_query_string = this.getSquery();
85                        } else if (!this.getQ().equals("")){
86                                full_query_string = this.getQ();
87                        } else {
88                                full_query_string = "";
89                        }
90               
91                return full_query_string;
92         }
93         
94        /**
95         * uses base_url + url_pattern (parametrized by actionkey) to form a url
96         * @return the URL to the component-file
97         * @throws Exception
98         */
99         @Override
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               
106                Query query = new Query(getSquery(), getQ(),getActionkey());
107
108        // check if the query could get parsed
109                if (query.isStatus(Query.PARSEERROR)) {
110                        Admin.notifyUser("MDRPA.query.PARSEERROR:" + query.getMsg());
111                        // pass this bad news to the client
112                        setUserMsg(query.getMsg());
113                        return null;
114                } else {
115                        query.setMaxdepth(getMaxdepth());               
116                        query.setCollection(getCollection());
117                        query.setColumns(getColumns());
118                        query.setMaximumItems(getMaximumItems());
119                        query.setStartItem(getStartItem());
120                        query.setOptions(getOptions());
121                        query.setSort(getSort());
122               
123                        URL targetURL = null;
124                        targetURL =new URL( getBaseURL(), urls.get(getActionkey()) + query.toURLParam() );
125                        Admin.notifyUser("MDRPA.targetURL.query.toURLParam:" + query.toURLParam());
126                        Admin.notifyUser("MDRPA.targetURL:" + targetURL);
127                return targetURL;
128                }
129        }
130
131
132        @Override
133        public InputStream getSourceStream() throws IOException, NoStylesheetException {
134               
135                /*if (getCommand() == null){
136                        try {
137                                return getSourcePz2();
138                        } catch (Exception e) {
139                                // TODO Auto-generated catch block
140                                e.printStackTrace();
141                        }
142                }
143                        */
144                return super.getSourceStream();
145        }
146       
147        @Override
148        public void prepare() throws Exception{
149                super.prepare();
150               
151        }
152}
Note: See TracBrowser for help on using the repository browser.