Tuyji / probatron4j

Automatically exported from code.google.com/p/probatron4j
0 stars 0 forks source link

Enhance the code to be more usable from the Java code #5

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
IMHO, the current version of Probatron4J is specifically designed for
command line usages. It is not very usable from the java code.

The expectations that I have from Probatron4J is -  
  Should take a xml document and schematron schema, validate the document
against schema and return result in the form of an object. 
The object (say ValidationResult) should have a method which tells whether
validation is successful and another method to return list of error messages.

I tried to use the SchematronSchema class to do the validation for me.
The problems that I faced are -
1. The SchematronSchema.validateCandidate(URL url) method takes URL of the
candidate xml document. This is useful if the xml to be verified is a file
or URL. However, in the java code, the xml is likely to be in the form of a
String or stream. There is no way to convert string to URL, without
writting the string to a file and its a bad solution.

SchematronSchema has a validateCandidate(InputStream is) method, but it is
private.

2. After validation, validateCandidate() method returns ValidationReport
object which holds the bytes for the complete report XML. There is no class
in probatron jar which helps to retrieve error messages from this report XML.

Solutions that I propose - 
1. Make SchematronSchema.validateCandidate(InputStream is) method public,
so that xml which is in the form of String can be passed for validation. We
can also create a overloaded method which takes string.

2. Provide a mechanism to get the validation result in the form of a object
with the list of error messages. 
To do this, we need to create a Document object from the result stream and
then apply the XPath '//failed-assert/text/text()' to get the error messages.

I am using 0.7.1 version of Probatron4J.

Please let me know your opinion. I can provide the patch for the required
changes.

Original issue reported on code.google.com by asdh...@gmail.com on 16 Sep 2009 at 4:26

GoogleCodeExporter commented 9 years ago
@asdhoke

Many thanks for this great input. Yes! I completely agree this was a problem 
with
0.7.1 -- it was entirely command-line focussed.

For 0.7.2 there is a new Session object intended to represent a validation 
session
(broadly: applying a schema to a candidate and getting a report). I'm hoping to 
use
this as the mechanism by which other software can use Probatron.

The resulting SVRL report is encapsulated by the new ValidationReport class. 
This is
currently pretty basic -- it allows the user to stream the validation report 
out.

I think an API onto SVRL is beyond the scope of Probatron4J. The reports are
available as XML and so the user is free to choose whatever standard API they 
like to
interrogate it.

Anyway, those are my thoughts for now ... let me know what you think ...

- Alex.

Original comment by alex.bro...@gmail.com on 5 Oct 2009 at 1:24