Ignore:
Timestamp:
08/25/11 20:21:23 (13 years ago)
Author:
vronk
Message:

started cleaning up code, adding inline-documentation;
also changes to output method in xsl (xhtml)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/GenericProxyAction.java

    r1491 r1495  
    2626
    2727import org.apache.struts2.interceptor.ServletRequestAware;
    28 
    2928import com.opensymphony.xwork2.ActionSupport;
    30 
    3129import eu.clarin.cmdi.mdservice.model.Diagnostics;
    3230
    3331/**
    34  * main Struts 2 controller
    35  * responds to requests (collections, model, recordset)
    36  * by dispatching the requests to appropriate internal methods and filling the inputStream with the result
     32 * main Struts2 controller (ie implemenets the struts' execute()-method), all other Actions are derived from. 
     33 * Defines the methods used for retrieving the data
     34 * and provides basic implementation where possible.
    3735 * 
    3836 * @author vronk
    39  *
    4037 */
    4138public class GenericProxyAction extends ActionSupport
     
    6966        private String repository;
    7067        //private Map<String,Object> session;
    71          private HttpServletRequest request;
    72          private long duration = 0;
    73          
     68        private HttpServletRequest request;
     69        private long duration = 0;
     70        private InputStream resultStream;
     71        private InputStream sourceStream;
     72        protected URL base_url ;
     73               
    7474         public GenericProxyAction(){
    7575                 super();
     
    198198        }
    199199
     200        /**
     201         * is used in struts.xml to dynamically set the mime-type of the result, depending on the format-parameter
     202         * @return
     203         */
    200204        public String getActionContentType() {
    201205                if (format.toLowerCase().startsWith("html")) {
     
    269273
    270274        /**
    271          * primitive identification of the target-proxy
    272          * base for finding the right base_url in the props
     275         * internal identification of the target-proxy
     276         * base for finding the right base_url in the properties
    273277         * subclass has to override with its specific proxykey
    274          * @return
     278         * @return the key identifying this type of proxy
    275279         */
    276280        public String getProxyKey() {
     
    278282        }
    279283       
     284        /**
     285         * TODO: check what this does, where it is used?
     286         * @return
     287         */
    280288        public String getUserMsg() {
    281289                return userMsg;
     
    286294        }
    287295       
     296        /**
     297         * TODO: check what this does, where it is used?
     298         * @return
     299         */
    288300        @Override
    289301        public void setServletRequest(HttpServletRequest arg0) {
     
    294306                return request;
    295307        }
    296 
    297 
    298         private InputStream resultStream;
    299         private InputStream sourceStream;
    300308
    301309        /**
     
    335343        }
    336344       
    337         protected URL base_url ;
    338        
     345        /**
     346         * Reads URI from the configuration (mdservice.properties) based on the proxy-key
     347         * @return the base-URI of the target repository or registry
     348         */
     349        public String getBaseURI() {           
     350                String uri =Admin.getConfig().getProperty(getProxyKey() + ".uri");             
     351                return uri;
     352        }
     353
     354        /**
     355         * Provides the base-URL specific to given target repository or registry
     356         * @return
     357         * @throws MalformedURLException
     358         */     
    339359        public URL getBaseURL() throws MalformedURLException {         
    340360                if (base_url == null) {
     
    344364        }
    345365       
    346         public String getBaseURI() {           
    347                 String uri =Admin.getConfig().getProperty(getProxyKey() + ".uri");             
    348                 return uri;
    349         }
    350 
    351        
     366        /**
     367         * Constructs the actual URL to be send to the target repository/registry
     368         * It has to be overridden by the subclasses
     369         * as every target service has a different request-pattern. 
     370         * @return URL of the target request
     371         * @throws IOException
     372         */
    352373        public URL getTargetRequest() throws IOException {
    353         // URL targetURL =new URL( base_url, compname + ".xml");
    354                 URL targetURL = getBaseURL();     
    355                      
     374                URL targetURL = getBaseURL();                     
    356375        return targetURL;
    357376        }
    358377       
    359         /*
    360         public String getRequestKey() {
    361                 String key="";
    362                 if (getActionkey()!=null) {
    363                         key += getActionkey() + "//-" ;
    364                 }
    365                 if (getQ()!=null) {
    366                         key += getQ() + "//-" ;
    367                 }
    368                 if (getCollection()!=null) {
    369                         key += getCollection();
    370                 }
    371                  
    372                 return key;
    373         }
    374 */
    375 
     378        /**
     379         * Constructs an unambiguous key for the request (encoding all the parameters).
     380         * This is used as identifier for caching
     381         * @return key unambiguously encoding the request
     382         */
     383       
    376384         public String getRequestKey() {
    377385                        String key="";
     
    416424                        }else{
    417425                                key +="//-" ;
    418                         }
    419                        
     426                        }                       
    420427                         
    421                         return key;
    422         }
     428                return key;
     429        }
     430         
     431         
    423432        public InputStream getSourceStream() throws IOException, NoStylesheetException {               
    424433                return getTargetRequest().openStream();
    425                 //      Admin.notifyUser(getProxyKey() + ".getSourceStream() - unable to open stream: " + getTargetRequest(); 
    426         }
    427        
     434 
     435        }
     436       
     437        /*
     438         * TODO: this should go to Utilities!
     439         */
    428440        public  static String convertStreamToString(InputStream is) { 
    429441               
     
    677689        }
    678690       
     691        /**
     692         * This is the work-horse function.
     693         * It does two things:
     694         * a) check if the source data is already in cache (based on cache-key that is constructed from the request parameters)
     695         * b) if format-parameter provided, invokes the transformation.
     696         * at the end the data to be returned as result is contained in the resultStream
     697         * If format is xml, then the data from sourceStream is passed further as resultStream.
     698         *   
     699         * @throws Exception  This is handled by struts (is mapped to some result in struts.xml based on the Exception-Class)
     700         */
    679701       
    680702        public void prepare() throws Exception {               
     
    716738                        resultStream = sourceStream;   
    717739                }else {
     740                        MDTransformer transformer = new MDTransformer();
    718741                        // set URL as srcFile (for MDTransformer to pass to xsl-scripts)
    719                         MDTransformer transformer = new MDTransformer();
     742                        // TODO: WHY??
    720743                        transformer.setSrcFile(getTargetRequest());
    721                         // getColumns
    722                 //      Admin.notifyUser("GPA.getRepository, before xsl:" + getRepository());
    723744                        transformer.setParams(createTransformerParams());
    724                        
    725                         resultStream = transformer.transformXML(sourceStream);//, getFullFormat(), getColumns(), getStartRecord(), getMaximumRecords(),getLang(),getQ(),String.valueOf(getRepository()));
     745                        // here the transformation is invoked
     746                        resultStream = transformer.transformXML(sourceStream);
    726747                }
    727748                       
     
    730751
    731752        /**
    732          * default Action method
     753         * default Action method that gets called by Struts. Everything interesting happens in prepare()
    733754         */
    734755        public String execute() throws Exception {
Note: See TracChangeset for help on using the changeset viewer.