KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gui > updatecenterwizard > settings > CatalogXMLFileParser


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package gui.updatecenterwizard.settings;
21
22 import java.io.File JavaDoc;
23 import java.io.FileInputStream JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.lang.Integer JavaDoc;
26 import java.lang.StringBuffer JavaDoc;
27 import java.util.*;
28 import java.text.SimpleDateFormat JavaDoc;
29 import java.text.ParseException JavaDoc;
30 import java.util.Vector JavaDoc;
31 import javax.xml.parsers.SAXParser JavaDoc;
32 import javax.xml.parsers.SAXParserFactory JavaDoc;
33 import javax.xml.transform.TransformerException JavaDoc;
34 import org.xml.sax.Attributes JavaDoc;
35 import org.xml.sax.SAXException JavaDoc;
36 import org.xml.sax.XMLReader JavaDoc;
37 import org.xml.sax.helpers.*;
38
39 /**
40  *
41  * @author Jaromir.Uhrik@Sun.Com
42  */

43
44 public class CatalogXMLFileParser extends DefaultHandler{
45     public static final String JavaDoc CATALOG = "catalog";
46     public static final String JavaDoc NAME = "name";
47     public static final String JavaDoc FILE = "file";
48     public static final String JavaDoc PROXY_HOST = "proxy_host";
49     public static final String JavaDoc PROXY_PORT = "proxy_port";
50     public static final String JavaDoc MODULES = "modules";
51     
52     CatalogDataValues data;
53     StringBuffer JavaDoc buffer;
54     
55     /** Creates a new instance of StatHandler */
56     public CatalogXMLFileParser() throws SAXException JavaDoc{
57         data = null;
58     }
59     
60     /**
61      * Handles start of the document.
62      */

63     
64     public void startDocument() throws SAXException JavaDoc {
65     }
66     
67     
68     /**
69      * Handles start of some element.
70      */

71     public void startElement(String JavaDoc namespaceURI, String JavaDoc sName, String JavaDoc qName, Attributes JavaDoc attrs) throws SAXException JavaDoc {
72         buffer = new StringBuffer JavaDoc();
73         
74         if (qName.equals(CATALOG)) {
75             data = new CatalogDataValues();
76         }
77     }
78     
79     /**
80      * Handles character data.
81      */

82     public void characters(char buf[], int offset, int len) throws SAXException JavaDoc {
83         buffer.append(buf, offset, len);
84     }
85     
86     /**
87      * Handles ends of some elements.
88      */

89     public void endElement(String JavaDoc namespaceURI, String JavaDoc sName, String JavaDoc qName) throws SAXException JavaDoc {
90         
91         if (qName.equals(CATALOG)) {
92         }
93         if (qName.equals(NAME)) {
94             if (buffer.length() > 0){
95                 data.setUcName(buffer.toString());
96             }
97         }
98         if (qName.equals(FILE)) {
99             if (buffer.length() > 0){
100                 data.setUcFile(buffer.toString());
101             }
102         }
103         if (qName.equals(PROXY_HOST)) {
104             if (buffer.length() > 0){
105                 data.setProxyHost(buffer.toString());
106             }
107         }
108         if (qName.equals(PROXY_PORT)) {
109             if (buffer.length() > 0){
110                 data.setProxyPort(buffer.toString());
111             }
112         }
113         if (qName.equals(MODULES)) {
114             if (buffer.length() > 0){
115                 data.setModules(buffer.toString());
116             }
117         }
118     }
119     
120     public CatalogDataValues getData(){
121         return data;
122     }
123     
124 }
Popular Tags