Return-Path: Delivered-To: apmail-xml-cocoon-dev-archive@xml.apache.org Received: (qmail 3657 invoked by uid 500); 27 Jan 2003 13:37:19 -0000 Mailing-List: contact cocoon-dev-help@xml.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: cocoon-dev@xml.apache.org Delivered-To: mailing list cocoon-dev@xml.apache.org Received: (qmail 3587 invoked from network); 27 Jan 2003 13:37:12 -0000 Message-ID: <007601c2c609$230fab70$c243e39e@BIPA194> From: "Oskar Casquero" To: , Subject: ValidationTransformer Date: Mon, 27 Jan 2003 14:36:14 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Hi, I am trying to do a ValidationTransformer that will validate an xml document with a grammar (W3C Schema, RELAX NG, DTD). To do this I am using JARV, that gives a validation interface which can control a validation engine (for example, Xerces-2) through the suitable driver. I have done the first version of the ValidationTransformer via DOM. To do it, I modified the WriteDOMSessionTransformer, implementing ErrorHandler interface and adding to it the code necessary to validate with W3C schemas (another grammars can be used setting the grammar type as a parameter in the sitemap). setup method: public void setup(SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws ProcessingException, SAXException, IOException, Exception { ... schema = parameters.getParameter(MyValidationTransformer.SCHEMA, null); if (schema!=null) { getLogger().debug("MyValidationTransformer: "+ MyValidationTransformer.SCHEMA + "=" + schema); } else { getLogger().error("MyValidationTransformer: need " + MyValidationTransformer.SCHEMA + " parameters"); } File schemaFile = new File("/usr/local/jakarta-tomcat-4.0.4/webapps/cocoon/RTF/schemas/" + schema); VerifierFactory factory = VerifierFactory.newInstance("http://www.w3.org/2001/XMLSchema"); getLogger().debug("MyValidationTransformer: JARV implementation obtained"); Schema schemaObject = factory.compileSchema(schemaFile); getLogger().debug("MyValidationTransformer: schema compiled"); verifier = schemaObject.newVerifier(); verifier.setErrorHandler(this); getLogger().debug("MyValidationTransformer: errorHandler configured"); } catch (Exception e) { getLogger().debug("MyValidationTransformer: JARV error: " + e.getMessage() + ", " + e.getCause()); } } endElement method: public void endElement(String uri, String name, String raw) throws SAXException { if (name.equalsIgnoreCase(rootElement) && sessionAvailable) { ... getLogger().debug("MyValidationTransformer: DOM tree is in session object"); verifier.verify(builder.getDocument()); getLogger().debug("MyValidationTransformer: DOM tree verified"); } ... } error method for ErrorHandler implementation: public void error( final SAXParseException spe ) throws SAXException { String message = "Error parsing " + spe.getSystemId() + " (line " + spe.getLineNumber() + " col. " + spe.getColumnNumber() + "): " + spe.getMessage(); getLogger().error( message, spe ); throw new SAXException( message, spe ); } I check the transformer with the following pipeline: if I send a valid document it must return the document without doing any transformation; if the document is not valid, an error message must be returned by cocoon containing ErrorHandler's exception message. This works well. But if I try to add after the generator, the document is returned to the browser, despite it is not valid. So I think that the ValidationTransformer is not working well, but I am not totally sure, because the error is logged in sitemap.log. So, why is the error logged into sitemap.log, but not returned as an exception error message to the client? Could be because of the way in how cocoon works, because when the validation of the DOM tree is starting or being done, the pipeline process is already complete? The alternative is to perform the validation via SAX, but I don't know how to mix the verifierHandler and the contentHandler of the transformer in order to make available incoming SAX events for the verifierHandler. I try to do: public void setup(SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws ProcessingException, SAXException, IOException, Exception { ... VerifierHandler verifierHandler = verifier.getVerifierHandler(); super.setContentHandler(verifierHandler); ... } so that as the transformer receives SAX events from a generator or another transfomer, the verifierHandler will also receive them, and if the documents is not valid and exception will be thrown by the ErrorHandler. But I don't know why, the super.setContentHandler(verifierHandler) is not working (???) Oskar --------------------------------------------------------------------- To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org For additional commands, email: cocoon-dev-help@xml.apache.org