1 16 package org.apache.cocoon.samples.errorhandling; 17 18 import org.apache.avalon.framework.parameters.Parameters; 19 20 import org.apache.cocoon.ProcessingException; 21 import org.apache.cocoon.environment.SourceResolver; 22 import org.apache.cocoon.generation.AbstractGenerator; 23 import org.apache.cocoon.xml.XMLUtils; 24 25 import org.xml.sax.SAXException ; 26 27 import java.io.IOException ; 28 import java.util.Map ; 29 30 38 public class ExceptionGenerator extends AbstractGenerator { 39 40 private String exception; 41 private int code; 42 43 public void setup(SourceResolver resolver, Map objectModel, String src, Parameters parameters) 44 throws ProcessingException, SAXException , IOException { 45 super.setup(resolver, objectModel, src, parameters); 46 47 this.exception = parameters.getParameter("exception", super.source); 48 this.code = Integer.parseInt(parameters.getParameter("code", "0")); 49 50 if (parameters.getParameterAsBoolean("setup", false)) { 52 ExceptionAction.exception(this.exception, this.code); 53 } 54 } 55 56 59 public void generate() 60 throws ProcessingException , SAXException , IOException { 61 this.contentHandler.startDocument(); 62 this.contentHandler.startElement("", "html", "html", XMLUtils.EMPTY_ATTRIBUTES); 63 this.contentHandler.startElement("", "body", "body", XMLUtils.EMPTY_ATTRIBUTES); 64 this.contentHandler.startElement("", "p", "p", XMLUtils.EMPTY_ATTRIBUTES); 65 66 String text = ExceptionAction.exception(this.exception, this.code); 67 this.contentHandler.characters(text.toCharArray(), 0, text.length()); 68 69 this.contentHandler.endElement("", "p", "p"); 70 this.contentHandler.endElement("", "body", "body"); 71 this.contentHandler.endElement("", "html", "html"); 72 this.contentHandler.endDocument(); 73 } 74 } 75 | Popular Tags |