1 19 20 package org.netbeans.modules.web.jsf; 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 JSFGrammarQueryManager extends org.netbeans.modules.xml.api.model.GrammarQueryManager 33 { 34 private static final String XMLNS_ATTR="xmlns"; private static final String JSF_TAG="faces-config"; 37 public java.util.Enumeration enabled(org.netbeans.modules.xml.api.model.GrammarEnvironment ctx) { 38 if (ctx.getFileObject() == null) return null; 39 Enumeration en = ctx.getDocumentChildren(); 40 while (en.hasMoreElements()) { 41 Node next = (Node ) en.nextElement(); 42 if (next.getNodeType() == next.DOCUMENT_TYPE_NODE) { 43 return null; } else if (next.getNodeType() == next.ELEMENT_NODE) { 45 Element element = (Element ) next; 46 String tag = element.getTagName(); 47 if (JSF_TAG.equals(tag)) { 48 String xmlns = element.getAttribute(XMLNS_ATTR); 49 if (xmlns!=null && JSFCatalog.JAVAEE_NS.equals(xmlns)){ 50 return org.openide.util.Enumerations.singleton (next); 51 } 52 } 53 } 54 } 55 56 return null; 57 } 58 59 public java.beans.FeatureDescriptor getDescriptor() { 60 return new java.beans.FeatureDescriptor (); 61 } 62 63 65 public org.netbeans.modules.xml.api.model.GrammarQuery getGrammar(org.netbeans.modules.xml.api.model.GrammarEnvironment ctx) { 66 UserCatalog catalog = UserCatalog.getDefault(); 67 if (catalog != null) { 68 EntityResolver resolver = catalog.getEntityResolver(); 69 if (resolver != null) { 70 try { 71 String schema = JSFCatalog.JSF_ID_1_2; 72 InputSource inputSource = resolver.resolveEntity(schema, null); 73 if (inputSource!=null) { 74 return DTDUtil.parseDTD(true, inputSource); 75 } 76 } catch(SAXException e) { 77 e.printStackTrace(System.out); 78 } catch(java.io.IOException e) { 79 e.printStackTrace(System.out); 80 } 81 } 82 } 83 return null; 84 } 85 86 } 87 | Popular Tags |