comparison src/de/mpiwg/itgroup/eSciDoc/Tools/EScidocBasicHandler.java @ 2:fab8e78184fa

minor
author dwinter
date Mon, 10 Jan 2011 12:42:27 +0100
parents c6929e63b0b8
children 58b52df9763c
comparison
equal deleted inserted replaced
1:6b0267cb40ed 2:fab8e78184fa
234 HttpEntity entity = new InputStreamEntity(body, -1); 234 HttpEntity entity = new InputStreamEntity(body, -1);
235 ((HttpEntityEnclosingRequestBase)httpBase).setEntity(entity); 235 ((HttpEntityEnclosingRequestBase)httpBase).setEntity(entity);
236 } 236 }
237 } 237 }
238 238
239 logger.debug("executing request:"+httpBase.getRequestLine()); 239 //logger.debug("executing request:"+httpBase.getRequestLine());
240 240
241 241
242 HttpResponse status = httpclient.execute(httpBase); 242 HttpResponse status = httpclient.execute(httpBase);
243 //HttpEntity responseEntity = response.getEntity(); 243 //HttpEntity responseEntity = response.getEntity();
244 244
508 508
509 509
510 510
511 public HttpResponse submitAnObject(eSciDocXmlObject obj, String comment) throws ClientProtocolException, IOException, JDOMException { 511 public HttpResponse submitAnObject(eSciDocXmlObject obj, String comment) throws ClientProtocolException, IOException, JDOMException {
512 try { 512 try {
513 addVersionPid(obj); 513 //addVersionPid(obj);
514 } catch (Exception e) { 514 } catch (Exception e) {
515 // TODO: handle exception 515 // TODO: handle exception
516 } 516 }
517 517
518 String retTxt = obj.printXML(); 518 String retTxt = obj.printXML();
538 //new ByteArrayInputStream(filter.getBytes())); 538 //new ByteArrayInputStream(filter.getBytes()));
539 539
540 //String command = context+"/resources/members"; 540 //String command = context+"/resources/members";
541 541
542 HttpResponse result =eScidocGet(command); 542 HttpResponse result =eScidocGet(command);
543 //InputStream text=result.getEntity().getContent();
544 //String tmtxt = convertStreamToString(text);
545 //System.out.println(tmtxt);
543 Document dom = new SAXBuilder().build(result.getEntity().getContent()); 546 Document dom = new SAXBuilder().build(result.getEntity().getContent());
544 XPath xp = EScidocTools.getESciDocXpath(objectXpath); 547 XPath xp = EScidocTools.getESciDocXpath(objectXpath);
548
545 549
546 List<Element> attr = (List<Element>)xp.selectNodes(dom); 550 List<Element> attr = (List<Element>)xp.selectNodes(dom);
547 ArrayList<eSciDocXmlObject> ret = new ArrayList<eSciDocXmlObject>(); 551 ArrayList<eSciDocXmlObject> ret = new ArrayList<eSciDocXmlObject>();
548 for (Element el: attr){ 552 for (Element el: attr){
549 ret.add(new eSciDocXmlObject(el)); 553 ret.add(new eSciDocXmlObject(el));
550 } 554 }
551 return ret; 555 return ret;
552 } 556 }
553 557
558 public Integer getNumberOfHitsFromFilterResult(String command,
559 String objectXPath, int mode) throws IOException, IllegalStateException, JDOMException {
560 String query="";
561 if(mode==0 | mode==2){
562 query="query=%22/properties/version/status%22=pending";
563 } else {
564 query="query=%22/properties/version/status%22=submitted";
565 }
566
567 HttpResponse result =eScidocGet(command+"?maximumRecords=1&"+query);
568 //InputStream text=result.getEntity().getContent();
569 //String tmtxt = convertStreamToString(text);
570 //System.out.println(tmtxt);
571 Document dom = new SAXBuilder().build(result.getEntity().getContent());
572 XPath xp = EScidocTools.getESciDocXpath("//srw:numberOfRecords");
573
574 Element attr = (Element)xp.selectSingleNode(dom);
575
576 Integer tmpInt = Integer.valueOf(attr.getText());
577 return tmpInt;
578 }
579
554 public boolean addVersionPid(eSciDocXmlObject obj) throws ClientProtocolException, IOException, JDOMException{ 580 public boolean addVersionPid(eSciDocXmlObject obj) throws ClientProtocolException, IOException, JDOMException{
555 //HttpResponse ret = eScidocGet(href); 581 //HttpResponse ret = eScidocGet(href);
556 //String retTxt = EScidocBasicHandler.convertStreamToString(ret.getEntity().getContent()); 582 //String retTxt = EScidocBasicHandler.convertStreamToString(ret.getEntity().getContent());
557 583
558 String retTxt = obj.printXML(); 584 String retTxt = obj.printXML();
569 595
570 HttpResponse result = eScidocPost(command, EScidocBasicHandler.convertStringToStream(param)); 596 HttpResponse result = eScidocPost(command, EScidocBasicHandler.convertStringToStream(param));
571 597
572 int code = result.getStatusLine().getStatusCode(); 598 int code = result.getStatusLine().getStatusCode();
573 result.getEntity().consumeContent(); 599 result.getEntity().consumeContent();
574 if (code!=200) 600 if (code!=200){
601 if(code==450)
602 return false;
575 return false; 603 return false;
604 }
576 return true; 605 return true;
577 606
578 607
579 } 608 }
580 609
677 fw.write(idStr+","+urlStr+"\n"); 706 fw.write(idStr+","+urlStr+"\n");
678 } 707 }
679 fw.close(); 708 fw.close();
680 return ret; 709 return ret;
681 } 710 }
711
712
713
714
682 } 715 }