Desktop tool for browsing account info from EVE-Online
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

NamespaceStack.java 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*--
  2. $Id: NamespaceStack.java,v 1.14 2007/11/10 05:29:01 jhunter Exp $
  3. Copyright (C) 2000-2007 Jason Hunter & Brett McLaughlin.
  4. All rights reserved.
  5. Redistribution and use in source and binary forms, with or without
  6. modification, are permitted provided that the following conditions
  7. are met:
  8. 1. Redistributions of source code must retain the above copyright
  9. notice, this list of conditions, and the following disclaimer.
  10. 2. Redistributions in binary form must reproduce the above copyright
  11. notice, this list of conditions, and the disclaimer that follows
  12. these conditions in the documentation and/or other materials
  13. provided with the distribution.
  14. 3. The name "JDOM" must not be used to endorse or promote products
  15. derived from this software without prior written permission. For
  16. written permission, please contact <request_AT_jdom_DOT_org>.
  17. 4. Products derived from this software may not be called "JDOM", nor
  18. may "JDOM" appear in their name, without prior written permission
  19. from the JDOM Project Management <request_AT_jdom_DOT_org>.
  20. In addition, we request (but do not require) that you include in the
  21. end-user documentation provided with the redistribution and/or in the
  22. software itself an acknowledgement equivalent to the following:
  23. "This product includes software developed by the
  24. JDOM Project (http://www.jdom.org/)."
  25. Alternatively, the acknowledgment may be graphical using the logos
  26. available at http://www.jdom.org/images/logos.
  27. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  28. WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  29. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  30. DISCLAIMED. IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT
  31. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  32. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  33. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  34. USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  35. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  36. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  38. SUCH DAMAGE.
  39. This software consists of voluntary contributions made by many
  40. individuals on behalf of the JDOM Project and was originally
  41. created by Jason Hunter <jhunter_AT_jdom_DOT_org> and
  42. Brett McLaughlin <brett_AT_jdom_DOT_org>. For more information
  43. on the JDOM Project, please see <http://www.jdom.org/>.
  44. */
  45. package org.jdom.output;
  46. import java.util.*;
  47. import org.jdom.Namespace;
  48. /**
  49. * A non-public utility class used by both <code>{@link XMLOutputter}</code> and
  50. * <code>{@link SAXOutputter}</code> to manage namespaces in a JDOM Document
  51. * during output.
  52. *
  53. * @version $Revision: 1.14 $, $Date: 2007/11/10 05:29:01 $
  54. * @author Elliotte Rusty Harolde
  55. * @author Fred Trimble
  56. * @author Brett McLaughlin
  57. */
  58. class NamespaceStack {
  59. private static final String CVS_ID =
  60. "@(#) $RCSfile: NamespaceStack.java,v $ $Revision: 1.14 $ $Date: 2007/11/10 05:29:01 $ $Name: jdom_1_1 $";
  61. /** The prefixes available */
  62. private Stack prefixes;
  63. /** The URIs available */
  64. private Stack uris;
  65. /**
  66. * This creates the needed storage.
  67. */
  68. NamespaceStack() {
  69. prefixes = new Stack();
  70. uris = new Stack();
  71. }
  72. /**
  73. * This will add a new <code>{@link Namespace}</code>
  74. * to those currently available.
  75. *
  76. * @param ns <code>Namespace</code> to add.
  77. */
  78. public void push(Namespace ns) {
  79. prefixes.push(ns.getPrefix());
  80. uris.push(ns.getURI());
  81. }
  82. /**
  83. * This will remove the topmost (most recently added)
  84. * <code>{@link Namespace}</code>, and return its prefix.
  85. *
  86. * @return <code>String</code> - the popped namespace prefix.
  87. */
  88. public String pop() {
  89. String prefix = (String)prefixes.pop();
  90. uris.pop();
  91. return prefix;
  92. }
  93. /**
  94. * This returns the number of available namespaces.
  95. *
  96. * @return <code>int</code> - size of the namespace stack.
  97. */
  98. public int size() {
  99. return prefixes.size();
  100. }
  101. /**
  102. * Given a prefix, this will return the namespace URI most
  103. * rencently (topmost) associated with that prefix.
  104. *
  105. * @param prefix <code>String</code> namespace prefix.
  106. * @return <code>String</code> - the namespace URI for that prefix.
  107. */
  108. public String getURI(String prefix) {
  109. int index = prefixes.lastIndexOf(prefix);
  110. if (index == -1) {
  111. return null;
  112. }
  113. String uri = (String)uris.elementAt(index);
  114. return uri;
  115. }
  116. /**
  117. * This will print out the size and current stack, from the
  118. * most recently added <code>{@link Namespace}</code> to
  119. * the "oldest," all to <code>System.out</code>.
  120. */
  121. public String toString() {
  122. StringBuffer buf = new StringBuffer();
  123. String sep = System.getProperty("line.separator");
  124. buf.append("Stack: " + prefixes.size() + sep);
  125. for (int i = 0; i < prefixes.size(); i++) {
  126. buf.append(prefixes.elementAt(i) + "&" + uris.elementAt(i) + sep);
  127. }
  128. return buf.toString();
  129. }
  130. }