--- projects/cms/source/util/uk/org/iscream/cms/util/XMLPacketMaker.java 2001/03/10 02:03:55 1.12 +++ projects/cms/source/util/uk/org/iscream/cms/util/XMLPacketMaker.java 2001/03/16 00:39:42 1.15 @@ -1,75 +1,60 @@ //---PACKAGE DECLARATION--- -package uk.ac.ukc.iscream.util; +package uk.org.iscream.util; //---IMPORTS--- import java.io.*; -import java.util.ArrayList; - import org.xml.sax.*; -import org.xml.sax.helpers.*; -import javax.xml.parsers.SAXParserFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; +import javax.xml.parsers.*; /** * XMLPacketMaker - Creates an XMLPacket object. * * @author $Author: tdb $ - * @version $Id: XMLPacketMaker.java,v 1.12 2001/03/10 02:03:55 tdb Exp $ + * @version $Id: XMLPacketMaker.java,v 1.15 2001/03/16 00:39:42 tdb Exp $ */ -public class XMLPacketMaker extends DefaultHandler { +public class XMLPacketMaker { //---FINAL ATTRIBUTES--- /** * The current CVS revision of this class */ - public final String REVISION = "$Revision: 1.12 $"; + public final String REVISION = "$Revision: 1.15 $"; + + /** + * A reference to the system saxParser factory + */ + private final SAXParserFactory _factory = SAXParserFactory.newInstance(); //---STATIC METHODS--- //---CONSTRUCTORS--- - /** - * Constructor for accepting XML input. - * - * @param xml A String of XML to process. - */ - public XMLPacketMaker (String xml) { - _xml = xml; - } - - /** - * A static reference to the system saxParser factory - */ - private static SAXParserFactory factory = SAXParserFactory.newInstance(); - - //---PUBLIC METHODS--- /** * Method to create an XML packet from the data this * class was constructed with. * + * @param xml the XML String to parse * @return an XMLPacket representing the XML String given * @throws InvalidXMLException if the XML cannot be parsed */ - public XMLPacket createXMLPacket() throws InvalidXMLException { + public XMLPacket createXMLPacket(String xml) throws InvalidXMLException { // Create the XMLPacket to store values in. XMLPacket packet = new XMLPacket(); try { // Parse the input - InputSource inputSource = new InputSource(new StringReader(_xml)); - SAXParser saxParser = factory.newSAXParser(); - - saxParser.parse(inputSource, new XMLStringParser(packet)); + InputSource inputSource = new InputSource(new StringReader(xml)); + _factory.newSAXParser().parse(inputSource, new XMLStringParser(packet)); } catch (Exception e) { // couldn't parse the XML for some reason - throw new InvalidXMLException("Could not parse the XML: "+_xml); + throw new InvalidXMLException("Could not parse the XML: "+xml); } + // parsed successfully, return the packet return packet; } @@ -78,7 +63,7 @@ public class XMLPacketMaker extends DefaultHandler { * Overrides the {@link java.lang.Object#toString() Object.toString()} * method to provide clean logging (every class should have this). * - * This uses the uk.ac.ukc.iscream.util.NameFormat class + * This uses the uk.org.iscream.util.NameFormat class * to format the toString() * * @return the name of this class and its CVS revision @@ -95,11 +80,6 @@ public class XMLPacketMaker extends DefaultHandler { //---ACCESSOR/MUTATOR METHODS--- //---ATTRIBUTES--- - - /** - * Holds the xml - */ - String _xml; /** * This is the friendly identifier of the