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.7
Committed: Tue Dec 12 20:44:30 2000 UTC (23 years, 4 months ago) by ajm
Branch: MAIN
Changes since 1.6: +111 -86 lines
Log Message:
use FormatName now for toStrings

File Contents

# User Rev Content
1 ajm 1.7 //---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.6 2000/12/07 23:26:16 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.6 $";
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, e.toString());
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     * This uses the uk.ac.ukc.iscream.util.NameFormat class
70     * to format the toString()
71     *
72     * @return the name of this class and its CVS revision
73     */
74     public String toString() {
75     return FormatName.getName(
76     _name,
77     getClass().getName(),
78     REVISION);
79     }
80    
81     //---PRIVATE METHODS---
82    
83     //---ACCESSOR/MUTATOR METHODS---
84    
85     //---ATTRIBUTES---
86    
87     /**
88     * Holds the xml
89     */
90     String _xml;
91    
92     /**
93     * This holds a reference to the
94     * system logger that is being used.
95     */
96     private Logger _logger = ReferenceManager.getInstance().getLogger();
97    
98     /**
99     * This is the friendly identifier of the
100     * component this class is running in.
101     * eg, a Filter may be called "filter1",
102     * If this class does not have an owning
103     * component, a name from the configuration
104     * can be placed here. This name could also
105     * be changed to null for utility classes.
106     */
107     private String _name = null;
108    
109     //---STATIC ATTRIBUTES---
110    
111     }