1 6 7 package com.sun.japex.report; 8 import org.xml.sax.*; 9 import org.xml.sax.helpers.DefaultHandler ; 10 11 import javax.xml.parsers.SAXParserFactory ; 12 import javax.xml.parsers.ParserConfigurationException ; 13 import javax.xml.parsers.SAXParser ; 14 15 import java.io.*; 16 import java.util.ArrayList ; 17 import java.util.Map ; 18 import java.util.HashMap ; 19 23 public class ReportDataParser extends DefaultHandler { 24 static final String DRIVER = "driver"; 25 static final String TESTCASE = "testCase"; 26 27 StringBuffer textBuffer; 28 Map _reports; 29 TrendReportParams _params; 30 31 ResultPerDriver _resultPerDriver = null; 32 boolean _driverStart = false; 33 boolean _testStart = false; 34 String _currentDriverName = null; 35 String _currentTestName = null; 36 37 38 39 public ReportDataParser(TrendReportParams params) { 40 _params = params; 41 } 42 public Map getReports() { 43 return _reports; 44 } 45 49 public void startDocument() 50 throws SAXException 51 { 52 } 54 55 public void endDocument() 56 throws SAXException 57 { 58 } 60 61 public void startElement(String namespaceURI, 62 String sName, String qName, Attributes attrs) 65 throws SAXException 66 { 67 String eName = sName; if ("".equals(eName)) eName = qName; 70 if (eName.equals(DRIVER)) { 71 if (attrs != null) { 73 for (int i = 0; i < attrs.getLength(); i++) { 74 String aName = attrs.getLocalName(i); if ("".equals(aName)) aName = attrs.getQName(i); 76 78 if (_params.isDriverSpecified()) { 79 if (aName.equals("name") && attrs.getValue(i).equals(_params.driver())) { 80 _driverStart = true; 82 _resultPerDriver = new ResultPerDriver(); 83 _currentDriverName = attrs.getValue(i); 84 } 85 } 86 } 87 } 88 } else if (_driverStart) { 89 if (eName.equals(TESTCASE)) { 90 if (attrs != null) { 91 for (int i = 0; i < attrs.getLength(); i++) { 92 String aName = attrs.getLocalName(i); if ("".equals(aName)) aName = attrs.getQName(i); 94 if (aName.equals("name")) { 95 _currentTestName = attrs.getValue(i); 96 } 97 } 98 } 99 _testStart = true; 100 } 101 } 102 } 103 104 public void endElement(String namespaceURI, 105 String sName, String qName ) 108 throws SAXException 109 { 110 String eName = sName; if ("".equals(eName)) eName = qName; if(eName.equals(DRIVER)) { 114 if (_driverStart) { 115 if (_reports == null) { 116 _reports = new HashMap (); 117 } 118 _reports.put(_currentDriverName, _resultPerDriver); 119 _resultPerDriver = null; 120 } 123 _driverStart = false; 125 } else if (_driverStart) { 126 if (_testStart) { 127 if (eName.equals("resultValue")) { 128 _resultPerDriver.addResult(_currentTestName, textBuffer.toString()); 129 } else if (eName.equals(TESTCASE)) { 130 _testStart = false; 131 } 132 } else { 133 if (eName.equals("resultHarmMean")) { 134 136 _resultPerDriver.setHarmMean(textBuffer.toString()); 137 } else if (eName.equals("resultGeomMean")) { 139 _resultPerDriver.setGeomMean(textBuffer.toString()); 140 } else if (eName.equals("resultAritMean")) { 141 _resultPerDriver.setAritMean(textBuffer.toString()); 142 } 143 } 144 } 145 textBuffer = null; 146 } 147 148 public void characters(char buf[], int offset, int len) 149 throws SAXException 150 { 151 String s = new String (buf, offset, len); 152 if (textBuffer == null) { 153 textBuffer = new StringBuffer (s); 154 } else { 155 textBuffer.append(s); 156 } 157 } 158 159 } 160 | Popular Tags |