home *** CD-ROM | disk | FTP | other *** search
- package org.apache.cocoon.samples.errorhandling;
-
- import java.io.IOException;
- import org.apache.cocoon.ProcessingException;
- import org.apache.cocoon.ResourceNotFoundException;
- import org.apache.cocoon.environment.ObjectModelHelper;
- import org.apache.cocoon.environment.Request;
- import org.apache.cocoon.generation.AbstractGenerator;
- import org.xml.sax.Attributes;
- import org.xml.sax.SAXException;
- import org.xml.sax.helpers.AttributesImpl;
-
- public class ExceptionGenerator extends AbstractGenerator {
- public static final String PAR_EXCEPTION = "exception";
- public static final String PAR_CODE = "code";
-
- public void generate() throws IOException, SAXException, ProcessingException {
- Request request = ObjectModelHelper.getRequest(this.objectModel);
- String exception = request.getParameter("exception");
- String text = null;
- if (exception == null) {
- text = "No exception occured.";
- } else {
- if (exception.equals("validation")) {
- throw new ProcessingException(new ValidationException());
- }
-
- if (exception.equals("application")) {
- throw new ProcessingException(new ApplicationException(Integer.parseInt(request.getParameter("code"))));
- }
-
- if (exception.equals("resourceNotFound")) {
- throw new ProcessingException(new ResourceNotFoundException(""));
- }
-
- if (exception.equals("nullPointer")) {
- throw new NullPointerException();
- }
-
- if (exception.equals("error")) {
- throw new Error("Error");
- }
-
- text = "Unknown exception requested.";
- }
-
- Attributes noAttrs = new AttributesImpl();
- this.contentHandler.startDocument();
- this.contentHandler.startElement("", "html", "html", noAttrs);
- this.contentHandler.startElement("", "body", "body", noAttrs);
- this.contentHandler.startElement("", "p", "p", noAttrs);
- this.contentHandler.characters(text.toCharArray(), 0, text.length());
- this.contentHandler.endElement("", "p", "p");
- this.contentHandler.endElement("", "body", "body");
- this.contentHandler.endElement("", "html", "html");
- this.contentHandler.endDocument();
- }
- }
-