Changeset 1540 for MDService2


Ignore:
Timestamp:
09/19/11 10:39:55 (13 years ago)
Author:
gaba
Message:

Utils.java in place of Helpers and Admin
Diagnostics changes in GenericAction?
code arrangement, comments

Location:
MDService2/branches/MDService_simple3
Files:
1 added
25 edited

Legend:

Unmodified
Added
Removed
  • MDService2/branches/MDService_simple3/WorkspaceProfile.xml

    r1516 r1540  
    7878            </item>
    7979            <item>
     80               <type></type>
     81               <id>compreg</id>
     82               <name>compreg</name>
     83               <url>http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/</url>
     84               <url_prefix></url_prefix>
     85               <format>xml</format>
     86            </item>
     87            <item>
    8088               <type>dcr</type>
    8189               <id>isocat</id>
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/AdminAction.java

    r1512 r1540  
    11package eu.clarin.cmdi.mdservice.action;
    22
    3 import java.io.ByteArrayInputStream;
    4 import java.io.IOException;
    5 import java.net.MalformedURLException;
    6 import java.net.URL;
    7 import java.text.DateFormat;
    8 import java.text.SimpleDateFormat;
    9 import java.util.Date;
    103import java.util.HashMap;
    114
    125import eu.clarin.cmdi.mdservice.internal.Cache;
    13 
    14 import net.sf.json.JSONObject;
    15 import net.sf.json.xml.XMLSerializer;
    166
    177/*
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/CompRegistryProxyAction.java

    r1536 r1540  
    11 package eu.clarin.cmdi.mdservice.action;
    22
    3 import java.io.IOException;
    43import java.io.InputStream;
    5 import java.net.URL;
    6 
    7 import eu.clarin.cmdi.mdservice.internal.Admin;
    84import eu.clarin.cmdi.mdservice.internal.Cache;
    95import eu.clarin.cmdi.mdservice.internal.MDTransformer;
    10 import eu.clarin.cmdi.mdservice.model.Diagnostic;
    11 import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
    126import eu.clarin.cmdi.mdservice.proxy.BasicProxy;
    13 import eu.clarin.cmdi.mdservice.proxy.MDRepoProxy;
    14 import eu.clarin.cmdi.mdservice.proxy.Pz2Proxy;
    15 import eu.clarin.cmdi.mdservice.proxy.SRUProxy;
    167
    178/**
     
    128119                try {
    129120               
    130                         //Admin.notifyUser("CRPA.prepare");
     121                        //log.debug("CRPA.prepare");
    131122                        if (!getActionkey().equals("elements")) {
    132123                                super.prepare();
     
    136127                                getTargetProxy().checkParams();
    137128                               
    138 //                              Admin.notifyUser("CRPA.prepareSourceStream - elements");
     129//                              log.debug("CRPA.prepareSourceStream - elements");
    139130                                String xcid;
    140131                                InputStream _sourceStream;
     
    144135                                _sourceStream = Cache.getCache().getFromCache(getRequestKey());
    145136                                if (_sourceStream == null) {
    146                 //                              Admin.notifyUser("CRPA.prepareSourceStream- profiles");
     137                //                              log.debug("CRPA.prepareSourceStream- profiles");
    147138                                                //setActionkey("profiles");
    148139                                                //setFormat("xmlresolved");
     
    151142                                                        __sourceStream = getSourceStream();
    152143                                                        xcid = Cache.getCache().putInCache(getRequestKey(),__sourceStream);                     
    153                                                         //Admin.notifyUser("CRPA-putting in cache: " + getRequestKey());       
     144                                                        //log.debug("CRPA-putting in cache: " + getRequestKey());       
    154145                                                        __sourceStream = Cache.getCache().getFromCache(getRequestKey());
    155146                                                } else{
    156                                                         //Admin.notifyUser("CRPA-reading from cache: " + getRequestKey());     
     147                                                        //log.debug("CRPA-reading from cache: " + getRequestKey());     
    157148                                                }
    158                                 //              Admin.notifyUser("CCCRPA." + getTargetRequest());
    159                                         //      Admin.notifyUser("CCCRPA." + getFullFormat());
     149                                //              log.debug("CCCRPA." + getTargetRequest());
     150                                        //      log.debug("CCCRPA." + getFullFormat());
    160151                                                MDTransformer transformer = new MDTransformer();
    161152                                                transformer.setSrcFile(getTargetProxy().getTargetRequest());
    162153                                                //transformer.setParams(createTransformerParams());
    163154                                                _sourceStream = transformer.transformXML(__sourceStream);//, getFullFormat(),null,null,null,null,null,null);
    164                                         //      Admin.notifyUser("CRPA.- elements");
     155                                        //      log.debug("CRPA.- elements");
    165156                                                //setActionkey("elements");
    166157                                                //setFormat("htmllist");
    167158                                                xcid = Cache.getCache().putInCache(getRequestKey(),_sourceStream);                     
    168                                 //              Admin.notifyUser("CRPA-putting in cache: " + getRequestKey());
     159                                //              log.debug("CRPA-putting in cache: " + getRequestKey());
    169160                                                _sourceStream = Cache.getCache().getFromCache(getRequestKey());
    170161                                } /*else {
    171                                                 Admin.notifyUser("CRPA-reading from cache: " + getRequestKey());
     162                                                log.debug("CRPA-reading from cache: " + getRequestKey());
    172163                                }*/
    173164                                        /*
    174165                                File file=new File(Cache.getCache().formPath(getRequestKey()));
    175                                 Admin.notifyUser("File-absolutePath " + file.getAbsolutePath());
     166                                log.debug("File-absolutePath " + file.getAbsolutePath());
    176167                                URL url = null;
    177168                                   try{
    178169                                           url = file.toURL();
    179                                            Admin.notifyUser("URL-tostring " + url.toString());
     170                                           log.debug("URL-tostring " + url.toString());
    180171                                           }  catch (MalformedURLException me){
    181172                                  }
     
    193184                                }
    194185               
    195                                 Admin.notifyUser(getProxyKey() + " success:" + (_resultStream!=null));
     186                                log.debug(getProxyKey() + " success:" + (_resultStream!=null));
    196187                               
    197188                                setSourceStream(_sourceStream);
     
    207198                                        out.write(buf,0,len);
    208199                                    out.close();
    209         Admin.notifyUser("terms_autocomplete.txt");
     200        log.debug("terms_autocomplete.txt");
    210201                                }
    211202                                */
     
    244235                        targetURL =new URL( getTargetProxy().getBaseURL(), getActionkey() + "/clarin.eu:cr1:" + compid);
    245236                }
    246 //              Admin.notifyUser("CompReg.targetURL:" + targetURL);             
     237//              log.debug("CompReg.targetURL:" + targetURL);           
    247238     //   URLConnection urlConnection = targetURL.openConnection();
    248239//        urlConnection.setRequestProperty("Accept", "application/xml");                 
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/DCRProxyAction.java

    r1536 r1540  
    11package eu.clarin.cmdi.mdservice.action;
    22
    3 import java.io.IOException;
    4 import java.io.InputStream;
    5 import java.net.MalformedURLException;
    6 import java.net.URL;
    73import java.net.URLConnection;
    8 import java.util.HashMap;
    9 
    10 import javax.xml.transform.stream.StreamSource;
    11 import javax.xml.xpath.XPath;
    12 import javax.xml.xpath.XPathConstants;
    13 import javax.xml.xpath.XPathExpression;
    14 import javax.xml.xpath.XPathExpressionException;
    15 import javax.xml.xpath.XPathFactory;
    16 
    174import org.apache.log4j.Logger;
    18 import org.w3c.dom.Document;
    19 import org.w3c.dom.Node;
    20 import org.w3c.dom.NodeList;
    21 
    22 import eu.clarin.cmdi.mdservice.internal.Admin;
    235import eu.clarin.cmdi.mdservice.model.Termset;
    246import eu.clarin.cmdi.mdservice.proxy.BasicProxy;
     
    6244
    6345                Termset res = (Termset) Termset.getTermset(dcr_id);
    64                 if (res==null)          Admin.notifyUser("getDCR(): no termset found for:" + dcr_id);
     46                if (res==null)          log.debug("getDCR(): no termset found for:" + dcr_id);
    6547                //else
    66                         //Admin.notifyUser("getDCR():" + res.getAttr("id") + ":" + res.getAttr("url") );
     48                        //log.debug("getDCR():" + res.getAttr("id") + ":" + res.getAttr("url") );
    6749               
    6850                return res;
     
    155137                }
    156138               
    157 //              Admin.notifyUser("DCRProxy.targetURL:" + targetURL);
     139//              log.debug("DCRProxy.targetURL:" + targetURL);
    158140
    159141            return targetURL;
     
    168150                //TODO NOT integrated in PROXY
    169151                if ((getQ().equals(ALL) || getQ()==null || getQ().equals("")) && (getActionkey().equals(DATCATS))) {
    170                         log.debug("serving terms.file:" + Admin.getConfig().getProperty("terms.file"));
    171                         resultStream = this.getClass().getClassLoader().getResourceAsStream(Admin.getConfig().getProperty("terms.file"));
     152                        log.debug("serving terms.file:" + Utils.getConfig().getProperty("terms.file"));
     153                        resultStream = this.getClass().getClassLoader().getResourceAsStream(Utils.getConfig().getProperty("terms.file"));
    172154                } else {
    173155               
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/GenericAction.java

    r1536 r1540  
    11package eu.clarin.cmdi.mdservice.action;
    22
    3 import java.io.ByteArrayInputStream;
    43import java.io.IOException;
    54import java.io.InputStream;
    6 import java.io.StringWriter;
    75import java.net.URLConnection;
    86import java.util.HashMap;
     
    108
    119import javax.servlet.http.HttpServletRequest;
    12 import javax.xml.transform.TransformerFactory;
    13 import javax.xml.transform.dom.DOMSource;
    14 import javax.xml.transform.stream.StreamResult;
    15 
    1610import org.apache.log4j.Logger;
    1711import org.apache.struts2.interceptor.ServletRequestAware;
    1812import org.w3c.dom.Document;
    19 import org.w3c.dom.Node;
    2013
    2114import com.opensymphony.xwork2.ActionSupport;
    2215
    2316import eu.clarin.cmdi.mdservice.internal.Cache;
    24 import eu.clarin.cmdi.mdservice.internal.Helpers;
    2517import eu.clarin.cmdi.mdservice.internal.MDTransformer;
    2618import eu.clarin.cmdi.mdservice.internal.NoStylesheetException;
     19import eu.clarin.cmdi.mdservice.internal.Utils;
     20import eu.clarin.cmdi.mdservice.model.Diagnostic;
    2721import eu.clarin.cmdi.mdservice.model.Diagnostics;
    2822import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
     
    3226
    3327/**
    34  * main Struts2 controller (ie implemenets the struts' execute()-method), all other Actions are derived from.   
     28 * Main Struts2 controller (ie implemenets the struts' execute()-method), all other Actions are derived from.   
    3529 * Defines the methods used for retrieving the data
    3630 * and provides basic implementation where possible.
     
    4236implements ServletRequestAware
    4337{
     38       
    4439        public static Logger log = Logger.getLogger("GenericAction");
    4540        private static final long serialVersionUID = 1L;
    4641       
    47        
    4842        private Diagnostics diagnostics;
     43
    4944        /**
    5045         * Properties to be filled by Struts with according request-parameters
     
    5550       
    5651        private String actionContentType;
    57         private String userMsg;
    5852        private HttpServletRequest request;
    5953        private long duration = 0;
     
    6559        private ProxyInterface target_proxy;
    6660               
    67                                
     61         /**
     62          * Gets the target proxy.
     63          *             
     64          * @return target proxy
     65          */
    6866        public ProxyInterface getTargetProxy() {
    6967                return target_proxy;
    7068        }
    7169
     70        /**
     71         * Sets the particular proxy and its  source action.
     72         *
     73         * @param proxy - interface to be set
     74         */
    7275        public void setTargetProxy(ProxyInterface proxy) {
    7376                target_proxy = proxy;
     
    7578        }
    7679
    77 /**
    78  * Empty implementation, subclasses have to decide themselves, which proxy to take.
    79  */     
     80        /**
     81        * Empty implementation, subclasses have to decide themselves, which proxy to take.
     82        */     
    8083        public void setTargetProxy() {
    8184        }
    8285
    83          public Diagnostics getDiagnostics(){
     86       
     87        /**
     88         * Gets the diagnostics.
     89         *
     90         * @return diagnostics
     91         */
     92        public Diagnostics getDiagnostics(){
    8493                 if (diagnostics == null){
    8594                         diagnostics  = new Diagnostics();
    8695                 }
    8796                 return this.diagnostics;
    88          }
     97        }
    8998         
    90          public void setDiagnostics(Diagnostics diagnostics){
     99        /**
     100         * Sets the diagnostics.
     101         *
     102         * @param diagnostics
     103         */
     104        public void setDiagnostics(Diagnostics diagnostics){
    91105                 this.diagnostics = diagnostics;
    92          }
     106        }
    93107         
    94          public String getQ() {
     108        /**
     109         * Gets string variable q.
     110         *
     111         * @return
     112         */
     113        public String getQ() {
    95114                        return q;
    96          }
    97 
    98          public void setQ(String q) {
     115        }
     116
     117        /**
     118         * Sets the variable q.
     119         *
     120         * @param q
     121         */
     122        public void setQ(String q) {
    99123                        this.q = q;
    100          }
    101        
    102          public void setFormat(String format) {
     124        }
     125       
     126        /**
     127         * Sets the variable format. Used by Struts in case the format is part of the request path.
     128         * In the case the format is part of the request parameters, it is read by servlet request.
     129         *
     130         * @param format
     131         */
     132        public void setFormat(String format) {
    103133                        this.format = format;
    104          }
    105        
    106          public String getActionkey() {
     134        }
     135       
     136       
     137        public String getActionkey() {
    107138                        return actionkey;
    108139                }
     
    111142                        actionkey = actionKey;
    112143                }
    113                
    114          public String getScanClause() {
     144       
     145        /**
     146         * Gets the scanClause parameter from the parameter map.
     147         *
     148         * @return
     149         */
     150        public String getScanClause() {
    115151                 return getParam("scanClause");
    116          }
    117          public String getRecordPacking() {
     152        }
     153       
     154        /**
     155         * Gets the recordPacking parameter from the parameter map.
     156         *
     157         * @return
     158         */
     159        public String getRecordPacking() {
    118160                 return getParam("recordPacking");
    119          }
    120          public String getQuery() {
     161        }
     162       
     163        public String getQuery() {
    121164                 return getParam("query");
    122          }
    123          public String getStartRecord() {
     165        }
     166       
     167        public String getStartRecord() {
    124168                 return getParam("startRecord");
    125          }
    126          public String getMaximumRecords() {
     169        }
     170       
     171        public String getMaximumRecords() {
    127172                 return getParam("maximumRecords");
    128          }
    129          public String getFormat() {
     173        }
     174       
     175        public String getFormat() {
    130176                        return getParam("format");
    131          }
    132          public String getCache() {
     177        }
     178       
     179        public String getCache() {
    133180                        return getParam("cache");
    134          }
    135          public String getRepository() {
     181        }
     182       
     183        public String getRepository() {
    136184                        return getParam("repository");
    137          }
    138          public String getLang() {
     185        }
     186       
     187        public String getLang() {
    139188                        return getParam("lang");
    140          }
    141          public String getCollections() {
     189        }
     190       
     191        public String getCollections() {
    142192                        return getParam("collections");
    143          }
    144          public String getColumns() {
     193        }
     194       
     195        public String getColumns() {
    145196                        return getParam("columns");
    146          }
    147           public String getMaxdepth() {
     197        }
     198       
     199        public String getMaxdepth() {
    148200                 return getParam("maxdepth");
    149          }
     201        }
    150202         
    151203       
    152204        /**
    153          * is used in struts.xml to dynamically set the mime-type of the result, depending on the format-parameter
     205         * Is used in struts.xml to dynamically set the mime-type of the result, depending on the format-parameter
     206         *
    154207         * @return
    155208         */
     
    173226                return actionkey + "2" + getFormat();
    174227        }
    175 
    176 
    177         /**
    178          * TODO: this should be replaced by the diagnostics-mechanism
    179          * @return
    180          */
    181         public String getUserMsg() {
    182                 return userMsg;
    183         }
    184 
    185         public void setUserMsg(String userMsg) {
    186                 this.userMsg = this.userMsg + "\n" + userMsg;
    187         }
    188        
    189         /**
    190          * needed to acquire the original ServletRequest
     228       
     229        /**
     230         * Needed to acquire the original ServletRequest
    191231         * (want to access the raw params - in loadParams())
    192232         * @return
     
    202242
    203243        /**
    204          * The stream holding the resulting data to be sent back to the user as response
     244         * The stream holding the resulting data to be sent back to the user as response.
    205245         * @return
    206246         */
     
    208248                return resultStream;
    209249    }
     250       
    210251        public void setResultStream(InputStream _resultStream){
    211252                resultStream = _resultStream;
    212253        }
     254       
    213255        public void setSourceStream(InputStream _sourceStream){
    214256                sourceStream = _sourceStream;
     
    217259         
    218260        /**
    219          * Get the sourceStream from the target proxy   
     261         * Get the sourceStream from the target proxy.   
    220262         * @return
    221263         * @throws IOException
    222264         * @throws NoStylesheetException
    223265         */
    224                 public InputStream getSourceStream() throws IOException, NoStylesheetException {               
     266        public InputStream getSourceStream() throws IOException, NoStylesheetException {               
    225267                        return getTargetProxy().getSourceStream();
    226                 }
    227                
     268        }
     269               
     270        /**
     271         * Add parameter into local parameter map.
     272         *
     273         * @param key - parameter key
     274         * @param value - parameter value
     275         */
     276        public void addParam(String key, String value){
     277                String[] sarr = new String[1];
     278                sarr[0] = value;
     279                params.put(key, sarr); 
     280        }
    228281        /**
    229282         * Reads in all the parameters of the request into an internal structure.
     
    233286         * This shall allow more flexibility in using the parameters in the subclasses (and less getter/setter stuff)
    234287         * at the cost of circumventing the Struts-way.
    235          */
    236         public void addParam(String key, String value){
    237                         String[] sarr = new String[1];
    238                         sarr[0] = value;
    239                         params.put(key, sarr); 
    240         }
    241        
    242         /*
    243          * sru params
    244          *  /*
     288         *
     289         *
     290         * The params are completed to fulfill sru params standard an also the params needed by XSL transformation
     291         * are added.
     292         *
     293         *  SRU PARAMS:
    245294     * version
    246295     * operation
     
    338387        }
    339388       
     389        /**
     390         * Gets the local parameter map.
     391         *
     392         * @return
     393         */
    340394        public Map<String,String[]> getParams() {               
    341395                return params;
     
    364418        /**
    365419         * Constructs an unambiguous key for the request (encoding all the parameters).
    366          * This is used as identifier for caching
     420         * This is used as identifier for caching .
     421         *
    367422         * @return key unambiguously encoding the request
    368423         */
     
    411466       
    412467         
     468        /**
     469         * Adds the duration value of the action execution to the request key.
     470         *
     471         * @return
     472         */
    413473        public String addDurationKey(){
    414474                String req_key = getRequestKey();
     
    423483       
    424484       
    425         /**
    426          * This is the work-horse function.
    427          * It does two things:
    428          * a) check if the source data is already in cache (based on cache-key that is constructed from the request parameters)
    429          * b) if format-parameter provided, invokes the transformation.
    430          * at the end the data to be returned as result is contained in the resultStream
    431          * If format is xml, then the data from sourceStream is passed further as resultStream.
    432          *   
    433          * @throws Exception  This is handled by struts (is mapped to some result in struts.xml based on the Exception-Class)
    434          */
    435485        public String getTargetRequestParams(){
    436486                return "";
     
    441491        }
    442492
     493        /**
     494         * This is the work-horse function.
     495         * It does more things:
     496         * a) Loads the request parameters.
     497         * b) Creates the concerned proxy object.
     498         * c) Checks if the source data is already in cache (based on cache-key that is constructed from the request parameters).
     499         * d) If diagnostics occurred  during function, the diagnostics data will be  added into source data.
     500         * e) If format-parameter provided, invokes the transformation.
     501         * 
     502         *
     503         * At the end the data to be returned as result is contained in the resultStream
     504         * If format is xml, then the data from sourceStream is passed further as resultStream.
     505         *
     506         * If exception occurred within prepare function , it will be caught and written
     507         * as diagnostics system error.
     508         *   
     509         */
    443510        public void prepare()  {
    444511                       
    445512                try{
    446513                        loadParams();
     514                       
    447515                        setTargetProxy();
     516                        if (getTargetProxy() == null) return;                   
    448517                        getTargetProxy().checkParams();
     518                       
     519                        // Do not continue if something is fatal.
     520                        if (getDiagnostics().Exists()) return;
    449521                       
    450522                        String req_key = getRequestKey();
     
    453525                        log.debug(getActionkey() + ".targetURL: " + getTargetProxy().getTargetRequest() + " .format:" + getFullFormat());
    454526                       
    455                         // Caching
    456                         String xcid;
     527                        //Caching
    457528               
    458529                        if (getCache().equals(Cache.SKIP)) {
     
    465536                                }
    466537                                if (sourceStream == null) { // either not in cache or cache_flag=refresh
    467                                         //sourceStream = getTargetRequest().openStream();
    468538                                        long startMillis = System.currentTimeMillis();
    469539                                        sourceStream = getSourceStream();
    470540                                        duration = System.currentTimeMillis() - startMillis;
    471541                                        req_key = addDurationKey();
    472                                        
    473                                         long now = System.currentTimeMillis();
    474                                         xcid = Cache.getCache().putInCache(req_key,sourceStream);                       
    475                                         //Admin.notifyUser("putting in cache: " + req_key);                     
     542                                        String xcid = Cache.getCache().putInCache(req_key,sourceStream);                       
     543                                        log.debug("putting in cache: " + req_key + ", " + xcid);                       
    476544                                        sourceStream = Cache.getCache().getFromCache(req_key);
    477                                 } /* else {
    478                                         Admin.notifyUser("reading from cache: " + req_key);
    479                                 } */
    480                         }
    481                        
    482                         // add diagnostics non fatal
     545                                } else {
     546                                        log.debug("reading from cache: " + req_key);
     547                                }
     548                        }
     549                       
     550                        // append diagnostics to sourcestream
    483551                        if (getDiagnostics().Exists()){
    484                                 Document doc ;
    485                                 Node r_element;
    486                                 // fatal error
    487                                 //TODO getDiagnostics().Exists("fatal");
    488                                 if (sourceStream == null){
    489                                         //TODO rootelemname ???
    490                                         doc = Helpers.createDocument("rootelemname");
    491                                         r_element = doc.getFirstChild();
    492                                 } else {
    493                                         doc = Helpers.getDocument(sourceStream);
    494                                         //TODO tagname by class
    495                                         r_element=  doc.getElementsByTagName("searchRetrieveResponse").item(0);
    496                                 }
     552                                if (sourceStream == null) return;
    497553                               
    498                                 Document ddoc = getDiagnostics().buildXMLDocument();
    499                                 Node d_element=  ddoc.getElementsByTagName("diagnostics").item(0);
    500                                 doc.adoptNode(d_element);
    501                                 r_element.appendChild(d_element);
    502                                 DOMSource source = new DOMSource(doc);   
    503                                 StringWriter xmlAsWriter = new StringWriter();   
    504                                 StreamResult result = new StreamResult(xmlAsWriter);   
    505                                 TransformerFactory.newInstance().newTransformer().transform(source, result);
    506                                 this.setSourceStream(new ByteArrayInputStream(xmlAsWriter.toString().getBytes("UTF-8")));
     554                                Document doc = Utils.stream2Document(sourceStream);
     555                                //TODO tagname by class
     556                                doc = Utils.append2Document(doc, "searchRetrieveResponse",  getDiagnostics().buildXMLDocument());
     557                                this.setSourceStream(Utils.document2Stream(doc));
    507558                        }
    508559                       
     
    515566                                // TODO: WHY??
    516567                                transformer.setSrcFile(getTargetProxy().getTargetRequest());
    517                                 //transformer.setParams(createTransformerParams());
    518568                                transformer.setParams(getParams());
    519569                                // here the transformation is invoked
     
    522572
    523573                }catch (Exception e){
     574                        log.error(Utils.errorMessage(e));
    524575                        //TODO add exception to diagnostic ?
     576                        getDiagnostics().Add(Diagnostic.SYSTEM_ERROR, Utils.errorMessage(e));
    525577                        return;
    526578                }
     
    530582
    531583        /**
    532          * default Action method that gets called by Struts. Everything interesting happens in prepare()
     584         *  Default Action method that gets called by Struts. Everything interesting happens in prepare()
     585         *  In case an error occurred in prepare and the result stream is not returned, the diagnostics will be returned
     586         *  as result.
     587         * 
     588         *  @throws Exception  This is handled by struts (is mapped to some result in struts.xml based on the Exception-Class).
    533589         */
    534590        public String execute() throws Exception {
    535 //              HttpServletRequest request = ServletActionContext.getRequest();
    536                 //Admin.notifyUser("session-attrs:");
    537         //Admin.notifyUser(getServletRequest().getRemoteUser() );
    538         //Admin.notifyUser(String.valueOf(getSession()));
    539        
    540         long now = System.currentTimeMillis();
    541 
    542                 prepare();
    543                 long duration = (System.currentTimeMillis() - now);
    544                 //duration
    545 
     591               
     592        prepare();
     593               
    546594                if (resultStream == null) {
     595                        // diagnostics to resultstream
    547596                        if (getDiagnostics().Exists()){
    548                                 Document doc ;
    549                                 Node r_element;
    550                                 // fatal error
    551                                 //TODO getDiagnostics().Exists("fatal");
    552                                 doc = Helpers.createDocument("Error");
    553                                 r_element = doc.getFirstChild();
    554                                
    555                                 Document ddoc = getDiagnostics().buildXMLDocument();
    556                                 Node d_element=  ddoc.getElementsByTagName("diagnostics").item(0);
    557                                 doc.adoptNode(d_element);
    558                                 r_element.appendChild(d_element);
    559                                 DOMSource source = new DOMSource(doc);   
    560                                 StringWriter xmlAsWriter = new StringWriter();   
    561                                 StreamResult result = new StreamResult(xmlAsWriter);   
    562                                 TransformerFactory.newInstance().newTransformer().transform(source, result);
    563                                 this.setResultStream(new ByteArrayInputStream(xmlAsWriter.toString().getBytes("UTF-8")));
    564 
     597                                this.setResultStream( Utils.document2Stream(getDiagnostics().buildXMLDocument()));
     598                                return SUCCESS;
    565599                        }
    566600                        return ERROR;   
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/GenericProxyAction.java

    r1532 r1540  
    1212import org.apache.struts2.interceptor.ServletRequestAware;
    1313
    14 import eu.clarin.cmdi.mdservice.internal.Admin;
     14import eu.clarin.cmdi.mdservice.internal.Utils;
    1515import eu.clarin.cmdi.mdservice.internal.Cache;
    1616import eu.clarin.cmdi.mdservice.internal.MDTransformer;
     
    303303         */
    304304        public String getBaseURI() {           
    305                 String uri =Admin.getConfig().getProperty(getProxyKey() + ".uri");             
     305                String uri =Utils.getConfig().getProperty(getProxyKey() + ".uri");             
    306306                return uri;
    307307        }
     
    314314        public URL getBaseURL() throws MalformedURLException {         
    315315                if (base_url == null) {
    316                         base_url = new URL(getBaseURI());//Admin.getConfig().getProperty(getProxyKey() + ".uri"));
     316                        base_url = new URL(getBaseURI());//Utils.getConfig().getProperty(getProxyKey() + ".uri"));
    317317                }
    318318                return base_url;
     
    453453                try{
    454454                        String req_key = getRequestKey();
    455                         Admin.notifyUser("request_key: " +  req_key);
    456                         Admin.notifyUser(getProxyKey() + ".targetURL: " + getTargetRequest() + " .format:" + getFullFormat());
     455                        //log.debug("request_key: " +  req_key);
     456                        //log.debug(getProxyKey() + ".targetURL: " + getTargetRequest() + " .format:" + getFullFormat());
    457457                       
    458458                        // Caching
    459459                        String xcid;
    460460               
    461                         // Admin.notifyUser("GPA.prepareSourceStream");
     461                        // log.debug("GPA.prepareSourceStream");
    462462                       
    463463                        if (getCache().equals(Cache.SKIP)) {
     
    478478                                        long now = System.currentTimeMillis();
    479479                                        xcid = Cache.getCache().putInCache(req_key,sourceStream);                       
    480                                         //Admin.notifyUser("putting in cache: " + req_key);                     
     480                                        //log.debug("putting in cache: " + req_key);                   
    481481                                        sourceStream = Cache.getCache().getFromCache(req_key);
    482482                                } /* else {
    483                                         Admin.notifyUser("reading from cache: " + req_key);
     483                                        log.debug("reading from cache: " + req_key);
    484484                                } */
    485485                        }
     
    511511
    512512               
    513                 //Admin.notifyUser("session-attrs:");
    514         //Admin.notifyUser(getServletRequest().getRemoteUser() );
    515         //Admin.notifyUser(String.valueOf(getSession()));
     513                //log.debug("session-attrs:");
     514        //log.debug(getServletRequest().getRemoteUser() );
     515        //log.debug(String.valueOf(getSession()));
    516516       
    517517        long now = System.currentTimeMillis();
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/RepoAction.java

    r1532 r1540  
    11package eu.clarin.cmdi.mdservice.action;
    22
    3 import java.io.BufferedInputStream;
    4 import java.io.BufferedReader;
    5 import java.io.File;
    6 import java.io.FileInputStream;
    7 import java.io.IOException;
    8 import java.io.InputStream;
    9 import java.io.InputStreamReader;
    10 import java.net.MalformedURLException;
    11 import java.net.URISyntaxException;
    123import java.net.URL;
    13 import java.util.Arrays;
    14 import java.util.Collections;
    15 import java.util.HashMap;
    16 import java.util.Iterator;
    17 import java.util.Map;
    18 import java.util.Set;
    19 import java.util.Map.Entry;
    20 
    21 import javax.servlet.http.HttpServletRequest;
    22 import javax.servlet.http.HttpSession;
    23 import javax.xml.transform.TransformerException;
    24 
    25 import net.sf.json.JSON;
    26 import net.sf.json.JSONArray;
    27 import net.sf.json.JSONObject;
    28 import net.sf.json.JSONSerializer;
    29 //import net.sf.saxon.Controller;
    30 //import net.sf.saxon.event.MessageEmitter;
    31 
    324
    335import org.apache.log4j.Logger;
    34 import org.apache.struts2.interceptor.ServletRequestAware;
    35 import com.opensymphony.xwork2.ActionSupport;
    36 
    37 import eu.clarin.cmdi.mdservice.internal.Cache;
    38 import eu.clarin.cmdi.mdservice.internal.NoStylesheetException;
    396import eu.clarin.cmdi.mdservice.model.Diagnostic;
    40 import eu.clarin.cmdi.mdservice.model.Diagnostics;
    417import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
    428import eu.clarin.cmdi.mdservice.proxy.MDRepoProxy;
     
    4511
    4612/**
    47  * a Struts2 controller, responsible for calls to repositories.
     13 * A Struts2 controller, responsible for calls to repositories.
    4814 * After 2011-09 rework Action and Proxy are decoupled.
    4915 * So Action calls appropriate Proxy based upon the target repository type
     
    5723 */
    5824public class RepoAction extends GenericAction
    59 //implements ServletRequestAware
    6025{
    6126
     
    6328        private static Logger log = Logger.getLogger("RepoAction");
    6429       
    65         /**
    66          * Properties to be filled by Struts with according request-parameters
    67          */     
    68         private String actionkey;
    69        
    70         private String squery; 
    71         private String collection;
    72         private String columns;
    73         private String startItem;
    74         private String maximumItems;
    75         private String sort;   
    76         private int maxdepth;   
    77         //private String format="xml"; // default no transformation
    78         private String options;
    79 
    80         //private Map<String,Object> session;
    8130        protected URL base_url ;
    8231
     
    8938         * If the type is not recognized - that is a bad user error   
    9039         */
    91                 public void setTargetProxy(){
     40        public void setTargetProxy(){
    9241                                               
    9342                        if (getRepository()==null) {
     
    11362                            default:
    11463                                //TODO error  = bad workspaceProfile configuration
    115                                 getDiagnostics().Add(Diagnostic.SYSTEM_ERROR, "error in workspaceprofile configuration", "repository=" + getRepository() );
     64                                getDiagnostics().Add(Diagnostic.SYSTEM_ERROR, "Error in workspaceprofile configuration", "repository=" + getRepository() );
    11665                        }
    11766                       
    118                 }
    119         /*
    120         public String getSquery() {
    121                 return squery;
    122         }
    123 
    124         public void setSquery(String psquery) {
    125                 if (psquery==null) psquery="";
    126                 this.squery = psquery;
    127         }
    128        
    129         public String getCollection() {
    130                 return collection;
    131         }
    132 
    133         public void setCollection(String collection) {
    134                 this.collection = collection;
    135         }
    136        
    137         //TODO defaults
    138         public String getColumns() {
    139                 String cols = columns;
    140                 return cols;
    141         }
    142 
    143         public void setColumns(String columns) {
    144                 this.columns = columns;
    145         }
    146        
    147         public int getMaxdepth() {
    148                 return maxdepth;
    149         }
    150 
    151         public void setMaxdepth(int maxdepth) {
    152                 this.maxdepth = maxdepth;
    153         }
    154 /*
    155         public String getFormat() {
    156                 return format;
    157         }
    158 
    159         public void setFormat(String format) {
    160                 this.format = format;
    161         }
    162 
    163         public String getOptions() {
    164                 return options;
    165         }
    166 
    167         public void setOptions(String options) {
    168                 this.options = options;
    169         }
    170 
    171        
    172         public String getActionkey() {
    173                 return actionkey;
    174         }
    175 
    176         public void setActionkey(String actionKey) {
    177                 actionkey = actionKey;
    178         }
    179 
    180        
    181         public String getStartItem() {
    182                 return startItem;
    183         }
    184 
    185         public void setStartItem(String startItem) {
    186                 this.startItem = startItem;
    187         }
    188 
    189         public String getMaximumItems() {
    190                 return maximumItems;
    191         }
    192 
    193         public void setMaximumItems(String maximumItems) {
    194                 this.maximumItems = maximumItems;
    19567        }
    19668       
    19769
    198         public String getSort() {
    199                 return sort;
    200         }
    201 
    202         public void setSort(String sort) {
    203                 this.sort = sort;
    204         }
    205 */
    206 
    20770        /**
    208          * internal identification of the target-proxy
     71         * Internal identification of the target-proxy
    20972         * base for finding the right base_url in the properties
    210          * subclass has to override with its specific proxykey
     73         * subclass has to override with its specific proxykey.
     74         *
    21175         * @return the key identifying this type of proxy
    21276         */
    21377        public String getProxyKey() {
    21478                return "";
    215         }
    216                
    217         /**
    218          * Constructs an unambiguous key for the request (encoding all the parameters).
    219          * This is used as identifier for caching
    220          * @return key unambiguously encoding the request
    221          */
    222         /*
    223          public String getRequestKey() {
    224                         String key="";
    225                         if (getActionkey()!=null) {
    226                                 key += getActionkey() + "//-" ;
    227                         }else {
    228                                 key +="//-" ;
    229                         }
    230                         if (getQ()!=null) {
    231                                 key += getQ() + "//-" ;
    232                         } else {
    233                                 key +="//-" ;
    234                         }
    235                         if (getCollection()!=null) {
    236                                 key += getCollection() + "//-";
    237                         } else {
    238                                 key +="//-" ;
    239                         }
    240                         if (getSquery()!=null) {
    241                                 key += getSquery() + "//-" ;
    242                         } else {
    243                                 key +="//-" ;
    244                         }
    245                         if (getStartItem()!=null) {
    246                                 key += getStartItem() + "//-";
    247                         }
    248                                 else{
    249                                         key +="//-" ;
    250                         }
    251                         if (getMaximumItems()!=null) {
    252                                 key += getMaximumItems() + "//-";
    253                         }
    254                         else{
    255                                 key +="//-" ;
    256                         }
    257                        
    258                         key += getRepository()  + "//-";
    259                         key += getMaxdepth()  + "//-";
    260                        
    261                         if (getLang()!=null) {
    262                                 key += getLang() + "//-";
    263                         }else{
    264                                 key +="//-" ;
    265                         }                       
    266                          
    267                 return key;
    268         }
    269          */
    270         /*     
    271          @Override
    272         public Map<String,String> createTransformerParams(){
    273                
    274                 Map<String, String> map = new HashMap<String, String>();
    275 
    276                 Set<Entry<String, String[]>> set = getParams().entrySet();
    277                 Iterator<Entry<String, String[]>> i = set.iterator();
    278 
    279             while(i.hasNext()){
    280               Map.Entry<String,String[]> e = (Map.Entry<String,String[]>)i.next();
    281               if (xsl_map.containsKey((String)e.getKey())) {
    282                   map.put(xsl_map.get((String)e.getKey()), (String)e.getValue()[0]);
    283               }
    284              
    285             }
    286             return map;
    287             */
    288             /*
    289                 HashMap<String,String> hm = new HashMap<String,String>();
    290                
    291             if (getFullFormat() != null){
    292                         hm.put("format", getFullFormat());
    293             }
    294                 if (getColumns() != null){
    295                         hm.put("cols", getColumns());
    296                 } else {
    297                         hm.put("cols", "");
    298                 }
    299                 if (getStartItem() != null){
    300                         hm.put("startItem", getStartItem());
    301                 }
    302                 if (getMaximumItems() != null){
    303                         hm.put("maximumItems", getMaximumItems());     
    304                 }
    305                 if (getLang() != null){
    306                         hm.put("lang", getLang());
    307                 }
    308                 if (getQ() != null){
    309                         hm.put("q", getQ());
    310                 }
    311                 //if (getRepository() != null){
    312                 hm.put("repository_name", String.valueOf(getRepository()));
    313                 hm.put("repository_type", WorkspaceProfile.getRepositoryType(this.getRepository()));
    314                 //}
    315        
    316                 return hm;
    317         }
    318                 */
    319        
    320        
     79        }       
    32180
    32281}
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/SRUAction.java

    r1524 r1540  
    99import java.io.UnsupportedEncodingException;
    1010import java.util.HashMap;
    11 import java.util.Iterator;
    12 import java.util.Map;
    13 import java.util.Set;
    14 
    15 import javax.xml.parsers.DocumentBuilder;
    16 import javax.xml.parsers.DocumentBuilderFactory;
    1711import javax.xml.parsers.ParserConfigurationException;
    1812import javax.xml.transform.TransformerConfigurationException;
     
    2519import org.w3c.dom.Document;
    2620import org.w3c.dom.Node;
    27 import org.xml.sax.InputSource;
    28 import org.xml.sax.SAXException;
    2921
    3022import eu.clarin.cmdi.mdservice.internal.Cache;
    31 import eu.clarin.cmdi.mdservice.internal.Helpers;
     23import eu.clarin.cmdi.mdservice.internal.Utils;
    3224
    3325
     
    230222        */
    231223        public String getDiagnosticStreamName() throws TransformerConfigurationException, UnsupportedEncodingException, ParserConfigurationException, TransformerException, TransformerFactoryConfigurationError{
    232                 this.setResultStream(getDiagnostics().buildXMLStream());
     224                this.setResultStream(Utils.document2Stream(getDiagnostics().buildXMLDocument()));//getDiagnostics().buildXMLStream());
    233225                return "resultStream";
    234226        }
     
    246238        @Override
    247239        public String getBaseURI() {           
    248                 Admin.notifyUser("SRU-repositorypath:" + WorkspaceProfile.getRepositoryPath(getRepository()));
    249                 String uri = WorkspaceProfile.getRepositoryPath(getRepository());//Admin.getConfig().getProperty(getProxyKey() + ".uri");               
     240                log.debug("SRU-repositorypath:" + WorkspaceProfile.getRepositoryPath(getRepository()));
     241                String uri = WorkspaceProfile.getRepositoryPath(getRepository());//Utils.getConfig().getProperty(getProxyKey() + ".uri");               
    250242                return uri;
    251243        }
     
    302294                } else {
    303295                        if (operation.equals("explain") || operation == null){
    304                                 Admin.notifyUser("explaining", "debug");
     296                                log.debug("explaining", "debug");
    305297                        }else {
    306298                                if (operation.equals("scan")){
     
    426418                // add diagnostics
    427419                if (getDiagnostics().Exists()){
    428                         Document doc = Helpers.getDocument(this.getResultStream());
     420                        Document doc = Utils.stream2Document(getResultStream());
    429421                        Node r_element=  doc.getElementsByTagName("searchRetrieveResponse").item(0);
    430422                        Document ddoc = getDiagnostics().buildXMLDocument();
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/TermsProxyAction.java

    r1524 r1540  
    88import javax.xml.transform.TransformerException;
    99
    10 import eu.clarin.cmdi.mdservice.internal.Admin;
     10import org.apache.log4j.Logger;
     11
     12import eu.clarin.cmdi.mdservice.internal.Utils;
    1113import eu.clarin.cmdi.mdservice.internal.MDTransformer;
    1214import eu.clarin.cmdi.mdservice.internal.NoStylesheetException;
     
    2325public class TermsProxyAction extends GenericProxyAction {
    2426
     27        public static Logger log = Logger.getLogger("TermsProxyAction");
     28       
    2529        private static final long serialVersionUID = 1L;
    2630
     
    115119                URL targetURL = null;
    116120                //targetURL = new URL(getBaseURI() + getQ());
    117                 Admin.notifyUser("TPA.q: " + getBaseURI() + getQ() + getRepository());
     121                log.debug("TPA.q: " + getBaseURI() + getQ() + getRepository());
    118122                // FIXME: this looks like an ugly hack!
    119123                //if (getMaxdepth()==0)  setMaxdepth(1);
     
    126130        public InputStream getSourceStream() throws IOException, NoStylesheetException{
    127131                String type = getTSAttr("type");
    128                 Admin.notifyUser("TPA.getSourceStream.TStype: " + type);
     132                log.debug("TPA.getSourceStream.TStype: " + type);
    129133                if (type.equals("dcr") | type.equals("rr")) {   
    130134                        // if dcr|rr call model/matrix/all: http://localhost:8080/MDService2/model/matrix/?q=all
     
    132136                        URL matrix_all_URL = new URL(getBaseURI() + ALL + "&repository="+ getRepository());
    133137                        //URL matrix_all_URL = new URL(getBaseURI() + ALL );
    134                         Admin.notifyUser("TPA.getSourceStream: " + getBaseURI() + ALL);
     138                        log.debug("TPA.getSourceStream: " + getBaseURI() + ALL);
    135139                        InputStream stream_matrix_all = matrix_all_URL.openStream();
    136140                        InputStream resultStream=null;
     
    143147                                //transformer.getParams().put("format","terms2extract");
    144148                               
    145                                 Admin.notifyUser("TPA.getSourceStream.transformer.effectiveTranskey: " + transformer.getTranskey() + ", for Termset:" + getTSAttr("name") + '#' + getTSAttr("id"));
     149                                log.debug("TPA.getSourceStream.transformer.effectiveTranskey: " + transformer.getTranskey() + ", for Termset:" + getTSAttr("name") + '#' + getTSAttr("id"));
    146150                                resultStream = transformer.transformXML(stream_matrix_all);//, "terms2extract", getColumns(), getStartRecord(), getMaximumRecords(),getLang(),getQ(), getRepositoryPath());
    147151                                                               
    148152                        } catch (InterruptedException e) {                             
    149                                 Admin.notifyUser("TPA.getSourceStream(): "+ e.getMessage());
     153                                log.debug("TPA.getSourceStream(): "+ e.getMessage());
    150154                        } catch (TransformerException e) {                             
    151                                 Admin.notifyUser("TPA.getSourceStream(): "+ e.getMessage());
     155                                log.debug("TPA.getSourceStream(): "+ e.getMessage());
    152156                        }                       
    153157                        return resultStream;
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/VirtualCollectionProxyAction.java

    r1530 r1540  
    88import java.net.URL;
    99import java.net.URLConnection;
    10 import java.util.HashMap;
    11 
    1210import org.w3c.dom.NodeList;
    1311
    14 import eu.clarin.cmdi.mdservice.internal.Admin;
     12import eu.clarin.cmdi.mdservice.internal.Utils;
    1513import eu.clarin.cmdi.mdservice.internal.Cache;
    16 import eu.clarin.cmdi.mdservice.internal.Helpers;
    1714import eu.clarin.cmdi.mdservice.internal.MDTransformer;
     15import eu.clarin.cmdi.mdservice.internal.Utils;
    1816
    1917/**
     
    7977                // find the workspace data
    8078                NodeList list = (NodeList) getWorkspaceData();
    81         InputStream is = Helpers.DocumentToStream(list.item(0));
     79        InputStream is = Utils.document2Stream(list.item(0));
    8280                //xslt transform to request data
    8381                MDTransformer transformer = new MDTransformer();
     
    10098                // find out
    10199                //"http://clarin.ids-mannheim.de/vcr/service/virtualcollection";
    102                 String urlstring = Admin.getConfig().getProperty("virtualcollection.uri");
     100                String urlstring = Utils.getConfig().getProperty("virtualcollection.uri");
    103101                String vcrstr = (String)getVcrid();//getQueryVcrid();
    104102                if (!vcrstr.equals("0")){
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/WorkspaceAction.java

    r1532 r1540  
    33import java.io.BufferedInputStream;
    44import java.io.ByteArrayInputStream;
    5 import java.io.ByteArrayOutputStream;
    65import java.io.File;
    76import java.io.FileInputStream;
     
    2120import javax.xml.parsers.ParserConfigurationException;
    2221import javax.xml.transform.OutputKeys;
    23 import javax.xml.transform.Result;
    24 import javax.xml.transform.Source;
    2522import javax.xml.transform.Transformer;
    2623import javax.xml.transform.TransformerConfigurationException;
     
    4946import org.xml.sax.SAXException;
    5047
    51 import eu.clarin.cmdi.mdservice.internal.Admin;
    52 import eu.clarin.cmdi.mdservice.internal.Helpers;
     48import eu.clarin.cmdi.mdservice.internal.Utils;
    5349import eu.clarin.cmdi.mdservice.internal.MDTransformer;
    5450import eu.clarin.cmdi.mdservice.model.Diagnostic;
     
    164160        public WorkspaceAction () {     
    165161                this.elementtype = WorkspaceAction.SE_WORKSPACE;
    166                 workspacefilename = Admin.getConfig().getProperty("workspaceprofile.path") + Admin.getConfig().getProperty("workspace.file");
     162                workspacefilename = Utils.getConfig().getProperty("workspaceprofile.path") + Utils.getConfig().getProperty("workspace.file");
    167163                if (workspace_doc == null){
    168                         //workspacefilename = Admin.getConfig().getProperty("workspace.path") + Admin.getConfig().getProperty("workspace.file");
     164                        //workspacefilename = Utils.getConfig().getProperty("workspace.path") + Utils.getConfig().getProperty("workspace.file");
    169165                        initDocument();
    170166                }
     
    228224        public String getBasePath() {           
    229225                if (base_path == null) {
    230                         base_path = Admin.getConfig().getProperty(getProxyKey() + ".path");
     226                        base_path = Utils.getConfig().getProperty(getProxyKey() + ".path");
    231227                }
    232228                return base_path;
     
    248244                        File f = new File(getBasePath() + profilename);
    249245                        if (! f.exists()){
    250                                 //Admin.notifyUser(" not exists");
     246                                //log.debug(" not exists");
    251247                                profilename = "WorkspaceProfile_default.xml";
    252248                        }
     
    260256                if (profilename == null){
    261257                        profilename = PROFILENAME_DEFAULT;
    262                         Admin.notifyUser("WorkspaceProfilePath not specified (USER, SERVER)!");
    263                 }
    264                
    265                 Admin.notifyUser("WorkspaceProfilename : " + profilename);
     258                        log.debug("WorkspaceProfilePath not specified (USER, SERVER)!");
     259                }
     260               
     261                log.debug("WorkspaceProfilename : " + profilename);
    266262                return profilename;
    267263        }
     
    277273            try{
    278274                    url=file.toURI().toURL();
    279                     //Admin.notifyUser("url "  + url);
     275                    //log.debug("url "  + url);
    280276            } catch (MalformedURLException e){
    281                 //Admin.notifyUser("" + e);
     277                //log.debug("" + e);
    282278            }
    283279                return url;
     
    308304        }
    309305       
    310         /*
    311         @Override
    312         public void prepare() throws Exception {               
    313                
    314                 //Admin.notifyUser("execute:");
    315                 InputStream in = getSourceStream();
    316                 this.setSourceStream(in);
    317                 if (getFormat().equals("xml")) {                       
    318                         setResultStream(in);   
    319                 }else { //JSON
    320                         // set srcFile (for MDTransformer to pass to xsl-scripts)
    321                         MDTransformer transformer = new MDTransformer();
    322                         transformer.setSrcFile(getURL());
    323                         transformer.setParams(MDTransformer.createParamsMap(getFullFormat()));
    324                         setResultStream(transformer.transformXML(in));//, getFullFormat()));
    325                         //setSessionData(getResultStream());
    326                 }
    327                        
    328                 Admin.notifyUser(getProxyKey() + " success:" + (getResultStream()!=null));
    329         }
    330 
    331         public void changeNodeName(Document doc, Node node, String new_name){
    332                 // Create an element with the new name
    333                 Node node2 = (Node ) doc.createElement(new_name);
    334                 // Copy the attributes to the new element NamedNodeMap attrs = element.getAttributes(); for (int i=0; i<attrs.getLength(); i++) { Attr attr2 = (Attr)doc.importNode(attrs.item(i), true); element2.getAttributes().setNamedItem(attr2); }
    335                 // Move all the children
    336                 while (node.hasChildNodes()) { node2.appendChild(node.getFirstChild()); }
    337                 // Replace the old node with the new node
    338                 Admin.notifyUser("replace:" + node2.getNodeName() + "," + node.getNodeName());
    339                 node.getParentNode().replaceChild(node2, node);
    340         }
    341 
    342         public void administrateQid() throws IOException, SAXException, ParserConfigurationException, TransformerException{
    343                 WorkspaceAction wa = new WorkspaceAction();
    344                 wa.setType("Admin");
    345                
    346                 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    347         DocumentBuilder builder;
    348 
    349                 builder = factory.newDocumentBuilder();
    350                 Document  document = builder.parse(wa.getSourceStream());
    351                 // find user-filename-id or create one
    352                 //add qid
    353                 //NodeList list = document.getElementsByTagName("e");
    354                 //Admin.notifyUser("list:" + list.getLength());
    355 
    356                 // save the changes
    357                 Transformer transformer;
    358                 transformer = TransformerFactory.newInstance().newTransformer();
    359                 transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    360                 StreamResult result = new StreamResult(new StringWriter());
    361                 DOMSource source = new DOMSource(document);
    362                 transformer.transform(source, result);
    363                 String xmlString = result.getWriter().toString();
    364                 InputStream is_xml = new ByteArrayInputStream( xmlString.getBytes( ) );
    365                 Admin.writeToFile(wa.getPath(), is_xml);
    366                 //wa.save();
    367         }
    368        
    369         public String save() throws IOException, SAXException, ParserConfigurationException, TransformerException {
    370                
    371         String jsonData = getData();
    372              
    373         Admin.notifyUser("JSON data:"+jsonData);
    374         if ((!this.getType().equals(ADMIN)) && this.getQid() != null) {
    375                         administrateQid();
    376                 }
    377        
    378         XMLSerializer serializer = new XMLSerializer();
    379                 JSON json = JSONSerializer.toJSON( jsonData );
    380                 if (this.getType().equals(ADMIN)){
    381                         serializer.setRootName("Admin");
    382                 } else {
    383                         serializer.setRootName("WorkspaceProfile");     
    384                 }
    385                 serializer.setElementName("item");
    386         serializer.setTypeHintsEnabled(false);
    387         String xml = serializer.write( json );
    388         Admin.notifyUser("XML:" + xml);
    389        
    390         InputStream is_xml = new ByteArrayInputStream( xml.getBytes( ) );
    391        
    392         Admin.writeToFile(getPath(), is_xml);
    393    
    394         String ret = "1";
    395                 this.setResultStream( new ByteArrayInputStream(ret.getBytes()));
    396                                
    397 
    398                 return SUCCESS;
    399         }
    400 */
     306       
    401307        public void changeQueryId(Document doc, String from_id, String to_id) throws XPathExpressionException{
    402308                InputStream is = null;
     
    692598        serializer.setTypeHintsEnabled(false);
    693599        String xml = serializer.write( json );
    694         //Admin.notifyUser("XML:" + xml);
     600        //log.debug("XML:" + xml);
    695601        InputStream is_xml = new ByteArrayInputStream( xml.getBytes( ) );
    696602        // add to document
    697         //Admin.writeToFile(getPath(), is_xml);
     603        //Utils.writeToFile(getPath(), is_xml);
    698604        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    699605        DocumentBuilder builder = factory.newDocumentBuilder();
     
    970876                }
    971877                // nodelistto stream
    972                 InputStream is = Helpers.DocumentToStream(list.item(0));
     878                InputStream is = Utils.document2Stream(list.item(0));
    973879                this.setSourceStream(is);     
    974880               
     
    1022928                                        this.saveDocument();
    1023929                                       
    1024                                         //Admin.notifyUser("new document");
     930                                        //log.debug("new document");
    1025931                                } catch (ParserConfigurationException e) {
    1026932                                        // TODO Auto-generated catch block
     
    1051957                         init = true;
    1052958                    }  catch (IOException ex){
    1053                         //Admin.notifyUser("initCacheCounter:" + ex.toString());
     959                        //log.debug("initCacheCounter:" + ex.toString());
    1054960                        ex.printStackTrace();
    1055961                    }
     
    1070976                //workspace_doc.getFirstChild().getAttributes().getNamedItem("idcounter").setNodeValue(i.toString());
    1071977               
    1072                 //Admin.notifyUser("writeCacheCounter:" + i.toString());
     978                //log.debug("writeCacheCounter:" + i.toString());
    1073979                // write xml
    1074980                Transformer transformer;
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/WorkspaceRepositoryAction.java

    r1530 r1540  
    11package eu.clarin.cmdi.mdservice.action;
    22
    3 import java.io.BufferedInputStream;
    4 import java.io.ByteArrayInputStream;
    5 import java.io.ByteArrayOutputStream;
    6 import java.io.File;
    7 import java.io.FileInputStream;
    8 import java.io.FileWriter;
    9 import java.io.IOException;
    10 import java.io.InputStream;
    11 import java.io.StringWriter;
    12 import java.io.UnsupportedEncodingException;
    13 import java.net.MalformedURLException;
    14 import java.net.URL;
    15 import java.text.DateFormat;
    16 import java.text.SimpleDateFormat;
    17 import java.util.Date;
    18 import java.util.HashMap;
    19 
    20 import javax.xml.parsers.DocumentBuilder;
    21 import javax.xml.parsers.DocumentBuilderFactory;
    22 import javax.xml.parsers.ParserConfigurationException;
    23 import javax.xml.transform.OutputKeys;
    24 import javax.xml.transform.Result;
    25 import javax.xml.transform.Source;
    26 import javax.xml.transform.Transformer;
    27 import javax.xml.transform.TransformerConfigurationException;
    28 import javax.xml.transform.TransformerException;
    29 import javax.xml.transform.TransformerFactory;
    30 import javax.xml.transform.TransformerFactoryConfigurationError;
    31 import javax.xml.transform.dom.DOMSource;
    32 import javax.xml.transform.stream.StreamResult;
    33 import javax.xml.xpath.XPath;
    34 import javax.xml.xpath.XPathConstants;
    35 import javax.xml.xpath.XPathExpression;
    36 import javax.xml.xpath.XPathExpressionException;
    37 import javax.xml.xpath.XPathFactory;
    38 
    39 import net.sf.json.JSON;
    40 import net.sf.json.JSONObject;
    41 import net.sf.json.JSONSerializer;
    42 import net.sf.json.xml.XMLSerializer;
    43 
    443import org.apache.log4j.Logger;
    45 import org.w3c.dom.DOMException;
    46 import org.w3c.dom.Document;
    47 import org.w3c.dom.Element;
    48 import org.w3c.dom.Node;
    49 import org.w3c.dom.NodeList;
    50 import org.xml.sax.SAXException;
    51 
    52 import eu.clarin.cmdi.mdservice.internal.Admin;
    53 import eu.clarin.cmdi.mdservice.internal.Cache;
    54 import eu.clarin.cmdi.mdservice.internal.MDTransformer;
    55 import eu.clarin.cmdi.mdservice.model.Diagnostic;
    56 import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
    57 
    584
    595/**
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/internal/Cache.java

    r1513 r1540  
    3535
    3636import org.apache.commons.lang.StringEscapeUtils;
     37import org.apache.log4j.Logger;
    3738import org.w3c.dom.Document;
    3839import org.w3c.dom.Element;
     
    5051 * mapping the request parameters to the indexed files.</p>
    5152 *
    52  * This is an internal object, direct user access to cache-data via interface is only possible via <code>AdminAction</code>
     53 * This is an internal object, direct user access to cache-data via interface is only possible via <code>...Action</code>
    5354 * @author master
    5455 *
     
    5657
    5758public class Cache {
     59       
     60        private static Logger log = Logger.getLogger("Cache");
     61       
    5862        public static String PREFIX = "xc_";
    5963       
     
    7276       
    7377        public Cache () {               
    74                 cachepath = Admin.getConfig().getProperty("cache.path");
    75                 cacheindex_path = cachepath + Admin.getConfig().getProperty("cacheindex.file");
     78                cachepath = Utils.getConfig().getProperty("cache.path");
     79                cacheindex_path = cachepath + Utils.getConfig().getProperty("cacheindex.file");
    7680                cachecounter = initCachecounter();
    7781               
     
    125129        public String putInCache(String key_info, InputStream instream) {
    126130
    127                 Admin.notifyUser("CACHE.putInCache:"+key_info);
     131                log.debug("CACHE.putInCache:"+key_info);
    128132                Integer c = getCounter();
    129133                String xc;
    130134               
    131                
    132135                //update xml_structure
    133136                Element e = cacheindex_doc.createElement("f");
    134                 //Attr attr = cacheindex_doc.createAttribute("id");
    135                 //attr.setValue(c.toString());
    136                 //e.setNamedItem(attr);
    137137                e.setAttribute("id", c.toString());
    138138                String[] key_array = key_info.split("//-");
     
    197197               
    198198                // update XML-counter
    199             //Admin.writeToFile(formPath(id + xc),instream);
    200                
    201199                updateCachecounter();
    202200               
    203201                xc = PREFIX + key_array[0] + "_" + c.toString();
    204                 Admin.notifyUser("CACHE.putInCache.filename:" + xc + ".xml");
    205                 Admin.writeToFile(cachepath + xc + ".xml",instream);
     202                log.debug("CACHE.putInCache.filename:" + xc + ".xml");
     203                Utils.write2File(cachepath + xc + ".xml",instream);
    206204               
    207205            return xc;
     
    213211               
    214212                   File f = new File (formPath(key_info));
    215                    //Admin.notifyUser("CACHE.getFromCache:"+key_info);
    216                    
    217213                   
    218214                    if (f.exists()) { // read from file to InputStream;
    219                         Admin.notifyUser("CACHE.getFromCache.fromfile:"+f.getName() + "[#" + key_info + "]");
     215                        log.debug("CACHE.getFromCache.fromfile:"+f.getName() + "[#" + key_info + "]");
    220216                        InputStream instream;
    221217                                try {
     
    224220                                        return instream;
    225221                                } catch (FileNotFoundException e) {
    226                                         // TODO Auto-generated catch block
    227                                         e.printStackTrace();
     222                                        Utils.errorMessage(e);
    228223                                        return null;
    229224                                }
    230225                       
    231226                    } else { //not cached, my dear
    232                         Admin.notifyUser("CACHE.getFromCache: NOT CACHED" + "[#" + key_info + "]");
     227                        log.debug("CACHE.getFromCache: NOT CACHED" + "[#" + key_info + "]");
    233228                        return null;
    234229                    }       
     
    245240                query = new Query("", str,"recordset","");
    246241                if (query.isStatus(Query.PARSEERROR)) {
    247                         Admin.notifyUser("Cache.transformQuery.PARSEERROR:" + query.getMsg());
     242                        log.debug("Cache.transformQuery.PARSEERROR:" + query.getMsg());
    248243                        // pass this bad news to the client
    249                         //setUserMsg(query.getMsg());
    250244                        transformed = "";
    251245                } else {
    252246                        transformed =  Query.getSimpleQueryString(str);
    253247                        transformed = StringEscapeUtils.escapeXml(transformed);
    254                         //Admin.notifyUser("CACHE.transformQuery:"+transformed);
     248                        //log.debug("CACHE.transformQuery:"+transformed);
    255249                }
    256250                return transformed;
     
    268262               
    269263                if(key_array.length > 1){
    270                 //      Admin.notifyUser("formPATH- querystring:" + key_array[1]);
     264                //      log.debug("formPATH- querystring:" + key_array[1]);
    271265                        if (key_array[0].equals("recordset")){
    272266                                query_str = this.transformQuery(key_array[1]); 
    273                         //      Admin.notifyUser("formPATH- querystring-transformed:" + query_str);
     267                        //      log.debug("formPATH- querystring-transformed:" + query_str);
    274268                        }
    275269                        else {
     
    319313                }
    320314               
    321                 //Admin.notifyUser("formPath:xpath:"+xpath_expr);
     315                //log.debug("formPath:xpath:"+xpath_expr);
    322316                //creating an XPathFactory:
    323317        XPathFactory factory = XPathFactory.newInstance();
     
    335329                        path = cachepath + PREFIX + key_array[0] + "_"+id + ".xml";
    336330                }  else if (list.getLength() > 1){
    337                         Admin.notifyUser("formPath ERROR:!!!:multiple paths:"+key_info);
     331                        log.debug("formPath ERROR:!!!:multiple paths:"+key_info);
    338332                       
    339333                }
    340334               
    341335                } catch (XPathExpressionException e) {
    342                         // TODO Auto-generated catch block
    343                         Admin.notifyUser("ERROR Cache.formPath: "+xpath_expr);
     336                        log.debug("ERROR Cache.formPath: "+xpath_expr);
     337                        log.error(Utils.errorMessage(e));
    344338                }
    345339               
     
    353347       
    354348        /**
    355          * read counter-integer from file in cache
     349         * Read counter-integer from file in cache
    356350         * or start that file
    357351         * @return The current maximum cache counter
     
    360354               
    361355                Integer counter = start_cache;
    362                 boolean init=false;
    363356                String fname = cacheindex_path;
    364357                File f = new File (fname);
    365358               
    366                 //Admin.notifyUser("initCacheCounter");
    367359                if (!f.exists()) {
    368360                                // create new  counter document
     
    378370                                        writeCachecounter(counter);
    379371                                       
    380                                         //Admin.notifyUser("new document");
    381372                                } catch (ParserConfigurationException e) {
    382                                         // TODO Auto-generated catch block
    383                                         e.printStackTrace();
     373                                        log.error(Utils.errorMessage(e));
    384374                                }
    385                                
    386                         //} catch (IOException e2) {
    387                         //      Admin.notifyUser("ERROR creating cache counter");
    388                         //      e2.printStackTrace();
    389                         //}
    390375            }
    391376                else {
     
    399384                                                        cacheindex_doc = docBuilder.parse(fname);
    400385                                        } catch (SAXException e) {
    401                                                         // TODO Auto-generated catch block
    402                                                        
    403                                                         e.printStackTrace();
     386                                                log.error(Utils.errorMessage(e));
    404387                                        }
    405388                                } catch (ParserConfigurationException e) {
    406                                                 // TODO Auto-generated catch block
    407                                                 e.printStackTrace();
     389                                        log.error(Utils.errorMessage(e));
    408390                                }
    409391                               
    410392                         //read counter
    411393                         counter = new Integer(cacheindex_doc.getFirstChild().getAttributes().getNamedItem("idcounter").getNodeValue());
    412                          init = true;
    413                     }  catch (IOException ex){
    414                         //Admin.notifyUser("initCacheCounter:" + ex.toString());
    415                         ex.printStackTrace();
     394                    }  catch (IOException e){
     395                        log.error(Utils.errorMessage(e));
    416396                    }
    417397                }
    418398               
    419399            return counter;
    420             /*
    421               //use buffering, reading one line at a time
    422               //FileReader always assumes default encoding is OK!
    423                 BufferedReader input =  new BufferedReader(new FileReader(f));
    424                         try {
    425                                 String line = null; //not declared within while loop
    426                         /*
    427                         * readLine is a bit quirky :
    428                         * it returns the content of a line MINUS the newline.
    429                         * it returns null only for the END of the stream.
    430                         * it returns an empty String if two newlines appear in a row.
    431                         *
    432                         try {
    433                                         if (( line = input.readLine()) != null){
    434                                                 try {
    435                                                         counter = new Integer(line);
    436                                                 } catch (NumberFormatException e) {
    437                                                 // if not a number, write a number
    438                                                         init=true;     
    439                                                 } 
    440                                         } else {
    441                                                 init=true;
    442                                         }
    443                                 } catch (IOException e) {
    444                                         init=true;
    445                                 }
    446                        
    447                         if (init) {                                                     
    448                             writeCachecounter( start_cache);                                   
    449                         }
    450                        
    451                 } finally {
    452                 input.close();
    453              }   
    454              */         
    455400        }
    456401
    457402        public void updateCachecounter () {
    458                 //Admin.notifyUser("CACHEcounter:" + cachecounter);
    459403            writeCachecounter( cachecounter);
    460404        }
     
    464408                cacheindex_doc.getFirstChild().getAttributes().getNamedItem("idcounter").setNodeValue(i.toString());
    465409               
    466                 //Admin.notifyUser("writeCacheCounter:" + i.toString());
    467410                // write xml
    468411                Transformer transformer;
     
    476419                        try {
    477420                                transformer.transform(source, result);
    478                         } catch (TransformerException e1) {
    479                                 // TODO Auto-generated catch block
    480                                 e1.printStackTrace();
     421                        } catch (TransformerException e) {
     422                                log.error(Utils.errorMessage(e));
    481423                        }
    482424
    483425                        String xmlString = result.getWriter().toString();
    484                         //Admin.notifyUser("writeCacheCounter:" + xmlString);
    485                         //Admin.writeToFile("", result);
    486 
    487426
    488427                        File f = new File (cacheindex_path);
     
    494433                                        fw.close();
    495434                                } catch (IOException e) {
    496                                         // TODO Auto-generated catch block
    497                                         e.printStackTrace();
     435                                        log.error(Utils.errorMessage(e));
    498436                                }       
    499437                        } catch (IOException e) {
    500                                 // TODO Auto-generated catch block
    501                                 e.printStackTrace();
    502                         }
    503                 } catch (TransformerConfigurationException e2) {
    504                         // TODO Auto-generated catch block
    505                         e2.printStackTrace();
    506                 } catch (TransformerFactoryConfigurationError e2) {
    507                         // TODO Auto-generated catch block
    508                         e2.printStackTrace();
    509                 }
    510                
    511                        
    512 
    513                 /*
    514                 File f = new File (Admin.getConfig().getProperty("cache.path") + "counter.txt");
    515            
    516                 try {
    517                         Writer output = new BufferedWriter(new FileWriter(f));         
    518               //FileWriter always assumes default encoding is OK!
    519                         try {
    520                                 output.write( i);
    521                         } finally {
    522                                 output.close();
    523                         }       
    524                 } catch (IOException e) {
    525                         // TODO Auto-generated catch block
    526                         e.printStackTrace();
    527                 }
    528                 */
     438                                log.error(Utils.errorMessage(e));
     439                        }
     440                } catch (TransformerConfigurationException e) {
     441                        log.error(Utils.errorMessage(e));
     442                } catch (TransformerFactoryConfigurationError e) {
     443                        log.error(Utils.errorMessage(e));
     444                }
     445               
    529446        }
    530447       
    531448        public InputStream clear(HashMap<String,String> clear_params) throws ParserConfigurationException, TransformerConfigurationException, TransformerException, TransformerFactoryConfigurationError {
    532449                String xpath_expr = "";
    533                 Integer removed = 0;
    534450                InputStream is = null;
    535451               
     
    604520                        Result outputTarget = new StreamResult(outputStream);
    605521                        TransformerFactory.newInstance().newTransformer().transform(xmlSource, outputTarget);
    606                         is = new ByteArrayInputStream(outputStream.toByteArray());
    607 
    608                         removed = list.getLength();
     522                        is = new ByteArrayInputStream(outputStream.toByteArray());
    609523               
    610524                } catch (XPathExpressionException e) {
    611                         // TODO Auto-generated catch block
    612                         e.printStackTrace();
     525                        log.error(Utils.errorMessage(e));
    613526                }
    614527               
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/internal/MDTransformer.java

    r1527 r1540  
    3131import net.sf.saxon.event.MessageEmitter;
    3232
    33 //import com.icl.saxon.*;
    34 //import com.icl.saxon.FeatureKeys;
    35 //import com.icl.saxon.Loader;
    36 //import com.icl.saxon.output.Emitter;
    37 
    38 
    3933/**
    4034 * Helper class, encapsulating the xsl-transformations handling.
    41  * The contract is, that the requester passes a key, which can be resolved to a xsl-script (momentary mapped in properties: Admin.getConfig())
     35 * The contract is, that the requester passes a key, which can be resolved to a xsl-script (momentary mapped in properties: Utils.getConfig())
    4236 *
    4337 * Bad things happen, if the key or the appropriate xsl-file do not exist - well the client gets a diagnostic message.
     
    5044public class MDTransformer {
    5145       
    52         private static Logger log = Logger.getLogger("MDRepoProxy");
     46        private static Logger log = Logger.getLogger("MDTransformer");
    5347       
    5448        private URL srcFile ;
     
    8680                return this.params;
    8781        }
    88         /**
    89          * get the path to the transform-xsl file from properties, based on the key (aka format-parameter)
     82
     83        /**
     84         * Get the path to the xsl file from properties, based on the key (aka format-parameter)
    9085         * @param key
    9186         * @return
     
    9489        private String getXSLPath (String key) throws NoStylesheetException {           
    9590                String xslpath = "";
    96                 String xslfilename= Admin.getConfig().getProperty("xsl." + key);
     91                String xslfilename= Utils.getConfig().getProperty("xsl." + key);
    9792               
    9893                if (xslfilename!=null) {                       
    99                         xslpath =  Admin.getConfig().getProperty("scripts.path") + xslfilename;
     94                        xslpath =  Utils.getConfig().getProperty("scripts.path") + xslfilename;
    10095                } else {
    10196                        throw new NoStylesheetException("No Stylesheet found for format-key: " + key);
     
    10499                return xslpath;
    105100        }
    106 
    107101        /**
    108102         * Tries to load the stylesheet based on the key.
     
    135129        }
    136130
    137         /**
    138          * Makes the request-parameters available in the stylesheets
    139          * by translating them to stylesheet-parameters
    140          * @param transformer
    141          */
    142         public void SetTransformerParameters(Transformer transformer){
    143                
    144                 Set<Entry<String, String[]>> set = params.entrySet();
    145                 Iterator<Entry<String, String[]>> i = set.iterator();
    146 
    147             while(i.hasNext()){
    148               Map.Entry<String,String[]> e = (Map.Entry<String,String[]>)i.next();
    149               transformer.setParameter((String)e.getKey(), (String)e.getValue()[0]);
    150             }
    151         }
    152131       
    153132        /**
     
    187166                        File f = new File(srcFile.getPath());
    188167                           
    189                         //Admin.notifyUser("src:" + srcFile.getFile());
    190                         //Admin.notifyUser("fpath:" + f.getAbsolutePath());
     168                        //log.debug("src:" + srcFile.getFile());
     169                        //log.debug("fpath:" + f.getAbsolutePath());
    191170                        String root_uri =  srcFile.toString();
    192171                        String xsrcfile =  srcFile.getFile();
     
    218197                // Write <xsl:message>
    219198                writeXslMessages(w);
    220                 ///Admin.notifyUser(w.getBuffer().toString());         
     199                ///log.debug(w.getBuffer().toString());         
    221200   }
    222201       
     
    258237                return transformXML ( xmlStream);
    259238        }
    260 
    261239
    262240        /**
     
    315293                try {
    316294                        while ((s = br.readLine()) != null){
    317                         Admin.notifyUser(s);
     295                        log.debug(s);
    318296                }
    319297                } catch (IOException e) {
    320                         // TODO Auto-generated catch block
    321                         e.printStackTrace();
     298                        log.error(Utils.errorMessage(e));
    322299                }
    323300        }
     301
     302        /**
     303         * Makes the request-parameters available in the stylesheets
     304         * by translating them to stylesheet-parameters
     305         * @param transformer
     306         */
     307        public void SetTransformerParameters(Transformer transformer){
     308               
     309                Set<Entry<String, String[]>> set = params.entrySet();
     310                Iterator<Entry<String, String[]>> i = set.iterator();
     311
     312            while(i.hasNext()){
     313              Map.Entry<String,String[]> e = (Map.Entry<String,String[]>)i.next();
     314              transformer.setParameter((String)e.getKey(), (String)e.getValue()[0]);
     315            }
     316        }
     317
    324318       
    325319        public static HashMap<String,String[]> createParamsMap(String key){
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/model/Diagnostic.java

    r1511 r1540  
    1111 */
    1212
    13 import java.io.IOException;
    14 import java.io.InputStream;
    15 import java.net.MalformedURLException;
    16 import java.net.URL;
    1713import java.util.HashMap;
    1814
    19 import javax.xml.parsers.DocumentBuilder;
    20 import javax.xml.parsers.DocumentBuilderFactory;
    21 
    22 import org.apache.commons.io.IOUtils;
    2315import org.w3c.dom.Attr;
    2416import org.w3c.dom.Document;
    2517import org.w3c.dom.Element;
    26 import org.z3950.zing.cql.CQLNode;
    27 import org.z3950.zing.cql.CQLParseException;
    28 import org.z3950.zing.cql.CQLParser;
    29 
    30 import eu.clarin.cmdi.mdservice.internal.Admin;
    31 import eu.clarin.cmdi.mdservice.internal.MDTransformer;
    3218
    3319public class Diagnostic {       
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/model/Diagnostics.java

    r1514 r1540  
    1111 */
    1212
    13 import java.io.ByteArrayInputStream;
    14 import java.io.IOException;
    1513import java.io.InputStream;
    16 import java.io.StringWriter;
    17 import java.io.UnsupportedEncodingException;
    18 import java.net.MalformedURLException;
    19 import java.net.URL;
    2014import java.util.ArrayList;
    2115import java.util.Iterator;
    22 import java.util.List;
    2316
    2417import javax.xml.parsers.DocumentBuilder;
    2518import javax.xml.parsers.DocumentBuilderFactory;
    2619import javax.xml.parsers.ParserConfigurationException;
    27 import javax.xml.transform.OutputKeys;
    28 import javax.xml.transform.Transformer;
    29 import javax.xml.transform.TransformerConfigurationException;
    30 import javax.xml.transform.TransformerException;
    31 import javax.xml.transform.TransformerFactory;
    32 import javax.xml.transform.TransformerFactoryConfigurationError;
    33 import javax.xml.transform.dom.DOMSource;
    34 import javax.xml.transform.stream.StreamResult;
    3520
    36 import org.apache.commons.io.IOUtils;
    3721import org.w3c.dom.Document;
    3822import org.w3c.dom.Element;
    39 import org.z3950.zing.cql.CQLNode;
    40 import org.z3950.zing.cql.CQLParseException;
    41 import org.z3950.zing.cql.CQLParser;
    42 
    43 import eu.clarin.cmdi.mdservice.internal.Admin;
    44 import eu.clarin.cmdi.mdservice.internal.MDTransformer;
    4523
    4624public class Diagnostics {     
     
    8765                         
    8866                          Element d = doc.createElement("diagnostics");
    89                           Iterator itr = list.iterator();
     67                          Iterator<Diagnostic> itr = list.iterator();
    9068                                while(itr.hasNext())
    9169                                        d.appendChild(((Diagnostic)itr.next()).buildXMLNode(doc));
     
    9573                return doc;
    9674        }
    97         // @SuppressWarnings("unchecked")
     75       
     76        //TODO to Utils.java
     77        /*
    9878        public InputStream buildXMLStream() throws ParserConfigurationException, TransformerConfigurationException, TransformerException, TransformerFactoryConfigurationError, UnsupportedEncodingException{
    9979                if (xmlstream == null){
     
    10787                return xmlstream;
    10888        }
     89        */
    10990       
    11091        public boolean Accepted(){
     
    11293               
    11394                if (this.list.size() > 0){
    114                          Iterator itr = list.iterator();
     95                         Iterator<Diagnostic> itr = list.iterator();
    11596                                while(itr.hasNext() && accepted)
    11697                                {
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/model/Query.java

    r1517 r1540  
    2121import javax.xml.parsers.DocumentBuilderFactory;
    2222
     23import org.apache.log4j.Logger;
    2324import org.w3c.dom.Document;
    2425import org.z3950.zing.cql.CQLNode;
     
    2627import org.z3950.zing.cql.CQLParser;
    2728
    28 import eu.clarin.cmdi.mdservice.internal.Admin;
     29import eu.clarin.cmdi.mdservice.internal.Utils;
    2930import eu.clarin.cmdi.mdservice.internal.MDTransformer;
    3031import eu.clarin.cmdi.mdservice.internal.NoStylesheetException;
    3132
    3233public class Query {   
     34       
     35        public static Logger log = Logger.getLogger("Query");
     36       
    3337        public static String COLLECTION = "collection";
    3438        public static String COLUMNS = "columns";
     
    170174                        full_query_string = "";
    171175                }
    172                 Admin.notifyUser("QUERY.FULLQUERYSTRING:" + full_query_string);
     176                log.debug("QUERY.FULLQUERYSTRING:" + full_query_string);
    173177                if (type.equals(RECORDSET) && (full_query_string.length() > 0)) {       
    174178                        parse();
     
    331335                                simple_form = simple_form + rel + arr_or[j];
    332336                        }
    333                         //Admin.notifyUser(simple_form);
     337                       
    334338                        if (arr_or.length > 1){
    335339                                simple_form = "(" + simple_form + ") ";
     
    392396                                //  probably not the best place to handle -> move to repository: sanitize-query?
    393397                        String corrid = getQueryString().replace(":","\\:").toLowerCase();
    394                         Admin.notifyUser("Query.toURLParam.corrid=" + corrid);
     398                        log.debug("Query.toURLParam.corrid=" + corrid);
    395399                        targetRequest = "//MdSelfLink[ft:query(.,'" + corrid + "')]";                   
    396400                } else {
     
    446450                 
    447451          try {
    448                 Admin.notifyUser(toXCQL());
     452                log.debug(toXCQL());
    449453                       
    450454               
     
    453457                Document doc = builder.parse(new org.xml.sax.InputSource(new java.io.StringReader(toXCQL())));
    454458                       
    455                 //Admin.notifyUser("document created");
     459                //log.debug("document created");
    456460                SearchClauses searchclauses = new SearchClauses(doc);
    457461                //do the processing
     
    459463                String xml_s = searchclauses.toXML();
    460464               
    461                 //Admin.notifyUser("AAAA2:" + xml_s);
     465               
    462466          }
    463467                catch (Exception e) {
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/model/Result.java

    r1511 r1540  
    66import javax.xml.transform.TransformerException;
    77
    8 import eu.clarin.cmdi.mdservice.internal.Admin;
     8import org.apache.log4j.Logger;
     9
     10import eu.clarin.cmdi.mdservice.internal.Utils;
    911import eu.clarin.cmdi.mdservice.internal.MDTransformer;
    1012import eu.clarin.cmdi.mdservice.internal.NoStylesheetException;
     
    2123public class Result {
    2224
     25        public static Logger log = Logger.getLogger("Result");
    2326        /**
    2427         * available formats
     
    5962                } else {       
    6063                        transformkey = parentQuery.getType() + "2" + format;
    61                         Admin.notifyUser("transformkey: " + transformkey );
     64                        log.debug("transformkey: " + transformkey );
    6265                        MDTransformer transformer = new MDTransformer();
    6366                        transformer.setParams(MDTransformer.createParamsMap(transformkey));
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/model/SearchClauses.java

    r1511 r1540  
    1616import org.w3c.dom.NodeList;
    1717
    18 import eu.clarin.cmdi.mdservice.internal.Admin;
     18import eu.clarin.cmdi.mdservice.internal.Utils;
    1919import eu.clarin.cmdi.mdservice.action.DCRProxyAction;
    2020
     
    3535                }
    3636                xml_document=  _doc;
    37                 Admin.notifyUser("SCCCCC: constuctor");
     37                //log.debug("SCCCCC: constuctor");
    3838                deserialize();
    3939                // do processing
     
    103103                        deserialize(b,nodeList.item(1), nodeList.item(2),0);
    104104                }else{
    105                         Admin.notifyUser("SCCCCC: deserialize");
     105                        //log.debug("SCCCCC: deserialize");
    106106                        if (node.getNodeName().equals("searchClause")){
    107107                       
     
    111111                        }
    112112                }
    113                 Admin.notifyUser("SCCCCC: list " + list[0][0].getIndex() + list[0][0].getValue());
     113                //log.debug("SCCCCC: list " + list[0][0].getIndex() + list[0][0].getValue());
    114114               
    115115               
     
    165165               
    166166                // remove old document
    167                 Admin.notifyUser("SCCCCC: serialize");
    168                 Admin.notifyUser("SCCCCC: " + xml_document.getChildNodes().getLength());
     167                //log.debug("SCCCCC: serialize");
     168                //log.debug("SCCCCC: " + xml_document.getChildNodes().getLength());
    169169                xml_document.removeChild(xml_document.getFirstChild());
    170                 Admin.notifyUser("SCCCCC: CLEARED " + xml_document.getChildNodes().getLength());
     170                //log.debug("SCCCCC: CLEARED " + xml_document.getChildNodes().getLength());
    171171               
    172172                if ((getLastAnd() == 1) && (getLastOr(0) == 1)){
    173                         Admin.notifyUser("SCCCCC: searchClause ");
     173                        //log.debug("SCCCCC: searchClause ");
    174174                        root = xml_document.createElement("searchClause");
    175175                        e = xml_document.createElement("index");
     
    232232                        }
    233233                xml_string = sw.toString();
    234                 Admin.notifyUser("SERIALIZED-XML:  " + xml_string);
     234                //log.debug("SERIALIZED-XML:  " + xml_string);
    235235                } catch (TransformerConfigurationException e1) {
    236236                        // TODO Auto-generated catch block
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/model/Termset.java

    r1511 r1540  
    99import javax.xml.xpath.XPathFactory;
    1010
     11import org.apache.log4j.Logger;
    1112import org.w3c.dom.Document;
    1213import org.w3c.dom.Node;
    1314import org.w3c.dom.NodeList;
    1415
    15 import eu.clarin.cmdi.mdservice.internal.Admin;
     16import eu.clarin.cmdi.mdservice.internal.Utils;
    1617
    1718public class Termset {
    1819
     20        public static Logger log = Logger.getLogger("Termset");
     21       
    1922        private final static HashMap<String,Object> termsets = new HashMap<String,Object>();
    2023       
     
    5154               
    5255                Termset res = (Termset) getTermsets().get(ts_id);
    53                 if (res==null) Admin.notifyUser("getTermset(): no termset found for:" + ts_id);
     56                if (res==null) log.debug("getTermset(): no termset found for:" + ts_id);
    5457                //else
    55                         //Admin.notifyUser("getDCR():" + res.getAttr("id") + ":" + res.getAttr("url") );               
     58                        //log.debug("getDCR():" + res.getAttr("id") + ":" + res.getAttr("url") );               
    5659                return res;
    5760        }
     
    6568
    6669        public static void initTermsets() {
    67                         Document dcrs_setup = Admin.getXMLDocument(Admin.getConfig().getProperty("terms.file"));
     70                        Document dcrs_setup = Utils.load2Document(Utils.getConfig().getProperty("terms.file"));
    6871               
    69                 //      Admin.loadFile(Admin.getConfig().getProperty("service.list.file"));             
    70                         Admin.notifyUser("initTermsets().loaded.");                                     
     72                //      Utils.load2(Utils.getConfig().getProperty("service.list.file"));                 
     73                        log.debug("initTermsets().loaded.");                                   
    7174                        //.getDocumentElement().getLocalName()
    72                         //Document chains_doc = Admin.getXMLDocument(Admin.getConfig().getProperty("chains.file"));
     75                        //Document chains_doc = Utils.load2Document(Utils.getConfig().getProperty("chains.file"));
    7376       
    74                         //Admin.notifyUser("formPath:xpath:"+xpath_expr);
     77                        //log.debug("formPath:xpath:"+xpath_expr);
    7578                        //creating an XPathFactory:
    7679                XPathFactory factory = XPathFactory.newInstance();
     
    9194                                Termset ts = new Termset(n);                   
    9295                                                       
    93                                 Admin.notifyUser("reading in Termset: " + ts.getAttr("id"));
     96                                log.debug("reading in Termset: " + ts.getAttr("id"));
    9497                                termsets.put(ts.getAttr("id"), ts );
    9598                        }   
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/model/WorkspaceProfile.java

    r1538 r1540  
    1111import net.sf.json.JSONArray;
    1212import net.sf.json.JSONObject;
    13 import eu.clarin.cmdi.mdservice.internal.Admin;
    14 import eu.clarin.cmdi.mdservice.action.GenericProxyAction;
    15 import eu.clarin.cmdi.mdservice.internal.Helpers;
    1613import eu.clarin.cmdi.mdservice.internal.MDTransformer;
     14import eu.clarin.cmdi.mdservice.internal.Utils;
    1715import eu.clarin.cmdi.mdservice.action.WorkspaceAction;
    1816import eu.clarin.cmdi.mdservice.internal.NoStylesheetException;
     
    220218
    221219        public static JSONArray createRepositories() throws IOException, InterruptedException, TransformerException, NoStylesheetException{
    222                 String path = Admin.getConfig().getProperty("workspaceprofile.path") + WorkspaceAction.WORKSPACE_FILENAME;//PROFILENAME_SERVER;
     220                String path = Utils.getConfig().getProperty("workspaceprofile.path") + WorkspaceAction.WORKSPACE_FILENAME;//PROFILENAME_SERVER;
    223221                File file=new File(path);
    224222                InputStream in  = new BufferedInputStream( new FileInputStream(path));;
     
    229227                InputStream jsonstream = transformer.transformXML(in);
    230228               
    231                 JSONObject json = JSONObject.fromObject(Helpers.convertStreamToString(jsonstream));
     229                JSONObject json = JSONObject.fromObject(Utils.streamToString(jsonstream));
    232230                JSONArray wparray = json.getJSONObject("Profiles").getJSONArray("WorkspaceProfiles");
    233231                JSONArray array = null;
     
    254252       
    255253        public static JSONObject createOptions() throws IOException, InterruptedException, TransformerException, NoStylesheetException{
    256                 String path = Admin.getConfig().getProperty("workspaceprofile.path") + WorkspaceAction.WORKSPACE_FILENAME;//PROFILENAME_SERVER;
     254                String path = Utils.getConfig().getProperty("workspaceprofile.path") + WorkspaceAction.WORKSPACE_FILENAME;//PROFILENAME_SERVER;
    257255                File file=new File(path);
    258256                InputStream in  = new BufferedInputStream( new FileInputStream(path));;
     
    263261                InputStream jsonstream = transformer.transformXML(in);
    264262               
    265                 JSONObject json = JSONObject.fromObject(Helpers.convertStreamToString(jsonstream));
     263                JSONObject json = JSONObject.fromObject(Utils.streamToString(jsonstream));
    266264                JSONArray wparray = json.getJSONObject("Profiles").getJSONArray("WorkspaceProfiles");
    267265                JSONObject obj = null;
     
    306304       
    307305        public static JSONArray createTermsets() throws IOException, InterruptedException, TransformerException, NoStylesheetException{
    308                 String path = Admin.getConfig().getProperty("workspaceprofile.path") + WorkspaceAction.WORKSPACE_FILENAME;//PROFILENAME_SERVER;
     306                String path = Utils.getConfig().getProperty("workspaceprofile.path") + WorkspaceAction.WORKSPACE_FILENAME;//PROFILENAME_SERVER;
    309307                File file=new File(path);
    310308                InputStream in  = new BufferedInputStream( new FileInputStream(path));;
     
    315313                InputStream jsonstream = transformer.transformXML(in);
    316314               
    317                 JSONObject json = JSONObject.fromObject(Helpers.convertStreamToString(jsonstream));
     315                JSONObject json = JSONObject.fromObject(Utils.streamToString(jsonstream));
    318316                JSONArray wparray = json.getJSONObject("Profiles").getJSONArray("WorkspaceProfiles");
    319317                JSONArray array = null;
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/BasicProxy.java

    r1536 r1540  
    11package eu.clarin.cmdi.mdservice.proxy;
    22
    3 import java.io.File;
    43import java.io.IOException;
    54import java.io.InputStream;
    6 import java.io.StringReader;
    7 import java.io.StringWriter;
    85import java.net.MalformedURLException;
    9 import java.net.URISyntaxException;
    106import java.net.URL;
    117import java.net.URLConnection;
    12 import java.util.HashMap;
    13 import java.io.ByteArrayInputStream;
    14 
    15 import javax.xml.parsers.DocumentBuilder;
    16 import javax.xml.parsers.DocumentBuilderFactory;
    17 import javax.xml.transform.OutputKeys;
    18 import javax.xml.transform.Transformer;
    19 import javax.xml.transform.TransformerException;
    20 import javax.xml.transform.TransformerFactory;
    21 import javax.xml.transform.dom.DOMSource;
    22 import javax.xml.transform.stream.StreamResult;
    23 
    248import org.apache.log4j.Logger;
    25 import org.w3c.dom.Document;
    26 import org.w3c.dom.Node;
    27 import org.w3c.dom.NodeList;
    28 import org.xml.sax.InputSource;
    29 
    309import eu.clarin.cmdi.mdservice.action.GenericAction;
    31 import eu.clarin.cmdi.mdservice.action.RepoAction;
    32 import eu.clarin.cmdi.mdservice.internal.Admin;
    3310import eu.clarin.cmdi.mdservice.internal.NoStylesheetException;
    34 import eu.clarin.cmdi.mdservice.model.Diagnostic;
    35 import eu.clarin.cmdi.mdservice.model.Query;
    36 import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
     11import eu.clarin.cmdi.mdservice.model.Termset;
    3712
    3813/**
     
    9671               
    9772        public String getBaseURI() {           
    98                 String uri =Admin.getConfig().getProperty(getSourceAction().getActionkey() + ".uri");                           
     73                //String uri =Utils.getConfig().getProperty(getSourceAction().getActionkey() + ".uri");
     74                String uri = Termset.getTermsetAttr(getSourceAction().getActionkey(), "url");
    9975                return uri;
    10076        }
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/MDRepoProxy.java

    r1515 r1540  
    11package eu.clarin.cmdi.mdservice.proxy;
    22
    3 import java.io.File;
    43import java.io.IOException;
    5 import java.io.InputStream;
    6 import java.io.StringReader;
    7 import java.io.StringWriter;
    8 import java.net.MalformedURLException;
    9 import java.net.URISyntaxException;
    104import java.net.URL;
    115import java.util.HashMap;
    12 import java.io.ByteArrayInputStream;
    13 
    14 import javax.xml.parsers.DocumentBuilder;
    15 import javax.xml.parsers.DocumentBuilderFactory;
    16 import javax.xml.transform.OutputKeys;
    17 import javax.xml.transform.Transformer;
    18 import javax.xml.transform.TransformerException;
    19 import javax.xml.transform.TransformerFactory;
    20 import javax.xml.transform.dom.DOMSource;
    21 import javax.xml.transform.stream.StreamResult;
    22 
    236import org.apache.log4j.Logger;
    24 import org.w3c.dom.Document;
    25 import org.w3c.dom.Node;
    26 import org.w3c.dom.NodeList;
    27 import org.xml.sax.InputSource;
    28 
    29 import eu.clarin.cmdi.mdservice.internal.NoStylesheetException;
    307import eu.clarin.cmdi.mdservice.model.Query;
    318import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
     
    11087                        URL targetURL = null;
    11188                        targetURL =new URL( getBaseURL(), urls.get(getActionkey()) + query.toURLParam() );
    112                         Admin.notifyUser("MDRPA.targetURL.query.toURLParam:" + query.toURLParam());
    113                         Admin.notifyUser("MDRPA.targetURL:" + targetURL);
     89                        log.debug("MDRPA.targetURL.query.toURLParam:" + query.toURLParam());
     90                        log.debug("MDRPA.targetURL:" + targetURL);
    11491                return targetURL;
    11592                }
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/SRUProxy.java

    r1511 r1540  
    259259        public String getBaseURI() {           
    260260                log.debug("SRU-repositorypath:" + WorkspaceProfile.getRepositoryPath(getSourceAction().getRepository()));
    261                 String uri = WorkspaceProfile.getRepositoryPath(getSourceAction().getRepository());//Admin.getConfig().getProperty(getProxyKey() + ".uri");             
     261                String uri = WorkspaceProfile.getRepositoryPath(getSourceAction().getRepository());//Utils.getConfig().getProperty(getProxyKey() + ".uri");             
    262262                return uri;
    263263        }
     
    319319                } else {
    320320                        if (operation.equals("explain") || operation == null){
    321                                 Admin.notifyUser("explaining", "debug");
     321                                log.debug("explaining", "debug");
    322322                        }else {
    323323                                if (operation.equals("scan")){
  • MDService2/branches/MDService_simple3/src/struts.xml

    r1532 r1540  
    1 <?xml version="1.0" encoding="UTF-8"?>
    21<!DOCTYPE struts PUBLIC
    32    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
     
    2120                              <param name="location">/Error.jsp</param>                     
    2221                            </result> -->
    23                             <result name="error" type="stream">
    24                                 <param name="contentType">text/xml</param>
    25                                 <param name="inputName">resultStream</param>
    26                             </result>
     22                            <result name="error">/Error.jsp</result>
    2723                            <!-- <result name="error" type="redirectAction"></result>
    2824                             -->
Note: See TracChangeset for help on using the changeset viewer.