1 16 17 package org.apache.xerces.dom; 18 19 import java.util.StringTokenizer ; 20 import java.util.Vector ; 21 import org.w3c.dom.DOMImplementationList ; 22 import org.w3c.dom.DOMImplementationSource ; 23 import org.w3c.dom.DOMImplementation ; 24 import org.apache.xerces.dom.DOMImplementationListImpl; 25 26 38 public class DOMImplementationSourceImpl 39 implements DOMImplementationSource { 40 41 50 public DOMImplementation getDOMImplementation(String features) { 51 DOMImplementation impl = 53 CoreDOMImplementationImpl.getDOMImplementation(); 54 if (testImpl(impl, features)) { 55 return impl; 56 } 57 impl = DOMImplementationImpl.getDOMImplementation(); 59 if (testImpl(impl, features)) { 60 return impl; 61 } 62 63 return null; 64 } 65 66 77 public DOMImplementationList getDOMImplementationList(String features) { 78 DOMImplementation impl = CoreDOMImplementationImpl.getDOMImplementation(); 80 final Vector implementations = new Vector (); 81 if (testImpl(impl, features)) { 82 implementations.addElement(impl); 83 } 84 impl = DOMImplementationImpl.getDOMImplementation(); 85 if (testImpl(impl, features)) { 86 implementations.addElement(impl); 87 } 88 89 return new DOMImplementationListImpl(implementations); 90 } 91 92 boolean testImpl(DOMImplementation impl, String features) { 93 94 StringTokenizer st = new StringTokenizer (features); 95 String feature = null; 96 String version = null; 97 98 if (st.hasMoreTokens()) { 99 feature = st.nextToken(); 100 } 101 while (feature != null) { 102 boolean isVersion = false; 103 if (st.hasMoreTokens()) { 104 char c; 105 version = st.nextToken(); 106 c = version.charAt(0); 107 switch (c) { 108 case '0': case '1': case '2': case '3': case '4': 109 case '5': case '6': case '7': case '8': case '9': 110 isVersion = true; 111 } 112 } else { 113 version = null; 114 } 115 if (isVersion) { 116 if (!impl.hasFeature(feature, version)) { 117 return false; 118 } 119 if (st.hasMoreTokens()) { 120 feature = st.nextToken(); 121 } else { 122 feature = null; 123 } 124 } else { 125 if (!impl.hasFeature(feature, null)) { 126 return false; 127 } 128 feature = version; 129 } 130 } 131 return true; 132 } 133 } 134 | Popular Tags |