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.ResourceNotFoundException; 22 import org.apache.cocoon.acting.AbstractAction; 23 import org.apache.cocoon.environment.Redirector; 24 import org.apache.cocoon.environment.SourceResolver; 25 26 import org.xml.sax.SAXException ; 27 28 import java.io.IOException ; 29 import java.util.Map ; 30 31 38 public class ExceptionAction extends AbstractAction { 39 40 public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) 41 throws Exception { 42 String exception = parameters.getParameter("exception", source); 43 int code = parameters.getParameterAsInteger("code", 1); 44 exception(exception, code); 45 return null; 46 } 47 48 public static String exception(String exception, int code) 49 throws ProcessingException , SAXException , IOException { 50 if (exception == null) { 51 return "No exception occured."; 52 } else if (exception.equals("validation")) { 53 throw new ProcessingException(new ValidationException("Validation Exception Message")); 54 } else if (exception.equals("application")) { 55 throw new ProcessingException(new ApplicationException(code, "Application Exception " + code + " Message")); 56 } else if (exception.equals("processing")) { 57 throw new ProcessingException("Processing Exception Message"); 58 } else if (exception.equals("notFound")) { 59 throw new ResourceNotFoundException("Resource Not Found Exception Message"); 60 } else if (exception.equals("sax")) { 61 throw new SAXException ("SAX Exception Message"); 62 } else if (exception.equals("saxWrapped")) { 63 throw new SAXException (new ProcessingException("Processing Exception Wrapped In SAX Exception Message")); 64 } else if (exception.equals("nullPointer")) { 65 throw new NullPointerException ("Null Pointer Exception Message"); 66 } else if (exception.equals("io")) { 67 throw new IOException ("IO Exception Message"); 68 } else if (exception.equals("error")) { 69 throw new Error ("Error Message"); 70 } else { 71 return "Unknown exception requested."; 72 } 73 } 74 } 75 | Popular Tags |