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.5
Committed: Thu Nov 30 02:38:17 2000 UTC (23 years, 5 months ago) by ajm
Branch: MAIN
Changes since 1.4: +3 -4 lines
Log Message:
Changed package structure
uk.ac.ukc.iscream.refman and xml -> uk.ac.ukc.iscream.util

File Contents

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