Ignore:
Timestamp:
10/16/10 20:09:34 (14 years ago)
Author:
vronk
Message:

dcr/rr terms htmllist, welcome-message

File:
1 edited

Legend:

Unmodified
Added
Removed
  • MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/model/Termset.java

    r768 r795  
    33import java.util.HashMap;
    44
     5import javax.xml.xpath.XPath;
     6import javax.xml.xpath.XPathConstants;
     7import javax.xml.xpath.XPathExpression;
     8import javax.xml.xpath.XPathExpressionException;
     9import javax.xml.xpath.XPathFactory;
     10
     11import org.w3c.dom.Document;
    512import org.w3c.dom.Node;
     13import org.w3c.dom.NodeList;
     14
     15import eu.clarin.cmdi.mdservice.action.Admin;
    616
    717public class Termset {
    818
     19        private final static HashMap<String,Object> termsets = new HashMap<String,Object>();
     20       
    921        private final HashMap<String,String> attrs = new HashMap<String,String>();
    1022       
    11         public Termset () {
    12                
     23        public Termset () {             
    1324        }
    1425
     
    1627                this.setAttrs(n);
    1728        }
    18 
     29       
    1930        public void setAttrs(Node n) {
    2031       
     
    2940          return attrs.get(key);
    3041        }
     42
     43        public static HashMap<String, Object> getTermsets() {
     44                if (termsets.size() == 0) {
     45                        initTermsets();                 
     46                }
     47                return termsets;
     48        }
     49
     50        public static Termset getTermset(String ts_id) {               
     51               
     52                Termset res = (Termset) getTermsets().get(ts_id);
     53                if (res==null) Admin.notifyUser("getTermset(): no termset found for:" + ts_id);
     54                //else
     55                        //Admin.notifyUser("getDCR():" + res.getAttr("id") + ":" + res.getAttr("url") );               
     56                return res;
     57        }
     58       
     59        public static String getTermsetAttr(String ts_id, String key) {
     60                Termset ts = getTermset(ts_id);
     61                String val="";
     62                if (ts!=null) val= ts.getAttr(key);
     63                 return val;
     64        }
     65
     66        public static void initTermsets() {
     67                        Document dcrs_setup = Admin.getXMLDocument(Admin.getConfig().getProperty("terms.file"));
     68               
     69                //      Admin.loadFile(Admin.getConfig().getProperty("service.list.file"));             
     70                        Admin.notifyUser("initTermsets().loaded.");                                     
     71                        //.getDocumentElement().getLocalName()
     72                        //Document chains_doc = Admin.getXMLDocument(Admin.getConfig().getProperty("chains.file"));
     73       
     74                        //Admin.notifyUser("formPath:xpath:"+xpath_expr);
     75                        //creating an XPathFactory:
     76                XPathFactory factory = XPathFactory.newInstance();
     77                //using this factory to create an XPath object:
     78                XPath xpath = factory.newXPath();
     79                //XPath object created compiles the XPath expression:
     80                XPathExpression expr;
     81                        try {
     82                                expr = xpath.compile("//Termset");
     83                                //expression is evaluated with respect to a certain context node which is doc.
     84                        Object result = expr.evaluate(dcrs_setup, XPathConstants.NODESET);
     85                        NodeList list = (NodeList) result;
     86       
     87                        // <Termset type="dcr" id="isocat" label="isoCAT" url="http://www.isocat.org/rest/" format="dcif" />
     88                        for (int i = 0; i<list.getLength();i++) {
     89                                //String value = list.item(i).getTextContent();
     90                                Node n = list.item(i);                         
     91                                Termset ts = new Termset(n);                   
     92                                                       
     93                                Admin.notifyUser("reading in Termset: " + ts.getAttr("id"));
     94                                termsets.put(ts.getAttr("id"), ts );
     95                        }   
     96                        } catch (XPathExpressionException e) {
     97                                // TODO Auto-generated catch block
     98                                e.printStackTrace();
     99                        }
     100
     101        }
     102       
    31103       
    32104}
Note: See TracChangeset for help on using the changeset viewer.