[
https://jira.jboss.org/jira/browse/JBSEAM-3388?page=com.atlassian.jira.pl...
]
Arron Ferguson commented on JBSEAM-3388:
----------------------------------------
As for a quick little utility class, include something like the following for validation
against an XML schema:
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.XMLConstants;
/**
* <p>Validate XML documents against an XML schema</p>
* @author Arron Ferguson
*/
public class XMLValidate extends DefaultHandler
{
public XMLValidate(String file)
{
parse(file);
}
private void parse(String file)
{
try
{
// create a schema ... from the document
SchemaFactory sf =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema();
// now parse, set us as error handler
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
spf.setSchema(schema);
SAXParser sp = spf.newSAXParser();
sp.parse(file, this);
} catch(Exception e)
{
e.printStackTrace();
}
}
public void warning(SAXParseException ex)
{
System.err.println("[WARNING]: line: " + ex.getLineNumber()
+ " col: " + ex.getColumnNumber());
System.err.println("[MESSAGE]: " + ex.getMessage() + "\n");
}
public void error(SAXParseException ex)
{
System.err.println("[ERROR]: line: " + ex.getLineNumber()
+ " col: " + ex.getColumnNumber());
System.err.println("[MESSAGE]: " + ex.getMessage() + "\n");
}
public void fatalError(SAXParseException ex) throws SAXException
{
System.err.println("[FATALERROR]: line: " + ex.getLineNumber()
+ " col: " + ex.getColumnNumber());
System.err.println("[MESSAGE]: " + ex.getMessage() +
"\n");
}
public static void main(String args[])
{
if (args.length != 1 || args == null)
{
System.err.println("Usage: <schema file name>");
System.err.println("Example: java XMLValidate myfile.xml");
System.exit(1);
}
XMLValidate me = new XMLValidate(args[0]);
}
}
Pages.xml file should be validated against its schema at runtime
----------------------------------------------------------------
Key: JBSEAM-3388
URL:
https://jira.jboss.org/jira/browse/JBSEAM-3388
Project: Seam
Issue Type: Feature Request
Components: Core
Affects Versions: 2.1.0.BETA1
Environment: N/A
Reporter: Arron Ferguson
Priority: Minor
The pages.xml file that is used in Seam apps should really be validated when the
WAR/package is deployed on the server. This would help alleviate a lot of the false
positives (i.e., bug reports that are not due to bugs but are in fact users adding
mistakes to the pages.xml file). Additionally Seam team developers would form a tighter
contractual binding of what the specs state should happen, with what the API
implementation is actually doing. This would most likely result in a reduction in bug
reports due to false positives as well as actual bugs.
To complement this, a blurb in the Seam manual on how to create an Ant task with
validation could be added as well as a small sample application for validating pages.xml
files with the pages.xsd schema. If I have time later today I'll post to this report a
snippet of code for each.
- Arron
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira