Changeset 1481
- Timestamp:
- 08/18/11 12:25:18 (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
r1467 r1481 523 523 } 524 524 525 public Boolean isSRURepository(){ 526 //Boolean issru = false; 527 String typestr = ""; 525 public String getRepositoryType(){ 526 String typestr = ""; 528 527 529 528 if (repositories == null ) { … … 548 547 } 549 548 } 549 550 return (typestr); 551 552 } 553 public Boolean isSRURepository(){ 554 //Boolean issru = false; 555 String typestr = getRepositoryType(); 550 556 551 557 return (typestr.equals("sru")); … … 594 600 595 601 } 602 596 603 597 604 public void prepare() throws Exception { -
MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/Pz2ProxyAction.java
r1472 r1481 14 14 import javax.xml.parsers.DocumentBuilder; 15 15 import javax.xml.parsers.DocumentBuilderFactory; 16 import javax.xml.parsers.ParserConfigurationException; 16 17 import javax.xml.transform.OutputKeys; 17 18 import javax.xml.transform.Transformer; … … 20 21 import javax.xml.transform.dom.DOMSource; 21 22 import javax.xml.transform.stream.StreamResult; 23 import javax.xml.xpath.XPath; 24 import javax.xml.xpath.XPathConstants; 25 import javax.xml.xpath.XPathExpression; 26 import javax.xml.xpath.XPathExpressionException; 27 import javax.xml.xpath.XPathFactory; 22 28 23 29 import org.w3c.dom.Document; … … 25 31 import org.w3c.dom.NodeList; 26 32 import org.xml.sax.InputSource; 33 import org.xml.sax.SAXException; 27 34 28 35 import eu.clarin.cmdi.mdservice.model.Query; … … 74 81 return block; 75 82 } 83 84 @Override 85 protected void initialize(){ 86 super.initialize(); 87 this.setActionkey("pazpar2"); 88 } 89 76 90 //TODO cache after analysis 77 91 @Override … … 121 135 } 122 136 137 138 @Override 139 public InputStream getSourceStream() throws IOException { 140 if (getCommand().equals("")){ 141 try { 142 return getSourcePz2(); 143 } catch (Exception e) { 144 // TODO Auto-generated catch block 145 e.printStackTrace(); 146 } 147 } 148 149 return super.getSourceStream(); 150 } 151 152 public Document getDocument(InputStream is){ 153 Document doc = null; 154 DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); 155 DocumentBuilder docBuilder; 156 try { 157 docBuilder = docFactory.newDocumentBuilder(); 158 doc = docBuilder.parse(is); 159 } catch (ParserConfigurationException e) { 160 // TODO Auto-generated catch block 161 e.printStackTrace(); 162 } catch (SAXException e) { 163 // TODO Auto-generated catch block 164 e.printStackTrace(); 165 } catch (IOException e) { 166 // TODO Auto-generated catch block 167 e.printStackTrace(); 168 } 169 return doc; 170 } 171 public String getDocumentData(InputStream is, String expression){ 172 String sessionid = ""; 173 174 XPathFactory factory = XPathFactory.newInstance(); 175 XPath xpath = factory.newXPath(); 176 XPathExpression expr; 177 try { 178 expr = xpath.compile(expression); 179 sessionid = (String) expr.evaluate(getDocument(is), XPathConstants.STRING); 180 } catch (XPathExpressionException e) { 181 // TODO Auto-generated catch block 182 e.printStackTrace(); 183 } 184 185 return sessionid; 186 187 } 188 public InputStream getSourcePz2() throws Exception { 189 190 InputStream is = null; 191 192 //init 193 setCommand("init"); 194 String sessionID = getDocumentData(this.getSourceStream(), "//init/session"); 195 // get result 196 setCommand("search"); 197 setSessionID(sessionID); 198 String ok = getDocumentData(this.getSourceStream(),"//search/status"); 199 200 String activeclients = "1"; 201 setCommand("show"); 202 while (Integer.parseInt(activeclients) > 0){ 203 is = this.getSourceStream(); 204 activeclients = getDocumentData(is, "//show/activeclients"); 205 206 } 207 return is; 208 } 209 210 123 211 }
Note: See TracChangeset
for help on using the changeset viewer.