source: MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/RepoProxy.java @ 1569

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

simple changes, exception for CQL parse error added

File size: 4.8 KB
Line 
1package eu.clarin.cmdi.mdservice.proxy;
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.util.Map;
13import java.io.ByteArrayInputStream;
14
15import javax.xml.parsers.DocumentBuilder;
16import javax.xml.parsers.DocumentBuilderFactory;
17import javax.xml.transform.OutputKeys;
18import javax.xml.transform.Transformer;
19import javax.xml.transform.TransformerException;
20import javax.xml.transform.TransformerFactory;
21import javax.xml.transform.dom.DOMSource;
22import javax.xml.transform.stream.StreamResult;
23
24import org.apache.log4j.Logger;
25import org.w3c.dom.Document;
26import org.w3c.dom.Node;
27import org.w3c.dom.NodeList;
28import org.xml.sax.InputSource;
29
30import eu.clarin.cmdi.mdservice.action.GenericAction;
31import eu.clarin.cmdi.mdservice.action.RepoAction;
32import eu.clarin.cmdi.mdservice.internal.CQLParseException;
33import eu.clarin.cmdi.mdservice.internal.NoStylesheetException;
34import eu.clarin.cmdi.mdservice.model.Diagnostic;
35import eu.clarin.cmdi.mdservice.model.Query;
36import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
37
38/**
39 * Base class for implementation of proxies to target systems.
40 * This is now (after rework 2011-09) decoupled from the called Action.
41 *
42 * Defines the methods used for retrieving the data
43 * and provides basic implementation where possible.
44 *
45 * In contrast to base class BasicProxy RepoProxy tries to get the base_uri from WorkspaceProfile (based on the repository-parameter)
46 * 
47 * @author vronk
48 *
49 */
50public class RepoProxy extends BasicProxy{
51
52        private static final long serialVersionUID = 1L;
53        private static Logger log = Logger.getLogger("RepoProxy");
54 
55        private String proxy_key = "repo";
56               
57        // should perhaps be RepoAction, but it gets complicated with the types
58        private GenericAction source_action;
59       
60       
61        public GenericAction getSourceAction() {
62                        return source_action;
63        }
64       
65/*      public RepoAction getSourceAction() {
66                return source_action;
67}*/
68       
69        @Override
70        public void setSourceAction(GenericAction action) {             
71                source_action = action;
72               
73        }
74       
75        /**
76         * Convenience function to access the request-parameters in the Action 
77         * @param key
78         * @return
79         */
80        public String getParam(String key) {
81                return getSourceAction().getParam(key);
82        }
83       
84        public Map<String,String[]> getParams() {
85                return getSourceAction().getParams();
86        }
87       
88        public void checkParams() {
89                // required Params
90                // check and set defaults
91                if (WorkspaceProfile.getRepositoryPath(getParam("repository")) == null) {
92                        getSourceAction().getDiagnostics().Add(Diagnostic.UNSUPPORTED_PARAMETERVALUE, "repository");
93                }
94                if (getParam("repository")=="") {
95                        getSourceAction().getDiagnostics().Add(Diagnostic.MANDATORY_NOTSUPPLIED, "repository");
96                }
97        }
98       
99       
100        /**
101         * identification of the target-proxy (type)
102         * base for finding the right base_url in the props
103         * subclass has to override with its specific proxykey
104         * @return
105         */
106        public String getProxyKey() {                           
107                        return proxy_key;               
108        }
109
110        /**
111         * Override of the basic method provided by the super-class:
112         * Read the repository-uri from the WorkspaceProfile based on the repository-parameter
113         */
114               
115        public String getBaseURI() {           
116                String uri = WorkspaceProfile.getRepositoryPath(getSourceAction().getRepository());             
117                return uri;
118        }
119
120        /**
121         * Provides the base-URL specific to given target repository or registry
122         * @return
123         * @throws MalformedURLException
124         */     
125        public URL getBaseURL() throws MalformedURLException {         
126                URL base_url = new URL(getBaseURI());           
127                return base_url;
128        }
129       
130       
131        public InputStream getSourceStream() throws IOException, NoStylesheetException, CQLParseException {
132                return getTargetRequest().openStream();         
133        }
134 
135         public String fullQueryString(){
136                String  full_query_string= "TODO: construct fullQueryString";
137               
138                /* matej 20110903
139                 *  String full_query_string= this.getQ();
140                       
141                if (!getSquery().equals("") && !this.getQ().equals("")){
142                                full_query_string = "(" + this.getSquery() + " ) and (" + this.getQ() + ")";
143                        } else if (!this.getSquery().equals("")) {
144                                full_query_string = this.getSquery();
145                        } else if (!this.getQ().equals("")){
146                                full_query_string = this.getQ();
147                        } else {
148                                full_query_string = "";
149                        }
150                */
151                return full_query_string;
152         }
153         
154
155        /**
156         * uses base_url + url_pattern (parametrized by actionkey) to form a url
157         * @return the full target-request URL to be sent to the target repository
158         * @throws CQLParseException
159         * @throws Exception
160         */     
161        public URL getTargetRequest() throws IOException, CQLParseException {
162                 
163               
164                //URL targetURL =new URL( getBaseURL(), urls.get(getActionkey()) + query.toURLParam() );
165                URL targetURL =getBaseURL();
166               
167                log.debug("getTargetRequest().targetURL:" + targetURL);
168            return targetURL;
169               
170        }
171
172       
173
174}       
Note: See TracBrowser for help on using the repository browser.