1 19 20 package org.netbeans.modules.j2ee.dd.impl.client; 21 22 import java.io.IOException ; 23 import javax.xml.parsers.ParserConfigurationException ; 24 import javax.xml.parsers.SAXParser ; 25 import javax.xml.parsers.SAXParserFactory ; 26 import org.netbeans.modules.j2ee.dd.api.client.AppClient; 27 import org.netbeans.modules.j2ee.dd.impl.common.ParseUtils; 28 import org.openide.filesystems.FileObject; 29 import org.openide.util.NbBundle; 30 import org.xml.sax.*; 31 import org.xml.sax.helpers.DefaultHandler ; 32 33 34 41 public class ClientParseUtils { 42 43 44 46 public static String getVersion(java.io.InputStream is) throws java.io.IOException , SAXException { 47 return ParseUtils.getVersion(is, new VersionHandler(), DDResolver.getInstance()); 48 } 49 50 52 public static String getVersion(InputSource is) throws IOException , SAXException { 53 return ParseUtils.getVersion(is, new VersionHandler(), DDResolver.getInstance()); 54 } 55 56 private static class VersionHandler extends DefaultHandler { 57 public void startElement(String uri, String localName, String rawName, Attributes atts) throws SAXException { 58 if ("application-client".equals(rawName)) { String version = atts.getValue("version"); throw new SAXException(ParseUtils.EXCEPTION_PREFIX+(version==null?AppClient.VERSION_1_3:version)); 61 } 62 } 63 } 64 65 private static class DDResolver implements EntityResolver { 66 static DDResolver resolver; 67 static synchronized DDResolver getInstance() { 68 if (resolver==null) { 69 resolver=new DDResolver(); 70 } 71 return resolver; 72 } 73 public InputSource resolveEntity(String publicId, String systemId) { 74 if ("-//Sun Microsystems, Inc.//DTD J2EE Application Client 1.3//EN".equals(publicId)) { 75 return new InputSource("nbres:/org/netbeans/modules/j2ee/dd/impl/resources/application-client_1_3.dtd"); } else if ("http://java.sun.com/xml/ns/j2ee/application-client_1_4.xsd".equals(systemId)) { 77 return new InputSource("nbres:/org/netbeans/modules/j2ee/dd/impl/resources/application-client_1_4.xsd"); } else if ("http://java.sun.com/xml/ns/javaee/application-client_5.xsd".equals(systemId)) { 79 return new InputSource("nbres:/org/netbeans/modules/j2ee/dd/impl/resources/application-client_5.xsd"); } else { 81 return null; 83 } 84 } 85 } 86 87 88 public static SAXParseException parse(FileObject fo) 89 throws org.xml.sax.SAXException , java.io.IOException { 90 return parse(new InputSource(fo.getInputStream())); 92 } 93 94 public static SAXParseException parse (InputSource is) 95 throws org.xml.sax.SAXException , java.io.IOException { 96 return ParseUtils.parseDD(is, DDResolver.getInstance()); 97 } 98 99 100 } 101 | Popular Tags |