- Timestamp:
- 10/16/10 20:09:34 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/model/Termset.java
r768 r795 3 3 import java.util.HashMap; 4 4 5 import javax.xml.xpath.XPath; 6 import javax.xml.xpath.XPathConstants; 7 import javax.xml.xpath.XPathExpression; 8 import javax.xml.xpath.XPathExpressionException; 9 import javax.xml.xpath.XPathFactory; 10 11 import org.w3c.dom.Document; 5 12 import org.w3c.dom.Node; 13 import org.w3c.dom.NodeList; 14 15 import eu.clarin.cmdi.mdservice.action.Admin; 6 16 7 17 public class Termset { 8 18 19 private final static HashMap<String,Object> termsets = new HashMap<String,Object>(); 20 9 21 private final HashMap<String,String> attrs = new HashMap<String,String>(); 10 22 11 public Termset () { 12 23 public Termset () { 13 24 } 14 25 … … 16 27 this.setAttrs(n); 17 28 } 18 29 19 30 public void setAttrs(Node n) { 20 31 … … 29 40 return attrs.get(key); 30 41 } 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 31 103 32 104 }
Note: See TracChangeset
for help on using the changeset viewer.