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.8
Committed: Thu Jan 18 01:55:57 2001 UTC (23 years, 3 months ago) by tdb
Branch: MAIN
Changes since 1.7: +3 -13 lines
Log Message:
Removed references to the logger, to allow integration of XML classes into
the clients.

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 /**
14 * XMLPacketMaker - Creates an XMLPacket object.
15 *
16 * @author $Author: ajm4 $
17 * @version $Id: XMLPacketMaker.java,v 1.7 2000/12/12 20:44:30 ajm4 Exp $
18 */
19 public class XMLPacketMaker extends HandlerBase {
20
21 //---FINAL ATTRIBUTES---
22
23 /**
24 * The current CVS revision of this class
25 */
26 public final String REVISION = "$Revision: 1.7 $";
27
28 //---STATIC METHODS---
29
30 //---CONSTRUCTORS---
31
32 // Constructor for accepting XML input.
33 public XMLPacketMaker (String xml) {
34 _xml = xml;
35 }
36
37 //---PUBLIC METHODS---
38
39 public XMLPacket createXMLPacket() {
40
41 // Create the XMLPacket to store values in.
42 XMLPacket packet = new XMLPacket();
43
44 // Use the default (non-validating) parser
45 SAXParserFactory factory = SAXParserFactory.newInstance();
46 try {
47
48 // Parse the input
49 InputSource inputSource = new InputSource(new StringReader(_xml));
50 SAXParser saxParser = factory.newSAXParser();
51 saxParser.parse(inputSource, new XMLStringParser(packet));
52
53 }
54 catch (Exception e) {
55 return null;
56 }
57
58 return packet;
59 }
60
61 /**
62 * Overrides the {@link java.lang.Object#toString() Object.toString()}
63 * method to provide clean logging (every class should have this).
64 *
65 * This uses the uk.ac.ukc.iscream.util.NameFormat class
66 * to format the toString()
67 *
68 * @return the name of this class and its CVS revision
69 */
70 public String toString() {
71 return FormatName.getName(
72 _name,
73 getClass().getName(),
74 REVISION);
75 }
76
77 //---PRIVATE METHODS---
78
79 //---ACCESSOR/MUTATOR METHODS---
80
81 //---ATTRIBUTES---
82
83 /**
84 * Holds the xml
85 */
86 String _xml;
87
88 /**
89 * This is the friendly identifier of the
90 * component this class is running in.
91 * eg, a Filter may be called "filter1",
92 * If this class does not have an owning
93 * component, a name from the configuration
94 * can be placed here. This name could also
95 * be changed to null for utility classes.
96 */
97 private String _name = null;
98
99 //---STATIC ATTRIBUTES---
100
101 }