Changeset 768 for MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice
- Timestamp:
- 10/11/10 10:32:38 (14 years ago)
- 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 9 9 import java.util.Properties; 10 10 11 import javax.xml.parsers.DocumentBuilder; 12 import javax.xml.parsers.DocumentBuilderFactory; 13 import javax.xml.parsers.ParserConfigurationException; 14 15 import org.w3c.dom.Document; 16 import org.xml.sax.SAXException; 17 11 18 import net.sf.json.JSON; 12 19 import net.sf.json.JSONSerializer; 13 20 import net.sf.json.xml.XMLSerializer; 21 14 22 15 23 import eu.clarin.cmdi.mdservice.model.Query; … … 210 218 System.out.println(msg); 211 219 } 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 212 289 213 290 public static void copyStreams (InputStream in, OutputStream out) throws IOException, InterruptedException { -
MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/DCRProxyAction.java
r519 r768 3 3 import java.io.IOException; 4 4 import java.io.InputStream; 5 import java.net.MalformedURLException; 5 6 import java.net.URL; 6 7 import 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 17 import org.w3c.dom.Document; 18 import org.w3c.dom.Node; 19 import org.w3c.dom.NodeList; 20 21 import eu.clarin.cmdi.mdservice.model.Termset; 7 22 8 23 /** … … 17 32 public class DCRProxyAction extends GenericProxyAction { 18 33 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 19 42 private static final long serialVersionUID = 1L; 20 43 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 } 22 83 23 84 @Override … … 25 86 return proxy_key; 26 87 } 27 28 88 29 89 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 } 33 115 34 116 /** … … 41 123 42 124 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")); 46 148 } 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 56 150 /* need to set Request-Property: Accept to xml 57 151 * for to get dcif/xml from DCR-server by means of content negotiation */ 58 152 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 60 165 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 64 211 } -
MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/GenericProxyAction.java
r764 r768 36 36 private String startRecord; 37 37 private String maximumRecords; 38 private String lang="en"; 38 39 private int maxdepth; 39 40 private String format; … … 137 138 } 138 139 140 141 public String getLang() { 142 return lang; 143 } 144 145 public void setLang(String lang) { 146 this.lang = lang; 147 } 139 148 140 149 public String getFullFormat() { … … 193 202 */ 194 203 195 pr ivateURL base_url ;204 protected URL base_url ; 196 205 197 206 public URL getBaseURL() throws MalformedURLException { -
MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/MDTransformer.java
r745 r768 98 98 //Admin.notifyUser(this.getClass().getClassLoader().getResource(xslPath).toString()); 99 99 //Admin.notifyUser(this.getClass().getClassLoader().getResource(xslPath).getPath()); 100 100 101 101 102 streamSource.setSystemId(this.getClass().getClassLoader().getResource(xslPath).toString());
Note: See TracChangeset
for help on using the changeset viewer.