1 16 package sample.google.search; 17 18 19 import org.apache.axis2.clientapi.AsyncResult; 20 import org.apache.axis2.clientapi.Callback; 21 import org.apache.axis2.om.OMElement; 22 import org.apache.axis2.om.OMNode; 23 import org.apache.axis2.soap.SOAPBody; 24 import org.apache.axis2.soap.SOAPEnvelope; 25 26 import java.util.Iterator ; 27 28 36 public class ClientCallbackHandler extends Callback { 37 38 41 private String beginHTML = "<HTML><HEAD><TITLE>Wow</TITLE></HEAD><BODY>"; 42 43 46 private String endHTML = "</BODY></HTML>"; 47 48 51 private String snippet = beginHTML; 52 53 56 private String strURL; 57 58 61 private String tempStr; 62 63 64 private GUIHandler handler; 65 66 public ClientCallbackHandler(GUIHandler handler) { 67 this.handler = handler; 68 } 69 70 75 76 public void onComplete(AsyncResult result) { 77 AsyncResult myResult = result; 78 extractDetails(myResult); 79 } 80 81 89 private void extractDetails(AsyncResult result) { 90 Iterator iterator,iterator2; 91 OMNode node; 92 SOAPBody body; 93 OMElement operation, elem; 94 SOAPEnvelope resEnvelope; 95 resEnvelope = result.getResponseEnvelope(); 112 body = resEnvelope.getBody(); 113 operation = body.getFirstElement(); 114 if (body.hasFault()){ 115 snippet = 116 snippet + 117 "A Fault message recieved, Check your Licence key. Else you have reached the" + 118 " daily limit of 1000 requests"; 119 } else { 120 OMElement part = operation.getFirstElement(); 121 122 iterator = part.getChildren(); 123 while (iterator.hasNext()) { 124 node = (OMNode) iterator.next(); 125 if (node.getType() == OMNode.ELEMENT_NODE) { 126 elem = (OMElement) node; 127 String str = elem.getLocalName(); 128 if (str.equals("resultElements")) { 130 Iterator iterator0 = elem.getChildren(); 132 while (iterator0.hasNext()) { 133 node = (OMNode) iterator0.next(); 134 if (node.getType() == OMNode.ELEMENT_NODE) { 135 elem = (OMElement) node; 136 if (elem.getLocalName().equals("item")) { 137 iterator2 = elem.getChildren(); 138 while (iterator2.hasNext()) { 139 node = (OMNode) iterator2.next(); 140 if (node.getType() == OMNode.ELEMENT_NODE) { 141 elem = (OMElement) node; 142 String str3 = elem.getLocalName(); 143 System.out.println(str3); 144 if (elem.getLocalName().equals("snippet")) { 145 tempStr = elem.getText(); 147 148 snippet = snippet + tempStr; 150 } 151 152 if (elem.getLocalName().equals("URL")) { 153 strURL = elem.getText(); 155 } 156 } 157 } 158 } 159 snippet = snippet + "<br> URL:-<a HREF=" + strURL + ">" + strURL + 160 "</a\n\n> <br><br>"; 161 } 162 } 163 } 164 } 165 } 166 } 167 snippet = snippet + endHTML; 168 this.handler.showResults(snippet); 169 } 170 171 public void reportError(Exception e) { 172 e.printStackTrace(); 173 } 174 } | Popular Tags |