ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/util/uk/org/iscream/cms/util/XMLPacketMaker.java
(Generate patch)

Comparing projects/cms/source/util/uk/org/iscream/cms/util/XMLPacketMaker.java (file contents):
Revision 1.7 by ajm, Tue Dec 12 20:44:30 2000 UTC vs.
Revision 1.10 by tdb, Thu Mar 1 16:55:11 2001 UTC

# Line 10 | Line 10 | import javax.xml.parsers.SAXParserFactory;
10   import javax.xml.parsers.ParserConfigurationException;
11   import javax.xml.parsers.SAXParser;
12  
13 import uk.ac.ukc.iscream.core.*;
14
13   /**
14   * XMLPacketMaker - Creates an XMLPacket object.
15   *
# Line 31 | Line 29 | public class XMLPacketMaker extends HandlerBase {
29  
30   //---CONSTRUCTORS---
31  
32 <    // Constructor for accepting XML input.
32 >    /**
33 >     * Constructor for accepting XML input.
34 >     *
35 >     * @param xml A String of XML to process.
36 >     */
37      public XMLPacketMaker (String xml) {
38          _xml = xml;
39      }
40  
41   //---PUBLIC METHODS---
42  
43 <    public XMLPacket createXMLPacket() {
43 >    /**
44 >     * Method to create an XML packet from the data this
45 >     * class was constructed with.
46 >     *
47 >     * @return an XMLPacket representing the XML String given
48 >     * @throws InvalidXMLException if the XML cannot be parsed
49 >     */
50 >    public XMLPacket createXMLPacket() throws InvalidXMLException {
51  
52          // Create the XMLPacket to store values in.
53          XMLPacket packet = new XMLPacket();
# Line 46 | Line 55 | public class XMLPacketMaker extends HandlerBase {
55          // Use the default (non-validating) parser
56          SAXParserFactory factory = SAXParserFactory.newInstance();
57          try {
49
58              // Parse the input
59              InputSource inputSource = new InputSource(new StringReader(_xml));
60              SAXParser saxParser = factory.newSAXParser();
61              saxParser.parse(inputSource, new XMLStringParser(packet));
54
62          }
63          catch (Exception e) {
64 <            _logger.write(this.toString(), Logger.WARNING, e.toString());
65 <            _logger.write(this.toString(), Logger.WARNING, "An invalid XML UDP packet has been detected: "+packet.printAll());
59 <            return null;
64 >            // couldn't parse the XML for some reason
65 >            throw new InvalidXMLException("Could not parse the XML: "+_xml);
66          }
67 <        
67 >        // parsed successfully, return the packet
68          return packet;
69      }
70  
# Line 88 | Line 94 | public class XMLPacketMaker extends HandlerBase {
94       * Holds the xml
95       */
96      String _xml;
91    
92    /**
93     * This holds a reference to the
94     * system logger that is being used.
95     */
96    private Logger _logger = ReferenceManager.getInstance().getLogger();
97      
98      /**
99       * This is the friendly identifier of the

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines