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.5 by ajm, Thu Nov 30 02:38:17 2000 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;
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 extends DefaultHandler {
21  
22   //---FINAL ATTRIBUTES---
23  
# Line 26 | 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 <
46 <        // Use the default (non-validating) parser
47 <        SAXParserFactory factory = SAXParserFactory.newInstance();
61 >        
62          try {
49
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));
54
68          }
69          catch (Exception e) {
70 <            _logger.write(this.toString(), Logger.WARNING, "An invalid XML UDP packet has been detected: "+packet.printAll());
71 <            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  
# Line 65 | Line 78 | public class XMLPacketMaker extends HandlerBase {
78       * Overrides the {@link java.lang.Object#toString() Object.toString()}
79       * method to provide clean logging (every class should have this).
80       *
81 +     * This uses the uk.ac.ukc.iscream.util.NameFormat class
82 +     * to format the toString()
83 +     *
84       * @return the name of this class and its CVS revision
85       */
86      public String toString() {
87 <        return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")";
87 >        return FormatName.getName(
88 >            _name,
89 >            getClass().getName(),
90 >            REVISION);
91      }
92  
93   //---PRIVATE METHODS---
# Line 77 | Line 96 | public class XMLPacketMaker extends HandlerBase {
96  
97   //---ATTRIBUTES---
98  
99 +    /**
100 +     * Holds the xml
101 +     */
102      String _xml;
103 <    Logger _logger = ReferenceManager.getInstance().getLogger();
103 >    
104 >    /**
105 >     * This is the friendly identifier of the
106 >     * component this class is running in.
107 >     * eg, a Filter may be called "filter1",
108 >     * If this class does not have an owning
109 >     * component,  a name from the configuration
110 >     * can be placed here.  This name could also
111 >     * be changed to null for utility classes.
112 >     */
113 >    private String _name = null;
114  
115   //---STATIC ATTRIBUTES---
116  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines