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.17
Committed: Sat May 18 18:16:04 2002 UTC (21 years, 11 months ago) by tdb
Branch: MAIN
Changes since 1.16: +22 -3 lines
Log Message:
i-scream is now licensed under the GPL. I've added the GPL headers to every
source file, and put a full copy of the license in the appropriate places.
I think I've covered everything. This is going to be a mad commit ;)

File Contents

# User Rev Content
1 tdb 1.17 /*
2     * i-scream central monitoring system
3     * Copyright (C) 2000-2002 i-scream
4     *
5     * This program is free software; you can redistribute it and/or
6     * modify it under the terms of the GNU General Public License
7     * as published by the Free Software Foundation; either version 2
8     * of the License, or (at your option) any later version.
9     *
10     * This program is distributed in the hope that it will be useful,
11     * but WITHOUT ANY WARRANTY; without even the implied warranty of
12     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13     * GNU General Public License for more details.
14     *
15     * You should have received a copy of the GNU General Public License
16     * along with this program; if not, write to the Free Software
17     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18     */
19    
20 ajm 1.7 //---PACKAGE DECLARATION---
21 tdb 1.16 package uk.org.iscream.cms.server.util;
22 ajm 1.7
23     //---IMPORTS---
24     import java.io.*;
25     import org.xml.sax.*;
26 tdb 1.13 import javax.xml.parsers.*;
27 ajm 1.7
28     /**
29     * XMLPacketMaker - Creates an XMLPacket object.
30     *
31 tdb 1.17 * @author $Author: tdb $
32     * @version $Id: XMLPacketMaker.java,v 1.16 2001/05/29 17:02:35 tdb Exp $
33 ajm 1.7 */
34 tdb 1.13 public class XMLPacketMaker {
35 ajm 1.7
36     //---FINAL ATTRIBUTES---
37    
38     /**
39     * The current CVS revision of this class
40     */
41 tdb 1.17 public final String REVISION = "$Revision: 1.16 $";
42 tdb 1.15
43     /**
44     * A reference to the system saxParser factory
45     */
46     private final SAXParserFactory _factory = SAXParserFactory.newInstance();
47 tdb 1.11
48 ajm 1.7 //---STATIC METHODS---
49    
50     //---CONSTRUCTORS---
51    
52     //---PUBLIC METHODS---
53    
54 tdb 1.9 /**
55     * Method to create an XML packet from the data this
56     * class was constructed with.
57     *
58 tdb 1.13 * @param xml the XML String to parse
59 tdb 1.9 * @return an XMLPacket representing the XML String given
60 tdb 1.10 * @throws InvalidXMLException if the XML cannot be parsed
61 tdb 1.9 */
62 tdb 1.13 public XMLPacket createXMLPacket(String xml) throws InvalidXMLException {
63 ajm 1.7
64     // Create the XMLPacket to store values in.
65     XMLPacket packet = new XMLPacket();
66 tdb 1.11
67 ajm 1.7 try {
68     // Parse the input
69 tdb 1.13 InputSource inputSource = new InputSource(new StringReader(xml));
70     _factory.newSAXParser().parse(inputSource, new XMLStringParser(packet));
71 ajm 1.7 }
72     catch (Exception e) {
73 tdb 1.10 // couldn't parse the XML for some reason
74 tdb 1.13 throw new InvalidXMLException("Could not parse the XML: "+xml);
75 ajm 1.7 }
76 tdb 1.13
77 tdb 1.10 // parsed successfully, return the packet
78 ajm 1.7 return packet;
79     }
80    
81     /**
82     * Overrides the {@link java.lang.Object#toString() Object.toString()}
83     * method to provide clean logging (every class should have this).
84     *
85 tdb 1.16 * This uses the uk.org.iscream.cms.server.util.NameFormat class
86 ajm 1.7 * to format the toString()
87     *
88     * @return the name of this class and its CVS revision
89     */
90     public String toString() {
91     return FormatName.getName(
92     _name,
93     getClass().getName(),
94     REVISION);
95     }
96    
97     //---PRIVATE METHODS---
98    
99     //---ACCESSOR/MUTATOR METHODS---
100    
101     //---ATTRIBUTES---
102    
103     /**
104     * This is the friendly identifier of the
105     * component this class is running in.
106     * eg, a Filter may be called "filter1",
107     * If this class does not have an owning
108     * component, a name from the configuration
109     * can be placed here. This name could also
110     * be changed to null for utility classes.
111     */
112     private String _name = null;
113    
114     //---STATIC ATTRIBUTES---
115    
116     }