Changeset 1496 for MDService2/trunk
- Timestamp:
- 08/26/11 20:40:35 (13 years ago)
- Location:
- MDService2/trunk/MDService2
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
MDService2/trunk/MDService2/WebContent/scripts/mdservice_model.js
r1493 r1496 804 804 uri = link('base',this.query_uri()); 805 805 } else { 806 if (type == "xml"){807 uri = link('sru',this.sruquery_uri());808 } else {806 //if (type == "xml"){ 807 // uri = link('sru',this.sruquery_uri()); 808 //} else { 809 809 uri = link('recordset',type, this.query_uri()); 810 }810 // } 811 811 } 812 812 return uri; … … 840 840 841 841 // USE CLIENT PAZPAR 842 /* 842 843 if (reptype=="pazpar"){ 843 844 //pazpar handling this … … 845 846 return; 846 847 } 848 */ 849 // ALL types = query uri, 850 // pazpar server usage 851 uri = link('recordset',this.format, this.query_uri()); 847 852 853 /* 848 854 if (reptype=="md" ){ 849 855 uri = link('recordset',this.format, this.query_uri()); … … 861 867 } 862 868 } 869 */ 863 870 864 871 -
MDService2/trunk/MDService2/WebContent/simple_index.jsp
r1423 r1496 17 17 <body> 18 18 <form action="recordset/htmlsimple/" method="get"> 19 <select name="repository"> 20 <option value="clarin.at-mirror">clarin.at-mirror</option> 21 <option value="gu.se-main">gu.se-main</option> 22 <option value="sru-corpus-ddcon">sru-corpus-ddcon</option> 23 <option value="pazpar">pazpar</option> 24 </select> 25 19 26 <input type="text" name="q" ></input> 20 27 -
MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/CollectionProxyAction.java
r1108 r1496 4 4 import java.net.MalformedURLException; 5 5 import java.net.URL; 6 7 import eu.clarin.cmdi.mdservice.model.WorkspaceProfile; 6 8 7 9 import net.sf.json.JSONObject; … … 55 57 if (base_url == null) { 56 58 //base_url = new URL(Admin.getConfig().getProperty(getProxyKey() + ".uri")); 57 base_url = new URL( getRepositoryPath());59 base_url = new URL(WorkspaceProfile.getRepositoryPath(getRepository())); 58 60 //Admin.notifyUser("TEST-URLnew:" + base_url.toString()); 59 61 -
MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/GenericProxyAction.java
r1495 r1496 28 28 import com.opensymphony.xwork2.ActionSupport; 29 29 import eu.clarin.cmdi.mdservice.model.Diagnostics; 30 import eu.clarin.cmdi.mdservice.model.WorkspaceProfile; 30 31 31 32 /** … … 42 43 private static final long serialVersionUID = 1L; 43 44 44 private static JSONArray repositories = null;45 private static JSONObject wp_options = null;46 45 47 46 private Diagnostics diagnostics; … … 78 77 79 78 public void setRepositoryByIndex(int id){ 80 try { 81 setRepositories(GenericProxyAction.createRepositories()); 82 // static repositories 83 net.sf.json.JSONArray json = getRepositories(); 79 80 net.sf.json.JSONArray json = WorkspaceProfile.getRepositories(); 84 81 if (json.size() > 0){ 85 82 repository = json.getJSONObject(id).getString("name"); 86 83 } 87 } catch (IOException e) { 88 // TODO Auto-generated catch block 89 e.printStackTrace(); 90 } catch (InterruptedException e) { 91 // TODO Auto-generated catch block 92 e.printStackTrace(); 93 } catch (TransformerException e) { 94 // TODO Auto-generated catch block 95 e.printStackTrace(); 96 } catch (NoStylesheetException e) { 97 // TODO Auto-generated catch block 98 e.printStackTrace(); 99 } 84 100 85 } 101 86 … … 327 312 */ 328 313 329 public JSONArray getRepositories(){330 return repositories;331 }332 333 public void setRepositories(JSONArray rep){334 GenericProxyAction.repositories = rep;335 }336 337 public JSONObject getWPOptions(){338 return wp_options;339 }340 341 public void setWPOptions(JSONObject op){342 GenericProxyAction.wp_options = op;343 }344 314 345 315 /** … … 435 405 } 436 406 437 /* 438 * TODO: this should go to Utilities! 439 */ 440 public static String convertStreamToString(InputStream is) { 441 442 BufferedReader reader = new BufferedReader(new InputStreamReader(is)); 443 StringBuilder sb = new StringBuilder(); 444 String line = null; 445 446 try { 447 while ((line = reader.readLine()) != null) { 448 sb.append(line + "\n"); 449 } 450 } catch (IOException e) { 451 // TODO Auto-generated catch block 452 e.printStackTrace(); 453 } finally { 454 try { 455 is.close(); 456 } catch (IOException e) { 457 // TODO Auto-generated catch block 458 e.printStackTrace(); 459 } 460 try { 461 is.reset(); 462 } catch (IOException e) { 463 // TODO Auto-generated catch block 464 e.printStackTrace(); 465 } 466 } 467 468 469 return sb.toString(); 470 } 471 472 473 public static JSONArray createRepositories() throws IOException, InterruptedException, TransformerException, NoStylesheetException{ 474 String path = Admin.getConfig().getProperty("workspaceprofile.path") + WorkspaceAction.WORKSPACE_FILENAME;//PROFILENAME_SERVER; 475 File file=new File(path); 476 InputStream in = new BufferedInputStream( new FileInputStream(path));; 477 478 MDTransformer transformer = new MDTransformer(); 479 transformer.setSrcFile(file.toURI().toURL()); 480 transformer.setParams(MDTransformer.createParamsMap("xml2json")); 481 InputStream jsonstream = transformer.transformXML(in); 482 483 JSONObject json = JSONObject.fromObject(convertStreamToString(jsonstream)); 484 JSONArray wparray = json.getJSONObject("Profiles").getJSONArray("WorkspaceProfiles"); 485 JSONArray array = null; 486 for (int i = 0; i < wparray.size(); ++i) { 487 JSONObject wp = wparray.getJSONObject(i); 488 if (wp.get("Repositories") != null){ 489 array = wp.getJSONArray("Repositories"); 490 break; 491 } 492 } 493 494 // repository as static variable 495 return array; 496 497 // repository as session attribute 498 /* 499 HttpSession session = getServletRequest().getSession(); 500 //JSONArray param = (JSONArray) session.getAttribute("repositories"); 501 JSONArray param = new JSONArray(); 502 param.add(array); 503 session.setAttribute("repositories", param); 504 */ 505 } 506 507 public static JSONObject createWPOptions() throws IOException, InterruptedException, TransformerException, NoStylesheetException{ 508 String path = Admin.getConfig().getProperty("workspaceprofile.path") + WorkspaceAction.WORKSPACE_FILENAME;//PROFILENAME_SERVER; 509 File file=new File(path); 510 InputStream in = new BufferedInputStream( new FileInputStream(path));; 511 512 MDTransformer transformer = new MDTransformer(); 513 transformer.setSrcFile(file.toURI().toURL()); 514 transformer.setParams(MDTransformer.createParamsMap("xml2json")); 515 InputStream jsonstream = transformer.transformXML(in); 516 517 JSONObject json = JSONObject.fromObject(convertStreamToString(jsonstream)); 518 JSONArray wparray = json.getJSONObject("Profiles").getJSONArray("WorkspaceProfiles"); 519 JSONObject obj = null; 520 for (int i = 0; i < wparray.size(); ++i) { 521 JSONObject wp = wparray.getJSONObject(i); 522 if (wp.get("Options") != null){ 523 obj = wp.getJSONObject("Options"); 524 break; 525 } 526 } 527 528 // options as static variable 529 return obj; 530 531 } 532 533 public String getWPOption(String opt_key){ 534 String option_val = null; 535 536 537 if (wp_options == null ) { 538 try { 539 setWPOptions(GenericProxyAction.createWPOptions()); 540 } catch (IOException e) { 541 // TODO Auto-generated catch block 542 e.printStackTrace(); 543 } catch (InterruptedException e) { 544 // TODO Auto-generated catch block 545 e.printStackTrace(); 546 } catch (TransformerException e) { 547 // TODO Auto-generated catch block 548 e.printStackTrace(); 549 } catch (NoStylesheetException e) { 550 // TODO Auto-generated catch block 551 e.printStackTrace(); 552 } 553 } 554 // static options 555 if (wp_options != null){ 556 net.sf.json.JSONObject json = getWPOptions(); 557 option_val = json.getString(opt_key); 558 } 559 560 561 return option_val; 562 563 } 564 565 public String getRepositoryPath(){ 566 String repository_path = null; 567 568 569 if (repositories == null ) { 570 try { 571 setRepositories(GenericProxyAction.createRepositories()); 572 } catch (IOException e) { 573 // TODO Auto-generated catch block 574 e.printStackTrace(); 575 } catch (InterruptedException e) { 576 // TODO Auto-generated catch block 577 e.printStackTrace(); 578 } catch (TransformerException e) { 579 // TODO Auto-generated catch block 580 e.printStackTrace(); 581 } catch (NoStylesheetException e) { 582 // TODO Auto-generated catch block 583 e.printStackTrace(); 584 } 585 } 586 // static repositories 587 net.sf.json.JSONArray json = getRepositories(); 588 for(int i=0;i<json.size();i++){ 589 if (json.getJSONObject(i).getString("name").equals(getRepository())){ 590 repository_path = json.getJSONObject(i).getString("uri"); 591 } 592 } 593 //Admin.notifyUser("REPOSITORY_PATH:" + repository_path); 594 595 //session repositories 596 /* 597 HttpSession session = getServletRequest().getSession(); 598 json = (net.sf.json.JSONArray) session.getAttribute("repositories"); 599 for(int i=0;i<json.size();i++){ 600 if (json.getJSONObject(i).getInt("id") == getRepository()){ 601 repository_path = json.getJSONObject(i).getString("uri"); 602 } 603 } 604 Admin.notifyUser("REPOSITORY_PATH-SESSIONATTR:" + repository_path); 605 */ 606 return repository_path; 607 608 } 609 610 public String getRepositoryType(){ 611 String typestr = ""; 612 613 if (repositories == null ) { 614 try { 615 setRepositories(GenericProxyAction.createRepositories()); 616 } catch (IOException e) { 617 // TODO Auto-generated catch block 618 e.printStackTrace(); 619 } catch (InterruptedException e) { 620 // TODO Auto-generated catch block 621 e.printStackTrace(); 622 } catch (TransformerException e) { 623 // TODO Auto-generated catch block 624 e.printStackTrace(); 625 } catch (NoStylesheetException e) { 626 // TODO Auto-generated catch block 627 e.printStackTrace(); 628 } 629 } 630 // static repositories 631 net.sf.json.JSONArray json = getRepositories(); 632 for(int i=0;i<json.size();i++){ 633 if (json.getJSONObject(i).getString("name").equals(getRepository())){ 634 typestr = json.getJSONObject(i).getString("type"); 635 } 636 } 637 638 return (typestr); 639 640 } 641 public Boolean isSRURepository(){ 642 //Boolean issru = false; 643 String typestr = getRepositoryType(); 644 645 return (typestr.equals("sru")); 646 647 } 648 public String addDurationKey(){ 407 408 409 public String addDurationKey(){ 649 410 String req_key = getRequestKey(); 650 411 … … 682 443 } 683 444 //if (getRepository() != null){ 684 hm.put("repository_name", String.valueOf(getRepository())); 445 hm.put("repository_name", String.valueOf(getRepository())); 446 hm.put("repository_type", WorkspaceProfile.getRepositoryType(this.getRepository())); 685 447 //} 686 448 -
MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/Helpers.java
r627 r1496 1 1 package eu.clarin.cmdi.mdservice.action; 2 2 3 import java.io.BufferedReader; 3 4 import java.io.IOException; 4 5 import java.io.InputStream; 6 import java.io.InputStreamReader; 5 7 import java.io.OutputStream; 6 8 import java.io.PrintStream; … … 10 12 import javax.xml.parsers.FactoryConfigurationError; 11 13 import javax.xml.parsers.ParserConfigurationException; 14 import javax.xml.xpath.XPath; 15 import javax.xml.xpath.XPathConstants; 16 import javax.xml.xpath.XPathExpression; 17 import javax.xml.xpath.XPathExpressionException; 18 import javax.xml.xpath.XPathFactory; 12 19 13 20 import org.w3c.dom.Document; … … 64 71 } 65 72 } 73 74 75 public static Document getDocument(InputStream is){ 76 Document doc = null; 77 DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); 78 DocumentBuilder docBuilder; 79 try { 80 docBuilder = docFactory.newDocumentBuilder(); 81 doc = docBuilder.parse(is); 82 } catch (ParserConfigurationException e) { 83 // TODO Auto-generated catch block 84 e.printStackTrace(); 85 } catch (SAXException e) { 86 // TODO Auto-generated catch block 87 e.printStackTrace(); 88 } catch (IOException e) { 89 // TODO Auto-generated catch block 90 e.printStackTrace(); 91 } 92 return doc; 93 } 94 95 public static String getDocumentData(InputStream is, String expression){ 96 String data = ""; 97 98 XPathFactory factory = XPathFactory.newInstance(); 99 XPath xpath = factory.newXPath(); 100 XPathExpression expr; 101 try { 102 expr = xpath.compile(expression); 103 data = (String) expr.evaluate(getDocument(is), XPathConstants.STRING); 104 } catch (XPathExpressionException e) { 105 // TODO Auto-generated catch block 106 e.printStackTrace(); 107 } 108 109 return data; 110 111 } 112 /* 113 * TODO: this should go to Utilities! 114 */ 115 public static String convertStreamToString(InputStream is) { 116 117 BufferedReader reader = new BufferedReader(new InputStreamReader(is)); 118 StringBuilder sb = new StringBuilder(); 119 String line = null; 120 121 try { 122 while ((line = reader.readLine()) != null) { 123 sb.append(line + "\n"); 124 } 125 } catch (IOException e) { 126 // TODO Auto-generated catch block 127 e.printStackTrace(); 128 } finally { 129 try { 130 is.close(); 131 } catch (IOException e) { 132 // TODO Auto-generated catch block 133 e.printStackTrace(); 134 } 135 try { 136 is.reset(); 137 } catch (IOException e) { 138 // TODO Auto-generated catch block 139 e.printStackTrace(); 140 } 141 } 142 143 144 return sb.toString(); 145 } 146 66 147 67 148 } -
MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/MDRepoProxyAction.java
r1495 r1496 27 27 28 28 import eu.clarin.cmdi.mdservice.model.Query; 29 import eu.clarin.cmdi.mdservice.model.WorkspaceProfile; 29 30 30 31 /** … … 49 50 @Override 50 51 public String getBaseURI() { 51 String uri = getRepositoryPath();52 String uri = WorkspaceProfile.getRepositoryPath(getRepository()); 52 53 return uri; 53 54 } … … 75 76 } 76 77 78 public String fullQueryString(){ 79 String full_query_string= this.getQ(); 80 81 if (!getSquery().equals("") && !this.getQ().equals("")){ 82 full_query_string = "(" + this.getSquery() + " ) and (" + this.getQ() + ")"; 83 } else if (!this.getSquery().equals("")) { 84 full_query_string = this.getSquery(); 85 } else if (!this.getQ().equals("")){ 86 full_query_string = this.getQ(); 87 } else { 88 full_query_string = ""; 89 } 90 91 return full_query_string; 92 } 93 77 94 /** 78 95 * uses base_url + url_pattern (parametrized by actionkey) to form a url … … 80 97 * @throws Exception 81 98 */ 99 @Override 82 100 public URL getTargetRequest() throws IOException { 83 101 // URL targetURL =new URL( base_url, compname + ".xml"); … … 113 131 114 132 @Override 133 public InputStream getSourceStream() throws IOException, NoStylesheetException { 134 135 /*if (getCommand() == null){ 136 try { 137 return getSourcePz2(); 138 } catch (Exception e) { 139 // TODO Auto-generated catch block 140 e.printStackTrace(); 141 } 142 } 143 */ 144 return super.getSourceStream(); 145 } 146 147 @Override 115 148 public void prepare() throws Exception{ 116 149 super.prepare(); -
MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/Pz2ProxyAction.java
r1492 r1496 34 34 35 35 import eu.clarin.cmdi.mdservice.model.Query; 36 import eu.clarin.cmdi.mdservice.model.WorkspaceProfile; 36 37 37 38 /** … … 122 123 @Override 123 124 public String getBaseURI() { 124 String uri = getRepositoryPath();125 String uri = WorkspaceProfile.getRepositoryPath(getRepository()); 125 126 return uri; 126 127 } … … 135 136 } 136 137 137 138 /* 138 139 @Override 139 140 public InputStream getSourceStream() throws IOException, NoStylesheetException { … … 186 187 187 188 } 189 */ 190 /* 188 191 public InputStream getSourcePz2() throws Exception { 189 192 … … 224 227 return is; 225 228 } 226 229 */ 227 230 228 231 } -
MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/SRUProxyAction.java
r1471 r1496 51 51 import eu.clarin.cmdi.mdservice.model.Diagnostic; 52 52 import eu.clarin.cmdi.mdservice.model.Diagnostics; 53 import eu.clarin.cmdi.mdservice.model.WorkspaceProfile; 53 54 54 55 … … 79 80 private String x_cmd_repository; 80 81 private String x_cmd_collections; 82 private Set paramSet; 81 83 82 84 private MDRepoProxyAction mdrepoproxyaction; … … 88 90 private static int OP_EXPLAIN = 2; 89 91 private static int OP_SCAN = 3; 92 90 93 91 94 //TODO cache after analysis … … 120 123 this.startRecord = 1; 121 124 this.maximumRecords = 50; 125 126 if (getServletRequest() != null){ 127 this.setX_cmd_repository(getServletRequest().getParameter("x-cmd-repository")); 128 this.setRepository(this.getX_cmd_repository()); 129 paramSet = getServletRequest().getParameterMap().entrySet(); 130 } 131 132 //TODO xsl usage according particular repositories ? 133 this.setActionkey("sru"); 122 134 } 123 135 … … 285 297 @Override 286 298 public String getBaseURI() { 287 Admin.notifyUser("SRU-repositorypath:" + getRepositoryPath());288 String uri = getRepositoryPath();//Admin.getConfig().getProperty(getProxyKey() + ".uri");299 Admin.notifyUser("SRU-repositorypath:" + WorkspaceProfile.getRepositoryPath(getRepository())); 300 String uri = WorkspaceProfile.getRepositoryPath(getRepository());//Admin.getConfig().getProperty(getProxyKey() + ".uri"); 289 301 return uri; 290 302 } … … 358 370 if (this.scanClause.equals("cmd.Repository")){ 359 371 XMLSerializer xmlserializer = new XMLSerializer(); 360 String xml = xmlserializer.write( mdrepoproxyaction.getRepositories() );372 String xml = xmlserializer.write( WorkspaceProfile.getRepositories());//mdrepoproxyaction.getRepositories() ); 361 373 this.setResultStream(new ByteArrayInputStream(xml.getBytes("UTF-8"))); 362 374 … … 498 510 } 499 511 512 //TODO create query + query.toURLParams ? 513 public String createURLParams(){ 514 String params = ""; 515 516 //TODO params 517 if (paramSet == null){ 518 if (!(operation == null)){ 519 params = params + "operation=" + operation; 520 } 521 if (!(version == null)){ 522 params = params + "&version=" + version; 523 } 524 if (!(query == null)){ 525 params = params + "&query=" + query; 526 } 527 if (getStartRecord() > 0){ 528 params = params + "&startRecord=" + String.valueOf(getStartRecord()); 529 } 530 if (getMaximumRecords()> 0){ 531 params = params + "&numRecords=" + String.valueOf(getMaximumRecords()); 532 } 533 } else { 534 Iterator i = paramSet.iterator(); 535 params = ""; 536 while(i.hasNext()){ 537 Map.Entry me = (Map.Entry)i.next(); 538 if (!(me.getKey().equals("x-cmd-repository") || me.getKey().equals("x-cmd-collections"))){ 539 params = params + "&" + me.getKey() + "=" + ((String[])me.getValue())[0]; 540 } 541 } 542 params = params.substring(1); 543 544 } 545 546 return params; 547 } 500 548 @Override 501 549 public URL getTargetRequest() throws IOException { … … 508 556 requestURI = this.getBaseURI(); 509 557 } 510 //TODO params 511 Set set = getServletRequest().getParameterMap().entrySet(); 512 Iterator i = set.iterator(); 513 String params = ""; 514 while(i.hasNext()){ 515 Map.Entry me = (Map.Entry)i.next(); 516 if (!(me.getKey().equals("x-cmd-repository") || me.getKey().equals("x-cmd-collections"))){ 517 params = params + "&" + me.getKey() + "=" + ((String[])me.getValue())[0]; 518 } 519 } 520 params = params.substring(1); 521 targetURL = new URL(requestURI + "?" + params); 558 559 targetURL = new URL(requestURI + "?" + createURLParams()); 522 560 return targetURL; 523 561 } … … 525 563 @Override 526 564 public void prepare() throws Exception{ 527 this.setX_cmd_repository(getServletRequest().getParameter("x-cmd-repository"));528 this.setRepository(this.getX_cmd_repository());565 //this.setX_cmd_repository(getServletRequest().getParameter("x-cmd-repository")); 566 //this.setRepository(this.getX_cmd_repository()); 529 567 //TODO xsl usage according particular repositories ? 530 this.setActionkey("sru");568 //this.setActionkey("sru"); 531 569 //this.setFormat("xml"); 532 570 533 571 //extern SRU repository 534 if ( this.isSRURepository() || this.getBaseURI() == null){572 if (WorkspaceProfile.isSRURepository(getRepository()) || this.getBaseURI() == null){ 535 573 super.prepare(); 536 574 } -
MDService2/trunk/MDService2/src/struts.xml
r1488 r1496 278 278 279 279 <!-- <action name="*/*" class="eu.clarin.cmdi.mdservice.action.MDServiceAction" method="{2}"> --> 280 <action name="*/*" class="eu.clarin.cmdi.mdservice.action.MDRepoProxyAction" method="execute"> 280 <!-- <action name="*/*" class="eu.clarin.cmdi.mdservice.action.MDRepoProxyAction" method="execute"> --> 281 <action name="*/*" class="eu.clarin.cmdi.mdservice.action.RepoProxyAction" method="execute"> 281 282 <param name="format">{2}</param> 282 283 <param name="actionkey">{1}</param> … … 289 290 <!-- We accept the q-param encoded in the url as well. 290 291 Especially meant for simple queries (for example for collections) --> 291 <action name="*/*/*/*" class="eu.clarin.cmdi.mdservice.action.MDRepoProxyAction" method="execute"> 292 <!-- <action name="*/*/*/*" class="eu.clarin.cmdi.mdservice.action.MDRepoProxyAction" method="execute"> --> 293 <action name="*/*/*/*" class="eu.clarin.cmdi.mdservice.action.RepoProxyAction" method="execute"> 294 292 295 <param name="actionkey">{1}</param> 293 296 <param name="format">{2}</param>
Note: See TracChangeset
for help on using the changeset viewer.