Ignore:
Timestamp:
07/12/10 12:46:30 (14 years ago)
Author:
gaba
Message:

load profiles,terms (elements) in 2 steps , using cache

Location:
MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action
Files:
4 edited

Legend:

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

    r521 r582  
    8181                        InputStream instream;
    8282                                try {
    83                                         instream = new FileInputStream(f);
     83                                        instream = new FileInputStream(f);
     84
    8485                                        return instream;
    8586                                } catch (FileNotFoundException e) {
  • MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/CompRegistryProxyAction.java

    r519 r582  
    1 package eu.clarin.cmdi.mdservice.action;
     1 package eu.clarin.cmdi.mdservice.action;
    22
     3import java.io.File;
     4import java.io.FileOutputStream;
    35import java.io.IOException;
    46import java.io.InputStream;
     7import java.io.OutputStream;
    58import java.net.MalformedURLException;
    69import java.net.URL;
     
    3639        public String getFullFormat() {
    3740                if (compid==null || compid.equals("")) {
    38                         return "complist2" + getFormat();
     41                        if (getActionkey().equals("elements")){
     42                                return "terms2" + getFormat(); 
     43                        } else {
     44                                return "complist2" + getFormat();
     45                        }
    3946                } else {
    4047                        return "comp2" + getFormat();
     
    6067        }
    6168
    62        
     69               
     70        @SuppressWarnings("deprecation")       
     71        @Override
     72        public void prepare() throws Exception {               
     73               
     74                Admin.notifyUser("CRPA.prepare");
     75                if (!getActionkey().equals("elements")) {
     76                        super.prepare();
     77                } else  {
     78                        Admin.notifyUser("CRPA.prepareSourceStream - elements");
     79                        String xcid;
     80                        InputStream _sourceStream;
     81                        InputStream __sourceStream;
     82                        InputStream _resultStream;
     83                       
     84                        _sourceStream = Cache.getCache().getFromCache(getRequestKey());
     85                        if (_sourceStream == null) {
     86                                        Admin.notifyUser("CRPA.prepareSourceStream- profiles");
     87                                        setActionkey("profiles");
     88                                        setFormat("xmlresolved");
     89                                        __sourceStream = Cache.getCache().getFromCache(getRequestKey());
     90                                        if (__sourceStream == null) {
     91                                                __sourceStream = getSourceStream();
     92                                                xcid = Cache.getCache().putInCache(getRequestKey(),__sourceStream);                     
     93                                                Admin.notifyUser("CRPA-putting in cache: " + getRequestKey()); 
     94                                                __sourceStream = Cache.getCache().getFromCache(getRequestKey());
     95                                        } else{
     96                                                Admin.notifyUser("CRPA-reading from cache: " + getRequestKey());       
     97                                        }
     98                                        Admin.notifyUser("CCCRPA." + getTargetRequest());
     99                                        Admin.notifyUser("CCCRPA." + getFullFormat());
     100                                        MDTransformer.getMDTransformer().setSrcFile(getTargetRequest());
     101                                        _sourceStream = MDTransformer.getMDTransformer().transformXML(__sourceStream, getFullFormat());
     102                                        Admin.notifyUser("CRPA.- elements");
     103                                        setActionkey("elements");
     104                                        setFormat("htmllist");
     105                                        xcid = Cache.getCache().putInCache(getRequestKey(),_sourceStream);                     
     106                                        Admin.notifyUser("CRPA-putting in cache: " + getRequestKey());
     107                                        _sourceStream = Cache.getCache().getFromCache(getRequestKey());
     108                        }  else {
     109                                        Admin.notifyUser("CRPA-reading from cache: " + getRequestKey());
     110                        }
     111                                /*
     112                        File file=new File(Cache.getCache().formPath(getRequestKey()));
     113                        Admin.notifyUser("File-absolutePath " + file.getAbsolutePath());
     114                        URL url = null;
     115                           try{
     116                                   url = file.toURL();
     117                                   Admin.notifyUser("URL-tostring " + url.toString());
     118                                   }  catch (MalformedURLException me){
     119                          }
     120                         */
     121
     122                        MDTransformer.getMDTransformer().setSrcFile(getTargetRequest());
     123                        _resultStream = MDTransformer.getMDTransformer().transformXML(_sourceStream, getFullFormat());
     124
     125                        setSourceStream(_sourceStream);
     126                        setResultStream(_resultStream);
     127                       
     128                        if (getFormat().equals("txt")) {
     129                                File f=new File(Cache.getCache().formPath("terms_autocomplete.txt"));
     130                            OutputStream out=new FileOutputStream(f);
     131                            byte buf[]=new byte[1024];
     132                            int len;
     133                            while((len=getResultStream().read(buf))>0)
     134                                out.write(buf,0,len);
     135                            out.close();
     136Admin.notifyUser("terms_autocomplete.txt");
     137                        }
     138                       
     139                       
     140                }
     141
     142        }
     143
     144
    63145        /**
    64146         * uses base_url and (optionally) compid to form a url
  • MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/GenericProxyAction.java

    r535 r582  
    106106                return resultStream;
    107107    }
    108 
     108        public void setResultStream(InputStream _resultStream){
     109                resultStream = _resultStream;
     110        }
     111        public void setSourceStream(InputStream _sourceStream){
     112                sourceStream = _sourceStream;
     113        }
     114       
    109115        /*
    110116        public InputStream getSourceStream() throws IOException {
     
    150156        }
    151157       
     158       
    152159        public void prepare() throws Exception {               
    153160               
     
    156163               
    157164                // Caching
    158                 // does not work yet  see Cache.java for details
    159                
    160                         String xcid;
     165                String xcid;
     166                Admin.notifyUser("GPA.prepareSourceStream");
     167                sourceStream = Cache.getCache().getFromCache(getRequestKey());
     168                if (sourceStream == null) {
     169                        //sourceStream = getTargetRequest().openStream();
     170                        sourceStream = getSourceStream();
     171                        xcid = Cache.getCache().putInCache(getRequestKey(),sourceStream);                       
     172                        Admin.notifyUser("putting in cache: " + getRequestKey());                       
    161173                        sourceStream = Cache.getCache().getFromCache(getRequestKey());
    162                         if (sourceStream == null) {
    163                                 //sourceStream = getTargetRequest().openStream();
    164                                 sourceStream = getSourceStream();
    165                                 xcid = Cache.getCache().putInCache(getRequestKey(),sourceStream);                       
    166                                 Admin.notifyUser("putting in cache: " + getRequestKey());                       
    167                                 sourceStream = Cache.getCache().getFromCache(getRequestKey());
    168                         }  else {
    169                                 Admin.notifyUser("reading from cache: " + getRequestKey());
    170                         }
    171        
    172 
    173                
     174                }  else {
     175                        Admin.notifyUser("reading from cache: " + getRequestKey());
     176                }
     177       
    174178                if (format.equals("xml")) {                     
    175179                        resultStream = sourceStream;   
  • MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/MDTransformer.java

    r501 r582  
    114114                Transformer transformer = tfactory.newTransformer(
    115115                                                                        getXSLStreamSource(transkey));
     116               
     117                transformer.setParameter("format", transkey);
     118               
     119                if (srcFile!=null) {
    116120                       
    117                 transformer.setParameter("format", transkey);
    118                
    119                 if (srcFile!=null) {
    120121                        File f = new File(srcFile.getPath());
    121                        
     122                           
    122123                        //Admin.notifyUser("src:" + srcFile.getFile());
    123124                        //Admin.notifyUser("fpath:" + f.getAbsolutePath());
     
    138139                StreamSource src =new StreamSource();                   
    139140                src.setInputStream(in);
    140                
    141141                // Transform the source XML to out-stream
    142142                transformer.transform(src, stream );
Note: See TracChangeset for help on using the changeset viewer.