/** * Revert to the previous Namespace context. * * <p>Normally, you should pop the context at the end of each * XML element. After popping the context, all Namespace prefix * mappings that were previously in force are restored.</p> * * <p>You must not attempt to declare additional Namespace * prefixes after popping a context, unless you push another * context first.</p> * * @see #pushContext() */ public void popContext () { contexts[contextPos].clear(); contextPos--; if (contextPos < 0) { throw new EmptyStackException(); } currentContext = contexts[contextPos]; }
/** * Declare a Namespace prefix for this context. * * @param prefix The prefix to declare. * @param uri The associated Namespace URI. * @see org.xml.sax.helpers.NamespaceSupport#declarePrefix(java.lang.String, java.lang.String) */ void declarePrefix (String prefix, String uri) { // Lazy processing... if (!declsOK) throw new IllegalStateException ( "can't declare any more prefixes in this context"); if (!declSeen) { copyTables(); } if (declarations == null) { declarations = new Vector(); } prefix = prefix.intern(); uri = uri.intern(); if ("".equals(prefix)) { defaultNS = uri; } else { prefixTable.put(prefix, uri); uriTable.put(uri, prefix); // may wipe out another prefix } declarations.addElement(prefix); }
boolean isAttribute) String myParts[] = currentContext.processName(qName, isAttribute); if (myParts == null) { return null;
return false; } else { currentContext.declarePrefix(prefix, uri); return true;
/** * Return an enumeration of all prefixes currently declared. * * <p><strong>Note:</strong> if there is a default prefix, it will not be * returned in this enumeration; check for the default prefix * using the {@link #getURI getURI} with an argument of "".</p> * * @return An enumeration of all prefixes declared in the * current context except for the empty (default) * prefix. * @see #getDeclaredPrefixes() * @see #getURI(String) */ public Enumeration getPrefixes () { return currentContext.getPrefixes(); }
/** * Return one of the prefixes mapped to a Namespace URI. * * <p>If more than one prefix is currently mapped to the same * URI, this method will make an arbitrary selection; if you * want all of the prefixes, use the {@link #getPrefixes} * method instead.</p> * * @param uri The Namespace URI. * @return One of the prefixes currently mapped to the URI supplied, * or null if none is mapped * or "" if the URI is assigned to the default Namespace. * @see #getPrefixes(java.lang.String) * @see #getURI(String) */ public String getPrefix(String uri) { return currentContext.getPrefix(uri); }
/** * Look up one of the prefixes associated with a URI in this context. * * <p>Since many prefixes may be mapped to the same URI, * the return value may be unreliable.</p> * * @param uri The URI to look up. * @return The associated prefix, or null if none is declared. * @see #getPrefixes() */ String getPrefix(String uri) { if (defaultNS.equals(uri)) return ""; return getPrefix2(uri); }
/** * Return an enumeration of all prefixes declared in this context. * * <p>The empty (default) prefix will be included in this * enumeration; note that this behaviour differs from that of * {@link #getPrefix} and {@link #getPrefixes}.</p> * * @return An enumeration of all prefixes declared in this * context. * @see #getPrefixes() * @see #getURI(String) */ public Enumeration getDeclaredPrefixes () { return currentContext.getDeclaredPrefixes(); }
/** * Look up a prefix and get the currently-mapped Namespace URI. * * <p>This method looks up the prefix in the current context. * Use the empty string ("") for the default Namespace.</p> * * @param prefix The prefix to look up. * @return The associated Namespace URI, or null if the prefix * is undeclared in this context. * @see #getPrefix(String) * @see #getPrefixes() */ public String getURI (String prefix) { return currentContext.getURI(prefix); }
/** * Similar to the {@link #getPrefix(String)} method but this method * doesn't look for the default namespace and will always return * a non-empty prefix or null. * * @since JAXB 1.0.2 */ public String getPrefix2(String uri) { return currentContext.getPrefix2(uri); }
/** * Create the root-level Namespace context. */ Context () { copyTables(); }
/** * Reset this Namespace support object for reuse. * * <p>It is necessary to invoke this method before reusing the * Namespace support object for a new session.</p> */ public void reset () { contexts = new Context[32]; contextPos = 0; contexts[contextPos] = currentContext = new Context(); currentContext.declarePrefix("xml", XMLNS); }