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
Revision: 1.4
Committed: Thu Nov 30 02:04:18 2000 UTC (23 years, 5 months ago) by tdb
Branch: MAIN
Changes since 1.3: +10 -11 lines
Log Message:
Changes to stop passing the Logger references etc around. Makes use of the new
Reference Manager.

File Contents

# Content
1 //---PACKAGE DECLARATION---
2 package uk.ac.ukc.iscream.xml;
3
4 //---IMPORTS---
5 import java.io.*;
6 import java.util.ArrayList;
7
8 import org.xml.sax.*;
9 import javax.xml.parsers.SAXParserFactory;
10 import javax.xml.parsers.ParserConfigurationException;
11 import javax.xml.parsers.SAXParser;
12
13 import uk.ac.ukc.iscream.core.*;
14 import uk.ac.ukc.iscream.refman.*;
15
16 /**
17 * XMLPacketMaker - Creates an XMLPacket object.
18 *
19 * @author $Author: tdb1 $
20 * @version $Id: XMLPacketMaker.java,v 1.3 2000/11/29 19:11:53 tdb1 Exp $
21 */
22 public class XMLPacketMaker extends HandlerBase {
23
24 //---FINAL ATTRIBUTES---
25
26 /**
27 * The current CVS revision of this class
28 */
29 public final String REVISION = "$Revision: 1.3 $";
30
31 //---STATIC METHODS---
32
33 //---CONSTRUCTORS---
34
35 // Constructor for accepting XML input.
36 public XMLPacketMaker (String xml) {
37 _xml = xml;
38 }
39
40 //---PUBLIC METHODS---
41
42 public XMLPacket createXMLPacket() {
43
44 // Create the XMLPacket to store values in.
45 XMLPacket packet = new XMLPacket();
46
47 // Use the default (non-validating) parser
48 SAXParserFactory factory = SAXParserFactory.newInstance();
49 try {
50
51 // Parse the input
52 InputSource inputSource = new InputSource(new StringReader(_xml));
53 SAXParser saxParser = factory.newSAXParser();
54 saxParser.parse(inputSource, new XMLStringParser(packet));
55
56 }
57 catch (Exception e) {
58 _logger.write(this.toString(), Logger.WARNING, "An invalid XML UDP packet has been detected: "+packet.printAll());
59 return null;
60 }
61
62 return packet;
63 }
64
65 /**
66 * Overrides the {@link java.lang.Object#toString() Object.toString()}
67 * method to provide clean logging (every class should have this).
68 *
69 * @return the name of this class and its CVS revision
70 */
71 public String toString() {
72 return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")";
73 }
74
75 //---PRIVATE METHODS---
76
77 //---ACCESSOR/MUTATOR METHODS---
78
79 //---ATTRIBUTES---
80
81 String _xml;
82 Logger _logger = ReferenceManager.getInstance().getLogger();
83
84 //---STATIC ATTRIBUTES---
85
86 }