1 18 19 package org.apache.jmeter.protocol.http.modifier; 20 21 import java.io.CharArrayWriter ; 22 import java.util.HashMap ; 23 import java.util.LinkedList ; 24 import java.util.List ; 25 import java.util.Map ; 26 27 import org.xml.sax.Attributes ; 28 import org.xml.sax.ContentHandler ; 29 import org.xml.sax.Locator ; 30 import org.xml.sax.SAXException ; 31 32 38 public class UserParameterXMLContentHandler implements ContentHandler 39 { 40 44 private List userThreads = new LinkedList (); 47 48 private String paramname = ""; 49 private String paramvalue = ""; 50 private Map nameValuePair = new HashMap (); 51 52 53 private CharArrayWriter contents = new CharArrayWriter (); 54 55 59 62 public void setDocumentLocator(Locator locator) 63 { 64 } 65 66 public void startDocument() throws SAXException 67 { 68 } 69 70 public void endDocument() throws SAXException 71 { 72 } 73 74 public void startPrefixMapping(String prefix, String uri) 75 throws SAXException 76 { 77 } 78 79 public void endPrefixMapping(String prefix) throws SAXException 80 { 81 } 82 83 public void startElement( 84 String namespaceURL, 85 String localName, 86 String qName, 87 Attributes atts) 88 throws SAXException 89 { 90 91 contents.reset(); 92 93 if (qName.equals("parameter")) 96 { 97 paramname = ""; 98 paramvalue = ""; 99 } 100 101 if (qName.equals("thread")) 104 { 105 nameValuePair = new HashMap (); 106 } 107 108 } 109 110 public void endElement(String namespaceURI, String localName, String qName) 111 throws SAXException 112 { 113 if (qName.equals("paramname")) 114 { 115 paramname = contents.toString(); 116 } 117 if (qName.equals("paramvalue")) 118 { 119 paramvalue = contents.toString(); 120 } 121 if (qName.equals("parameter")) 122 { 123 nameValuePair.put(paramname, paramvalue); 124 } 125 if (qName.equals("thread")) 126 { 127 userThreads.add(nameValuePair); 128 } 129 } 130 131 public void characters(char ch[], int start, int length) 132 throws SAXException 133 { 134 contents.write(ch, start, length); 135 } 136 137 public void ignorableWhitespace(char ch[], int start, int length) 138 throws SAXException 139 { 140 } 141 142 public void processingInstruction(String target, String date) 143 throws SAXException 144 { 145 } 146 147 public void skippedEntity(String name) throws SAXException 148 { 149 } 150 151 154 155 159 public List getParsedParameters() 160 { 161 return userThreads; 162 } 163 } 164 | Popular Tags |