1 5 package xdoclet.loader; 6 7 import java.io.IOException ; 8 9 import javax.xml.parsers.ParserConfigurationException ; 10 import javax.xml.parsers.SAXParser ; 11 import javax.xml.parsers.SAXParserFactory ; 12 13 import org.xml.sax.Attributes ; 14 import org.xml.sax.InputSource ; 15 import org.xml.sax.SAXException ; 16 import org.xml.sax.SAXParseException ; 17 import org.xml.sax.helpers.DefaultHandler ; 18 19 26 class XDocletXmlParser extends DefaultHandler 27 { 28 private final SAXParserFactory _factory; 29 private XDocletModule module; 30 31 public XDocletXmlParser() 32 { 33 _factory = SAXParserFactory.newInstance(); 34 _factory.setValidating(false); 35 } 36 37 42 public XDocletModule parse(InputSource in) 43 { 44 try { 45 SAXParser parser = _factory.newSAXParser(); 46 47 parser.parse(in, this); 48 } 49 catch (IOException e) { 50 module = null; 51 e.printStackTrace(); 52 } 53 catch (IllegalArgumentException e) { 54 module = null; 55 e.printStackTrace(); 56 } 57 catch (ParserConfigurationException e) { 58 module = null; 59 e.printStackTrace(); 60 } 61 catch (SAXParseException e) { 62 module = null; 63 e.printStackTrace(); 64 System.out.println("location:" + in.getSystemId() + ":" + e.getLineNumber() + "," + e.getColumnNumber()); 65 } 66 catch (SAXException e) { 67 module = null; 68 e.printStackTrace(); 69 System.out.println("location:" + in.getSystemId()); 70 } 71 return module; 72 } 73 74 public void startDocument() 75 { 76 module = new XDocletModule(); 77 } 78 79 public void startElement(String namespaceURI, String localName, String qName, Attributes attributes) 80 { 81 82 if (qName.equals("taghandler")) { 83 module.addTagHandler( 84 attributes.getValue("namespace"), 85 attributes.getValue("class") 86 ); 87 } 88 else 89 if (qName.equals("subtask")) { 90 module.addSubTask( 91 attributes.getValue("name"), 92 attributes.getValue("implementation-class"), 93 attributes.getValue("parent-task-class") 94 ); 95 } 96 } 97 } 98 | Popular Tags |