KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > protocol > http > modifier > UserParameterXMLParser


1 // $Header: /home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/modifier/UserParameterXMLParser.java,v 1.6 2004/02/12 00:29:49 sebb Exp $
2
/*
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * 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 JavaDoc;
22 import java.util.List JavaDoc;
23
24 import org.apache.jmeter.util.JMeterUtils;
25 import org.xml.sax.InputSource JavaDoc;
26 import org.xml.sax.SAXException JavaDoc;
27 import org.xml.sax.XMLReader JavaDoc;
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: 1.6 $
35  */

36 public class UserParameterXMLParser
37 {
38     //private String vendorParseClass = "org.apache.xerces.parsers.SAXParser";
39

40     /**
41      * Parse all user parameter data defined in XML file.
42      *
43      * @param xmlURI name of the XML to load users parameter data
44      * @return all users name value pairs obtained from XML file
45      */

46     public List JavaDoc getXMLParameters(String JavaDoc xmlURI)
47         throws SAXException JavaDoc, IOException JavaDoc
48     {
49         //create instances needed for parsing
50
XMLReader JavaDoc reader = JMeterUtils.getXMLParser();
51         //XMLReaderFactory.createXMLReader(vendorParseClass);
52
UserParameterXMLContentHandler threadParametersContentHandler =
53             new UserParameterXMLContentHandler();
54         UserParameterXMLErrorHandler parameterErrorHandler =
55             new UserParameterXMLErrorHandler();
56
57         //register content handler
58
reader.setContentHandler(threadParametersContentHandler);
59
60         // register error handler
61
reader.setErrorHandler(parameterErrorHandler);
62
63         // Request validation
64
reader.setFeature("http://xml.org/sax/features/validation", true);
65
66         //parse
67
InputSource JavaDoc inputSource = new InputSource JavaDoc(xmlURI);
68         reader.parse(inputSource);
69
70         return threadParametersContentHandler.getParsedParameters();
71     }
72 }
73
Popular Tags