1 6 7 package org.netbeans.modules.piagetproject.layout; 8 9 13 import org.xml.sax.helpers.DefaultHandler ; 14 import org.xml.sax.SAXException ; 15 import org.xml.sax.Attributes ; 16 17 public class XMLParserHandler extends DefaultHandler { 18 19 String name, q; 20 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 { 31 layout = new Layout(); 32 } 33 34 public void endDocument() throws SAXException { 35 if(!init1||!init2)layout = null; 36 } 37 38 public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { 39 q = qName; 40 if(qIs("name")){ 41 layout.name = attributes.getValue("unique"); 42 init1 = true; 43 }else if(qIs("path")){ 44 String orientation = attributes.getValue("orientation"); 45 double weight = new Double (attributes.getValue("weight")).doubleValue(); 46 int number = new Integer (attributes.getValue("number")).intValue(); 47 layout.addPath(number, weight, orientation); 48 init2 = true; 49 50 }else if(qIs("editor-area")){ 51 layout.name = "editor"; 52 init1 = true; 53 } 54 } 55 56 57 public void endElement(String uri, String localName, String qName) throws SAXException { 58 } 59 60 61 public void characters(char ch[], int start, int length) throws SAXException { 62 } 63 64 private boolean qIs(String s){ 65 return q.equalsIgnoreCase(s); 66 } 67 68 public Layout getResultLayout(){ 69 return layout; 70 } 71 72 } 73 | Popular Tags |