1 6 7 package analyzer.layout; 8 9 13 import org.xml.sax.helpers.DefaultHandler ; 14 import org.xml.sax.SAXException ; 15 import org.xml.sax.Attributes ; 16 import java.util.*; 17 18 public class XMLParserHandler extends DefaultHandler { 19 20 String name,q; 21 int w,h; 23 ModeLayout layout; 24 boolean init1, init2; 25 26 public XMLParserHandler() { 27 init1=init2=false; 28 } 29 30 31 public void startDocument() throws SAXException { 32 layout=new ModeLayout(); 33 } 34 35 public void endDocument() throws SAXException { 36 if(!init1||!init2)layout=null; 37 } 38 39 public void startElement(String uri,String localName,String qName,Attributes attributes) throws SAXException { 40 q=qName; 41 if(qIs("name")){ 42 layout.name=attributes.getValue("unique"); 43 init1=true; 44 }else if(qIs("path")){ 45 String orientation=attributes.getValue("orientation"); 46 double weight=new Double (attributes.getValue("weight")).doubleValue(); 47 int number=new Integer (attributes.getValue("number")).intValue(); 48 layout.addPath(number,weight,orientation); 49 init2=true; 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 ModeLayout getResultLayout(){ 69 return layout; 70 } 71 72 } 73 | Popular Tags |