Changeset 1524 for MDService2


Ignore:
Timestamp:
09/08/11 10:32:36 (13 years ago)
Author:
gaba
Message:

sru-params

Location:
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/CompRegistryProxyAction.java

    r1512 r1524  
    127127                        if (_sourceStream == null) {
    128128        //                              Admin.notifyUser("CRPA.prepareSourceStream- profiles");
    129                                         setActionkey("profiles");
    130                                         setFormat("xmlresolved");
     129                                        //setActionkey("profiles");
     130                                        //setFormat("xmlresolved");
    131131                                        __sourceStream = Cache.getCache().getFromCache(getRequestKey());
    132132                                        if (__sourceStream == null) {
     
    142142                                        MDTransformer transformer = new MDTransformer();
    143143                                        transformer.setSrcFile(getTargetRequest());
    144                                         transformer.setParams(createTransformerParams());
     144                                        //transformer.setParams(createTransformerParams());
    145145                                        _sourceStream = transformer.transformXML(__sourceStream);//, getFullFormat(),null,null,null,null,null,null);
    146146                                //      Admin.notifyUser("CRPA.- elements");
    147                                         setActionkey("elements");
    148                                         setFormat("htmllist");
     147                                        //setActionkey("elements");
     148                                        //setFormat("htmllist");
    149149                                        xcid = Cache.getCache().putInCache(getRequestKey(),_sourceStream);                     
    150150                        //              Admin.notifyUser("CRPA-putting in cache: " + getRequestKey());
     
    170170                                MDTransformer transformer = new MDTransformer();
    171171                                transformer.setSrcFile(getTargetRequest());
    172                                 transformer.setParams(MDTransformer.createParamsMap(getFullFormat()));
     172                                //transformer.setParams(MDTransformer.createParamsMap(getFullFormat()));
    173173                                _resultStream = transformer.transformXML(_sourceStream);//, getFullFormat());
    174174                                       
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/GenericAction.java

    r1523 r1524  
    5353        /**
    5454         * Properties to be filled by Struts with according request-parameters
    55          */     
     55         */
    5656        private String actionkey = "generic";
    57         private String cache = Cache.SKIP;
    58         private String lang="en";
    5957        private String q;
    60         private String format="xml"; // default no transformation
     58       
    6159        private String actionContentType;
    6260        private String userMsg;
    6361        private HttpServletRequest request;
    6462        private long duration = 0;
    65         private String repository;
    6663        private InputStream resultStream;
    6764        private InputStream sourceStream;
    6865       
    6966        private Map<String,String[]> params;
    70        
    71 //      protected URL base_url ;
    7267       
    7368        private ProxyInterface target_proxy;
     
    8782 */     
    8883        public void setTargetProxy() {
    89 }
     84        }
    9085
    9186         public Diagnostics getDiagnostics(){
     
    10095         }
    10196         
     97         public String getQ() {
     98                        /*
     99                        if  (q == null) {
     100                                return "";
     101                        } else {
     102                                return q;
     103                        }       
     104                        */
     105                        return q;
     106         }
     107
     108         public void setQ(String q) {
     109                        //if (q == null) q="";
     110                        this.q = q;
     111         }
     112         
     113         public String getActionkey() {
     114                        return actionkey;
     115                }
     116
     117        public void setActionkey(String actionKey) {
     118                        actionkey = actionKey;
     119                }
     120               
     121         public String getRecordPacking() {
     122                 return getParam("recordPacking");
     123         }
     124         public String getFormat() {
     125                        return getParam("x-cmd-format");
     126         }
    102127         public String getCache() {
    103                 return cache;
    104         }
    105 
    106         public void setCache(String cache) {
    107                 this.cache = cache;
    108         }
    109 
    110         public String getFormat() {
    111                 return format;
    112         }
    113 
    114         public void setFormat(String format) {
    115                 this.format = format;
    116         }
     128                        return getParam("x-cmd-cache");
     129         }
     130         public String getRepository() {
     131                        return getParam("x-cmd-repository");
     132         }
     133         public String getLang() {
     134                        return getParam("x-cmd-lang");
     135         }
     136         public String getCollections() {
     137                        return getParam("x-cmd-collections");
     138         }
     139         public String getColumns() {
     140                        return getParam("x-cmd-columns");
     141         }
     142         public String getQuery() {
     143                 return getParam("query");
     144         }
     145         public String getStartRecord() {
     146                 return getParam("startRecord");
     147         }
     148         public String getMaximumRecords() {
     149                 return getParam("maximumRecords");
     150         }
     151         public String getMaxdepth() {
     152                 return getParam("x-cmd-maxdepth");
     153         }
    117154         
    118        
    119         public String getQ() {
    120                 if  (q == null) {
    121                         return "";
    122                 } else {
    123                         return q;
    124                 }               
    125         }
    126 
    127         public void setQ(String pq) {
    128                 if (pq == null) pq="";
    129                 /*
    130                 if (q != null){
    131                         if (q.trim().length() == 0){
    132                                 q = null;
    133                         }
    134                 }
    135                 */
    136                 this.q = pq;
    137         }
    138 
    139 
    140         public void setRepository(String repository) {
    141                 this.repository = repository;
    142         }
    143        
    144         public String getRepository() {
    145                 //default repository = 1 (set on init)
    146                 return repository;
    147         }
    148155       
    149156        /**
     
    152159         */
    153160        public String getActionContentType() {
    154                 if (format.toLowerCase().startsWith("html")) {
     161                if (this.getFormat().toLowerCase().startsWith("html")) {
    155162                        this.actionContentType = "text/html";           
    156163                        //this.actionContentType = "application/xhtml+xml";
     
    165172                this.actionContentType = actionContentType;
    166173        }
    167        
    168         public String getActionkey() {
    169                 return actionkey;
    170         }
    171 
    172         public void setActionkey(String actionKey) {
    173                 actionkey = actionKey;
    174         }
    175 
    176         public String getLang() {
    177                 return lang;
    178         }
    179 
    180         public void setLang(String lang) {
    181                 this.lang = lang;
    182         }
     174
    183175
    184176        public String getFullFormat() {         
    185                 return actionkey + "2" + format;
     177                return actionkey + "2" + getFormat();
    186178        }
    187179
     
    246238         * at the cost of circumventing the Struts-way.
    247239         */
     240        public void addParam(String key, String value){
     241                        String[] sarr = new String[1];
     242                        sarr[0] = value;
     243                        params.put(key, sarr); 
     244        }
     245       
     246        /*
     247         * sru params
     248         *  /*
     249     * version
     250     * operation
     251     * query
     252     * scanClause
     253     * startRecord
     254     * maximumRecords
     255     * recordPacking
     256     * recordSchema
     257     * recordXPath
     258     * resultSetTTL
     259     * sortKeys
     260     * stylesheet
     261     * x-cmd-repository
     262     * x-cmd-collections
     263     * x-cmd-columns
     264     * x-cmd-lang
     265     * x-cmd-format
     266     * x-cmd-cache
     267     * x-cmd-maxdepth
     268         */
    248269        @SuppressWarnings("unchecked")
    249270        protected void loadParams() {           
    250271                params = new HashMap(getServletRequest().getParameterMap());
    251272
    252                 if (!getQ().equals("")) {
    253                         String[] sarr = new String[1];
    254                         sarr[0] = getQ();
    255                         params.put("q", sarr);         
     273                if (getQ() != null) {
     274                        addParam("q",getQ());
    256275                }       
    257                 if (!params.containsKey("repository")){
    258                         String[] sarr = new String[1];
    259                         sarr[0] = getRepository();
    260                         params.put("repository", sarr);
    261                 }
    262                 String[] sarr2 = new String[1];
    263                 sarr2[0] =getFullFormat();
    264                 params.put("fullformat", sarr2);
    265         }
    266    
     276
     277                // set defaults
     278                if ( params.get("version") == null){
     279                        addParam("version","1.2");
     280                }
     281                if ( params.get("operation") == null){
     282                        addParam("operation","searchRetrieve");
     283                }
     284                if ( params.get("query") == null){
     285                        addParam("query",getParam("q"));
     286                }
     287                if ( params.get("startRecord") == null){
     288                        addParam("startRecord","1");
     289                }
     290                if ( params.get("maximumRecords") == null){
     291                        addParam("maximumRecords","50");
     292                }
     293                if ( params.get("x-cmd-maxdepth") == null){
     294                        addParam("x-cmd-maxdepth","2");
     295                }
     296                if ( params.get("x-cmd-repository") == null){
     297                        //addParam("x-cmd-repository","1");
     298                }
     299                if ( params.get("x-cmd-cache") == null){
     300                        addParam("x-cmd-cache",Cache.SKIP);
     301                }
     302                if ( params.get("x-cmd-lang") == null){
     303                        addParam("x-cmd-lang","en");
     304                }
     305        }
    267306       
    268307        public Map<String,String[]> getParams() {               
     
    303342                                key +="//-" ;
    304343                        }
    305                         /*if (getQ()!=null) {
    306                                 key += getQ() + "//-" ;
     344                        if (getQuery()!=null) {
     345                                key += getQuery() + "//-" ;
    307346                        } else {
    308347                                key +="//-" ;
    309348                        }
    310                         if (getCollection()!=null) {
    311                                 key += getCollection() + "//-";
     349                        if (getCollections()!=null) {
     350                                key += getCollections() + "//-";
    312351                        } else {
    313352                                key +="//-" ;
    314353                        }
    315                         if (getSquery()!=null) {
    316                                 key += getSquery() + "//-" ;
    317                         } else {
    318                                 key +="//-" ;
    319                         }
    320                         if (getStartItem()!=null) {
    321                                 key += getStartItem() + "//-";
     354                        if (this.getStartRecord()!=null) {
     355                                key += getStartRecord() + "//-";
    322356                        }
    323357                                else{
    324358                                        key +="//-" ;
    325359                        }
    326                         if (getMaximumItems()!=null) {
    327                                 key += getMaximumItems() + "//-";
     360                        if (getMaximumRecords()!=null) {
     361                                key += getMaximumRecords() + "//-";
    328362                        }
    329363                        else{
     
    339373                                key +="//-" ;
    340374                        }                       
    341                          */
     375
    342376                return key;
    343377        }
     
    355389        }
    356390       
     391        /*
    357392        private static final Map<String, String> xsl_map;
    358393    static {
     
    386421            return map;
    387422        }
    388         /*
     423       
    389424        public Map<String,String> createTransformerParams(){
    390425               
     
    505540                        // TODO: WHY??
    506541                        transformer.setSrcFile(getTargetProxy().getTargetRequest());
    507                         transformer.setParams(createTransformerParams());
     542                        //transformer.setParams(createTransformerParams());
     543                        transformer.setParams(getParams());
    508544                        // here the transformation is invoked
    509545                        resultStream = transformer.transformXML(sourceStream);
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/GenericProxyAction.java

    r1521 r1524  
    7979         }
    8080         
    81        
     81        /*
    8282         public Diagnostics getDiagnostics(){
    8383                 return this.diagnostics;
     
    105105                        }
    106106                }
    107                 */
     107               
    108108                this.q = pq;
    109109        }
     
    137137        public String getColumns() {
    138138                String cols = columns;
    139                 /*if (columns == null){
    140                         cols = "Id,Name,Title";
    141                 }
    142                 */
    143139                return cols;
    144140        }
     
    171167                this.options = options;
    172168        }
    173 
     169*/
    174170        /**
    175171         * is used in struts.xml to dynamically set the mime-type of the result, depending on the format-parameter
     
    343339         public String getRequestKey() {
    344340                        String key="";
     341                        /*
    345342                        if (getActionkey()!=null) {
    346343                                key += getActionkey() + "//-" ;
     
    384381                                key +="//-" ;
    385382                        }                       
    386                          
     383                         */
    387384                return key;
    388385        }
     
    494491                        // TODO: WHY??
    495492                        transformer.setSrcFile(getTargetRequest());
    496                         transformer.setParams(createTransformerParams());
     493                        //transformer.setParams(createTransformerParams());
    497494                        // here the transformation is invoked
    498495                        resultStream = transformer.transformXML(sourceStream);
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/GenericWorkspaceAction.java

    r1512 r1524  
    175175                        transformer.setSrcFile(getURL());
    176176                        //InputStream tmp_s =  MDTransformer.getMDTransformer().transformXML(sourceStream, "attr2elements");
    177                         transformer.setParams(MDTransformer.createParamsMap(getFullFormat()));
     177                        //transformer.setParams(MDTransformer.createParamsMap(getFullFormat()));
    178178                        InputStream s =  transformer.transformXML(sourceStream);//, getFullFormat());
    179179                        resultStream = getPart(s);
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/RepoAction.java

    r1523 r1524  
    9191                public void setTargetProxy(){
    9292                                               
    93                         if (getRepository()==null) setRepository("clarin.at-mirror");
     93                        //if (getRepository()==null) setRepository("clarin.at-mirror");
    9494                       
    9595                        switch (WorkspaceProfile.RepositoryType.toRepositoryType(WorkspaceProfile.getRepositoryType(getRepository())))
     
    109109                       
    110110                }
    111        
     111        /*
    112112        public String getSquery() {
    113113                return squery;
     
    130130        public String getColumns() {
    131131                String cols = columns;
    132                 /*if (columns == null){
    133                         cols = "Id,Name,Title";
    134                 }
    135                 */
    136132                return cols;
    137133        }
     
    156152                this.format = format;
    157153        }
    158 */
     154
    159155        public String getOptions() {
    160156                return options;
     
    199195                this.sort = sort;
    200196        }
    201 
     197*/
    202198
    203199        /**
     
    216212         * @return key unambiguously encoding the request
    217213         */
    218        
     214        /*
    219215         public String getRequestKey() {
    220216                        String key="";
     
    263259                return key;
    264260        }
    265          
     261         */
    266262        /*     
    267263         @Override
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/SRUAction.java

    r1521 r1524  
    4242         * Properties to be filled by Struts with according request-parameters
    4343         */     
     44        /*
    4445        private String q;
    4546        private String version;
     
    5859        private String x_cmd_collections;
    5960        private Set paramSet;
    60 
     61*/
    6162       
    6263        private static int OP_SEARCHRETRIEVE = 1;
     
    9495         protected void  initialize(){
    9596                 //repository = 1;
    96                  this.startRecord = 1;
    97                  this.maximumRecords = 50;
    98                  
     97                 //this.startRecord = 1;
     98                 //this.maximumRecords = 50;
     99                 /*
    99100                 if (getServletRequest() != null){
    100101                         this.setX_cmd_repository(getServletRequest().getParameter("x-cmd-repository"));
    101102                        //this.setRepository(this.getX_cmd_repository());
    102                          paramSet = getServletRequest().getParameterMap().entrySet();                   
     103                         //paramSet = getServletRequest().getParameterMap().entrySet();                 
    103104                 }
     105                 */
    104106                 
    105107         }
    106        
     108        /*
    107109         public String getQ() {
    108110                        return q;
     
    226228        }
    227229
    228        
     230        */
    229231        public String getDiagnosticStreamName() throws TransformerConfigurationException, UnsupportedEncodingException, ParserConfigurationException, TransformerException, TransformerFactoryConfigurationError{
    230232                this.setResultStream(getDiagnostics().buildXMLStream());
    231233                return "resultStream";
    232234        }
     235       
    233236        /**
    234237         * primitive identification of the target-proxy
     
    442445               
    443446                //TODO params
     447                /*
    444448                if (paramSet == null){
    445449                        if (!(operation == null)){
     
    470474
    471475                }
    472 
     476*/
    473477                return params;
    474478        }
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/TermsProxyAction.java

    r1512 r1524  
    138138                                this.setProxyKey("terms.dcr");
    139139                                MDTransformer transformer = new MDTransformer();
    140                                 transformer.setParams(createTransformerParams());
     140                                //transformer.setParams(createTransformerParams());
    141141                                /* IMPORTANT! change the format for the second phase:
    142142                                 * (but preserve the original format for the third phase. */                           
    143                                 transformer.getParams().put("format","terms2extract");
     143                                //transformer.getParams().put("format","terms2extract");
    144144                               
    145145                                Admin.notifyUser("TPA.getSourceStream.transformer.effectiveTranskey: " + transformer.getTranskey() + ", for Termset:" + getTSAttr("name") + '#' + getTSAttr("id"));
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/VirtualCollectionProxyAction.java

    r1512 r1524  
    3838        }
    3939        */
    40         @Override
     40        //@Override
    4141        protected void  initialize(){
    42                 setFormat("VC");
     42                //setFormat("VC");
    4343         }
    4444       
     
    5757                return uri;
    5858        }
    59        
     59        /*
    6060        @Override
    6161        public HashMap<String,String> createTransformerParams(){
     
    7373               
    7474        }
     75        */
    7576        public String publish() throws Exception {
    7677               
     
    8081                //xslt transform to request data
    8182                MDTransformer transformer = new MDTransformer();
    82                 transformer.setSrcFile(getTargetRequest());
    83                 transformer.setParams(createTransformerParams());
     83                transformer.setSrcFile(this.getTargetProxy().getTargetRequest());
     84                transformer.setParams(getParams());
     85                //transformer.setParams(createTransformerParams());
    8486                InputStream requestStream = transformer.transformXML(is);
    8587               
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/WorkspaceAction.java

    r1512 r1524  
    5959 *
    6060 */
    61 public class WorkspaceAction extends GenericProxyAction
     61public class WorkspaceAction extends GenericAction
    6262//implements ServletRequestAware
    6363{
     
    199199
    200200       
    201         @Override
     201        //@Override
    202202        public URL getBaseURL() {
    203203                File file=new File(getPath());
     
    208208            } catch (MalformedURLException e){
    209209                log.error("getBaseURL: JSON exception has been caught;\n getPath=" + getPath() );
    210                 Diagnostics().Add(Diagnostic.SYSTEM_ERROR, "WorkspaceAction.getBaseURL()", "JSON exception has been caught;\n getPath=" + getPath() );         
     210                getDiagnostics().Add(Diagnostic.SYSTEM_ERROR, "WorkspaceAction.getBaseURL()", "JSON exception has been caught;\n getPath=" + getPath() );               
    211211            }
    212212           
     
    505505                        else {
    506506                                // edit existing query
    507                                 NodeList wsnodelist = (NodeList) getQuery();
     507                                NodeList wsnodelist = (NodeList) getWorkspaceQuery();
    508508                        // remove
    509509                        //childeNode
     
    542542                                                else {
    543543                                                        // edit existing query
    544                                                         NodeList wsnodelist = (NodeList) getQuery();
     544                                                        NodeList wsnodelist = (NodeList) getWorkspaceQuery();
    545545                                                // remove
    546546                                                //childeNode
     
    827827        }
    828828       
    829         public Object getQuery() throws XPathExpressionException{
     829        public Object getWorkspaceQuery() throws XPathExpressionException{
    830830               
    831831                XPathFactory factory = XPathFactory.newInstance();
     
    980980                        MDTransformer transformer = new MDTransformer();
    981981                        transformer.setSrcFile(getURL());
    982                         transformer.setParams(MDTransformer.createParamsMap(getFullFormat()));
     982                        transformer.setParams(getParams());
     983                        //transformer.setParams(MDTransformer.createParamsMap(getFullFormat()));
    983984                        setResultStream(transformer.transformXML(is));//, getFullFormat()));
    984985                        //setSessionData(getResultStream());
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/internal/MDTransformer.java

    r1521 r1524  
    5353       
    5454        private URL srcFile ;
    55         private Map<String, String> params;
     55        private Map<String, String[]> params;
    5656               
    5757        // don't use singleton!! Bad things happen
     
    7878         * @return
    7979         */
    80         public void setParams(Map<String, String> map){
     80        public void setParams(Map<String, String[]> map){
    8181                this.params = map;
    8282        }
    8383       
    8484       
    85         public Map<String,String> getParams(){
     85        public Map<String,String[]> getParams(){
    8686                return this.params;
    8787        }
     
    131131       
    132132        public String getTranskey(){
    133                 return params.get("format");
     133                return params.get("x-cmd-format")[0];
    134134        }
    135135
     
    141141        public void SetTransformerParameters(Transformer transformer){
    142142               
    143                 Set<Entry<String, String>> set = params.entrySet();
    144                 Iterator<Entry<String, String>> i = set.iterator();
     143                Set<Entry<String, String[]>> set = params.entrySet();
     144                Iterator<Entry<String, String[]>> i = set.iterator();
    145145
    146146            while(i.hasNext()){
    147               Map.Entry<String,String> e = (Map.Entry<String,String>)i.next();
    148               transformer.setParameter((String)e.getKey(), (String)e.getValue());
     147              Map.Entry<String,String[]> e = (Map.Entry<String,String[]>)i.next();
     148              transformer.setParameter((String)e.getKey(), (String)e.getValue()[0]);
    149149            }
    150150        }
     
    322322        }
    323323       
    324         public static HashMap<String,String> createParamsMap(String transkey){
    325                 HashMap<String,String> hm = new HashMap<String,String>();
    326                
    327             if (transkey != null){
    328                         hm.put("format", transkey);
     324        public static HashMap<String,String[]> createParamsMap(String key){
     325                HashMap<String,String[]> hm = new HashMap<String,String[]>();
     326               
     327            if (key != null){
     328                String[] arrkey = new String[1];
     329                arrkey[0] = key;
     330                        hm.put("x-cmd-format", arrkey);
    329331            }
    330332            return hm;
    331333        }
     334       
    332335}
Note: See TracChangeset for help on using the changeset viewer.