source: MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/TermsProxyAction.java @ 911

Last change on this file since 911 was 911, checked in by gaba, 14 years ago
File size: 3.9 KB
Line 
1package eu.clarin.cmdi.mdservice.action;
2
3import java.io.File;
4import java.io.IOException;
5import java.io.InputStream;
6import java.net.MalformedURLException;
7import java.net.URL;
8import java.util.HashMap;
9import java.io.ByteArrayInputStream;
10
11import javax.xml.transform.TransformerException;
12
13import org.w3c.dom.Node;
14import org.w3c.dom.NodeList;
15
16import eu.clarin.cmdi.mdservice.model.Query;
17import eu.clarin.cmdi.mdservice.model.Termset;
18
19/**
20 * specialized subclass of main controller
21 * provides "Terms" the magic mix from mdrepo, compreg and datcats   
22 * by dispatching the requests to appropriate internal methods and filling the inputStream with the result
23 * 
24 * @author vronk
25 *
26 */
27public class TermsProxyAction extends GenericProxyAction {
28
29        private static final long serialVersionUID = 1L;
30
31        public static String ALL = "all";
32       
33        private String proxy_key = "terms";
34       
35        @Override
36        public String getProxyKey() {
37                return proxy_key;
38        }
39       
40/*      @Override
41        public String getFullFormat() {         
42                return "terms2extract";
43        }
44        */
45       
46        /*
47         @Override
48         public String getRequestKey() {
49                        String key="";
50                        if (getActionkey()!=null) {
51                                key += getActionkey() + "//-" ;
52                        }
53                        if (getQ()!=null) {
54                                key += getQ() + "//-" ;
55                        } else {
56                                key +="//-" ;
57                        }
58                        if (getCollection()!=null) {
59                                key += getCollection() + "//-";
60                        } else {
61                                key +="//-" ;
62                        }
63                        if (getSquery()!=null) {
64                                key += getSquery() + "//-" ;
65                        } else {
66                                key +="//-" ;
67                        }
68                        if (getStartRecord()!=null) {
69                                key += getStartRecord() + "//-";
70                        }
71                        if (getMaximumRecords()!=null) {
72                                key += getMaximumRecords();
73                        }
74                         
75                        return key;
76        }
77         */
78        public Termset getTermset() {           
79                String ts_id="";
80                if (getQ()!=null && !getQ().equals("")) ts_id = getQ();
81       
82                Termset res = (Termset) Termset.getTermset(ts_id);
83               
84                return res;
85        }
86       
87        public String getTSAttr(String key) {   
88                Termset ts = getTermset();
89                String val=""; 
90                if (ts!=null) val= ts.getAttr(key);
91                 return val;
92        }
93       
94        public URL getBaseURL() throws MalformedURLException {
95                       
96                if (base_url == null) {
97                        base_url = new URL(getBaseURI());
98                }
99               
100                return base_url;
101        }
102       
103       
104         /**
105         * uses base_url + url_pattern (parametrized by actionkey) to form a url
106         * @return the URL to the terms
107         * @throws Exception
108         */
109        public URL getTargetRequest() throws IOException {
110        // URL targetURL =new URL( base_url, compname + ".xml");
111       
112               
113                URL targetURL = null;
114                //targetURL = new URL(getBaseURI() + getQ());
115                Admin.notifyUser("TPA.q: " + getBaseURI() + getQ() + getRepository());         
116                targetURL = new URL(getBaseURI() + getQ() + "&maxdepth=" + getMaxdepth() + "&repository=" + getRepository());
117                // TPA.targetURL:http://localhost:8080/MDService2/model/matrix/?q=all
118            return targetURL;
119               
120        }
121       
122        public InputStream getSourceStream() throws IOException{
123                String type = getTSAttr("type");
124                if (type.equals("dcr") | type.equals("rr")) {   
125                        // if dcr|rr call model/matrix/all: http://localhost:8080/MDService2/model/matrix/?q=all
126                        // + run through terms2extract transform (parametrized with getQ()-param!!), to serve the subset = appropriate Termset
127                        URL matrix_all_URL = new URL(getBaseURI() + ALL + "&repository="+ getRepository());
128                        //URL matrix_all_URL = new URL(getBaseURI() + ALL );
129                        Admin.notifyUser("TPA.getSourceStream: " + getBaseURI() + ALL);
130                        InputStream stream_matrix_all = matrix_all_URL.openStream(); 
131                        InputStream resultStream=null;
132                        try {
133                                MDTransformer transformer = new MDTransformer();
134                                transformer.setParams(createTransformerParams());
135                                resultStream = transformer.transformXML(stream_matrix_all);//, "terms2extract", getColumns(), getStartRecord(), getMaximumRecords(),getLang(),getQ(), getRepositoryPath());
136                        } catch (InterruptedException e) {                             
137                                Admin.notifyUser("TPA.getSourceStream(): "+ e.getMessage());
138                        } catch (TransformerException e) {                             
139                                Admin.notifyUser("TPA.getSourceStream(): "+ e.getMessage());
140                        }                       
141                        return resultStream;
142                       
143                } else {
144                        return getTargetRequest().openStream();
145                }                 
146        }
147       
148}
Note: See TracBrowser for help on using the repository browser.