1 56 package org.jdom.output; 57 58 import java.util.*; 59 60 import org.jdom.Namespace; 61 62 72 class NamespaceStack { 73 74 private static final String CVS_ID = 75 "@(#) $RCSfile: NamespaceStack.java,v $ $Revision: 1.13 $ $Date: 2004/02/06 09:28:32 $ $Name: $"; 76 77 78 private Stack prefixes; 79 80 81 private Stack uris; 82 83 86 NamespaceStack() { 87 prefixes = new Stack(); 88 uris = new Stack(); 89 } 90 91 97 public void push(Namespace ns) { 98 prefixes.push(ns.getPrefix()); 99 uris.push(ns.getURI()); 100 } 101 102 108 public String pop() { 109 String prefix = (String )prefixes.pop(); 110 uris.pop(); 111 112 return prefix; 113 } 114 115 120 public int size() { 121 return prefixes.size(); 122 } 123 124 131 public String getURI(String prefix) { 132 int index = prefixes.lastIndexOf(prefix); 133 if (index == -1) { 134 return null; 135 } 136 String uri = (String )uris.elementAt(index); 137 return uri; 138 } 139 140 145 public String toString() { 146 StringBuffer buf = new StringBuffer (); 147 String sep = System.getProperty("line.separator"); 148 buf.append("Stack: " + prefixes.size() + sep); 149 for (int i = 0; i < prefixes.size(); i++) { 150 buf.append(prefixes.elementAt(i) + "&" + uris.elementAt(i) + sep); 151 } 152 return buf.toString(); 153 } 154 } 155 | Popular Tags |