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.2
Committed: Thu Nov 23 09:36:07 2000 UTC (23 years, 5 months ago) by pjm2
Branch: MAIN
Changes since 1.1: +6 -7 lines
Log Message:
Altered the printAll() method in the XMLPacket.

Added logging facilities to XMLPacketMaker.

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 import uk.ac.ukc.iscream.core.*;
11
12 // Paul Mutton, pjm2@ukc.ac.uk
13
14 // XMLPacketMaker - Creates an XMLPacket object.
15 public class XMLPacketMaker extends HandlerBase {
16
17 // Constructor for accepting XML input.
18 public XMLPacketMaker (String xml, Logger logger) {
19 this.xml = xml;
20 this.logger = logger;
21 }
22
23 public XMLPacket createXMLPacket() {
24
25 // Create the XMLPacket to store values in.
26 XMLPacket packet = new XMLPacket();
27
28 // Use the default (non-validating) parser
29 SAXParserFactory factory = SAXParserFactory.newInstance();
30 try {
31
32 // Parse the input
33 InputSource inputSource = new InputSource(new StringReader(xml));
34 SAXParser saxParser = factory.newSAXParser();
35 saxParser.parse(inputSource, new XMLStringParser(packet));
36
37 }
38 catch (Exception e) {
39 logger.write(this.toString(), Logger.WARNING, "An invalid XML UDP packet has been detected: "+packet.printAll());
40 //t.printStackTrace();
41 return null;
42 }
43
44 return packet;
45 }
46
47 String xml;
48 Logger logger;
49 }