01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: package org.apache.jmeter.protocol.http.modifier;
20:
21: import java.io.IOException;
22: import java.util.List;
23:
24: import org.apache.jmeter.util.JMeterUtils;
25: import org.xml.sax.InputSource;
26: import org.xml.sax.SAXException;
27: import org.xml.sax.XMLReader;
28:
29: /**
30: * Parse an XML file to obtain parameter name and value information for all
31: * users defined in the XML file.
32: *
33: * @author Mark Walsh
34: * @version $Revision: 493789 $
35: */
36: public class UserParameterXMLParser {
37: // private String vendorParseClass = "org.apache.xerces.parsers.SAXParser";
38:
39: /**
40: * Parse all user parameter data defined in XML file.
41: *
42: * @param xmlURI
43: * name of the XML to load users parameter data
44: * @return all users name value pairs obtained from XML file
45: */
46: public List getXMLParameters(String xmlURI) throws SAXException,
47: IOException {
48: // create instances needed for parsing
49: XMLReader reader = JMeterUtils.getXMLParser();
50: // XMLReaderFactory.createXMLReader(vendorParseClass);
51: UserParameterXMLContentHandler threadParametersContentHandler = new UserParameterXMLContentHandler();
52: UserParameterXMLErrorHandler parameterErrorHandler = new UserParameterXMLErrorHandler();
53:
54: // register content handler
55: reader.setContentHandler(threadParametersContentHandler);
56:
57: // register error handler
58: reader.setErrorHandler(parameterErrorHandler);
59:
60: // Request validation
61: reader.setFeature("http://xml.org/sax/features/validation",
62: true);
63:
64: // parse
65: InputSource inputSource = new InputSource(xmlURI);
66: reader.parse(inputSource);
67:
68: return threadParametersContentHandler.getParsedParameters();
69: }
70: }
|