Ignore:
Timestamp:
10/11/10 10:32:38 (14 years ago)
Author:
vronk
Message:

terms-matrix; model, datcats to terms; model-matrix-all!

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

Legend:

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

    r742 r768  
    99import java.util.Properties;
    1010
     11import javax.xml.parsers.DocumentBuilder;
     12import javax.xml.parsers.DocumentBuilderFactory;
     13import javax.xml.parsers.ParserConfigurationException;
     14
     15import org.w3c.dom.Document;
     16import org.xml.sax.SAXException;
     17
    1118import net.sf.json.JSON;
    1219import net.sf.json.JSONSerializer;
    1320import net.sf.json.xml.XMLSerializer;
     21
    1422
    1523import eu.clarin.cmdi.mdservice.model.Query;
     
    210218                System.out.println(msg);
    211219        }
     220
     221
     222        public static InputStream loadFile(String path) {
     223               
     224                InputStream file=null;
     225                 
     226                try {                   
     227                        file = Admin.class.getClassLoader().getResourceAsStream(path);
     228                       
     229//                   System.out.println(config_file);
     230                        if (file == null) {
     231                             Admin.notifyUser("File not found!: " + path);
     232                        } else {
     233                               
     234                                System.out.println("Reading in: " + Admin.class.getClassLoader().getResource(path));
     235                                //config_file = new FileInputStream(configPath);
     236                //              Properties test = new Properties();
     237                        //      test.load(file);
     238                        }
     239                        /*
     240                } catch (FileNotFoundException e) {
     241                        // TODO Auto-generated catch block
     242                        e.printStackTrace();
     243                        */
     244                }   catch (Exception e) {
     245                        // TODO Auto-generated catch block
     246                        e.printStackTrace();
     247                }
     248               
     249                return file;
     250        }
     251       
     252       
     253        public static Document getXMLDocument(String path) {
     254                Document retdoc=null;
     255                try {
     256                       
     257                DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
     258                DocumentBuilder docBuilder;
     259                        try {
     260                                docBuilder = docFactory.newDocumentBuilder();               
     261                                try {
     262                                        Admin.notifyUser("trying to read from:" + path);
     263                                        InputStream xmlstream =  loadFile(path);                                       
     264                                        //retdoc= docBuilder.parse(fname);
     265                                        retdoc= docBuilder.parse(xmlstream);
     266                                        Admin.notifyUser("read in:" + retdoc);
     267                                } catch (SAXException e) {
     268                                                // TODO Auto-generated catch block
     269                                                Admin.notifyUser(e.getMessage());
     270                                                e.printStackTrace();
     271                                }
     272                        } catch (ParserConfigurationException e) {
     273                                        // TODO Auto-generated catch block
     274                                Admin.notifyUser(e.getMessage());
     275                                        e.printStackTrace();
     276                        }
     277                       
     278                 
     279            }  catch (IOException ex){
     280                //Admin.notifyUser("initCacheCounter:" + ex.toString());
     281                ex.printStackTrace();
     282            } catch (Exception e) {
     283                Admin.notifyUser("Admin.getXMLDocument():" + e.getMessage());
     284            }
     285            return retdoc;
     286        }
     287       
     288
    212289       
    213290public static void copyStreams (InputStream in, OutputStream out) throws IOException, InterruptedException {           
  • MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/DCRProxyAction.java

    r519 r768  
    33import java.io.IOException;
    44import java.io.InputStream;
     5import java.net.MalformedURLException;
    56import java.net.URL;
    67import java.net.URLConnection;
     8import java.util.HashMap;
     9
     10import javax.xml.transform.stream.StreamSource;
     11import javax.xml.xpath.XPath;
     12import javax.xml.xpath.XPathConstants;
     13import javax.xml.xpath.XPathExpression;
     14import javax.xml.xpath.XPathExpressionException;
     15import javax.xml.xpath.XPathFactory;
     16
     17import org.w3c.dom.Document;
     18import org.w3c.dom.Node;
     19import org.w3c.dom.NodeList;
     20
     21import eu.clarin.cmdi.mdservice.model.Termset;
    722
    823/**
     
    1732public class DCRProxyAction extends GenericProxyAction {
    1833
     34        private String proxy_key = "dcregistry";
     35       
     36        private String dcrid;
     37       
     38        public static String ALL = "all";
     39        public static String DATCAT = "datcat";
     40        public static String DATCATS = "datcats";
     41       
    1942        private static final long serialVersionUID = 1L;
    2043       
    21         private String proxy_key = "dcregistry";
     44        private final static HashMap<String,Object> dcrs = new HashMap<String,Object>();
     45       
     46       
     47        public String getDcrid() {
     48                return dcrid;
     49        }
     50
     51        public void setDcrid(String dcrid) {
     52                this.dcrid = dcrid;
     53        }
     54
     55        public HashMap<String, Object> getDCRs() {
     56                if (dcrs.size()==0) {
     57                        initDCRs();                             
     58                }
     59                return dcrs;
     60        }
     61
     62        public Termset getDCR() {               
     63                String dcr_id="";
     64                if (getQ()!=null && !getQ().equals("")) dcr_id = getQ();
     65                // override with dcrid-param
     66                if (getDcrid()!=null && !getDcrid().equals("")) dcr_id = getDcrid();                   
     67
     68                Termset res = (Termset) getDCRs().get(dcr_id);
     69                if (res==null)
     70                        Admin.notifyUser("getDCR(): no termset found for:" + dcr_id);
     71                else
     72                        Admin.notifyUser("getDCR():" + res.getAttr("id") + ":" + res.getAttr("url") );
     73               
     74                return res;
     75        }
     76       
     77        public String getDCRAttr(String key) { 
     78                Termset dcr = getDCR();
     79                String val="";
     80                if (dcr!=null) val= dcr.getAttr(key);
     81                 return val;
     82        }
    2283       
    2384        @Override
     
    2586                return proxy_key;
    2687        }
    27        
    2888         
    2989        public String getFullFormat() {
    30                         return "dc2" + getFormat();             
    31         }
    32        
     90                Termset dcr = getDCR();
     91                String srcformat="", srctype="";
     92                if (dcr!=null){
     93                                srcformat = dcr.getAttr("format");
     94                                srctype = dcr.getAttr("type");
     95                } else {
     96                         srcformat = ALL;
     97                         srctype = "datcat";
     98                }
     99                        return srctype + "-" + srcformat  + "2" + getFormat();         
     100        }
     101       
     102        public URL getBaseURL() throws MalformedURLException {
     103               
     104                String url= getDCRAttr("url");
     105               
     106                if (base_url == null) {
     107                        if (url.equals("")) {
     108                                base_url = null;
     109                        } else {
     110                                base_url = new URL(url);
     111                        }
     112                }
     113                return base_url;
     114        }
    33115       
    34116        /**
     
    41123
    42124                URL targetURL = null;
    43                 if (getQ()==null || getQ().equals("")) {
    44                 //      Admin.notifyUser("ERROR DCRProxy.targetURL: missing param Q!");
    45                         targetURL =new URL( getBaseURL(), getActionkey());
     125       
     126                //if (getActionkey().equals(DATCATS)) {
     127                targetURL =getBaseURL();
     128                /*
     129                        if (getQ()==null || getQ().equals("")) {                       
     130                                        // get all available datcat-sets from terms_setup.xml
     131                               
     132                                targetURL =getBaseURL();
     133                        } else {
     134                                targetURL =new URL( getBaseURL(), "/" + getQ());
     135                        }
     136                        */
     137                Admin.notifyUser("DCRProxy.targetURL:" + targetURL);
     138
     139            return targetURL;
     140        }
     141       
     142        public InputStream getSourceStream() throws IOException {
     143
     144                InputStream resultStream = null;
     145                // if no arguments  - get the local-config file
     146                if ((getQ()==null || getQ().equals("")) && (getActionkey().equals(DATCATS))) {
     147                        resultStream = this.getClass().getClassLoader().getResourceAsStream(Admin.getConfig().getProperty("datcats.file"));             
    46148                } else {
    47                         targetURL =new URL( getBaseURL(), getActionkey() + "/" + getQ());
    48                 }
    49                 Admin.notifyUser("DCRProxy.targetURL:" + targetURL);
    50 
    51             return targetURL;
    52         }
    53        
    54         public InputStream getSourceStream() throws IOException {
    55        
     149               
    56150                /* need to set Request-Property: Accept to xml
    57151                 * for to get dcif/xml from DCR-server by means of content negotiation */
    58152                URLConnection urlConnection = getTargetRequest().openConnection();
    59         urlConnection.setRequestProperty("Accept", "application/dcif+xml");
     153               
     154                if (getDCRAttr("format").equals("dcif")) {             
     155                        urlConnection.setRequestProperty("Accept", "application/dcif+xml");
     156                        Admin.notifyUser("setting header Accept:" + urlConnection.getRequestProperty("Accept"));
     157                }
     158        //urlConnection.setRequestProperty("Accept-Language", getLang());
     159       
     160        //
     161                resultStream = urlConnection.getInputStream();
     162                }
     163        return resultStream;
     164       
    60165   
    61         return urlConnection.getInputStream();
    62    
    63         }       
     166        }
     167       
     168
     169        public void initDCRs() {
     170                if (dcrs.size() > 0) { 
     171                }
     172               
     173                Document dcrs_setup = Admin.getXMLDocument(Admin.getConfig().getProperty("datcats.file"));
     174       
     175        //      Admin.loadFile(Admin.getConfig().getProperty("service.list.file"));             
     176                Admin.notifyUser("initDCRs().loaded:" + dcrs_setup.getDocumentURI());
     177                Admin.notifyUser("firstchild:" + dcrs_setup.getFirstChild());           
     178                //.getDocumentElement().getLocalName()
     179                //Document chains_doc = Admin.getXMLDocument(Admin.getConfig().getProperty("chains.file"));
     180
     181                //Admin.notifyUser("formPath:xpath:"+xpath_expr);
     182                //creating an XPathFactory:
     183        XPathFactory factory = XPathFactory.newInstance();
     184        //using this factory to create an XPath object:
     185        XPath xpath = factory.newXPath();
     186        //XPath object created compiles the XPath expression:
     187        XPathExpression expr;
     188                try {
     189                        expr = xpath.compile("//Termset");
     190                        //expression is evaluated with respect to a certain context node which is doc.
     191                Object result = expr.evaluate(dcrs_setup, XPathConstants.NODESET);
     192                NodeList list = (NodeList) result;
     193
     194                // <Termset type="dcr" id="isocat" label="isoCAT" url="http://www.isocat.org/rest/" format="dcif" />
     195                for (int i = 0; i<list.getLength();i++) {
     196                        //String value = list.item(i).getTextContent();
     197                        Node n = list.item(i);                         
     198                        Termset ts = new Termset(n);                   
     199                                               
     200                        Admin.notifyUser("reading in dcr:" + ts.getAttr("id"));
     201                        dcrs.put(ts.getAttr("id"), ts );
     202                }   
     203                } catch (XPathExpressionException e) {
     204                        // TODO Auto-generated catch block
     205                        e.printStackTrace();
     206                }
     207
     208        }
     209       
     210
    64211}
  • MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/GenericProxyAction.java

    r764 r768  
    3636        private String startRecord;
    3737        private String maximumRecords;
     38        private String lang="en";
    3839        private int maxdepth;
    3940        private String format;
     
    137138        }
    138139       
     140
     141        public String getLang() {
     142                return lang;
     143        }
     144
     145        public void setLang(String lang) {
     146                this.lang = lang;
     147        }
    139148
    140149        public String getFullFormat() {         
     
    193202*/
    194203       
    195         private URL base_url ;
     204        protected URL base_url ;
    196205       
    197206        public URL getBaseURL() throws MalformedURLException {         
  • MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/MDTransformer.java

    r745 r768  
    9898                //Admin.notifyUser(this.getClass().getClassLoader().getResource(xslPath).toString());
    9999                //Admin.notifyUser(this.getClass().getClassLoader().getResource(xslPath).getPath());
     100               
    100101               
    101102                streamSource.setSystemId(this.getClass().getClassLoader().getResource(xslPath).toString());
Note: See TracChangeset for help on using the changeset viewer.