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.14
Committed: Wed Mar 14 23:25:30 2001 UTC (23 years, 1 month ago) by tdb
Branch: MAIN
Changes since 1.13: +4 -4 lines
Log Message:
The whole server package structure has been changed.
Old Package: uk.ac.ukc.iscream.*
New Package: uk.org.iscream.*

File Contents

# User Rev Content
1 ajm 1.7 //---PACKAGE DECLARATION---
2 tdb 1.14 package uk.org.iscream.util;
3 ajm 1.7
4     //---IMPORTS---
5     import java.io.*;
6     import org.xml.sax.*;
7 tdb 1.13 import javax.xml.parsers.*;
8 ajm 1.7
9     /**
10     * XMLPacketMaker - Creates an XMLPacket object.
11     *
12 tdb 1.9 * @author $Author: tdb1 $
13 tdb 1.14 * @version $Id: XMLPacketMaker.java,v 1.13 2001/03/10 04:03:52 tdb1 Exp $
14 ajm 1.7 */
15 tdb 1.13 public class XMLPacketMaker {
16 ajm 1.7
17     //---FINAL ATTRIBUTES---
18    
19     /**
20     * The current CVS revision of this class
21     */
22 tdb 1.14 public final String REVISION = "$Revision: 1.13 $";
23 tdb 1.11
24 ajm 1.7 //---STATIC METHODS---
25    
26     //---CONSTRUCTORS---
27    
28     //---PUBLIC METHODS---
29    
30 tdb 1.9 /**
31     * Method to create an XML packet from the data this
32     * class was constructed with.
33     *
34 tdb 1.13 * @param xml the XML String to parse
35 tdb 1.9 * @return an XMLPacket representing the XML String given
36 tdb 1.10 * @throws InvalidXMLException if the XML cannot be parsed
37 tdb 1.9 */
38 tdb 1.13 public XMLPacket createXMLPacket(String xml) throws InvalidXMLException {
39 ajm 1.7
40     // Create the XMLPacket to store values in.
41     XMLPacket packet = new XMLPacket();
42 tdb 1.11
43 ajm 1.7 try {
44     // Parse the input
45 tdb 1.13 InputSource inputSource = new InputSource(new StringReader(xml));
46     _factory.newSAXParser().parse(inputSource, new XMLStringParser(packet));
47 ajm 1.7 }
48     catch (Exception e) {
49 tdb 1.10 // couldn't parse the XML for some reason
50 tdb 1.13 throw new InvalidXMLException("Could not parse the XML: "+xml);
51 ajm 1.7 }
52 tdb 1.13
53 tdb 1.10 // parsed successfully, return the packet
54 ajm 1.7 return packet;
55     }
56    
57     /**
58     * Overrides the {@link java.lang.Object#toString() Object.toString()}
59     * method to provide clean logging (every class should have this).
60     *
61 tdb 1.14 * This uses the uk.org.iscream.util.NameFormat class
62 ajm 1.7 * to format the toString()
63     *
64     * @return the name of this class and its CVS revision
65     */
66     public String toString() {
67     return FormatName.getName(
68     _name,
69     getClass().getName(),
70     REVISION);
71     }
72    
73     //---PRIVATE METHODS---
74    
75     //---ACCESSOR/MUTATOR METHODS---
76    
77     //---ATTRIBUTES---
78    
79     /**
80     * This is the friendly identifier of the
81     * component this class is running in.
82     * eg, a Filter may be called "filter1",
83     * If this class does not have an owning
84     * component, a name from the configuration
85     * can be placed here. This name could also
86     * be changed to null for utility classes.
87     */
88     private String _name = null;
89    
90     //---STATIC ATTRIBUTES---
91 tdb 1.13
92     /**
93     * A static reference to the system saxParser factory
94     */
95     private static SAXParserFactory _factory = SAXParserFactory.newInstance();
96 ajm 1.7
97     }