[jdom-commits] CVS Update: jdom-contrib/src/java/org/jdom/contrib/input/scanner

nobody nobody at chimbo.servlets.com
Tue Apr 22 19:59:54 PDT 2003


****************************************
Date:   Tue Apr 22, 2003 @20:59:54 MDT
Author: 

Update of /home/cvs/jdom-contrib/src/java/org/jdom/contrib/input/scanner
In directory chimbo:/tmp/cvs-serv21555

Modified Files:
ElementScanner.java
Log Message:
Patch from Laurent:

> Is it possible to validate against a schema, like in this FAQ entry:
> http://www.jdom.org/docs/faq.html#schemas
> but when using elementScanner from the contrib to build the document?
>
> I would guess that I need to do:
> ElementScanner scanner = new ElementScanner();
> scanner.setFeature("http://apache.org/xml/features/validation/schema",
> true);
>
> but scanner.setFeature has not been written yet...

ElementScanner inherits from SAX's XMLFilterImpl which provides both
setFeature and setProperty methods. Yet, the code you propose won't work as
you have to attach ElementScanner to a parent (e.g. a SAX parser) before
calling XMLFilterImpl's setFeature or setProperty.

Try:
ElementScanner scanner = new ElementScanner(parser);
scanner.setFeature("http://apache.org/xml/features/validation/schema",
true);

Opposite to SAXBuilder, ElementScanner does not store features and properties
until a parser is available.
To add such support, you could add the following import statements and methods:

import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;

public void setFeature(String name, boolean value)
throws SAXNotRecognizedException, SAXNotSupportedException {
if (this.getParent() != null) {
this.getParent().setFeature(name, value);
}
this.parserBuilder.setFeature(name, value);
}

public void setProperty(String name, Object value)
throws SAXNotRecognizedException, SAXNotSupportedException {
if (this.getParent() != null) {
this.getParent().setProperty(name, value);
}
this.parserBuilder.setProperty(name, value);
}

Jason, I've attached a diff for you to merge the patch.

-jh-

===================================================================
File: no file ElementScanner.java		Status: Needs Checkout

   Working revision:	1.5	Wed Apr 23 02:59:54 2003
   Repository revision:	1.5	/home/cvs/jdom-contrib/src/java/org/jdom/contrib/input/scanner/ElementScanner.java,v

   Existing Tags:
	jdom_1_0_b9_rc2          	(revision: 1.4)
	jdom_1_0_b9_rc1          	(revision: 1.4)




More information about the jdom-commits mailing list