1 19 20 package org.netbeans.modules.j2ee.ddloaders.web; 21 import java.util.Enumeration ; 22 import org.w3c.dom.Element ; 23 import org.w3c.dom.Node ; 24 import org.xml.sax.*; 25 import org.netbeans.modules.xml.api.model.DTDUtil; 26 import org.netbeans.api.xml.services.UserCatalog; 27 28 32 public class DDGrammarQueryManager extends org.netbeans.modules.xml.api.model.GrammarQueryManager 33 { 34 private static final String XMLNS_ATTR="xmlns"; private static final String WEB_APP_TAG="web-app"; 37 private static final int WEB_APP_2_4 = 0; 38 private static final int WEB_APP_2_5 = 1; 39 40 private int version = WEB_APP_2_4; 41 42 public java.util.Enumeration enabled(org.netbeans.modules.xml.api.model.GrammarEnvironment ctx) { 43 if (ctx.getFileObject() == null) return null; 44 Enumeration en = ctx.getDocumentChildren(); 45 while (en.hasMoreElements()) { 46 Node next = (Node ) en.nextElement(); 47 if (next.getNodeType() == next.DOCUMENT_TYPE_NODE) { 48 return null; } else if (next.getNodeType() == next.ELEMENT_NODE) { 50 Element element = (Element ) next; 51 String tag = element.getTagName(); 52 if (WEB_APP_TAG.equals(tag)) { String xmlns = element.getAttribute(XMLNS_ATTR); 54 if (xmlns!=null && (DDCatalog.J2EE_NS.equals(xmlns) 55 || DDCatalog.JAVAEE_NS.equals(xmlns))){ 56 version = (DDCatalog.JAVAEE_NS.equals(xmlns)? WEB_APP_2_5 : WEB_APP_2_4); 57 return org.openide.util.Enumerations.singleton (next); 58 } 59 } 60 } 61 } 62 63 return null; 64 } 65 66 public java.beans.FeatureDescriptor getDescriptor() { 67 return new java.beans.FeatureDescriptor (); 68 } 69 70 72 public org.netbeans.modules.xml.api.model.GrammarQuery getGrammar(org.netbeans.modules.xml.api.model.GrammarEnvironment ctx) { 73 UserCatalog catalog = UserCatalog.getDefault(); 74 if (catalog != null) { 75 EntityResolver resolver = catalog.getEntityResolver(); 76 if (resolver != null) { 77 try { 78 String schema = DDCatalog.WEB_APP_2_4_ID; 81 InputSource inputSource = resolver.resolveEntity(schema, ""); 82 if (inputSource!=null) { 83 return DTDUtil.parseDTD(true, inputSource); 84 } 85 } catch(SAXException e) { 86 } catch(java.io.IOException e) { 87 } 88 } 89 } 90 return null; 91 } 92 93 } 94 | Popular Tags |