[jbossseam-issues] [JBoss JIRA] Commented: (JBSEAM-2938) org.jboss.seam.util.XML doesn't validate
Arron Ferguson (JIRA)
jira-events at lists.jboss.org
Fri Sep 5 13:54:38 EDT 2008
[ https://jira.jboss.org/jira/browse/JBSEAM-2938?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12428437#action_12428437 ]
Arron Ferguson commented on JBSEAM-2938:
----------------------------------------
Not sure if:
saxReader.setEntityResolver(new DTDEntityResolver());
saxReader.setValidation(true);
saxReader.setFeature("http://apache.org/xml/features/validation/schema",true);
With newer JVMs. Sun went and changed the whole XSD validation process and now requires you to use a SchemaFactory. Take a look at the code I put up in the closed/duplicate bug:
https://jira.jboss.org/jira/browse/JBSEAM-3388
That works with schemas and reports *everything*.
> org.jboss.seam.util.XML doesn't validate
> ----------------------------------------
>
> Key: JBSEAM-2938
> URL: https://jira.jboss.org/jira/browse/JBSEAM-2938
> Project: Seam
> Issue Type: Bug
> Components: Core
> Reporter: Christian Bauer
> Assignee: Norman Richards
> Priority: Minor
>
> The getRootElement() method is probably supposed to validate the XML file. However, it only sets a DTD EntityResolver:
> SAXReader saxReader = new SAXReader();
> saxReader.setEntityResolver(new DTDEntityResolver());
> saxReader.setMergeAdjacentText(true);
> return saxReader.read(stream).getRootElement();
> This might trigger some magic flag that says "validate against this DTD", but the dom4j documentation says otherwise: http://www.dom4j.org/faq.html#how-validate
> I've implemented my own routine which validates against my schema properly:
> try {
> SAXReader saxReader = new SAXReader();
> if (isSchemaValidating()) {
> saxReader.setEntityResolver(new DTDEntityResolver());
> saxReader.setValidation(true);
> saxReader.setFeature("http://apache.org/xml/features/validation/schema",true);
> }
> saxReader.setMergeAdjacentText(true);
> elements.put(fileInputStream.getKey(), saxReader.read(fileInputStream.getValue()).getRootElement());
> } catch (DocumentException dex) {
> Throwable nested = dex.getNestedException();
> if (nested != null) {
> if (nested instanceof FileNotFoundException) {
> throw new RuntimeException(
> "Can't find schema/DTD reference for file: "
> + fileInputStream.getKey() + "': "
> + nested.getMessage(), dex
> );
> } else if (nested instanceof UnknownHostException) {
> throw new RuntimeException(
> "Cannot connect to host from schema/DTD reference: "
> + nested.getMessage()
> + " - check that your schema/DTD reference is current", dex
> );
> }
> }
> throw new RuntimeException("Could not parse XML file: " + fileInputStream.getKey() ,dex);
> } catch (Exception ex) {
> throw new RuntimeException("Could not parse XML file: " + fileInputStream.getKey() ,ex);
> }
> I can use that with the classpath:// feature of the DTDEntityResolver (which is the same as in Hibernate):
> <?xml version="1.0" encoding="UTF-8"?>
> <plugin key="hw" label="Hello World"
> xmlns="http://jboss.com/products/seam/wiki/plugin"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation=
> "http://jboss.com/products/seam/wiki/plugin classpath://org/jboss/seam/wiki/core/plugin/plugin-1.0.xsd">
> ...
--
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
More information about the seam-issues
mailing list