1 // NamespaceSupport.java - generic Namespace support for SAX.
2 // http://www.saxproject.org
3 // Written by David Megginson
4 // This class is in the Public Domain.  NO WARRANTY!
5 // $Id: NamespaceSupport.java,v 1.15 2004/04/26 17:34:35 dmegginson Exp $
6 
7 package org.xml.sax.helpers;
8 
9 import android.compat.annotation.UnsupportedAppUsage;
10 import java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.EmptyStackException;
13 import java.util.Enumeration;
14 import java.util.Hashtable;
15 
16 /**
17  * Encapsulate Namespace logic for use by applications using SAX,
18  * or internally by SAX drivers.
19  *
20  * <blockquote>
21  * <em>This module, both source code and documentation, is in the
22  * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
23  * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
24  * for further information.
25  * </blockquote>
26  *
27  * <p>This class encapsulates the logic of Namespace processing: it
28  * tracks the declarations currently in force for each context and
29  * automatically processes qualified XML names into their Namespace
30  * parts; it can also be used in reverse for generating XML qnames
31  * from Namespaces.</p>
32  *
33  * <p>Namespace support objects are reusable, but the reset method
34  * must be invoked between each session.</p>
35  *
36  * <p>Here is a simple session:</p>
37  *
38  * <pre>
39  * String parts[] = new String[3];
40  * NamespaceSupport support = new NamespaceSupport();
41  *
42  * support.pushContext();
43  * support.declarePrefix("", "http://www.w3.org/1999/xhtml");
44  * support.declarePrefix("dc", "http://www.purl.org/dc#");
45  *
46  * parts = support.processName("p", parts, false);
47  * System.out.println("Namespace URI: " + parts[0]);
48  * System.out.println("Local name: " + parts[1]);
49  * System.out.println("Raw name: " + parts[2]);
50  *
51  * parts = support.processName("dc:title", parts, false);
52  * System.out.println("Namespace URI: " + parts[0]);
53  * System.out.println("Local name: " + parts[1]);
54  * System.out.println("Raw name: " + parts[2]);
55  *
56  * support.popContext();
57  * </pre>
58  *
59  * <p>Note that this class is optimized for the use case where most
60  * elements do not contain Namespace declarations: if the same
61  * prefix/URI mapping is repeated for each context (for example), this
62  * class will be somewhat less efficient.</p>
63  *
64  * <p>Although SAX drivers (parsers) may choose to use this class to
65  * implement namespace handling, they are not required to do so.
66  * Applications must track namespace information themselves if they
67  * want to use namespace information.
68  *
69  * @since SAX 2.0
70  * @author David Megginson
71  * @version 2.0.1 (sax2r2)
72  */
73 public class NamespaceSupport
74 {
75 
76 
77     ////////////////////////////////////////////////////////////////////
78     // Constants.
79     ////////////////////////////////////////////////////////////////////
80 
81 
82     /**
83      * The XML Namespace URI as a constant.
84      * The value is <code>http://www.w3.org/XML/1998/namespace</code>
85      * as defined in the "Namespaces in XML" * recommendation.
86      *
87      * <p>This is the Namespace URI that is automatically mapped
88      * to the "xml" prefix.</p>
89      */
90     public static final String XMLNS =
91     "http://www.w3.org/XML/1998/namespace";
92 
93 
94     /**
95      * The namespace declaration URI as a constant.
96      * The value is <code>http://www.w3.org/xmlns/2000/</code>, as defined
97      * in a backwards-incompatible erratum to the "Namespaces in XML"
98      * recommendation.  Because that erratum postdated SAX2, SAX2 defaults
99      * to the original recommendation, and does not normally use this URI.
100      *
101      *
102      * <p>This is the Namespace URI that is optionally applied to
103      * <em>xmlns</em> and <em>xmlns:*</em> attributes, which are used to
104      * declare namespaces.  </p>
105      *
106      * @since SAX 2.1alpha
107      * @see #setNamespaceDeclUris
108      * @see #isNamespaceDeclUris
109      */
110     public static final String NSDECL =
111     "http://www.w3.org/xmlns/2000/";
112 
113 
114     /**
115      * An empty enumeration.
116      */
117     @UnsupportedAppUsage
118     private static final Enumeration EMPTY_ENUMERATION = Collections.enumeration(Collections.emptyList());
119 
120 
121     ////////////////////////////////////////////////////////////////////
122     // Constructor.
123     ////////////////////////////////////////////////////////////////////
124 
125 
126     /**
127      * Create a new Namespace support object.
128      */
NamespaceSupport()129     public NamespaceSupport ()
130     {
131     reset();
132     }
133 
134 
135 
136     ////////////////////////////////////////////////////////////////////
137     // Context management.
138     ////////////////////////////////////////////////////////////////////
139 
140 
141     /**
142      * Reset this Namespace support object for reuse.
143      *
144      * <p>It is necessary to invoke this method before reusing the
145      * Namespace support object for a new session.  If namespace
146      * declaration URIs are to be supported, that flag must also
147      * be set to a non-default value.
148      * </p>
149      *
150      * @see #setNamespaceDeclUris
151      */
reset()152     public void reset ()
153     {
154     contexts = new Context[32];
155     namespaceDeclUris = false;
156     contextPos = 0;
157     contexts[contextPos] = currentContext = new Context();
158     currentContext.declarePrefix("xml", XMLNS);
159     }
160 
161 
162     /**
163      * Start a new Namespace context.
164      * The new context will automatically inherit
165      * the declarations of its parent context, but it will also keep
166      * track of which declarations were made within this context.
167      *
168      * <p>Event callback code should start a new context once per element.
169      * This means being ready to call this in either of two places.
170      * For elements that don't include namespace declarations, the
171      * <em>ContentHandler.startElement()</em> callback is the right place.
172      * For elements with such a declaration, it'd done in the first
173      * <em>ContentHandler.startPrefixMapping()</em> callback.
174      * A boolean flag can be used to
175      * track whether a context has been started yet.  When either of
176      * those methods is called, it checks the flag to see if a new context
177      * needs to be started.  If so, it starts the context and sets the
178      * flag.  After <em>ContentHandler.startElement()</em>
179      * does that, it always clears the flag.
180      *
181      * <p>Normally, SAX drivers would push a new context at the beginning
182      * of each XML element.  Then they perform a first pass over the
183      * attributes to process all namespace declarations, making
184      * <em>ContentHandler.startPrefixMapping()</em> callbacks.
185      * Then a second pass is made, to determine the namespace-qualified
186      * names for all attributes and for the element name.
187      * Finally all the information for the
188      * <em>ContentHandler.startElement()</em> callback is available,
189      * so it can then be made.
190      *
191      * <p>The Namespace support object always starts with a base context
192      * already in force: in this context, only the "xml" prefix is
193      * declared.</p>
194      *
195      * @see org.xml.sax.ContentHandler
196      * @see #popContext
197      */
pushContext()198     public void pushContext ()
199     {
200     int max = contexts.length;
201 
202     contexts [contextPos].declsOK = false;
203     contextPos++;
204 
205                 // Extend the array if necessary
206     if (contextPos >= max) {
207         Context newContexts[] = new Context[max*2];
208         System.arraycopy(contexts, 0, newContexts, 0, max);
209         max *= 2;
210         contexts = newContexts;
211     }
212 
213                 // Allocate the context if necessary.
214     currentContext = contexts[contextPos];
215     if (currentContext == null) {
216         contexts[contextPos] = currentContext = new Context();
217     }
218 
219                 // Set the parent, if any.
220     if (contextPos > 0) {
221         currentContext.setParent(contexts[contextPos - 1]);
222     }
223     }
224 
225 
226     /**
227      * Revert to the previous Namespace context.
228      *
229      * <p>Normally, you should pop the context at the end of each
230      * XML element.  After popping the context, all Namespace prefix
231      * mappings that were previously in force are restored.</p>
232      *
233      * <p>You must not attempt to declare additional Namespace
234      * prefixes after popping a context, unless you push another
235      * context first.</p>
236      *
237      * @see #pushContext
238      */
popContext()239     public void popContext ()
240     {
241     contexts[contextPos].clear();
242     contextPos--;
243     if (contextPos < 0) {
244         throw new EmptyStackException();
245     }
246     currentContext = contexts[contextPos];
247     }
248 
249 
250 
251     ////////////////////////////////////////////////////////////////////
252     // Operations within a context.
253     ////////////////////////////////////////////////////////////////////
254 
255 
256     /**
257      * Declare a Namespace prefix.  All prefixes must be declared
258      * before they are referenced.  For example, a SAX driver (parser)
259      * would scan an element's attributes
260      * in two passes:  first for namespace declarations,
261      * then a second pass using {@link #processName processName()} to
262      * interpret prefixes against (potentially redefined) prefixes.
263      *
264      * <p>This method declares a prefix in the current Namespace
265      * context; the prefix will remain in force until this context
266      * is popped, unless it is shadowed in a descendant context.</p>
267      *
268      * <p>To declare the default element Namespace, use the empty string as
269      * the prefix.</p>
270      *
271      * <p>Note that you must <em>not</em> declare a prefix after
272      * you've pushed and popped another Namespace context, or
273      * treated the declarations phase as complete by processing
274      * a prefixed name.</p>
275      *
276      * <p>Note that there is an asymmetry in this library: {@link
277      * #getPrefix getPrefix} will not return the "" prefix,
278      * even if you have declared a default element namespace.
279      * To check for a default namespace,
280      * you have to look it up explicitly using {@link #getURI getURI}.
281      * This asymmetry exists to make it easier to look up prefixes
282      * for attribute names, where the default prefix is not allowed.</p>
283      *
284      * @param prefix The prefix to declare, or the empty string to
285      *    indicate the default element namespace.  This may never have
286      *    the value "xml" or "xmlns".
287      * @param uri The Namespace URI to associate with the prefix.
288      * @return true if the prefix was legal, false otherwise
289      *
290      * @see #processName
291      * @see #getURI
292      * @see #getPrefix
293      */
declarePrefix(String prefix, String uri)294     public boolean declarePrefix (String prefix, String uri)
295     {
296     if (prefix.equals("xml") || prefix.equals("xmlns")) {
297         return false;
298     } else {
299         currentContext.declarePrefix(prefix, uri);
300         return true;
301     }
302     }
303 
304 
305     /**
306      * Process a raw XML qualified name, after all declarations in the
307      * current context have been handled by {@link #declarePrefix
308      * declarePrefix()}.
309      *
310      * <p>This method processes a raw XML qualified name in the
311      * current context by removing the prefix and looking it up among
312      * the prefixes currently declared.  The return value will be the
313      * array supplied by the caller, filled in as follows:</p>
314      *
315      * <dl>
316      * <dt>parts[0]</dt>
317      * <dd>The Namespace URI, or an empty string if none is
318      *  in use.</dd>
319      * <dt>parts[1]</dt>
320      * <dd>The local name (without prefix).</dd>
321      * <dt>parts[2]</dt>
322      * <dd>The original raw name.</dd>
323      * </dl>
324      *
325      * <p>All of the strings in the array will be internalized.  If
326      * the raw name has a prefix that has not been declared, then
327      * the return value will be null.</p>
328      *
329      * <p>Note that attribute names are processed differently than
330      * element names: an unprefixed element name will receive the
331      * default Namespace (if any), while an unprefixed attribute name
332      * will not.</p>
333      *
334      * @param qName The XML qualified name to be processed.
335      * @param parts An array supplied by the caller, capable of
336      *        holding at least three members.
337      * @param isAttribute A flag indicating whether this is an
338      *        attribute name (true) or an element name (false).
339      * @return The supplied array holding three internalized strings
340      *        representing the Namespace URI (or empty string), the
341      *        local name, and the XML qualified name; or null if there
342      *        is an undeclared prefix.
343      * @see #declarePrefix
344      * @see java.lang.String#intern */
processName(String qName, String parts[], boolean isAttribute)345     public String [] processName (String qName, String parts[],
346                   boolean isAttribute)
347     {
348     String myParts[] = currentContext.processName(qName, isAttribute);
349     if (myParts == null) {
350         return null;
351     } else {
352         parts[0] = myParts[0];
353         parts[1] = myParts[1];
354         parts[2] = myParts[2];
355         return parts;
356     }
357     }
358 
359 
360     /**
361      * Look up a prefix and get the currently-mapped Namespace URI.
362      *
363      * <p>This method looks up the prefix in the current context.
364      * Use the empty string ("") for the default Namespace.</p>
365      *
366      * @param prefix The prefix to look up.
367      * @return The associated Namespace URI, or null if the prefix
368      *         is undeclared in this context.
369      * @see #getPrefix
370      * @see #getPrefixes
371      */
getURI(String prefix)372     public String getURI (String prefix)
373     {
374     return currentContext.getURI(prefix);
375     }
376 
377 
378     /**
379      * Return an enumeration of all prefixes whose declarations are
380      * active in the current context.
381      * This includes declarations from parent contexts that have
382      * not been overridden.
383      *
384      * <p><strong>Note:</strong> if there is a default prefix, it will not be
385      * returned in this enumeration; check for the default prefix
386      * using the {@link #getURI getURI} with an argument of "".</p>
387      *
388      * @return An enumeration of prefixes (never empty).
389      * @see #getDeclaredPrefixes
390      * @see #getURI
391      */
getPrefixes()392     public Enumeration getPrefixes ()
393     {
394     return currentContext.getPrefixes();
395     }
396 
397 
398     /**
399      * Return one of the prefixes mapped to a Namespace URI.
400      *
401      * <p>If more than one prefix is currently mapped to the same
402      * URI, this method will make an arbitrary selection; if you
403      * want all of the prefixes, use the {@link #getPrefixes}
404      * method instead.</p>
405      *
406      * <p><strong>Note:</strong> this will never return the empty (default) prefix;
407      * to check for a default prefix, use the {@link #getURI getURI}
408      * method with an argument of "".</p>
409      *
410      * @param uri the namespace URI
411      * @return one of the prefixes currently mapped to the URI supplied,
412      *         or null if none is mapped or if the URI is assigned to
413      *         the default namespace
414      * @see #getPrefixes(java.lang.String)
415      * @see #getURI
416      */
getPrefix(String uri)417     public String getPrefix (String uri)
418     {
419     return currentContext.getPrefix(uri);
420     }
421 
422 
423     /**
424      * Return an enumeration of all prefixes for a given URI whose
425      * declarations are active in the current context.
426      * This includes declarations from parent contexts that have
427      * not been overridden.
428      *
429      * <p>This method returns prefixes mapped to a specific Namespace
430      * URI.  The xml: prefix will be included.  If you want only one
431      * prefix that's mapped to the Namespace URI, and you don't care
432      * which one you get, use the {@link #getPrefix getPrefix}
433      *  method instead.</p>
434      *
435      * <p><strong>Note:</strong> the empty (default) prefix is <em>never</em> included
436      * in this enumeration; to check for the presence of a default
437      * Namespace, use the {@link #getURI getURI} method with an
438      * argument of "".</p>
439      *
440      * @param uri The Namespace URI.
441      * @return An enumeration of prefixes (never empty).
442      * @see #getPrefix
443      * @see #getDeclaredPrefixes
444      * @see #getURI
445      */
getPrefixes(String uri)446     public Enumeration getPrefixes(String uri) {
447         ArrayList<String> prefixes = new ArrayList<String>();
448         Enumeration allPrefixes = getPrefixes();
449         while (allPrefixes.hasMoreElements()) {
450             String prefix = (String) allPrefixes.nextElement();
451             if (uri.equals(getURI(prefix))) {
452                 prefixes.add(prefix);
453             }
454         }
455         return Collections.enumeration(prefixes);
456     }
457 
458 
459     /**
460      * Return an enumeration of all prefixes declared in this context.
461      *
462      * <p>The empty (default) prefix will be included in this
463      * enumeration; note that this behaviour differs from that of
464      * {@link #getPrefix} and {@link #getPrefixes}.</p>
465      *
466      * @return An enumeration of all prefixes declared in this
467      *         context.
468      * @see #getPrefixes
469      * @see #getURI
470      */
getDeclaredPrefixes()471     public Enumeration getDeclaredPrefixes ()
472     {
473     return currentContext.getDeclaredPrefixes();
474     }
475 
476     /**
477      * Controls whether namespace declaration attributes are placed
478      * into the {@link #NSDECL NSDECL} namespace
479      * by {@link #processName processName()}.  This may only be
480      * changed before any contexts have been pushed.
481      *
482      * @param value the namespace declaration attribute state. A value of true
483      *              enables this feature, a value of false disables it.
484      *
485      * @since SAX 2.1alpha
486      *
487      * @exception IllegalStateException when attempting to set this
488      *    after any context has been pushed.
489      */
setNamespaceDeclUris(boolean value)490     public void setNamespaceDeclUris (boolean value)
491     {
492     if (contextPos != 0)
493         throw new IllegalStateException ();
494     if (value == namespaceDeclUris)
495         return;
496     namespaceDeclUris = value;
497     if (value)
498         currentContext.declarePrefix ("xmlns", NSDECL);
499     else {
500         contexts[contextPos] = currentContext = new Context();
501         currentContext.declarePrefix("xml", XMLNS);
502     }
503     }
504 
505     /**
506      * Returns true if namespace declaration attributes are placed into
507      * a namespace.  This behavior is not the default.
508      *
509      * @return true if namespace declaration attributes are enabled, false
510      *         otherwise.
511      * @since SAX 2.1alpha
512      */
isNamespaceDeclUris()513     public boolean isNamespaceDeclUris ()
514     { return namespaceDeclUris; }
515 
516 
517 
518     ////////////////////////////////////////////////////////////////////
519     // Internal state.
520     ////////////////////////////////////////////////////////////////////
521 
522     @UnsupportedAppUsage
523     private Context contexts[];
524     @UnsupportedAppUsage
525     private Context currentContext;
526     @UnsupportedAppUsage
527     private int contextPos;
528     @UnsupportedAppUsage
529     private boolean namespaceDeclUris;
530 
531 
532     ////////////////////////////////////////////////////////////////////
533     // Internal classes.
534     ////////////////////////////////////////////////////////////////////
535 
536     /**
537      * Internal class for a single Namespace context.
538      *
539      * <p>This module caches and reuses Namespace contexts,
540      * so the number allocated
541      * will be equal to the element depth of the document, not to the total
542      * number of elements (i.e. 5-10 rather than tens of thousands).
543      * Also, data structures used to represent contexts are shared when
544      * possible (child contexts without declarations) to further reduce
545      * the amount of memory that's consumed.
546      * </p>
547      */
548     final class Context {
549 
550     /**
551      * Create the root-level Namespace context.
552      */
553     @UnsupportedAppUsage
Context()554     Context ()
555     {
556         copyTables();
557     }
558 
559 
560     /**
561      * (Re)set the parent of this Namespace context.
562      * The context must either have been freshly constructed,
563      * or must have been cleared.
564      *
565      * @param context The parent Namespace context object.
566      */
setParent(Context parent)567     void setParent (Context parent)
568     {
569         this.parent = parent;
570         declarations = null;
571         prefixTable = parent.prefixTable;
572         uriTable = parent.uriTable;
573         elementNameTable = parent.elementNameTable;
574         attributeNameTable = parent.attributeNameTable;
575         defaultNS = parent.defaultNS;
576         declSeen = false;
577         declsOK = true;
578     }
579 
580     /**
581      * Makes associated state become collectible,
582      * invalidating this context.
583      * {@link #setParent} must be called before
584      * this context may be used again.
585      */
clear()586     void clear ()
587     {
588         parent = null;
589         prefixTable = null;
590         uriTable = null;
591         elementNameTable = null;
592         attributeNameTable = null;
593         defaultNS = null;
594     }
595 
596 
597     /**
598      * Declare a Namespace prefix for this context.
599      *
600      * @param prefix The prefix to declare.
601      * @param uri The associated Namespace URI.
602      * @see org.xml.sax.helpers.NamespaceSupport#declarePrefix
603      */
declarePrefix(String prefix, String uri)604     void declarePrefix(String prefix, String uri) {
605         // Lazy processing...
606         if (!declsOK) {
607             throw new IllegalStateException ("can't declare any more prefixes in this context");
608         }
609         if (!declSeen) {
610             copyTables();
611         }
612         if (declarations == null) {
613             declarations = new ArrayList<String>();
614         }
615 
616         prefix = prefix.intern();
617         uri = uri.intern();
618         if ("".equals(prefix)) {
619             if ("".equals(uri)) {
620                 defaultNS = null;
621             } else {
622                 defaultNS = uri;
623             }
624         } else {
625             prefixTable.put(prefix, uri);
626             uriTable.put(uri, prefix); // may wipe out another prefix
627         }
628         declarations.add(prefix);
629     }
630 
631 
632     /**
633      * Process an XML qualified name in this context.
634      *
635      * @param qName The XML qualified name.
636      * @param isAttribute true if this is an attribute name.
637      * @return An array of three strings containing the
638      *         URI part (or empty string), the local part,
639      *         and the raw name, all internalized, or null
640      *         if there is an undeclared prefix.
641      * @see org.xml.sax.helpers.NamespaceSupport#processName
642      */
processName(String qName, boolean isAttribute)643     String [] processName (String qName, boolean isAttribute)
644     {
645         String name[];
646         Hashtable table;
647 
648                     // detect errors in call sequence
649         declsOK = false;
650 
651                 // Select the appropriate table.
652         if (isAttribute) {
653         table = attributeNameTable;
654         } else {
655         table = elementNameTable;
656         }
657 
658                 // Start by looking in the cache, and
659                 // return immediately if the name
660                 // is already known in this content
661         name = (String[])table.get(qName);
662         if (name != null) {
663         return name;
664         }
665 
666                 // We haven't seen this name in this
667                 // context before.  Maybe in the parent
668                 // context, but we can't assume prefix
669                 // bindings are the same.
670         name = new String[3];
671         name[2] = qName.intern();
672         int index = qName.indexOf(':');
673 
674 
675                 // No prefix.
676         if (index == -1) {
677         if (isAttribute) {
678             if (qName == "xmlns" && namespaceDeclUris)
679             name[0] = NSDECL;
680             else
681             name[0] = "";
682         } else if (defaultNS == null) {
683             name[0] = "";
684         } else {
685             name[0] = defaultNS;
686         }
687         name[1] = name[2];
688         }
689 
690                 // Prefix
691         else {
692         String prefix = qName.substring(0, index);
693         String local = qName.substring(index+1);
694         String uri;
695         if ("".equals(prefix)) {
696             uri = defaultNS;
697         } else {
698             uri = (String)prefixTable.get(prefix);
699         }
700         if (uri == null
701             || (!isAttribute && "xmlns".equals (prefix))) {
702             return null;
703         }
704         name[0] = uri;
705         name[1] = local.intern();
706         }
707 
708                 // Save in the cache for future use.
709                 // (Could be shared with parent context...)
710         table.put(name[2], name);
711         return name;
712     }
713 
714 
715     /**
716      * Look up the URI associated with a prefix in this context.
717      *
718      * @param prefix The prefix to look up.
719      * @return The associated Namespace URI, or null if none is
720      *         declared.
721      * @see org.xml.sax.helpers.NamespaceSupport#getURI
722      */
getURI(String prefix)723     String getURI (String prefix)
724     {
725         if ("".equals(prefix)) {
726         return defaultNS;
727         } else if (prefixTable == null) {
728         return null;
729         } else {
730         return (String)prefixTable.get(prefix);
731         }
732     }
733 
734 
735     /**
736      * Look up one of the prefixes associated with a URI in this context.
737      *
738      * <p>Since many prefixes may be mapped to the same URI,
739      * the return value may be unreliable.</p>
740      *
741      * @param uri The URI to look up.
742      * @return The associated prefix, or null if none is declared.
743      * @see org.xml.sax.helpers.NamespaceSupport#getPrefix
744      */
getPrefix(String uri)745     String getPrefix (String uri)
746     {
747         if (uriTable == null) {
748         return null;
749         } else {
750         return (String)uriTable.get(uri);
751         }
752     }
753 
754 
755     /**
756      * Return an enumeration of prefixes declared in this context.
757      *
758      * @return An enumeration of prefixes (possibly empty).
759      * @see org.xml.sax.helpers.NamespaceSupport#getDeclaredPrefixes
760      */
getDeclaredPrefixes()761     Enumeration getDeclaredPrefixes() {
762         return (declarations == null) ? EMPTY_ENUMERATION : Collections.enumeration(declarations);
763     }
764 
765 
766     /**
767      * Return an enumeration of all prefixes currently in force.
768      *
769      * <p>The default prefix, if in force, is <em>not</em>
770      * returned, and will have to be checked for separately.</p>
771      *
772      * @return An enumeration of prefixes (never empty).
773      * @see org.xml.sax.helpers.NamespaceSupport#getPrefixes
774      */
getPrefixes()775     Enumeration getPrefixes ()
776     {
777         if (prefixTable == null) {
778         return EMPTY_ENUMERATION;
779         } else {
780         return prefixTable.keys();
781         }
782     }
783 
784 
785 
786     ////////////////////////////////////////////////////////////////
787     // Internal methods.
788     ////////////////////////////////////////////////////////////////
789 
790 
791     /**
792      * Copy on write for the internal tables in this context.
793      *
794      * <p>This class is optimized for the normal case where most
795      * elements do not contain Namespace declarations.</p>
796      */
copyTables()797     private void copyTables ()
798     {
799         if (prefixTable != null) {
800         prefixTable = (Hashtable)prefixTable.clone();
801         } else {
802         prefixTable = new Hashtable();
803         }
804         if (uriTable != null) {
805         uriTable = (Hashtable)uriTable.clone();
806         } else {
807         uriTable = new Hashtable();
808         }
809         elementNameTable = new Hashtable();
810         attributeNameTable = new Hashtable();
811         declSeen = true;
812     }
813 
814 
815 
816     ////////////////////////////////////////////////////////////////
817     // Protected state.
818     ////////////////////////////////////////////////////////////////
819 
820     Hashtable prefixTable;
821     Hashtable uriTable;
822     Hashtable elementNameTable;
823     Hashtable attributeNameTable;
824     String defaultNS = null;
825     boolean declsOK = true;
826 
827 
828 
829     ////////////////////////////////////////////////////////////////
830     // Internal state.
831     ////////////////////////////////////////////////////////////////
832 
833     private ArrayList<String> declarations = null;
834     private boolean declSeen = false;
835     private Context parent = null;
836     }
837 }
838 
839 // end of NamespaceSupport.java
840