1 19 20 package org.netbeans.modules.websvc.wsdl; 21 22 import java.io.*; 23 import java.util.Enumeration ; 24 25 import org.w3c.dom.*; 26 import org.xml.sax.InputSource ; 27 28 import org.openide.util.Enumerations; 29 30 import org.netbeans.modules.xml.api.model.GrammarEnvironment; 31 import org.netbeans.modules.xml.api.model.GrammarQuery; 32 import org.netbeans.modules.xml.api.model.GrammarQueryManager; 33 import org.netbeans.modules.xml.api.model.DTDUtil; 34 35 39 public class WSSchemaGrammarQueryMgr extends GrammarQueryManager 40 { 41 private static final String XMLNS_ATTR = "xmlns"; private static final String JAXRPC_CONFIG_TAG = "configuration"; private static final String WSDL_DEFINITIONS = "definitions"; 45 private static final int TYPE_WSDL = 0; 46 private static final int TYPE_JAXRPC_CONFIG = 1; 47 48 private static final String PUBLIC_WSDL="http://schemas.xmlsoap.org/wsdl/"; private static final String PUBLIC_SOAP="http://schemas.xmlsoap.org/wsdl/soap/"; private static final String PUBLIC_SOAPENC="http://schemas.xmlsoap.org/soap/encoding/"; private static final String PUBLIC_SCHEMA="http://www.w3.org/2001/XMLSchema"; 53 private int schema_type; 54 private String prefix, ns_wsdl, ns_soap, ns_soapenc, ns_schema; 55 56 public Enumeration enabled(GrammarEnvironment ctx) { 57 if (ctx.getFileObject() == null) { 58 return null; 59 } 60 61 Enumeration en = ctx.getDocumentChildren(); 62 while(en.hasMoreElements()) { 63 Node next = (Node) en.nextElement(); 64 if(next.getNodeType() == next.DOCUMENT_TYPE_NODE) { 65 schema_type=-1; 66 return null; } else if(next.getNodeType() == next.ELEMENT_NODE) { 68 prefix=null; 69 ns_wsdl="wsdl"; ns_soap="soap"; ns_soapenc="soapenc"; ns_schema="xsd"; Element element = (Element) next; 74 String tag = element.getTagName(); 75 if(JAXRPC_CONFIG_TAG.equals(tag)) { 76 String xmlns = element.getAttribute(XMLNS_ATTR); 77 if(WSSchemaCatalog.JAXRPC_CONFIG_1_1.equals(xmlns) || WSSchemaCatalog.JAXRPC_CONFIG_1_1_SLASH.equals(xmlns)) { 78 schema_type=TYPE_JAXRPC_CONFIG; 79 return Enumerations.singleton (next); 80 } 81 } else if (WSDL_DEFINITIONS.equals(tag)) { 82 schema_type=TYPE_WSDL; 83 prefix=""; 84 } else if (tag.endsWith(":"+WSDL_DEFINITIONS)) { 85 schema_type=TYPE_WSDL; 86 prefix = tag.substring(0,tag.indexOf(":"+WSDL_DEFINITIONS)); 87 } 88 if (prefix!=null) { 89 NamedNodeMap map = element.getAttributes(); 90 for (int i=0; i<map.getLength();i++) { 91 Attr attr = (Attr)map.item(i); 92 String name = attr.getName(); 93 if (name.startsWith("xmlns:")) { if (PUBLIC_WSDL.equals(attr.getValue())) 95 ns_wsdl=name.substring(6); else if (PUBLIC_SOAP.equals(attr.getValue())) 97 ns_soap=name.substring(6); else if (PUBLIC_SOAPENC.equals(attr.getValue())) 99 ns_soapenc=name.substring(6); else if (PUBLIC_SCHEMA.equals(attr.getValue())) 101 ns_schema=name.substring(6); } 103 } 104 return Enumerations.singleton (next); 105 } 106 } 107 } 108 109 return null; 110 } 111 112 public java.beans.FeatureDescriptor getDescriptor() { 113 return new java.beans.FeatureDescriptor (); 114 } 115 116 118 public GrammarQuery getGrammar(GrammarEnvironment ctx) { 119 InputSource inputSource=null; 120 switch (schema_type) { 121 case TYPE_WSDL: { 122 StringBuffer buffer=new StringBuffer (); 123 if (prefix.length()==0) { 124 buffer.append("<!ENTITY % root_prefix ''>"); } else { 126 buffer.append("<!ENTITY % root_prefix '"+prefix+":'>"); } 128 buffer.append("<!ENTITY % wsdl '"+ns_wsdl+"'>"); buffer.append("<!ENTITY % soap '"+ns_soap+"'>"); buffer.append("<!ENTITY % soapenc '"+ns_soapenc+"'>"); buffer.append("<!ENTITY % wsdl_prefix '"+ns_wsdl+":'>"); buffer.append("<!ENTITY % soap_prefix '"+ns_soap+":'>"); buffer.append("<!ENTITY % p '"+ns_schema+":'><!ENTITY % s ':"+ns_schema+"'>"); InputStream is = getClass().getResourceAsStream("/org/netbeans/modules/websvc/wsdl/resources/wsdl-soap.dtd"); BufferedReader br = new BufferedReader(new InputStreamReader(is)); 136 String line = null; 137 try { 138 while ((line=br.readLine())!=null) { 139 buffer.append(line); 140 } 141 br.close(); 142 } catch (IOException ex) { 143 return null; 144 } 145 inputSource = new InputSource (new StringReader(buffer.toString())); 146 inputSource.setSystemId("nbres:/org/netbeans/modules/websvc/wsdl/resources/wsdl-soap.dtd"); } break; 148 case TYPE_JAXRPC_CONFIG: { 149 inputSource = new InputSource ("nbres:/org/netbeans/modules/websvc/wsdl/config/resources/jax-rpc-ri-config_1_1.dtd"); }break; 151 } 152 if (inputSource!=null) { 153 return DTDUtil.parseDTD(true, inputSource); 154 } 155 return null; 156 } 157 } 158 | Popular Tags |