[ 
https://issues.apache.org/jira/browse/DIGESTER-173?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13600340#comment-13600340
 ] 

Ivan Diana commented on DIGESTER-173:
-------------------------------------

Hi Simone,

{quote}the better way to test against expected exceptions, is specifying them 
in the @Test annotation, i.e. @Test( expected = SAXParseException.class ){quote}
Ok

{quote}the default ErrorHandler just log exceptions, don't throw them, so I in 
the test I added an anonymous implementation that just rethrows the caught 
exception;{quote}
Right

{quote}for test classes, the *TetsCase suffix is preferred.{quote}
Ok, I changed the name of the test class in this patch to Digester173TestCase

{quote}Anyway, there are no tests for setFeature() method in DigesterLoader, so 
I don't close the issue until we'll have them.{quote}

I implemented three test methods now:
a) testDigesterLoaderFeature: very simply setFeature test
b) testDigesterLoaderFeatureError: method with ErrorHandler that rethrows the 
caught exception expected
c) testDigesterLoaderFeatureDisabled: parse the same xml file of 
testDigesterLoaderFeatureError (previous) method, but doesn't make or print 
errors thanks to disabling controls on dtd by some setFeature false

{quote}TIA and thanks a lot for contributing!{quote}
thanks to you for this good library
                
> No way to enable schema validation from DigesterLoader
> ------------------------------------------------------
>
>                 Key: DIGESTER-173
>                 URL: https://issues.apache.org/jira/browse/DIGESTER-173
>             Project: Commons Digester
>          Issue Type: Improvement
>    Affects Versions: 3.2
>            Reporter: Nick Williams
>            Assignee: Simone Tripodi
>            Priority: Critical
>         Attachments: DIGESTER-173.patch, LoaderDTDValidation.patch
>
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> It's possible that I'm using DigesterLoader with the improper assumptions, 
> but my belief is that it is meant to be a factor of sorts for creating 
> Digesters. If this is the case, the DigesterLoader interface is incomplete 
> (and, for that matter, even if it is not the case, the documentation 
> surrounding the use of Digester and DigesterLoader is seriously lacking).
> I originally used the following code to digest my XML files:
> {code}this.loader = DigesterLoader.newLoader(module);
> this.loader.setNamespaceAware(true);
> this.loader.setSchema(schema);
> this.loader.setValidating(true);
> this.loader.setErrorHandler(new DefaultThrowingErrorHandler());
> this.loader.setUseContextClassLoader(false);
> this.loader.setClassLoader(Digester.class.getClassLoader());
> ...
> this.loader.newDigester().parse(myFile);{code}
> However, I was getting strange errors "Document is invalid: no grammar found" 
> and "must match DOCTYPE root null". Since I wasn't using a DOCTYPE, I had no 
> idea why this was happening. Much Googling of other sources (the 
> documentation did not help me with this) finally made me realize that 
> setValidating() was turning on DTD validating, regardless of the fact that I 
> was actually using schemas.
> I finally figured out my code needed to be this:
> {code}this.loader = DigesterLoader.newLoader(module);
> this.loader.setNamespaceAware(true);
> this.loader.setSchema(schema);
> this.loader.setErrorHandler(new DefaultThrowingErrorHandler());
> this.loader.setUseContextClassLoader(false);
> this.loader.setClassLoader(Digester.class.getClassLoader());
> ...
> Digester digester = this.loader.newDigester();
> digester.setFeature("http://xml.org/sax/features/validation";, true);
> digester.setFeature("http://apache.org/xml/features/validation/schema";, true);
> digester.setFeature("http://apache.org/xml/features/validation/schema-full-checking";,
>  true);{code}
> As you can see, I have to first get a Digester from the factory and THEN 
> configure the digester further before I can use it. This is contrary to the 
> standard factory pattern.
> *Proposal 1*
> - Deprecate setValidating(boolean) in DigesterLoader and Digester and replace 
> them with setDoctypeValidating(boolean).
> - Add a setSchemaValidating(boolean) method to DigesterLoader and Digester.
> - Add a setFeature() method in DigesterLoader to mirror the one in Digester.
> *Proposal 2*
> - Document the setValidating(boolean) DigesterLoader and Digester methods 
> better to indicate that it is for DOCTYPE validation and should not be used 
> when using schemas.
> - Add a setFeature() method in DigesterLoader to mirror the one in Digester.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to