source: MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/RepoAction.java @ 1525

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

corrections

File size: 7.2 KB
Line 
1package eu.clarin.cmdi.mdservice.action;
2
3import java.io.BufferedInputStream;
4import java.io.BufferedReader;
5import java.io.File;
6import java.io.FileInputStream;
7import java.io.IOException;
8import java.io.InputStream;
9import java.io.InputStreamReader;
10import java.net.MalformedURLException;
11import java.net.URISyntaxException;
12import java.net.URL;
13import java.util.Arrays;
14import java.util.Collections;
15import java.util.HashMap;
16import java.util.Iterator;
17import java.util.Map;
18import java.util.Set;
19import java.util.Map.Entry;
20
21import javax.servlet.http.HttpServletRequest;
22import javax.servlet.http.HttpSession;
23import javax.xml.transform.TransformerException;
24
25import net.sf.json.JSON;
26import net.sf.json.JSONArray;
27import net.sf.json.JSONObject;
28import net.sf.json.JSONSerializer;
29//import net.sf.saxon.Controller;
30//import net.sf.saxon.event.MessageEmitter;
31
32
33import org.apache.log4j.Logger;
34import org.apache.struts2.interceptor.ServletRequestAware;
35import com.opensymphony.xwork2.ActionSupport;
36
37import eu.clarin.cmdi.mdservice.internal.Cache;
38import eu.clarin.cmdi.mdservice.internal.NoStylesheetException;
39import eu.clarin.cmdi.mdservice.model.Diagnostic;
40import eu.clarin.cmdi.mdservice.model.Diagnostics;
41import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
42import eu.clarin.cmdi.mdservice.proxy.MDRepoProxy;
43import eu.clarin.cmdi.mdservice.proxy.Pz2Proxy;
44import eu.clarin.cmdi.mdservice.proxy.SRUProxy;
45
46/**
47 * a Struts2 controller, responsible for calls to repositories.
48 * After 2011-09 rework Action and Proxy are decoupled.
49 * So Action calls appropriate Proxy based upon the target repository type
50 *
51 * responds to requests (collections, model, recordset)
52 * by dispatching the requests to appropriate Proxy and filling the inputStream with the result
53 * It is possible to switch target-repository dynamically  (on every request). I.e. the client explicitly selects one of the repositories.
54 *
55 * 
56 * @author vronk
57 */
58public class RepoAction extends GenericAction
59//implements ServletRequestAware
60{
61
62        private static final long serialVersionUID = 1L;
63        private static Logger log = Logger.getLogger("RepoAction");
64       
65        /**
66         * Properties to be filled by Struts with according request-parameters
67         */     
68        private String actionkey;
69       
70        private String squery; 
71        private String collection;
72        private String columns;
73        private String startItem;
74        private String maximumItems;
75        private String sort;   
76        private int maxdepth;   
77        //private String format="xml"; // default no transformation
78        private String options;
79
80        //private Map<String,Object> session;
81        protected URL base_url ;
82
83        @Override
84        public String getFullFormat() {         
85                return actionkey + "2" + getFormat();
86        }
87        /**
88         * Based on the repository type - we create a typed Proxy, that will do the work.
89         * If the type is not recognized - that is a bad user error   
90         */
91                public void setTargetProxy(){
92                                               
93                        //if (getRepository()==null) setRepository("clarin.at-mirror");
94                       
95                        switch (WorkspaceProfile.RepositoryType.toRepositoryType(WorkspaceProfile.getRepositoryType(getRepository())))
96                        {               
97                            case PAZPAR: 
98                                setTargetProxy(new Pz2Proxy());
99                                return;
100                            case SRU:
101                                setTargetProxy(new SRUProxy());
102                                return;
103                            case MD:
104                                setTargetProxy(new MDRepoProxy());
105                                return;
106                            default:
107                                getDiagnostics().Add(Diagnostic.MANDATORY_NOTSUPPLIED, "repository", "repository=" + getRepository() );
108                        }
109                       
110                }
111        /*
112        public String getSquery() {
113                return squery;
114        }
115
116        public void setSquery(String psquery) {
117                if (psquery==null) psquery="";
118                this.squery = psquery;
119        }
120       
121        public String getCollection() {
122                return collection;
123        }
124
125        public void setCollection(String collection) {
126                this.collection = collection;
127        }
128       
129        //TODO defaults
130        public String getColumns() {
131                String cols = columns;
132                return cols;
133        }
134
135        public void setColumns(String columns) {
136                this.columns = columns;
137        }
138       
139        public int getMaxdepth() {
140                return maxdepth;
141        }
142
143        public void setMaxdepth(int maxdepth) {
144                this.maxdepth = maxdepth;
145        }
146/*
147        public String getFormat() {
148                return format;
149        }
150
151        public void setFormat(String format) {
152                this.format = format;
153        }
154
155        public String getOptions() {
156                return options;
157        }
158
159        public void setOptions(String options) {
160                this.options = options;
161        }
162
163       
164        public String getActionkey() {
165                return actionkey;
166        }
167
168        public void setActionkey(String actionKey) {
169                actionkey = actionKey;
170        }
171
172       
173        public String getStartItem() {
174                return startItem;
175        }
176
177        public void setStartItem(String startItem) {
178                this.startItem = startItem;
179        }
180
181        public String getMaximumItems() {
182                return maximumItems;
183        }
184
185        public void setMaximumItems(String maximumItems) {
186                this.maximumItems = maximumItems;
187        }
188       
189
190        public String getSort() {
191                return sort;
192        }
193
194        public void setSort(String sort) {
195                this.sort = sort;
196        }
197*/
198
199        /**
200         * internal identification of the target-proxy
201         * base for finding the right base_url in the properties
202         * subclass has to override with its specific proxykey
203         * @return the key identifying this type of proxy
204         */
205        public String getProxyKey() {
206                return "";
207        }
208               
209        /**
210         * Constructs an unambiguous key for the request (encoding all the parameters).
211         * This is used as identifier for caching
212         * @return key unambiguously encoding the request
213         */
214        /*
215         public String getRequestKey() {
216                        String key="";
217                        if (getActionkey()!=null) {
218                                key += getActionkey() + "//-" ;
219                        }else {
220                                key +="//-" ;
221                        }
222                        if (getQ()!=null) {
223                                key += getQ() + "//-" ;
224                        } else {
225                                key +="//-" ;
226                        }
227                        if (getCollection()!=null) {
228                                key += getCollection() + "//-";
229                        } else {
230                                key +="//-" ;
231                        }
232                        if (getSquery()!=null) {
233                                key += getSquery() + "//-" ;
234                        } else {
235                                key +="//-" ;
236                        }
237                        if (getStartItem()!=null) {
238                                key += getStartItem() + "//-";
239                        }
240                                else{
241                                        key +="//-" ;
242                        }
243                        if (getMaximumItems()!=null) {
244                                key += getMaximumItems() + "//-";
245                        }
246                        else{
247                                key +="//-" ;
248                        }
249                       
250                        key += getRepository()  + "//-";
251                        key += getMaxdepth()  + "//-";
252                       
253                        if (getLang()!=null) {
254                                key += getLang() + "//-";
255                        }else{
256                                key +="//-" ;
257                        }                       
258                         
259                return key;
260        }
261         */
262        /*     
263         @Override
264        public Map<String,String> createTransformerParams(){
265               
266                Map<String, String> map = new HashMap<String, String>();
267
268                Set<Entry<String, String[]>> set = getParams().entrySet();
269                Iterator<Entry<String, String[]>> i = set.iterator();
270
271            while(i.hasNext()){
272              Map.Entry<String,String[]> e = (Map.Entry<String,String[]>)i.next();
273              if (xsl_map.containsKey((String)e.getKey())) {
274                  map.put(xsl_map.get((String)e.getKey()), (String)e.getValue()[0]);
275              }
276             
277            }
278            return map;
279            */
280            /*
281                HashMap<String,String> hm = new HashMap<String,String>();
282               
283            if (getFullFormat() != null){
284                        hm.put("format", getFullFormat());
285            }
286                if (getColumns() != null){
287                        hm.put("cols", getColumns());
288                } else {
289                        hm.put("cols", "");
290                }
291                if (getStartItem() != null){
292                        hm.put("startItem", getStartItem());
293                }
294                if (getMaximumItems() != null){
295                        hm.put("maximumItems", getMaximumItems());     
296                }
297                if (getLang() != null){
298                        hm.put("lang", getLang());
299                }
300                if (getQ() != null){
301                        hm.put("q", getQ());
302                }
303                //if (getRepository() != null){
304                hm.put("repository_name", String.valueOf(getRepository()));
305                hm.put("repository_type", WorkspaceProfile.getRepositoryType(this.getRepository()));
306                //}
307       
308                return hm;
309        }
310                */
311       
312       
313
314}
Note: See TracBrowser for help on using the repository browser.