1 57 package com.sun.org.apache.xerces.internal.xinclude; 58 59 import java.util.Enumeration ; 60 61 import com.sun.org.apache.xerces.internal.util.NamespaceSupport; 62 import com.sun.org.apache.xerces.internal.util.XMLSymbols; 63 import com.sun.org.apache.xerces.internal.xni.NamespaceContext; 64 65 79 public class MultipleScopeNamespaceSupport extends NamespaceSupport { 80 81 protected int[] fScope = new int[8]; 82 protected int fCurrentScope; 83 84 87 public MultipleScopeNamespaceSupport() { 88 super(); 89 fCurrentScope = 0; 90 fScope[0] = 0; 91 } 92 93 96 public MultipleScopeNamespaceSupport(NamespaceContext context) { 97 super(context); 98 fCurrentScope = 0; 99 fScope[0] = 0; 100 } 101 102 105 public Enumeration getAllPrefixes() { 106 int count = 0; 107 if (fPrefixes.length < (fNamespace.length / 2)) { 108 String [] prefixes = new String [fNamespaceSize]; 110 fPrefixes = prefixes; 111 } 112 String prefix = null; 113 boolean unique = true; 114 for (int i = fContext[fScope[fCurrentScope]]; 115 i <= (fNamespaceSize - 2); 116 i += 2) { 117 prefix = fNamespace[i]; 118 for (int k = 0; k < count; k++) { 119 if (fPrefixes[k] == prefix) { 120 unique = false; 121 break; 122 } 123 } 124 if (unique) { 125 fPrefixes[count++] = prefix; 126 } 127 unique = true; 128 } 129 return new Prefixes(fPrefixes, count); 130 } 131 132 public int getScopeForContext(int context) { 133 int scope = fCurrentScope; 134 while (context < fScope[scope]) { 135 scope--; 136 } 137 return scope; 138 } 139 140 143 public String getPrefix(String uri) { 144 return getPrefix(uri, fNamespaceSize, fScope[fCurrentScope]); 145 } 146 147 150 public String getURI(String prefix) { 151 return getURI(prefix, fNamespaceSize, fScope[fCurrentScope]); 152 } 153 154 public String getPrefix(String uri, int context) { 155 return getPrefix(uri, fContext[context+1], fScope[getScopeForContext(context)]); 156 } 157 158 public String getURI(String prefix, int context) { 159 return getURI(prefix, fContext[context+1], fScope[getScopeForContext(context)]); 160 } 161 162 public String getPrefix(String uri, int start, int end) { 163 if (uri == NamespaceContext.XML_URI) { 165 return XMLSymbols.PREFIX_XML; 166 } 167 if (uri == NamespaceContext.XMLNS_URI) { 168 return XMLSymbols.PREFIX_XMLNS; 169 } 170 171 for (int i = start; i > end; i -= 2) { 173 if (fNamespace[i - 1] == uri) { 174 if (getURI(fNamespace[i - 2]) == uri) 175 return fNamespace[i - 2]; 176 } 177 } 178 179 return null; 181 } 182 183 public String getURI(String prefix, int start, int end) { 184 if (prefix == XMLSymbols.PREFIX_XML) { 186 return NamespaceContext.XML_URI; 187 } 188 if (prefix == XMLSymbols.PREFIX_XMLNS) { 189 return NamespaceContext.XMLNS_URI; 190 } 191 192 for (int i = start; i > end; i -= 2) { 194 if (fNamespace[i - 2] == prefix) { 195 return fNamespace[i - 1]; 196 } 197 } 198 199 return null; 201 } 202 203 207 public void reset() { 208 fCurrentContext = fScope[fCurrentScope]; 209 fNamespaceSize = fContext[fCurrentContext]; 210 } 211 212 216 public void pushScope() { 217 if (fCurrentScope + 1 == fScope.length) { 218 int[] contextarray = new int[fScope.length * 2]; 219 System.arraycopy(fScope, 0, contextarray, 0, fScope.length); 220 fScope = contextarray; 221 } 222 pushContext(); 223 fScope[++fCurrentScope] = fCurrentContext; 224 } 225 226 230 public void popScope() { 231 fCurrentContext = fScope[fCurrentScope--]; 232 popContext(); 233 } 234 } 235 | Popular Tags |