2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
18
package org.apache.xerces.xni;
20
import java.util.Enumeration;
23
* Represents an interface to query namespace information.
25
* The prefix and namespace must be identical references for equal strings, thus
26
* each string should be internalized (@see String.intern())
27
* or added to the <code>SymbolTable</code>
29
* @see <a href="../../../../../xerces2/org/apache/xerces/util/SymbolTable.html">
30
* org.apache.xerces.util.SymbolTable</a>
32
* @author Andy Clark, IBM
34
* @version $Id: NamespaceContext.java,v 1.2 2009/12/10 03:18:46 matthewoliver Exp $
36
public interface NamespaceContext {
43
* The XML Namespace ("http://www.w3.org/XML/1998/namespace"). This is
44
* the Namespace URI that is automatically mapped to the "xml" prefix.
46
public final static String XML_URI = "http://www.w3.org/XML/1998/namespace".intern();
49
* XML Information Set REC
50
* all namespace attributes (including those named xmlns,
51
* whose [prefix] property has no value) have a namespace URI of http://www.w3.org/2000/xmlns/
53
public final static String XMLNS_URI = "http://www.w3.org/2000/xmlns/".intern();
56
// NamespaceContext methods
60
* Start a new Namespace context.
62
* A new context should be pushed at the beginning
63
* of each XML element: the new context will automatically inherit
64
* the declarations of its parent context, but it will also keep
65
* track of which declarations were made within this context.
70
public void pushContext();
73
* Revert to the previous Namespace context.
75
* The context should be popped at the end of each
76
* XML element. After popping the context, all Namespace prefix
77
* mappings that were previously in force are restored.
79
* Users must not attempt to declare additional Namespace
80
* prefixes after popping a context, unless you push another
85
public void popContext();
88
* Declare a Namespace prefix.
90
* This method declares a prefix in the current Namespace
91
* context; the prefix will remain in force until this context
92
* is popped, unless it is shadowed in a descendant context.
94
* Note that to declare a default Namespace, use the empty string.
95
* The prefixes "xml" and "xmlns" can't be rebound.
97
* Note that you must <em>not</em> declare a prefix after
98
* you've pushed and popped another Namespace.
100
* @param prefix The prefix to declare, or null for the empty
102
* @param uri The Namespace URI to associate with the prefix.
104
* @return true if the prefix was legal, false otherwise
107
* @see #getDeclaredPrefixAt
109
public boolean declarePrefix(String prefix, String uri);
113
* Look up a prefix and get the currently-mapped Namespace URI.
115
* This method looks up the prefix in the current context. If no mapping
116
* is found, this methods will continue lookup in the parent context(s).
117
* Use the empty string ("") for the default Namespace.
119
* @param prefix The prefix to look up.
121
* @return The associated Namespace URI, or null if the prefix
122
* is undeclared in this context.
124
public String getURI(String prefix);
127
* Look up a namespace URI and get one of the mapped prefix.
129
* This method looks up the namespace URI in the current context.
130
* If more than one prefix is currently mapped to the same URI,
131
* this method will make an arbitrary selection
132
* If no mapping is found, this methods will continue lookup in the
135
* @param uri The namespace URI to look up.
137
* @return One of the associated prefixes, or null if the uri
138
* does not map to any prefix.
142
public String getPrefix(String uri);
145
* Return a count of locally declared prefixes, including
146
* the default prefix if bound.
148
public int getDeclaredPrefixCount();
151
* Returns the prefix at the specified index in the current context.
153
public String getDeclaredPrefixAt(int index);
156
* Return an enumeration of all prefixes whose declarations are active
157
* in the current context. This includes declarations from parent contexts
158
* that have not been overridden.
159
* @return Enumeration
161
public Enumeration getAllPrefixes();
164
* Reset this Namespace support object for reuse.
166
* <p>It is necessary to invoke this method before reusing the
167
* Namespace support object for a new session.</p>
169
* <p>Note that implementations of this method need to ensure that
170
* the declaration of the prefixes "xmlns" and "xml" are available.</p>
176
} // interface NamespaceContext