1 17 package org.apache.jmeter.monitor.parser; 18 19 import java.io.ByteArrayInputStream ; 20 import java.io.IOException ; 21 22 import org.xml.sax.SAXException ; 23 import org.xml.sax.InputSource ; 24 25 import javax.xml.parsers.ParserConfigurationException ; 26 import javax.xml.parsers.SAXParser ; 27 import javax.xml.parsers.SAXParserFactory ; 28 29 import org.apache.jmeter.monitor.model.ObjectFactory; 30 import org.apache.jmeter.monitor.model.Status; 31 import org.apache.jmeter.samplers.SampleResult; 32 33 public abstract class ParserImpl implements Parser 34 { 35 private SAXParserFactory PARSERFACTORY = null; 36 private SAXParser PARSER = null; 37 private MonitorHandler DOCHANDLER = null; 38 private ObjectFactory FACTORY = null; 39 40 43 public ParserImpl(ObjectFactory factory) 44 { 45 super(); 46 this.FACTORY = factory; 47 try { 48 PARSERFACTORY = SAXParserFactory.newInstance(); 49 PARSER = PARSERFACTORY.newSAXParser(); 50 DOCHANDLER = new MonitorHandler(); 51 DOCHANDLER.setObjectFactory(this.FACTORY); 52 } catch (SAXException e) { 53 } catch (ParserConfigurationException e){ 56 } 59 } 60 61 66 public Status parseBytes(byte[] bytes) 67 { 68 try { 69 InputSource is = new InputSource (); 70 is.setByteStream(new ByteArrayInputStream (bytes)); 71 PARSER.parse(is,DOCHANDLER); 72 return DOCHANDLER.getContents(); 73 } catch (SAXException e){ 74 e.printStackTrace(); 75 return DOCHANDLER.getContents(); 77 } catch (IOException e){ 78 e.printStackTrace(); 79 return DOCHANDLER.getContents(); 81 } 82 } 83 84 88 public Status parseString(String content) 89 { 90 return parseBytes(content.getBytes()); 91 } 92 93 97 public Status parseSampleResult(SampleResult result) 98 { 99 return parseBytes(result.getResponseData()); 100 } 101 102 } 103 | Popular Tags |