namespacesupport.java
来自「JAVA 所有包」· Java 代码 · 共 482 行 · 第 1/2 页
JAVA
482 行
// prefix not found return null; } // getURI(String):String /** * @see com.sun.org.apache.xerces.internal.xni.NamespaceContext#getPrefix(String) */ public String getPrefix(String uri) { // find uri in current context for (int i = fNamespaceSize; i > 0; i -= 2) { if (fNamespace[i - 1] == uri) { if (getURI(fNamespace[i - 2]) == uri) return fNamespace[i - 2]; } } // uri not found return null; } // getPrefix(String):String /** * @see com.sun.org.apache.xerces.internal.xni.NamespaceContext#getDeclaredPrefixCount() */ public int getDeclaredPrefixCount() { return (fNamespaceSize - fContext[fCurrentContext]) / 2; } // getDeclaredPrefixCount():int /** * @see com.sun.org.apache.xerces.internal.xni.NamespaceContext#getDeclaredPrefixAt(int) */ public String getDeclaredPrefixAt(int index) { return fNamespace[fContext[fCurrentContext] + index * 2]; } // getDeclaredPrefixAt(int):String public Iterator getPrefixes(){ int count = 0; if (fPrefixes.length < (fNamespace.length/2)) { // resize prefix array String[] prefixes = new String[fNamespaceSize]; fPrefixes = prefixes; } String prefix = null; boolean unique = true; for (int i = 2; i < (fNamespaceSize-2); i += 2) { prefix = fNamespace[i + 2]; for (int k=0;k<count;k++){ if (fPrefixes[k]==prefix){ unique = false; break; } } if (unique){ fPrefixes[count++] = prefix; } unique = true; } return new IteratorPrefixes(fPrefixes, count); }//getPrefixes /** * @see com.sun.org.apache.xerces.internal.xni.NamespaceContext#getAllPrefixes() */ public Enumeration getAllPrefixes() { int count = 0; if (fPrefixes.length < (fNamespace.length/2)) { // resize prefix array String[] prefixes = new String[fNamespaceSize]; fPrefixes = prefixes; } String prefix = null; boolean unique = true; for (int i = 2; i < (fNamespaceSize-2); i += 2) { prefix = fNamespace[i + 2]; for (int k=0;k<count;k++){ if (fPrefixes[k]==prefix){ unique = false; break; } } if (unique){ fPrefixes[count++] = prefix; } unique = true; } return new Prefixes(fPrefixes, count); } public Vector getPrefixes(String uri){ int count = 0; String prefix = null; boolean unique = true; Vector prefixList = new Vector(); for (int i = fNamespaceSize; i >0 ; i -= 2) { if(fNamespace[i-1] == uri){ if(!prefixList.contains(fNamespace[i-2])) prefixList.add(fNamespace[i-2]); } } return prefixList; } /* * non-NamespaceContext methods */ /** * Checks whether a binding or unbinding for * the given prefix exists in the context. * * @param prefix The prefix to look up. * * @return true if the given prefix exists in the context */ public boolean containsPrefix(String prefix) { // find prefix in context for (int i = fNamespaceSize; i > 0; i -= 2) { if (fNamespace[i - 2] == prefix) { return true; } } // prefix not found return false; } /** * Checks whether a binding or unbinding for * the given prefix exists in the current context. * * @param prefix The prefix to look up. * * @return true if the given prefix exists in the current context */ public boolean containsPrefixInCurrentContext(String prefix) { // find prefix in current context for (int i = fContext[fCurrentContext]; i < fNamespaceSize; i += 2) { if (fNamespace[i] == prefix) { return true; } } // prefix not found return false; } protected final class IteratorPrefixes implements Iterator { private String[] prefixes; private int counter = 0; private int size = 0; /** * Constructor for Prefixes. */ public IteratorPrefixes(String [] prefixes, int size) { this.prefixes = prefixes; this.size = size; } /** * @see java.util.Enumeration#hasMoreElements() */ public boolean hasNext() { return (counter < size); } /** * @see java.util.Enumeration#nextElement() */ public Object next() { if (counter< size){ return fPrefixes[counter++]; } throw new NoSuchElementException("Illegal access to Namespace prefixes enumeration."); } public String toString(){ StringBuffer buf = new StringBuffer(); for (int i=0;i<size;i++){ buf.append(prefixes[i]); buf.append(" "); } return buf.toString(); } public void remove(){ throw new UnsupportedOperationException(); } } protected final class Prefixes implements Enumeration { private String[] prefixes; private int counter = 0; private int size = 0; /** * Constructor for Prefixes. */ public Prefixes(String [] prefixes, int size) { this.prefixes = prefixes; this.size = size; } /** * @see java.util.Enumeration#hasMoreElements() */ public boolean hasMoreElements() { return (counter< size); } /** * @see java.util.Enumeration#nextElement() */ public Object nextElement() { if (counter< size){ return fPrefixes[counter++]; } throw new NoSuchElementException("Illegal access to Namespace prefixes enumeration."); } public String toString(){ StringBuffer buf = new StringBuffer(); for (int i=0;i<size;i++){ buf.append(prefixes[i]); buf.append(" "); } return buf.toString(); } } } // class NamespaceSupport
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?