source: MDService2/branches/MDService_simple2/src/eu/clarin/cmdi/mdservice/model/Result.java @ 1511

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

brutal refactoring,
added new packages: proxies, internal,
very much restructured Action hierarchy.
Introduced division Action/Proxy?.
This is a first compiling version.
it's total mess.

File size: 2.8 KB
Line 
1package eu.clarin.cmdi.mdservice.model;
2
3import java.io.IOException;
4import java.io.InputStream;
5
6import javax.xml.transform.TransformerException;
7
8import eu.clarin.cmdi.mdservice.internal.Admin;
9import eu.clarin.cmdi.mdservice.internal.MDTransformer;
10import eu.clarin.cmdi.mdservice.internal.NoStylesheetException;
11
12/**
13 * Currently not used! Everything is done directly in MDRepoProxyAction.
14 * 
15 * Meant as Class holding the result of a query (parentQuery)
16 * This is a "passive" object, depending on its parentQuery
17 * which is setting the resultStream in its execute-method 
18 * @author vronk
19 *
20 */
21public class Result {
22
23        /**
24         * available formats
25         */
26        public static String XML = "xml";
27        public static String HTML = "html";
28        public static String HTMLSNIPPET = "htmlsnippet";
29       
30        private Query parentQuery;
31       
32        /**
33         * holds the stream receiving data from the provider (MDRepository...) 
34         */
35        private InputStream rawresult;
36       
37        public Result (Query q) {
38                parentQuery = q;
39        //      transformed_out = new ByteArrayOutputStream();
40                //setResultStream(new ByteArrayOutputStream());
41        }
42       
43               
44        /**
45         * this is the main method to get the formatted-result
46         * precondition: the rawresult already arrived, ie parentQuery.execute() already issued 
47         * @param format is passed as the transkey to the transformer
48         * @return the input stream with the formatted/transformed result
49         * @throws IOException
50         * @throws InterruptedException
51         * @throws TransformerException
52         * @throws NoStylesheetException
53         */
54        public InputStream getResultStream(String format) throws IOException, InterruptedException, TransformerException, NoStylesheetException {
55                String transformkey;
56               
57                if (format.equals(XML)) {
58                        return rawresult;
59                } else {       
60                        transformkey = parentQuery.getType() + "2" + format;
61                        Admin.notifyUser("transformkey: " + transformkey );
62                        MDTransformer transformer = new MDTransformer();
63                        transformer.setParams(MDTransformer.createParamsMap(transformkey));
64                        return transformer.transformXML(rawresult);//, transformkey);
65                }       
66        }
67
68        /**
69         * without format-parameter, you get the raw-data-stream (XML?) received from the provider
70         * @return
71         */
72        public InputStream getResultStream() {
73                return rawresult;               
74        }
75
76        public void getResultStream(String format, InputStream in) throws IOException, InterruptedException, TransformerException, NoStylesheetException {
77                        in = getResultStream(format);
78        }
79
80       
81        public void setInputStream(InputStream in) {
82                this.rawresult = in;           
83        }
84
85        /**
86         * a stub for a header to be returned with every result
87         * not used yet
88         * @return
89         */
90        public String getHeader() {
91                String header = "";
92                       
93                header = "<header>";
94                header += "<userquery>" + parentQuery.getQueryString() + "</userquery>"; 
95                header += "<xpathquery>" + parentQuery.toXPath() + "</xpathquery>";             
96                header += "</header>";
97               
98               
99                return header; 
100        }
101
102}
Note: See TracBrowser for help on using the repository browser.