1 package net.sf.saxon.instruct; 2 import net.sf.saxon.om.NamePool; 3 import net.sf.saxon.om.NamespaceConstant; 4 import net.sf.saxon.om.NamespaceResolver; 5 6 import java.io.Serializable ; 7 import java.util.ArrayList ; 8 import java.util.Iterator ; 9 10 18 19 public final class SavedNamespaceContext implements Serializable , NamespaceResolver { 20 21 26 private int[] namespaceCodes; 27 private NamePool namePool; 28 29 36 37 public SavedNamespaceContext(int[] nscodes, NamePool pool) { 38 namespaceCodes = nscodes; 39 namePool = pool; 40 } 41 42 46 47 public int[] getNamespaceCodes() { 48 return namespaceCodes; 49 } 50 51 59 60 public String getURIForPrefix(String prefix, boolean useDefault) { 61 62 if (prefix.equals("") && !useDefault) { 63 return ""; 64 } 65 66 if (prefix.equals("xml")) { 67 return NamespaceConstant.XML; 68 } 69 70 for (int i=namespaceCodes.length-1; i>=0; i--) { 71 if (namePool.getPrefixFromNamespaceCode(namespaceCodes[i]).equals(prefix)) { 72 return namePool.getURIFromNamespaceCode(namespaceCodes[i]); 73 } 74 } 75 76 if (prefix.equals("") && useDefault) { 77 return ""; 79 } else { 80 return null; 81 } 82 } 83 84 88 89 public Iterator iteratePrefixes() { 90 ArrayList prefixes = new ArrayList (namespaceCodes.length); 91 for (int i=0; i<namespaceCodes.length; i++) { 92 prefixes.add(namePool.getPrefixFromNamespaceCode(namespaceCodes[i])); 93 } 94 return prefixes.iterator(); 95 } 96 97 98 } 99 100 | Popular Tags |