Attachment 'ValidatorReportTransformer.java'

Download

   1 /** Creado en 27-feb-2004 */
   2 package fcc.ima.cocoon;
   3 
   4 import org.apache.cocoon.xml.XMLConsumer;
   5 import org.xml.sax.SAXException;
   6 import org.xml.sax.SAXParseException;
   7 
   8 /**It is very similar to the {@link ValidatorTransformer}.  
   9  * Instead of letting pass through all the SAX events and generate the report on the logs, 
  10  * it generates as output a report in XML format about the conformance of the XML input data 
  11  * it receives with any schema, DTD supplied to the transformer.  
  12  * It can be useful for debugging or quality control purposes
  13  * @author dperezcar */
  14 public class ValidatorReportTransformer extends AbstractValidatorTransformer {
  15 	protected XMLConsumer originalConsumer;
  16 
  17 	/** @see org.apache.cocoon.xml.XMLProducer#setConsumer(org.apache.cocoon.xml.XMLConsumer) */
  18 	public void setConsumer(XMLConsumer consumer) {
  19 		try {
  20 			originalConsumer = consumer;
  21 			super.setConsumer(getVerifierConsumer());
  22 		} catch (Exception e) {
  23 			throw new RuntimeException(e.toString());
  24 		}
  25 	}
  26 	/** @see org.apache.avalon.excalibur.pool.Recyclable#recycle() */
  27 	public void recycle() {
  28 		super.recycle();
  29 	}
  30 	/** @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException) */
  31 	public void error(SAXParseException exc) throws SAXException {
  32 		report("error", exc);
  33 	}
  34 	/** @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException) */
  35 	public void fatalError(SAXParseException exc) throws SAXException {
  36 		report("fatal-error", exc);
  37 	}
  38 	/** @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException) */
  39 	public void warning(SAXParseException exc) throws SAXException {
  40 		report("warning", exc);
  41 	}
  42 	/** @see org.xml.sax.ContentHandler#endDocument() */
  43 	public void endDocument() throws SAXException {
  44 		super.endDocument();
  45 		endElement("report");
  46 		originalConsumer.endDocument();
  47 	}
  48 
  49 	/** @see org.xml.sax.ContentHandler#startDocument() */
  50 	public void startDocument() throws SAXException {
  51 		originalConsumer.startDocument();
  52 		startElement("report");
  53 		super.startDocument();
  54 	}
  55 	private void startElement(String name) throws SAXException {
  56 		originalConsumer.startElement("", name, name, attr);
  57 	}
  58 	private void endElement(String name) throws SAXException {
  59 		originalConsumer.endElement("", name, name);
  60 	}
  61 	/**Reports an exception*/
  62 	private void report(String name, SAXParseException e) throws SAXException {
  63 		startElement(name);
  64 		String text = getErrorMsg(e);
  65 		originalConsumer.characters(text.toCharArray(), 0, text.length());
  66 		endElement(name);
  67 	}
  68 }

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.

You are not allowed to attach a file to this page.