1 19 package org.netbeans.modules.xsl.grammar; 20 21 import java.beans.FeatureDescriptor ; 22 import java.util.Enumeration ; 23 import org.netbeans.modules.xml.api.model.GrammarEnvironment; 24 import org.netbeans.modules.xml.api.model.GrammarQuery; 25 import org.netbeans.modules.xml.api.model.GrammarQueryManager; 26 import org.openide.filesystems.FileObject; 27 import org.w3c.dom.DocumentType ; 28 import org.w3c.dom.Element ; 29 import org.w3c.dom.Node ; 30 import org.xml.sax.InputSource ; 31 32 import org.openide.filesystems.FileObject; 33 34 import org.netbeans.modules.xsl.XSLDataObject; 35 import org.openide.loaders.DataObject; 36 import org.openide.loaders.DataObjectNotFoundException; 37 38 43 public class XSLGrammarQueryProvider extends GrammarQueryManager { 44 45 static final String PUBLIC = "!!! find it out"; static final String SYSTEM = "!!! find it out"; static final String NAMESPACE = XSLGrammarQuery.XSLT_NAMESPACE_URI; 48 49 private String prefix = null; 50 51 public Enumeration enabled(GrammarEnvironment ctx) { 52 53 if (ctx.getFileObject() == null) return null; 54 55 prefix = null; 56 Enumeration en = ctx.getDocumentChildren(); 57 while (en.hasMoreElements()) { 58 Node next = (Node ) en.nextElement(); 59 if (next.getNodeType() == next.DOCUMENT_TYPE_NODE) { 60 } else if (next.getNodeType() == next.ELEMENT_NODE) { 65 Element element = (Element ) next; 66 String tag = element.getTagName(); 67 if (tag.indexOf(":") == -1) { if ("transformation".equals(tag) || "stylesheet".equals(tag)) { String ns = element.getAttribute("xmlns"); if (NAMESPACE.equals(ns)) { 71 return org.openide.util.Enumerations.singleton (next); 72 } 73 } 74 } else { 75 prefix = tag.substring(0, tag.indexOf(":")); String local = tag.substring(tag.indexOf(":") + 1); if ("transformation".equals(local) || "stylesheet".equals(local)) { String ns = element.getAttribute("xmlns:" + prefix); if (NAMESPACE.equals(ns)) { 80 return org.openide.util.Enumerations.singleton (next); 81 } 82 } 83 } 84 } 85 } 86 87 FileObject fo = ctx.getFileObject(); 89 if (fo != null) { 90 if (XSLDataObject.MIME_TYPE.equals(fo.getMIMEType())) { 91 return org.openide.util.Enumerations.empty(); 95 } 96 } 97 98 return null; 99 } 100 101 public FeatureDescriptor getDescriptor() { 102 return new FeatureDescriptor (); 103 } 104 105 public GrammarQuery getGrammar(GrammarEnvironment input) { 106 try { 107 FileObject fo = input.getFileObject(); 108 if (fo == null) throw new IllegalStateException ("GrammarEnvironment has changed between enabled() and getGrammar()!"); DataObject dataObj = DataObject.find(fo); 110 return new XSLGrammarQuery(dataObj); 111 112 } catch (DataObjectNotFoundException e) { 113 throw new IllegalStateException ("Missing DataObject " + e.getFileObject() + "!"); } 115 } 116 117 } 118 | Popular Tags |