FileDocCategorySizeDatePackage
XStack.javaAPI DocExample4718Fri Feb 01 13:05:26 GMT 2002None

XStack

public class XStack extends DefaultHandler implements DeclHandler, LexicalHandler
Maintaining an Element/Attribute Stack

Fields Summary
private Locator
locator
private StackEntry
current
private Hashtable
extEntities
private static final String
xmlNamespace
Constructors Summary
Methods Summary
private voidaddMarker(java.lang.String label, java.lang.String uri)


          
     
    
	AttributesImpl	atts = new AttributesImpl ();

	if (locator != null && locator.getSystemId () != null)
	    uri = locator.getSystemId ();

	// guard against InputSource objects without system IDs
	if (uri == null)
	    throw new SAXParseException ("Entity URI is unknown", locator);

	// guard against illegal relative URIs (Xerces)
	try { new URL (uri); }
	catch (IOException e) {
	    throw new SAXParseException ("parser bug: relative URI", locator);
	}

	atts.addAttribute (xmlNamespace, "base", "xml:base", "CDATA", uri);
	current = new StackEntry ("", "", label, atts, current);
    
public voidattributeDecl(java.lang.String element, java.lang.String name, java.lang.String type, java.lang.String mode, java.lang.String defaultValue)

public voidcomment(char[] buf, int off, int len)

public voidelementDecl(java.lang.String name, java.lang.String model)

 
public voidendCDATA()

public voidendDTD()

public voidendDocument()

 current = null; 
public voidendElement(java.lang.String namespace, java.lang.String local, java.lang.String name)

 current = current.parent; 
public voidendEntity(java.lang.String name)

 current = current.parent; 
public voidexternalEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)

	if (name.charAt (0) == '%")
	    return;
	// absolutize URL
	try {
	    URL	url = new URL (locator.getSystemId ());
	    systemId = new URL (url, systemId).toString ();
	} catch (IOException e) {
	    // what could we do?
	}
	extEntities.put (name, systemId);
    
public java.net.URLgetBaseURI()

	return getBaseURI (current);
    
private java.net.URLgetBaseURI(XStack$StackEntry here)

	String		uri = null;

	while (uri == null && here != null) {
	    uri = here.atts.getValue (xmlNamespace, "base");
	    if (uri != null)
		break;
	    here = here.parent;
	}

	// marker for document or entity boundary?  absolute.
	if (here.qName.charAt (0) == '#")
	    return new URL (uri);

	// else it might be a relative uri.
	int		offset = uri.indexOf (":/");

	if (offset == -1 || uri.indexOf (':") < offset)
	    return new URL (getBaseURI (here.parent), uri);
	else
	    return new URL (uri);
    
public java.lang.StringgetInheritedAttribute(java.lang.String uri, java.lang.String name)

	String		retval = null;
	boolean		useNS = (uri != null && uri.length () != 0);

	for (StackEntry here = current;
		retval == null && here != null;
		here = here.parent) {
	    if (useNS)
		retval = here.atts.getValue (uri, name);
	    else
		retval = here.atts.getValue (name);
	}
	return retval;
    
public voidinternalEntityDecl(java.lang.String name, java.lang.String value)

 
public voidsetDocumentLocator(org.xml.sax.Locator l)

 locator = l; 
public voidstartCDATA()

public voidstartDTD(java.lang.String root, java.lang.String publicId, java.lang.String systemId)

public voidstartDocument()

 addMarker ("#DOCUMENT", null); 
public voidstartElement(java.lang.String namespace, java.lang.String local, java.lang.String name, org.xml.sax.Attributes attrs)

 current = new StackEntry (namespace, local, name, attrs, current); 
public voidstartEntity(java.lang.String name)

	String	uri = (String) extEntities.get (name);
	if (uri != null)
	    addMarker ("#ENTITY", uri);