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.8 by tdb, Thu Jan 18 01:55:57 2001 UTC vs.
Revision 1.12 by tdb, Sat Mar 10 02:03:55 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;
# Line 16 | Line 17 | import javax.xml.parsers.SAXParser;
17   * @author  $Author$
18   * @version $Id$
19   */
20 < public class XMLPacketMaker extends HandlerBase {
20 > public class XMLPacketMaker extends DefaultHandler {
21  
22   //---FINAL ATTRIBUTES---
23  
# Line 24 | Line 25 | public class XMLPacketMaker extends HandlerBase {
25       * The current CVS revision of this class
26       */
27      public final String REVISION = "$Revision$";
28 <    
28 >    
29   //---STATIC METHODS---
30  
31   //---CONSTRUCTORS---
32  
33 <    // Constructor for accepting XML input.
33 >    /**
34 >     * Constructor for accepting XML input.
35 >     *
36 >     * @param xml A String of XML to process.
37 >     */
38      public XMLPacketMaker (String xml) {
39          _xml = xml;
40      }
41  
42 +    /**
43 +     * A static reference to the system saxParser factory
44 +     */
45 +    private static SAXParserFactory factory = SAXParserFactory.newInstance();
46 +
47 +
48   //---PUBLIC METHODS---
49  
50 <    public XMLPacket createXMLPacket() {
50 >    /**
51 >     * Method to create an XML packet from the data this
52 >     * class was constructed with.
53 >     *
54 >     * @return an XMLPacket representing the XML String given
55 >     * @throws InvalidXMLException if the XML cannot be parsed
56 >     */
57 >    public XMLPacket createXMLPacket() throws InvalidXMLException {
58  
59          // Create the XMLPacket to store values in.
60          XMLPacket packet = new XMLPacket();
61 <
44 <        // Use the default (non-validating) parser
45 <        SAXParserFactory factory = SAXParserFactory.newInstance();
61 >        
62          try {
47
63              // Parse the input
64              InputSource inputSource = new InputSource(new StringReader(_xml));
65              SAXParser saxParser = factory.newSAXParser();
66 +            
67              saxParser.parse(inputSource, new XMLStringParser(packet));
52
68          }
69          catch (Exception e) {
70 <            return null;
70 >            // couldn't parse the XML for some reason
71 >            throw new InvalidXMLException("Could not parse the XML: "+_xml);
72          }
73 <        
73 >        // parsed successfully, return the packet
74          return packet;
75      }
76  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines