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.12 by tdb, Sat Mar 10 02:03:55 2001 UTC vs.
Revision 1.16 by tdb, Tue May 29 17:02:35 2001 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 < package uk.ac.ukc.iscream.util;
2 > package uk.org.iscream.cms.server.util;
3  
4   //---IMPORTS---
5   import java.io.*;
6 import java.util.ArrayList;
7
6   import org.xml.sax.*;
7 < import org.xml.sax.helpers.*;
10 < import javax.xml.parsers.SAXParserFactory;
11 < import javax.xml.parsers.ParserConfigurationException;
12 < import javax.xml.parsers.SAXParser;
7 > import javax.xml.parsers.*;
8  
9   /**
10   * XMLPacketMaker - Creates an XMLPacket object.
# Line 17 | Line 12 | import javax.xml.parsers.SAXParser;
12   * @author  $Author$
13   * @version $Id$
14   */
15 < public class XMLPacketMaker extends DefaultHandler {
15 > public class XMLPacketMaker {
16  
17   //---FINAL ATTRIBUTES---
18  
# Line 25 | Line 20 | public class XMLPacketMaker extends DefaultHandler {
20       * The current CVS revision of this class
21       */
22      public final String REVISION = "$Revision$";
23 +
24 +    /**
25 +     * A reference to the system saxParser factory
26 +     */
27 +    private final SAXParserFactory _factory = SAXParserFactory.newInstance();
28      
29   //---STATIC METHODS---
30  
31   //---CONSTRUCTORS---
32  
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
33   //---PUBLIC METHODS---
34  
35      /**
36       * Method to create an XML packet from the data this
37       * class was constructed with.
38       *
39 +     * @param xml the XML String to parse
40       * @return an XMLPacket representing the XML String given
41       * @throws InvalidXMLException if the XML cannot be parsed
42       */
43 <    public XMLPacket createXMLPacket() throws InvalidXMLException {
43 >    public XMLPacket createXMLPacket(String xml) throws InvalidXMLException {
44  
45          // Create the XMLPacket to store values in.
46          XMLPacket packet = new XMLPacket();
47          
48          try {
49              // Parse the input
50 <            InputSource inputSource = new InputSource(new StringReader(_xml));
51 <            SAXParser saxParser = factory.newSAXParser();
66 <            
67 <            saxParser.parse(inputSource, new XMLStringParser(packet));
50 >            InputSource inputSource = new InputSource(new StringReader(xml));
51 >            _factory.newSAXParser().parse(inputSource, new XMLStringParser(packet));
52          }
53          catch (Exception e) {
54              // couldn't parse the XML for some reason
55 <            throw new InvalidXMLException("Could not parse the XML: "+_xml);
55 >            throw new InvalidXMLException("Could not parse the XML: "+xml);
56          }
57 +        
58          // parsed successfully, return the packet
59          return packet;
60      }
# Line 78 | Line 63 | public class XMLPacketMaker extends DefaultHandler {
63       * Overrides the {@link java.lang.Object#toString() Object.toString()}
64       * method to provide clean logging (every class should have this).
65       *
66 <     * This uses the uk.ac.ukc.iscream.util.NameFormat class
66 >     * This uses the uk.org.iscream.cms.server.util.NameFormat class
67       * to format the toString()
68       *
69       * @return the name of this class and its CVS revision
# Line 95 | Line 80 | public class XMLPacketMaker extends DefaultHandler {
80   //---ACCESSOR/MUTATOR METHODS---
81  
82   //---ATTRIBUTES---
98
99    /**
100     * Holds the xml
101     */
102    String _xml;
83      
84      /**
85       * This is the friendly identifier of the

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines