1 16 package org.apache.xerces.xinclude; 17 18 import java.util.Enumeration ; 19 20 import org.apache.xerces.util.NamespaceSupport; 21 import org.apache.xerces.util.XMLSymbols; 22 import org.apache.xerces.xni.NamespaceContext; 23 24 38 public class MultipleScopeNamespaceSupport extends NamespaceSupport { 39 40 protected int[] fScope = new int[8]; 41 protected int fCurrentScope; 42 43 46 public MultipleScopeNamespaceSupport() { 47 super(); 48 fCurrentScope = 0; 49 fScope[0] = 0; 50 } 51 52 55 public MultipleScopeNamespaceSupport(NamespaceContext context) { 56 super(context); 57 fCurrentScope = 0; 58 fScope[0] = 0; 59 } 60 61 64 public Enumeration getAllPrefixes() { 65 int count = 0; 66 if (fPrefixes.length < (fNamespace.length / 2)) { 67 String [] prefixes = new String [fNamespaceSize]; 69 fPrefixes = prefixes; 70 } 71 String prefix = null; 72 boolean unique = true; 73 for (int i = fContext[fScope[fCurrentScope]]; 74 i <= (fNamespaceSize - 2); 75 i += 2) { 76 prefix = fNamespace[i]; 77 for (int k = 0; k < count; k++) { 78 if (fPrefixes[k] == prefix) { 79 unique = false; 80 break; 81 } 82 } 83 if (unique) { 84 fPrefixes[count++] = prefix; 85 } 86 unique = true; 87 } 88 return new Prefixes(fPrefixes, count); 89 } 90 91 public int getScopeForContext(int context) { 92 int scope = fCurrentScope; 93 while (context < fScope[scope]) { 94 scope--; 95 } 96 return scope; 97 } 98 99 102 public String getPrefix(String uri) { 103 return getPrefix(uri, fNamespaceSize, fContext[fScope[fCurrentScope]]); 104 } 105 106 109 public String getURI(String prefix) { 110 return getURI(prefix, fNamespaceSize, fContext[fScope[fCurrentScope]]); 111 } 112 113 public String getPrefix(String uri, int context) { 114 return getPrefix(uri, fContext[context+1], fContext[fScope[getScopeForContext(context)]]); 115 } 116 117 public String getURI(String prefix, int context) { 118 return getURI(prefix, fContext[context+1], fContext[fScope[getScopeForContext(context)]]); 119 } 120 121 public String getPrefix(String uri, int start, int end) { 122 if (uri == NamespaceContext.XML_URI) { 124 return XMLSymbols.PREFIX_XML; 125 } 126 if (uri == NamespaceContext.XMLNS_URI) { 127 return XMLSymbols.PREFIX_XMLNS; 128 } 129 130 for (int i = start; i > end; i -= 2) { 132 if (fNamespace[i - 1] == uri) { 133 if (getURI(fNamespace[i - 2]) == uri) 134 return fNamespace[i - 2]; 135 } 136 } 137 138 return null; 140 } 141 142 public String getURI(String prefix, int start, int end) { 143 if (prefix == XMLSymbols.PREFIX_XML) { 145 return NamespaceContext.XML_URI; 146 } 147 if (prefix == XMLSymbols.PREFIX_XMLNS) { 148 return NamespaceContext.XMLNS_URI; 149 } 150 151 for (int i = start; i > end; i -= 2) { 153 if (fNamespace[i - 2] == prefix) { 154 return fNamespace[i - 1]; 155 } 156 } 157 158 return null; 160 } 161 162 166 public void reset() { 167 fCurrentContext = fScope[fCurrentScope]; 168 fNamespaceSize = fContext[fCurrentContext]; 169 } 170 171 175 public void pushScope() { 176 if (fCurrentScope + 1 == fScope.length) { 177 int[] contextarray = new int[fScope.length * 2]; 178 System.arraycopy(fScope, 0, contextarray, 0, fScope.length); 179 fScope = contextarray; 180 } 181 pushContext(); 182 fScope[++fCurrentScope] = fCurrentContext; 183 } 184 185 189 public void popScope() { 190 fCurrentContext = fScope[fCurrentScope--]; 191 popContext(); 192 } 193 } 194 | Popular Tags |