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.11 by tdb, Sat Mar 10 00:49:39 2001 UTC

# Line 6 | Line 6 | import java.io.*;
6   import java.util.ArrayList;
7  
8   import org.xml.sax.*;
9 + import org.xml.sax.helpers.*;
10   import javax.xml.parsers.SAXParserFactory;
11   import javax.xml.parsers.ParserConfigurationException;
12   import javax.xml.parsers.SAXParser;
13  
13 import uk.ac.ukc.iscream.core.*;
14
14   /**
15   * XMLPacketMaker - Creates an XMLPacket object.
16   *
17   * @author  $Author$
18   * @version $Id$
19   */
20 < public class XMLPacketMaker extends HandlerBase {
20 > public class XMLPacketMaker {
21  
22   //---FINAL ATTRIBUTES---
23  
# Line 27 | Line 26 | public class XMLPacketMaker extends HandlerBase {
26       */
27      public final String REVISION = "$Revision$";
28      
29 +    /**
30 +     * A static reference to the system saxParser
31 +     * Use the default (non-validating) parser
32 +     */
33 +    private static SAXParser saxParser = null;
34 +    private static SAXParserFactory factory = SAXParserFactory.newInstance();
35 +    
36   //---STATIC METHODS---
37  
38   //---CONSTRUCTORS---
39  
40 <    // Constructor for accepting XML input.
40 >    /**
41 >     * Constructor for accepting XML input.
42 >     *
43 >     * @param xml A String of XML to process.
44 >     */
45      public XMLPacketMaker (String xml) {
46          _xml = xml;
47      }
48  
49   //---PUBLIC METHODS---
50  
51 <    public XMLPacket createXMLPacket() {
51 >    /**
52 >     * Method to create an XML packet from the data this
53 >     * class was constructed with.
54 >     *
55 >     * @return an XMLPacket representing the XML String given
56 >     * @throws InvalidXMLException if the XML cannot be parsed
57 >     */
58 >    public XMLPacket createXMLPacket() throws InvalidXMLException {
59  
60          // Create the XMLPacket to store values in.
61          XMLPacket packet = new XMLPacket();
62 <
46 <        // Use the default (non-validating) parser
47 <        SAXParserFactory factory = SAXParserFactory.newInstance();
62 >        
63          try {
49
64              // Parse the input
65              InputSource inputSource = new InputSource(new StringReader(_xml));
66 <            SAXParser saxParser = factory.newSAXParser();
66 >            
67 >            if (saxParser == null) {
68 >                saxParser = factory.newSAXParser();
69 >            }
70 >            
71              saxParser.parse(inputSource, new XMLStringParser(packet));
54
72          }
73          catch (Exception e) {
74 <            _logger.write(this.toString(), Logger.WARNING, e.toString());
75 <            _logger.write(this.toString(), Logger.WARNING, "An invalid XML UDP packet has been detected: "+packet.printAll());
59 <            return null;
74 >            // couldn't parse the XML for some reason
75 >            throw new InvalidXMLException("Could not parse the XML: "+_xml);
76          }
77 <        
77 >        // parsed successfully, return the packet
78          return packet;
79      }
80  
# Line 88 | Line 104 | public class XMLPacketMaker extends HandlerBase {
104       * Holds the xml
105       */
106      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();
107      
108      /**
109       * This is the friendly identifier of the

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines