| 17 | private List<String> keywords = new ArrayList<String>(); |
| 18 | |
| 19 | @Override |
| 20 | public MatchResult match(String strResponse, String keyword) { |
| 21 | MatchResult matchResult = new MatchResult(); |
| 22 | String rsqData = new String(getRspBody(strResponse.getBytes())); |
| 23 | try { |
| 24 | final SAXReader sax = new SAXReader(); |
| 25 | final Document document = sax.read(new ByteArrayInputStream(rsqData.getBytes())); |
| 26 | final Element root = document.getRootElement();// 获取根节点 |
| 27 | this.searchXml(root,keyword); |
| 28 | if(this.result.size() != 0){ |
| 29 | String res = result.get(0); |
| 30 | int start = rsqData.indexOf(res); //存在相同值的化,可能不准确,待优化 |
| 31 | int end = start + res.length(); |
| 32 | matchResult.setResult(res); |
| 33 | matchResult.setStart(start); |
| 34 | matchResult.setEnd(end); |
| 35 | }else{ |
| 36 | matchResult.setResult("Alert: No match to"); |
| 37 | } |
| 38 | }catch (Exception e){ |
| 39 | matchResult.setResult(String.format("Error: %s",e.getMessage())); |
| 40 | } |
| 41 | return matchResult; |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public String buildKeyword(String strResponse, String value) { |