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.13 by tdb, Sat Mar 10 04:03:52 2001 UTC

# Line 3 | Line 3 | package uk.ac.ukc.iscream.util;
3  
4   //---IMPORTS---
5   import java.io.*;
6 import java.util.ArrayList;
7
6   import org.xml.sax.*;
7 < import javax.xml.parsers.SAXParserFactory;
10 < import javax.xml.parsers.ParserConfigurationException;
11 < import javax.xml.parsers.SAXParser;
7 > import javax.xml.parsers.*;
8  
9   /**
10   * XMLPacketMaker - Creates an XMLPacket object.
# Line 16 | Line 12 | import javax.xml.parsers.SAXParser;
12   * @author  $Author$
13   * @version $Id$
14   */
15 < public class XMLPacketMaker extends HandlerBase {
15 > public class XMLPacketMaker {
16  
17   //---FINAL ATTRIBUTES---
18  
# Line 24 | Line 20 | public class XMLPacketMaker extends HandlerBase {
20       * The current CVS revision of this class
21       */
22      public final String REVISION = "$Revision$";
23 <    
23 >    
24   //---STATIC METHODS---
25  
26   //---CONSTRUCTORS---
27  
32    // Constructor for accepting XML input.
33    public XMLPacketMaker (String xml) {
34        _xml = xml;
35    }
36
28   //---PUBLIC METHODS---
29  
30 <    public XMLPacket createXMLPacket() {
30 >    /**
31 >     * Method to create an XML packet from the data this
32 >     * class was constructed with.
33 >     *
34 >     * @param xml the XML String to parse
35 >     * @return an XMLPacket representing the XML String given
36 >     * @throws InvalidXMLException if the XML cannot be parsed
37 >     */
38 >    public XMLPacket createXMLPacket(String xml) throws InvalidXMLException {
39  
40          // Create the XMLPacket to store values in.
41          XMLPacket packet = new XMLPacket();
42 <
44 <        // Use the default (non-validating) parser
45 <        SAXParserFactory factory = SAXParserFactory.newInstance();
42 >        
43          try {
47
44              // Parse the input
45 <            InputSource inputSource = new InputSource(new StringReader(_xml));
46 <            SAXParser saxParser = factory.newSAXParser();
51 <            saxParser.parse(inputSource, new XMLStringParser(packet));
52 <
45 >            InputSource inputSource = new InputSource(new StringReader(xml));
46 >            _factory.newSAXParser().parse(inputSource, new XMLStringParser(packet));
47          }
48          catch (Exception e) {
49 <            return null;
49 >            // couldn't parse the XML for some reason
50 >            throw new InvalidXMLException("Could not parse the XML: "+xml);
51          }
52          
53 +        // parsed successfully, return the packet
54          return packet;
55      }
56  
# Line 79 | Line 75 | public class XMLPacketMaker extends HandlerBase {
75   //---ACCESSOR/MUTATOR METHODS---
76  
77   //---ATTRIBUTES---
82
83    /**
84     * Holds the xml
85     */
86    String _xml;
78      
79      /**
80       * This is the friendly identifier of the
# Line 97 | Line 88 | public class XMLPacketMaker extends HandlerBase {
88      private String _name = null;
89  
90   //---STATIC ATTRIBUTES---
91 +
92 +    /**
93 +     * A static reference to the system saxParser factory
94 +     */
95 +    private static SAXParserFactory _factory = SAXParserFactory.newInstance();
96  
97   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines