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.3
Committed: Wed Nov 29 19:11:53 2000 UTC (23 years, 5 months ago) by tdb
Branch: MAIN
Changes since 1.2: +44 -6 lines
Log Message:
Made the files conform to the template source file. Also made changes to fit in
with the new packages structure. No actual code was changed.

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
15 /**
16 * XMLPacketMaker - Creates an XMLPacket object.
17 *
18 * @author $Author$
19 * @version $Id$
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.1 $";
29
30 //---STATIC METHODS---
31
32 //---CONSTRUCTORS---
33
34 // Constructor for accepting XML input.
35 public XMLPacketMaker (String xml, Logger logger) {
36 this.xml = xml;
37 this.logger = logger;
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 //t.printStackTrace();
60 return null;
61 }
62
63 return packet;
64 }
65
66 /**
67 * Overrides the {@link java.lang.Object#toString() Object.toString()}
68 * method to provide clean logging (every class should have this).
69 *
70 * @return the name of this class and its CVS revision
71 */
72 public String toString() {
73 return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")";
74 }
75
76 //---PRIVATE METHODS---
77
78 //---ACCESSOR/MUTATOR METHODS---
79
80 //---ATTRIBUTES---
81
82 String xml;
83 Logger logger;
84
85 //---STATIC ATTRIBUTES---
86
87 }