//throws SAXException /** * Process a qualified (prefixed) name. * * <p>If the name has an undeclared prefix, use only the qname * and make an ErrorHandler.error callback in case the app is * interested.</p> * * @param qName The qualified (prefixed) name. * @param isAttribute true if this is an attribute name. * @return The name split into three parts. * @exception SAXException The client may throw * an exception if there is an error callback. */ private String[] processName(String qName, bool isAttribute, bool useException) { String[] parts = nsSupport.processName(qName, nameParts, isAttribute); if (parts == null) { if (useException) throw makeException("Undeclared prefix: " + qName); reportError("Undeclared prefix: " + qName); parts = new String[3]; parts[0] = parts[1] = ""; parts[2] = qName.intern(); } return parts; }
//throws SAXException /** * Adapter implementation method; do not call. * Adapt a SAX1 startElement event. * * <p>If necessary, perform Namespace processing.</p> * * @param qName The qualified (prefixed) name. * @param qAtts The XML attribute list (with qnames). * @exception SAXException The client may raise a * processing exception. */ public void startElement(String qName, AttributeList qAtts) { // These are exceptions from the // first pass; they should be // ignored if there's a second pass, // but reported otherwise. java.util.Vector<SAXException> exceptions = null; // If we're not doing Namespace // processing, dispatch this quickly. if (!namespaces) { if (contentHandler != null) { attAdapter.setAttributeList(qAtts); contentHandler.startElement("", "", qName.intern(), attAdapter); } return; } // OK, we're doing Namespace processing. nsSupport.pushContext(); int length = qAtts.getLength(); // First pass: handle NS decls for (int i = 0; i < length; i++) { String attQName = qAtts.getName(i); if (!attQName.startsWith("xmlns")) continue; // Could be a declaration... String prefix; int n = attQName.indexOf(':'); // xmlns=... if (n == -1 && attQName.length() == 5) { prefix = ""; } else if (n != 5) { // XML namespaces spec doesn't discuss "xmlnsf:oo" // (and similarly named) attributes ... at most, warn continue; } else // xmlns:foo=... prefix = attQName.substring(n + 1); String value = qAtts.getValue(i); if (!nsSupport.declarePrefix(prefix, value)) { reportError("Illegal Namespace prefix: " + prefix); continue; } if (contentHandler != null) contentHandler.startPrefixMapping(prefix, value); } // Second pass: copy all relevant // attributes into the SAX2 AttributeList // using updated prefix bindings atts.clear(); for (int i = 0; i < length; i++) { String attQName = qAtts.getName(i); String type = qAtts.getType(i); String value = qAtts.getValue(i); // Declaration? if (attQName.startsWith("xmlns")) { String prefix; int n = attQName.indexOf(':'); if (n == -1 && attQName.length() == 5) { prefix = ""; } else if (n != 5) { // XML namespaces spec doesn't discuss "xmlnsf:oo" // (and similarly named) attributes ... ignore prefix = null; } else { prefix = attQName.substring(6); } // Yes, decl: report or prune if (prefix != null) { if (prefixes) { if (uris) // note funky case: localname can be null // when declaring the default prefix, and // yet the uri isn't null. atts.addAttribute(NamespaceSupport.XMLNS, prefix, attQName.intern(), type, value); else atts.addAttribute("", "", attQName.intern(), type, value); } continue; } } // Not a declaration -- report try { String[] attName = processName(attQName, true, true); atts.addAttribute(attName[0], attName[1], attName[2], type, value); } catch (SAXException e) { if (exceptions == null) exceptions = new java.util.Vector<SAXException>(); exceptions.addElement(e); atts.addAttribute("", attQName, attQName, type, value); } } // now handle the deferred exception reports if (exceptions != null && errorHandler != null) { for (int i = 0; i < exceptions.size(); i++) errorHandler.error((SAXParseException) (exceptions.elementAt(i))); } // OK, finally report the event. if (contentHandler != null) { String[] name = processName(qName, false, false); contentHandler.startElement(name[0], name[1], name[2], atts); } }
//throws SAXException /** * Adapter implementation method; do not call. * Adapt a SAX1 end element event. * * @param qName The qualified (prefixed) name. * @exception SAXException The client may raise a * processing exception. * @see org.xml.sax.DocumentHandler#endElement */ public void endElement(String qName) { // If we're not doing Namespace // processing, dispatch this quickly. if (!namespaces) { if (contentHandler != null) { contentHandler.endElement("", "", qName.intern()); } return; } // Split the name. String[] names = processName(qName, false, false); if (contentHandler != null) { contentHandler.endElement(names[0], names[1], names[2]); java.util.Enumeration<Object> prefixes = nsSupport.getDeclaredPrefixes(); //FIXME use Enumeration<String> while (prefixes.hasMoreElements()) { String prefix = (String)prefixes.nextElement(); contentHandler.endPrefixMapping(prefix); } } nsSupport.popContext(); }
/** * Process an XML qualified name in this context. * * @param qName The XML qualified name. * @param isAttribute true if this is an attribute name. * @return An array of three strings containing the * URI part (or empty string), the local part, * and the raw name, all internalized, or null * if there is an undeclared prefix. * @see org.xml.sax.helpers.NamespaceSupport#processName */ internal String[] processName(String qName, bool isAttribute) { String[] name; java.util.Hashtable<Object,Object> table; // detect errors in call sequence declsOK = false; // Select the appropriate table. if (isAttribute) { table = attributeNameTable; } else { table = elementNameTable; } // Start by looking in the cache, and // return immediately if the name // is already known in this content name = (String[])table.get(qName); if (name != null) { return name; } // We haven't seen this name in this // context before. Maybe in the parent // context, but we can't assume prefix // bindings are the same. name = new String[3]; name[2] = qName.intern(); int index = qName.indexOf(':'); // No prefix. if (index == -1) { if (isAttribute) { if (qName == "xmlns" && outer.namespaceDeclUris) name[0] = NSDECL; else name[0] = ""; } else if (defaultNS == null) { name[0] = ""; } else { name[0] = defaultNS; } name[1] = name[2]; } // Prefix else { String prefix = qName.substring(0, index); String local = qName.substring(index+1); String uri; if ("".equals(prefix)) { uri = defaultNS; } else { uri = (String)prefixTable.get(prefix); } if (uri == null || (!isAttribute && "xmlns".equals (prefix))) { return null; } name[0] = uri; name[1] = local.intern(); } // Save in the cache for future use. // (Could be shared with parent context...) table.put(name[2], name); return name; }
/** * 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 */ internal void declarePrefix(String prefix, String uri) { // Lazy processing... if (!declsOK) throw new java.lang.IllegalStateException ( "can't declare any more prefixes in this context"); if (!declSeen) { copyTables(); } if (declarations == null) { declarations = new java.util.Vector<Object>(); } prefix = prefix.intern(); uri = uri.intern(); if ("".equals(prefix)) { if ("".equals(uri)) { defaultNS = null; } else { defaultNS = uri; } } else { prefixTable.put(prefix, uri); uriTable.put(uri, prefix); // may wipe out another prefix } declarations.addElement(prefix); }
/// <summary> /// Constructor for the <c>MethodName</c> objects. This is /// used to create a method name representation of a method based /// on the method type and the Java Bean name of that method. /// </summary> /// <param name="method"> /// this is the actual method this is representing /// </param> /// <param name="type"> /// type used to determine if it is a set or get /// </param> /// <param name="name"> /// this is the Java Bean property name of the method /// </param> public MethodName(Method method, MethodType type, String name) { this.name = name.intern(); this.method = method; this.type = type; }