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.1
Committed: Wed Nov 22 08:40:53 2000 UTC (23 years, 5 months ago) by pjm2
Branch: MAIN
Log Message:
Gave the UDP and XML processing classes a new home with the filter.

UDPReaderThread has been renamed to FilterThread

XMLPacketParser has been renamed to XMLStringParser (as that's what it
does!)

File Contents

# Content
1 import java.io.*;
2 import java.util.ArrayList;
3
4 import org.xml.sax.*;
5
6 import javax.xml.parsers.SAXParserFactory;
7 import javax.xml.parsers.ParserConfigurationException;
8 import javax.xml.parsers.SAXParser;
9
10 // Paul Mutton, pjm2@ukc.ac.uk
11
12 // XMLPacketMaker - Creates an XMLPacket object.
13 public class XMLPacketMaker extends HandlerBase {
14
15 // No-args constructor. Generally not used.
16 public XMLPacketMaker () {
17 this.xml = "<packet></packet>";
18 }
19
20 // Constructor for accepting XML input.
21 public XMLPacketMaker (String xml) {
22 this.xml = xml;
23 }
24
25 public XMLPacket createXMLPacket() {
26
27 // Create the XMLPacket to store values in.
28 XMLPacket packet = new XMLPacket();
29
30 // Use the default (non-validating) parser
31 SAXParserFactory factory = SAXParserFactory.newInstance();
32 try {
33
34 // Parse the input
35 InputSource inputSource = new InputSource(new StringReader(xml));
36 SAXParser saxParser = factory.newSAXParser();
37 saxParser.parse(inputSource, new XMLStringParser(packet));
38
39 }
40 catch (Exception e) {
41 System.out.println("XMLPacketMaker - I just received an XML packet that did not contain valid XML.");
42 //t.printStackTrace();
43 return null;
44 }
45
46 return packet;
47 }
48
49 String xml;
50 }