KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > piagetproject > layout > XMLParserHandler


1 /*
2  * XMLParserHandler.java
3  *
4  * Created on April 22, 2005, 10:23 AM
5  */

6
7 package org.netbeans.modules.piagetproject.layout;
8
9 /**
10  *
11  * @author loicsegapelli
12  */

13 import org.xml.sax.helpers.DefaultHandler JavaDoc;
14 import org.xml.sax.SAXException JavaDoc;
15 import org.xml.sax.Attributes JavaDoc;
16
17 public class XMLParserHandler extends DefaultHandler JavaDoc{
18     
19     String JavaDoc name, q;
20     //double verticalWeight,horizontalWeight;
21
int w, h;
22     Layout layout;
23     boolean init1, init2;
24     
25     public XMLParserHandler() {
26         init1 = init2 = false;
27     }
28     
29     
30     public void startDocument() throws SAXException JavaDoc {
31         layout = new Layout();
32     }
33     
34     public void endDocument() throws SAXException JavaDoc {
35         if(!init1||!init2)layout = null;
36     }
37     
38     public void startElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc qName, Attributes JavaDoc attributes) throws SAXException JavaDoc {
39         q = qName;
40         if(qIs("name")){
41             layout.name = attributes.getValue("unique");
42             init1 = true;
43         }else if(qIs("path")){
44             String JavaDoc orientation = attributes.getValue("orientation");
45             double weight = new Double JavaDoc(attributes.getValue("weight")).doubleValue();
46             int number = new Integer JavaDoc(attributes.getValue("number")).intValue();
47             layout.addPath(number, weight, orientation);
48             init2 = true;
49             /* something specific for the .wswmgr file... */
50         }else if(qIs("editor-area")){
51             layout.name = "editor";
52             init1 = true;
53         }
54     }
55     
56     
57     public void endElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc qName) throws SAXException JavaDoc {
58     }
59     
60     
61     public void characters(char ch[], int start, int length) throws SAXException JavaDoc{
62     }
63     
64     private boolean qIs(String JavaDoc s){
65         return q.equalsIgnoreCase(s);
66     }
67     
68     public Layout getResultLayout(){
69         return layout;
70     }
71     
72 }
73
Popular Tags