XI.javaAPI DocExample6714Fri Feb 01 13:10:40 GMT 2002None


public final class XI extends XMLFilterImpl implements Locator, LexicalHandler
XInclude-like Processing Instruction

Fields Summary
private Locator
private Vector
private LexicalHandler
private static String
private int
Constructors Summary
Methods Summary
public voidcomment(char[] buf, int off, int len)

 if (lexicalHandler != null) lexicalHandler.comment (buf, off, len); 
public voidendCDATA()

 if (lexicalHandler != null) lexicalHandler.endCDATA (); 
public voidendDTD()

 if (lexicalHandler != null) lexicalHandler.endDTD (); 
public voidendDocument()

 pending.clear (); super.endDocument (); 
public voidendElement(java.lang.String u, java.lang.String l, java.lang.String q)

 --count; super.endElement (u, l, q); 
public voidendEntity(java.lang.String name)

 if (lexicalHandler != null) lexicalHandler.endEntity (name); 
public intgetColumnNumber()

 return (locator == null) ? -1 : locator.getColumnNumber (); 
public intgetLineNumber()

 return (locator == null) ? -1 : locator.getLineNumber (); 
public java.lang.StringgetPublicId()

 return (locator == null) ? null : locator.getPublicId (); 
public java.lang.StringgetSystemId()

 return (locator == null) ? null : locator.getSystemId (); 
public voidparse(org.xml.sax.InputSource in)

	XMLReader	parent = getParent ();

	if (parent != null)
	    parent.setProperty (lexicalID, this);
	super.parse (in);
public voidprocessingInstruction(java.lang.String target, java.lang.String data)

	if ("XInclude".equals (target)) {
	    // this should do full XML Base processing
	    // instead we just handle relative and absolute URLs
	    try {
		URL		url = new URL (getSystemId ());

		url = new URL (url, data.trim ());
		data = url.toString ();
	    } catch (Exception e) {
		throw new SAXParseException (
		    "XInclude, can't use URI: " + data, locator, e);
	    xinclude (data);
	} else
	    super.processingInstruction (target, data);
public voidsetDocumentLocator(org.xml.sax.Locator l)

	locator = l;
	super.setDocumentLocator (this);
public voidsetProperty(java.lang.String uri, java.lang.Object handler)

	if (lexicalID.equals (uri))
	    lexicalHandler = (LexicalHandler) handler;
	    super.setProperty (uri, handler);
public voidstartCDATA()

 if (lexicalHandler != null) lexicalHandler.startCDATA (); 
public voidstartDTD(java.lang.String root, java.lang.String publicId, java.lang.String systemId)

 if (lexicalHandler != null) lexicalHandler.startDTD (root, publicId, systemId); 
public voidstartDocument()

 pending.addElement (locator.getSystemId ()); super.startDocument (); 
public voidstartElement(java.lang.String u, java.lang.String l, java.lang.String q, org.xml.sax.Attributes a)

 count++; super.startElement (u, l, q, a); 
public voidstartEntity(java.lang.String name)

 if (lexicalHandler != null) lexicalHandler.startEntity (name); 
private voidxinclude(java.lang.String uri)

	XMLReader	helper;
	Scrubber	scrubber;

	if (count == 0)
	    throw new SAXParseException (
		    "XInclude, illegal location", locator);
	if (pending.contains (uri))
	    throw new SAXParseException (
		    "XInclude, circular inclusion", locator);

	// start with another parser acting just like us
	helper = XMLReaderFactory.createXMLReader ();
	helper.setEntityResolver (this);
	helper.setErrorHandler (this);

	// Set up the proxy locator and event filter.
	scrubber = new Scrubber (locator, this);
	locator = null;
	scrubber.setContentHandler (this);
	helper.setContentHandler (scrubber);
	helper.setProperty (lexicalID, scrubber);

	// we INTEND to discard DTDHandler and DeclHandler events

	// Merge the included document, except its DTD
	try {
	    pending.addElement (uri);
	    helper.parse (uri);
	} catch ( e) {
	    SAXParseException	err;
	    ErrorHandler	handler;
	    err = new SAXParseException (uri, locator, e);
	    handler = getErrorHandler ();
	    if (handler != null)
		handler.fatalError (err);
	    throw err;
	} finally {
	    pending.removeElement (uri);