1 23 24 package com.sun.enterprise.admin.servermgmt.util; 25 26 import org.xml.sax.Attributes ; 27 import org.xml.sax.InputSource ; 28 import org.xml.sax.SAXException ; 29 import org.xml.sax.EntityResolver ; 30 import org.xml.sax.helpers.DefaultHandler ; 31 import javax.xml.parsers.SAXParser ; 32 import javax.xml.parsers.SAXParserFactory ; 33 import java.io.File ; 34 35 public class DomainXmlSAXParser extends DefaultHandler { 36 private final String PROPERTY = "property"; 37 private int level = 0; 38 private String domainXmlEventListenerClass= null; 39 private File dtd; 40 41 public String getDomainXmlEventListenerClass() { 42 return domainXmlEventListenerClass; 43 } 44 45 public void parse(java.io.File domainXml,java.io.File dtd) throws javax.xml.parsers.ParserConfigurationException ,org.xml.sax.SAXException ,java.io.IOException { 46 this.dtd = dtd; 47 SAXParser saxParser; 48 SAXParserFactory factory = SAXParserFactory.newInstance(); 49 saxParser = factory.newSAXParser(); 50 saxParser.getXMLReader().setEntityResolver((EntityResolver )this); 51 saxParser.parse(domainXml,this); 52 } 53 54 55 public void startElement(String namespaceURI, String localName, String qName, Attributes attrs) 56 throws SAXException { 57 level++; 58 if ( level==2 && PROPERTY.equals(qName)){ 59 if (attrs != null) { 60 for (int i = 0; i < attrs.getLength(); i++) { 61 String aName = attrs.getQName(i); String aValue = attrs.getValue(aName); 63 if ("DomainXmlEventListenerClass".equals(aValue)) { 64 domainXmlEventListenerClass=attrs.getValue("value"); 65 } 66 } 67 } 68 } 69 } 70 71 72 public void endElement(String namespaceURI, String localName, String qName) 73 throws SAXException { 74 level--; 75 } 76 77 public InputSource resolveEntity(String publicId,String systemId) throws SAXException { 78 InputSource is = null; 79 try { 80 is = new InputSource (new java.io.FileInputStream (dtd)); 81 } catch(Exception e) { 82 throw new SAXException ("cannot resolve dtd", e); 83 } 84 return is; 85 } 86 } 87 88 89 | Popular Tags |