Changeset 1467 for MDService2/trunk/MDService2/src/eu/clarin/cmdi
- Timestamp:
- 07/22/11 21:31:08 (13 years ago)
- Location:
- MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/GenericProxyAction.java
r1455 r1467 525 525 public Boolean isSRURepository(){ 526 526 //Boolean issru = false; 527 String srustr = "";527 String typestr = ""; 528 528 529 529 if (repositories == null ) { … … 545 545 for(int i=0;i<json.size();i++){ 546 546 if (json.getJSONObject(i).getString("name").equals(getRepository())){ 547 srustr = json.getJSONObject(i).getString("sruextern");548 } 549 } 550 551 return ( srustr.equals("1"));547 typestr = json.getJSONObject(i).getString("type"); 548 } 549 } 550 551 return (typestr.equals("sru")); 552 552 553 553 } -
MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/SRUProxyAction.java
r1455 r1467 53 53 54 54 55 public class SRUProxyAction extends ActionSupport56 implements ServletRequestAware55 public class SRUProxyAction extends GenericProxyAction//ActionSupport 56 //implements ServletRequestAware 57 57 { 58 58 … … 82 82 private MDRepoProxyAction mdrepoproxyaction; 83 83 private TermsProxyAction termsproxyaction; 84 private InputStream resultStream;85 private HttpServletRequest request;84 //private InputStream resultStream; 85 //private HttpServletRequest request; 86 86 87 87 private static int OP_SEARCHRETRIEVE = 1; 88 88 private static int OP_EXPLAIN = 2; 89 89 private static int OP_SCAN = 3; 90 91 //TODO cache after analysis 92 @Override 93 public String getCache() { 94 return Cache.SKIP; 95 } 90 96 91 97 private final static HashMap<String,String> hash_operations = new HashMap<String,String>(); … … 116 122 } 117 123 118 @Override124 /*@Override 119 125 public void setServletRequest(HttpServletRequest arg0) { 120 126 request = arg0; … … 124 130 return request; 125 131 } 126 132 */ 127 133 public Diagnostics getDiagnostics(){ 128 134 return this.diagnostics; … … 141 147 this.q = q; 142 148 } 143 149 /* 144 150 public InputStream getResultStream() { 145 151 return resultStream; … … 148 154 resultStream = _resultStream; 149 155 } 150 156 */ 151 157 152 158 public String getVersion() { … … 264 270 265 271 public String getDiagnosticStreamName() throws TransformerConfigurationException, UnsupportedEncodingException, ParserConfigurationException, TransformerException, TransformerFactoryConfigurationError{ 266 resultStream = this.Diagnostics().buildXMLStream();272 this.setResultStream(this.Diagnostics().buildXMLStream()); 267 273 return "resultStream"; 268 274 } … … 275 281 public String getProxyKey() { 276 282 return ""; 283 } 284 285 @Override 286 public String getBaseURI() { 287 Admin.notifyUser("SRU-repositorypath:" + getRepositoryPath()); 288 String uri = getRepositoryPath();//Admin.getConfig().getProperty(getProxyKey() + ".uri"); 289 return uri; 277 290 } 278 291 … … 346 359 XMLSerializer xmlserializer = new XMLSerializer(); 347 360 String xml = xmlserializer.write( mdrepoproxyaction.getRepositories() ); 348 resultStream = new ByteArrayInputStream(xml.getBytes("UTF-8"));361 this.setResultStream(new ByteArrayInputStream(xml.getBytes("UTF-8"))); 349 362 350 363 } else { … … 359 372 } 360 373 361 public void prepare() throws UnsupportedEncodingException{374 public void sru2MD() throws UnsupportedEncodingException{ 362 375 // special handling of parameter setting, x-cmd-... not alowed in java 363 376 this.setX_cmd_collections(getServletRequest().getParameter("x-cmd-collections")); … … 393 406 } 394 407 408 public void prepareMD() throws Exception{ 409 sru2MD(); 410 if (Diagnostics().Accepted()){ 411 // root-explain 412 if (this.termsproxyaction != null) { 413 if (this.termsproxyaction.execute() == SUCCESS){ 414 this.setResultStream(this.termsproxyaction.getResultStream()); 415 //return SUCCESS; 416 } 417 } else { 418 //TODO diagnostic 419 if (this.mdrepoproxyaction.getTargetRequest() == null) { 420 Diagnostics().Add(Diagnostic.QUERYSYNTAXERROR); 421 //return ERROR; 422 } 423 if (this.mdrepoproxyaction.execute() == SUCCESS){ 424 this.setResultStream(this.mdrepoproxyaction.getResultStream()); 425 postprocess(); 426 //return SUCCESS; 427 } 428 } 429 } 430 //return ERROR; 431 } 432 395 433 public static String inputStreamAsString(InputStream stream) 396 434 throws IOException { … … 435 473 if (this.getRecordPacking().toLowerCase().equals("string")){ 436 474 try { 437 resultStream = IOUtils.toInputStream(StringEscapeUtils.escapeXml(inputStreamAsString(resultStream)));475 this.setResultStream(IOUtils.toInputStream(StringEscapeUtils.escapeXml(inputStreamAsString(this.getResultStream())))); 438 476 } catch (IOException e) { 439 477 // TODO Auto-generated catch block … … 446 484 // add diagnostics 447 485 if (Diagnostics().Exists()){ 448 Document doc = newDocumentFromInputStream( resultStream);486 Document doc = newDocumentFromInputStream(this.getResultStream()); 449 487 Node r_element= doc.getElementsByTagName("searchRetrieveResponse").item(0); 450 488 Document ddoc = Diagnostics().buildXMLDocument(); … … 456 494 StreamResult result = new StreamResult(xmlAsWriter); 457 495 TransformerFactory.newInstance().newTransformer().transform(source, result); 458 resultStream = new ByteArrayInputStream(xmlAsWriter.toString().getBytes("UTF-8")); 459 } 460 } 461 496 this.setResultStream(new ByteArrayInputStream(xmlAsWriter.toString().getBytes("UTF-8"))); 497 } 498 } 499 500 @Override 501 public URL getTargetRequest() throws IOException { 502 String requestURI = ""; 503 URL targetURL; 504 505 if (this.getBaseURI() == null){ 506 requestURI = this.getX_cmd_repository(); 507 } else { 508 requestURI = this.getBaseURI(); 509 } 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); 522 return targetURL; 523 } 524 525 @Override 526 public void prepare() throws Exception{ 527 this.setX_cmd_repository(getServletRequest().getParameter("x-cmd-repository")); 528 this.setRepository(this.getX_cmd_repository()); 529 //TODO xsl usage according particular repositories ? 530 //this.setActionkey("recordset"); 531 this.setFormat("xml"); 532 533 //extern SRU repository 534 if (this.isSRURepository() || this.getBaseURI() == null){ 535 super.prepare(); 536 } 537 else { 538 prepareMD(); 539 } 540 541 } 462 542 /** 463 543 * default Action method 464 544 */ 545 /* 465 546 public String execute() throws Exception { 466 547 this.setX_cmd_repository(getServletRequest().getParameter("x-cmd-repository")); … … 514 595 return ERROR; 515 596 } 516 597 */ 517 598 518 599 }
Note: See TracChangeset
for help on using the changeset viewer.