1 57 58 package com.sun.org.apache.xerces.internal.dom; 59 60 import java.util.StringTokenizer ; 61 import java.util.Vector ; 62 import org.w3c.dom.DOMImplementationList ; 63 import org.w3c.dom.DOMImplementationSource ; 64 import org.w3c.dom.DOMImplementation ; 65 import com.sun.org.apache.xerces.internal.dom.DOMImplementationListImpl; 66 67 77 public class DOMImplementationSourceImpl 78 implements DOMImplementationSource { 79 80 89 public DOMImplementation getDOMImplementation(String features) { 90 DOMImplementation impl = 92 CoreDOMImplementationImpl.getDOMImplementation(); 93 if (testImpl(impl, features)) { 94 return impl; 95 } 96 impl = DOMImplementationImpl.getDOMImplementation(); 98 if (testImpl(impl, features)) { 99 return impl; 100 } 101 102 return null; 103 } 104 105 116 public DOMImplementationList getDOMImplementationList(String features) { 117 DOMImplementation impl = CoreDOMImplementationImpl.getDOMImplementation(); 119 final Vector implementations = new Vector (); 120 if (testImpl(impl, features)) { 121 implementations.addElement(impl); 122 } 123 impl = DOMImplementationImpl.getDOMImplementation(); 124 if (testImpl(impl, features)) { 125 implementations.addElement(impl); 126 } 127 128 return new DOMImplementationListImpl(implementations); 129 } 130 131 boolean testImpl(DOMImplementation impl, String features) { 132 133 StringTokenizer st = new StringTokenizer (features); 134 String feature = null; 135 String version = null; 136 137 if (st.hasMoreTokens()) { 138 feature = st.nextToken(); 139 } 140 while (feature != null) { 141 boolean isVersion = false; 142 if (st.hasMoreTokens()) { 143 char c; 144 version = st.nextToken(); 145 c = version.charAt(0); 146 switch (c) { 147 case '0': case '1': case '2': case '3': case '4': 148 case '5': case '6': case '7': case '8': case '9': 149 isVersion = true; 150 } 151 } else { 152 version = null; 153 } 154 if (isVersion) { 155 if (!impl.hasFeature(feature, version)) { 156 return false; 157 } 158 if (st.hasMoreTokens()) { 159 feature = st.nextToken(); 160 } else { 161 feature = null; 162 } 163 } else { 164 if (!impl.hasFeature(feature, null)) { 165 return false; 166 } 167 feature = version; 168 } 169 } 170 return true; 171 } 172 } 173 | Popular Tags |