1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 2001, 2002 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xerces" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, International
  53. * Business Machines, Inc., http://www.apache.org. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package com.sun.org.apache.xerces.internal.xni;
  58. import java.util.Enumeration;
  59. /**
  60. * Represents an interface to query namespace information.
  61. * <p>
  62. * The prefix and namespace must be identical references for equal strings, thus
  63. * each string should be internalized (@see String.intern())
  64. * or added to the <code>SymbolTable</code>
  65. *
  66. * @see <a href="../../../../../xerces2/com/sun/org/apache/xerces/internal/util/SymbolTable.html">
  67. * com.sun.org.apache.xerces.internal.util.SymbolTable</a>
  68. *
  69. * @author Andy Clark, IBM
  70. *
  71. * @version $Id: NamespaceContext.java,v 1.10 2003/01/23 17:27:12 sandygao Exp $
  72. */
  73. public interface NamespaceContext {
  74. //
  75. // Constants
  76. //
  77. /**
  78. * The XML Namespace ("http://www.w3.org/XML/1998/namespace"). This is
  79. * the Namespace URI that is automatically mapped to the "xml" prefix.
  80. */
  81. public final static String XML_URI = "http://www.w3.org/XML/1998/namespace".intern();
  82. /**
  83. * XML Information Set REC
  84. * all namespace attributes (including those named xmlns,
  85. * whose [prefix] property has no value) have a namespace URI of http://www.w3.org/2000/xmlns/
  86. */
  87. public final static String XMLNS_URI = "http://www.w3.org/2000/xmlns/".intern();
  88. //
  89. // NamespaceContext methods
  90. //
  91. /**
  92. * Start a new Namespace context.
  93. * <p>
  94. * A new context should be pushed at the beginning
  95. * of each XML element: the new context will automatically inherit
  96. * the declarations of its parent context, but it will also keep
  97. * track of which declarations were made within this context.
  98. * <p>
  99. *
  100. * @see #popContext
  101. */
  102. public void pushContext();
  103. /**
  104. * Revert to the previous Namespace context.
  105. * <p>
  106. * The context should be popped at the end of each
  107. * XML element. After popping the context, all Namespace prefix
  108. * mappings that were previously in force are restored.
  109. * <p>
  110. * Users must not attempt to declare additional Namespace
  111. * prefixes after popping a context, unless you push another
  112. * context first.
  113. *
  114. * @see #pushContext
  115. */
  116. public void popContext();
  117. /**
  118. * Declare a Namespace prefix.
  119. * <p>
  120. * This method declares a prefix in the current Namespace
  121. * context; the prefix will remain in force until this context
  122. * is popped, unless it is shadowed in a descendant context.
  123. * <p>
  124. * Note that to declare a default Namespace, use the empty string.
  125. * The prefixes "xml" and "xmlns" can't be rebound.
  126. * <p>
  127. * Note that you must <em>not</em> declare a prefix after
  128. * you've pushed and popped another Namespace.
  129. *
  130. * @param prefix The prefix to declare, or null for the empty
  131. * string.
  132. * @param uri The Namespace URI to associate with the prefix.
  133. *
  134. * @return true if the prefix was legal, false otherwise
  135. *
  136. * @see #getURI
  137. * @see #getDeclaredPrefixAt
  138. */
  139. public boolean declarePrefix(String prefix, String uri);
  140. /**
  141. * Look up a prefix and get the currently-mapped Namespace URI.
  142. * <p>
  143. * This method looks up the prefix in the current context. If no mapping
  144. * is found, this methods will continue lookup in the parent context(s).
  145. * Use the empty string ("") for the default Namespace.
  146. *
  147. * @param prefix The prefix to look up.
  148. *
  149. * @return The associated Namespace URI, or null if the prefix
  150. * is undeclared in this context.
  151. */
  152. public String getURI(String prefix);
  153. /**
  154. * Look up a namespace URI and get one of the mapped prefix.
  155. * <p>
  156. * This method looks up the namespace URI in the current context.
  157. * If more than one prefix is currently mapped to the same URI,
  158. * this method will make an arbitrary selection
  159. * If no mapping is found, this methods will continue lookup in the
  160. * parent context(s).
  161. *
  162. * @param uri The namespace URI to look up.
  163. *
  164. * @return One of the associated prefixes, or null if the uri
  165. * does not map to any prefix.
  166. *
  167. * @see #getPrefix
  168. */
  169. public String getPrefix(String uri);
  170. /**
  171. * Return a count of locally declared prefixes, including
  172. * the default prefix if bound.
  173. */
  174. public int getDeclaredPrefixCount();
  175. /**
  176. * Returns the prefix at the specified index in the current context.
  177. */
  178. public String getDeclaredPrefixAt(int index);
  179. /**
  180. * Return an enumeration of all prefixes whose declarations are active
  181. * in the current context. This includes declarations from parent contexts
  182. * that have not been overridden.
  183. * @return Enumeration
  184. */
  185. public Enumeration getAllPrefixes();
  186. /**
  187. * Reset this Namespace support object for reuse.
  188. *
  189. * <p>It is necessary to invoke this method before reusing the
  190. * Namespace support object for a new session.</p>
  191. *
  192. * <p>Note that implementations of this method need to ensure that
  193. * the declaration of the prefixes "xmlns" and "xml" are available.</p>
  194. */
  195. public void reset();
  196. } // interface NamespaceContext