giacomo 01/12/30 13:50:47
Modified: src/org/apache/cocoon Constants.java Notificable.java
Notification.java Notifier.java
src/org/apache/cocoon/components/language/markup/sitemap/java
sitemap.xsl
src/org/apache/cocoon/components/pipeline
AbstractEventPipeline.java
src/org/apache/cocoon/servlet CocoonServlet.java
src/org/apache/cocoon/sitemap ErrorNotifier.java
sitemap.roles
webapp sitemap.xmap
webapp/protected sitemap.xmap
webapp/stylesheets simple-samples2html.xsl
webapp/sub/stylesheets error2html.xsl
Added: src/org/apache/cocoon/components/notification
DefaultNotifyingBuilder.java Notifier.java
Notifying.java NotifyingBuilder.java
NotifyingCascadingRuntimeException.java
NotifyingObjects.java SimpleNotifyingBean.java
Log:
added patches from Nicola Ken Barozzi enhancing the Error Notification part of cocoon
Revision Changes Path
1.16 +10 -2 xml-cocoon2/src/org/apache/cocoon/Constants.java
Index: Constants.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/Constants.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- Constants.java 17 Dec 2001 20:42:28 -0000 1.15
+++ Constants.java 30 Dec 2001 21:50:46 -0000 1.16
@@ -59,7 +59,8 @@
* The <code>Constants</code> use throughout the core of the Cocoon engine.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
- * @version CVS $Revision: 1.15 $ $Date: 2001/12/17 20:42:28 $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Peter Royal</a>
+ * @version CVS $Revision: 1.16 $ $Date: 2001/12/30 21:50:46 $
*/
public interface Constants {
@@ -260,11 +261,16 @@
*
*/
String LINK_OBJECT = "link";
+
+ /**
+ * The name of a <code>NotifyingObjects</code> object in the so called
objectModel <code>Map</code>.
+ */
+ String NOTIFYING_OBJECTS = "notifying-objects";
/**
* Describe variable <code>INDEX_URI</code> here.
*
- * FIXME(GP): It seems to be (CLI) Environment specifix!
+ * FIXME(GP): It seems to be (CLI) Environment specific!
*/
String INDEX_URI = "index";
@@ -309,3 +315,5 @@
boolean DESCRIPTOR_RELOADABLE_DEFAULT = true;
}
+
+
1.2 +5 -37 xml-cocoon2/src/org/apache/cocoon/Notificable.java
Index: Notificable.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/Notificable.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Notificable.java 9 May 2001 20:49:27 -0000 1.1
+++ Notificable.java 30 Dec 2001 21:50:46 -0000 1.2
@@ -8,49 +8,17 @@
package org.apache.cocoon;
-import java.util.HashMap;
+import org.apache.cocoon.components.notification.Notifying;
/**
* Interface for Objects that can notify something.
*
- * @author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a> Aisa
+ * @author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a>
+ * @deprecated Now another interface is used
+ * @see org.apache.components.notification.Notifying
* @created 24 August 2000
*/
-public interface Notificable {
+public interface Notificable extends Notifying{
- /**
- * Gets the Type attribute of the Notificable object
- */
- String getType();
-
- /**
- * Gets the Title attribute of the Notificable object
- */
- String getTitle();
-
- /**
- * Gets the Source attribute of the Notificable object
- */
- String getSource();
-
- /**
- * Gets the Sender attribute of the Notificable object
- */
- String getSender();
-
- /**
- * Gets the Message attribute of the Notificable object
- */
- String getMessage();
-
- /**
- * Gets the Description attribute of the Notificable object
- */
- String getDescription();
-
- /**
- * Gets the ExtraDescriptions attribute of the Notificable object
- */
- HashMap getExtraDescriptions();
}
1.8 +10 -261 xml-cocoon2/src/org/apache/cocoon/Notification.java
Index: Notification.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/Notification.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Notification.java 17 Oct 2001 10:06:24 -0000 1.7
+++ Notification.java 30 Dec 2001 21:50:46 -0000 1.8
@@ -8,282 +8,31 @@
package org.apache.cocoon;
+import org.apache.cocoon.components.notification.SimpleNotifyingBean;
+
import org.apache.avalon.framework.CascadingThrowable;
import org.xml.sax.SAXException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.HashMap;
+import java.util.Map;
/**
* Generates an XML representation of the current notification.
*
- * @author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a> Aisa
+ * @author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a>
+ * @deprecated Now another interface is used
+ * @see org.apache.components.notification.SimpleNotifyingBean
* @created 24 August 2000
*/
-public class Notification implements Notificable {
-
- /**
- * The type of the notification. Examples can be "warning" or "error"
- */
- private String type = "";
-
- /**
- * The title of the notification.
- */
- private String title = "";
-
- /**
- * The source that generates the notification.
- */
- private String source = "";
-
- /**
- * The sender of the notification.
- */
- private String sender = "";
-
- /**
- * The notification itself.
- */
- private String message = "";
-
- /**
- * A more detailed description of the notification.
- */
- private String description = "";
-
- /**
- * A Hashtable containing extra notifications that do
- */
- private HashMap extraDescriptions = new HashMap();
-
- /**
- * Constructor for the Notification object
- */
+public class Notification extends SimpleNotifyingBean {
+
public Notification(Object sender) {
- setSender(sender);
- }
-
- /**
- * Constructor for the Notification object
- *
- * @param o Description of Parameter
- */
- public Notification(Object sender, Object o) {
- this(sender);
- setType("object");
- setTitle("Object notification");
- setSource(o.getClass().getName());
- setMessage(o.toString());
- }
-
- /**
- * Constructor for the Notification object
- *
- * @param t Description of Parameter
- */
- public Notification(Object sender, Throwable t) {
- this(sender);
- setType("error");
- setTitle("Cocoon error");
- if(t != null)
- {
- setSource(t.getClass().getName());
- setMessage(t.getMessage());
- setDescription(t.toString());
-
- extraDescriptions.put("exception", t.toString());
- // get the stacktrace: if the exception is a SAXException,
- // the stacktrace of the embedded exception is used as the
- // SAXException does not append it automatically
- Throwable stackTraceException;
- if (t instanceof SAXException
- && ((SAXException)t).getException() != null) {
- stackTraceException = ((SAXException)t).getException();
- } else {
- stackTraceException = t;
- }
- StringWriter sw = new StringWriter();
- stackTraceException.printStackTrace(new PrintWriter(sw));
- extraDescriptions.put("stacktrace", sw.toString());
-
- // Add nested throwables description
- sw = new StringWriter();
- appendCauses(new PrintWriter(sw), stackTraceException);
-
- String causes = sw.toString();
- if (causes != null && causes.length() != 0) {
- extraDescriptions.put("original exception", causes);
- }
-
-/* Now handled by appendCauses()
- // if the throwable is a CascadingThrowable the strack trace
- // is automatically appended by the CascadingThrowable, so we
- // only have to deal with the case if the embedded exception
- // of the CascadingThrowable is a SAXException.
- if (t instanceof CascadingThrowable) {
- Throwable cause = ((CascadingThrowable)t).getCause();
- if(cause != null && cause instanceof SAXException) {
- cause = ((SAXException)cause).getException();
- if(cause != null) {
- extraDescriptions.put("original exception",
cause.toString());
- stackTrace = new StringWriter();
- cause.printStackTrace(new PrintWriter(stackTrace));
- extraDescriptions.put("original exception stacktrace",
stackTrace.toString());
- }
- }
- }
-*/
- }
- }
-
- /**
- * Print recursively all nested causes of a Throwable in a PrintWriter.
- */
- public void appendCauses(PrintWriter out, Throwable t) {
- Throwable cause = null;
- if (t instanceof CascadingThrowable) {
- cause = ((CascadingThrowable)t).getCause();
- } else if (t instanceof SAXException) {
- cause = ((SAXException)t).getException();
- } else if (t instanceof java.sql.SQLException) {
- cause = ((java.sql.SQLException)t).getNextException();
- }
-
- if (cause != null) {
- out.print("Original exception : ");
- cause.printStackTrace(out);
- out.println();
-
- // Recurse
- appendCauses(out, cause);
- }
- }
-
- /**
- * Sets the Type attribute of the Notification object
- *
- *@param type The new Type value
- */
- public void setType(String type) {
- this.type = type;
- }
-
- /**
- * Sets the Title attribute of the Notification object
- *
- *@param title The new Title value
- */
- public void setTitle(String title) {
- this.title = title;
- }
-
- /**
- * Sets the Source attribute of the Notification object
- *
- *@param source The new Source value
- */
- public void setSource(String source) {
- this.source = source;
- }
-
- /**
- * Sets the Sender attribute of the Notification object
- *
- *@param sender The new sender value
- */
- private void setSender(Object sender) {
- this.sender = sender.getClass().getName();
- }
-
- /**
- * Sets the Sender attribute of the Notification object
- *
- *@param sender The new sender value
- */
- private void setSender(String sender) {
- this.sender = sender;
- }
-
- /**
- * Sets the Message attribute of the Notification object
- *
- *@param message The new Message value
- */
- public void setMessage(String message) {
- this.message = message;
- }
-
- /**
- * Sets the Description attribute of the Notification object
- *
- *@param description The new Description value
- */
- public void setDescription(String description) {
- this.description = description;
- }
-
- /**
- * Sets the ExtraDescriptions attribute of the Notification object
- *
- *@param extraDescriptions The new ExtraDescriptions value
- */
- public void addExtraDescription(String extraDescriptionDescription,
- String extraDescription) {
- this.extraDescriptions.put(extraDescriptionDescription,
- extraDescription);
- }
-
- /**
- * Gets the Type attribute of the Notification object
- */
- public String getType() {
- return type;
- }
-
- /**
- * Gets the Title attribute of the Notification object
- */
- public String getTitle() {
- return title;
- }
-
- /**
- * Gets the Source attribute of the Notification object
- */
- public String getSource() {
- return source;
- }
-
- /**
- * Gets the Sender attribute of the Notification object
- */
- public String getSender() {
- return sender;
- }
-
- /**
- * Gets the Message attribute of the Notification object
- */
- public String getMessage() {
- return message;
- }
-
- /**
- * Gets the Description attribute of the Notification object
- */
- public String getDescription() {
- return description;
- }
+ super(sender);
+ }
- /**
- * Gets the ExtraDescriptions attribute of the Notification object
- */
- public HashMap getExtraDescriptions() {
- return extraDescriptions;
- }
}
1.7 +7 -118 xml-cocoon2/src/org/apache/cocoon/Notifier.java
Index: Notifier.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/Notifier.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Notifier.java 11 Oct 2001 07:28:15 -0000 1.6
+++ Notifier.java 30 Dec 2001 21:50:46 -0000 1.7
@@ -8,132 +8,21 @@
package org.apache.cocoon;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.AttributesImpl;
+//NKB Import commented to prevent name clashing - using full name instead
+//import org.apache.cocoon.components.notification.Notifier;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.HashMap;
-import java.util.Iterator;
/**
* Generates an XML representation of the current notification.
*
- * @author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a> Aisa
+ * @author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
- * @version CVS $Revision: 1.6 $ $Date: 2001/10/11 07:28:15 $
+ *@deprecated Now another class is used
+ * @see org.apache.components.notification.Notifier
+ * @version CVS $Revision: 1.7 $ $Date: 2001/12/30 21:50:46 $
*/
-public class Notifier {
+public class Notifier extends org.apache.cocoon.components.notification.Notifier{
- /**
- * Generate notification information as a response.
- * The notification is directly written to the OutputStream.
- * @param n The <code>Notificable</code> object
- * @param outputStream The output stream the notification is written to
- * This could be <code>null</code>.
- * @return The content type for this notification
- * (currently always text/html)
- */
- public static String notify(Notificable n, OutputStream outputStream)
- throws IOException {
- StringBuffer sb = new StringBuffer();
-
- sb.append("<html><head><title>").append(n.getTitle()).append("</title>");
- sb.append("<STYLE><!--H1{font-family : sans-serif,Arial,Tahoma;color :
white;background-color : #0086b2;} ");
- sb.append("BODY{font-family : sans-serif,Arial,Tahoma;color :
black;background-color : white;} ");
- sb.append("B{color : white;background-color : #0086b2;} ");
- sb.append("HR{color : #0086b2;} ");
- sb.append("--></STYLE> ");
- sb.append("</head><body>");
- sb.append("<h1>Cocoon 2 - ").append(n.getTitle()).append("</h1>");
- sb.append("<HR size=\"1\" noshade>");
- sb.append("<p><b>type</b> ").append(n.getType()).append("</p>");
- sb.append("<p><b>message</b>
<u>").append(n.getMessage()).append("</u></p>");
- sb.append("<p><b>description</b>
<u>").append(n.getDescription()).append("</u></p>");
- sb.append("<p><b>sender</b> ").append(n.getSender()).append("</p>");
- sb.append("<p><b>source</b> ").append(n.getSource()).append("</p>");
-
- HashMap extraDescriptions = n.getExtraDescriptions();
- Iterator keyIter = extraDescriptions.keySet().iterator();
-
- while (keyIter.hasNext()) {
- String key = (String) keyIter.next();
-
-
sb.append("<p><b>").append(key).append("</b><pre>").append(extraDescriptions.get(key)).append("</pre></p>");
- }
-
- sb.append("<HR size=\"1\" noshade>");
- sb.append("</body></html>");
-
- if (outputStream != null) outputStream.write(sb.toString().getBytes());
- // FIXME (SM) how can we send the error with the proper content type?
-
- return "text/html";
- }
-
- /**
- * Generate notification information in XML format.
- */
- public static void notify(Notificable n, ContentHandler ch) throws SAXException
{
-
- final String PREFIX = Constants.ERROR_NAMESPACE_PREFIX;
- final String URI = Constants.ERROR_NAMESPACE_URI;
-
- // Start the document
- ch.startDocument();
- ch.startPrefixMapping(PREFIX, URI);
-
- // Root element.
- AttributesImpl atts = new AttributesImpl();
-
- atts.addAttribute(URI, "type", PREFIX+":type", "CDATA", n.getType());
- atts.addAttribute(URI, "sender", PREFIX+":sender", "CDATA", n.getSender());
- ch.startElement(URI, "notify", PREFIX+":notify", atts);
- ch.startElement(URI, "title", PREFIX+":title", new AttributesImpl());
- ch.characters(n.getTitle().toCharArray(), 0, n.getTitle().length());
- ch.endElement(URI, "title", PREFIX+":title");
- ch.startElement(URI, "source", PREFIX+":source", new AttributesImpl());
- ch.characters(n.getSource().toCharArray(), 0, n.getSource().length());
- ch.endElement(URI, "source", PREFIX+":source");
- ch.startElement(URI, "message", PREFIX+":message", new AttributesImpl());
-
- if (n.getMessage() != null) {
- ch.characters(n.getMessage().toCharArray(), 0,
- n.getMessage().length());
- }
-
- ch.endElement(URI, "message", PREFIX+":message");
- ch.startElement(URI, "description", PREFIX+":description",
- new AttributesImpl());
- ch.characters(n.getDescription().toCharArray(), 0,
- n.getDescription().length());
- ch.endElement(URI, "description", PREFIX+":description");
-
- HashMap extraDescriptions = n.getExtraDescriptions();
- Iterator keyIter = extraDescriptions.keySet().iterator();
-
- while (keyIter.hasNext()) {
- String key = (String) keyIter.next();
-
- atts = new AttributesImpl();
-
- atts.addAttribute(URI, "description", PREFIX+":description", "CDATA",
- key);
- ch.startElement(URI, "extra", PREFIX+":extra", atts);
- ch.characters(extraDescriptions.get(key).toString().toCharArray(),
- 0, (extraDescriptions.get(key).toString())
- .length());
- ch.endElement(URI, "extra", PREFIX+":extra");
- }
-
- // End root element.
- ch.endElement(URI, "notify", PREFIX+":notify");
-
- // End the document.
- ch.endPrefixMapping(PREFIX);
- ch.endDocument();
- }
}
1.59 +29 -5
xml-cocoon2/src/org/apache/cocoon/components/language/markup/sitemap/java/sitemap.xsl
Index: sitemap.xsl
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/components/language/markup/sitemap/java/sitemap.xsl,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -r1.58 -r1.59
--- sitemap.xsl 29 Dec 2001 11:49:44 -0000 1.58
+++ sitemap.xsl 30 Dec 2001 21:50:46 -0000 1.59
@@ -114,19 +114,24 @@
import org.apache.cocoon.components.pipeline.StreamPipeline;
import org.apache.cocoon.components.pipeline.EventPipeline;
import org.apache.cocoon.sitemap.Sitemap;
- import org.apache.cocoon.sitemap.ErrorNotifier;
+ import org.apache.cocoon.sitemap.NotifyingGenerator;
import org.apache.cocoon.sitemap.ContentAggregator;
import org.apache.cocoon.sitemap.Manager;
import org.apache.cocoon.sitemap.SitemapRedirector;
import org.apache.cocoon.components.language.markup.xsp.XSPRequestHelper;
import org.apache.cocoon.components.language.markup.xsp.XSPResponseHelper;
+ import org.apache.cocoon.components.notification.NotifyingBuilder;
+ import org.apache.cocoon.components.notification.Notifying;
+ import org.apache.cocoon.components.notification.NotifyingObjects;
/**
* This is the automatically generated class from the sitemap definitions
*
* @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
- * @version CVS $Id: sitemap.xsl,v 1.58 2001/12/29 11:49:44 giacomo Exp $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken
Barozzi</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Peter
Royal</a>
+ * @version CVS $Id: sitemap.xsl,v 1.59 2001/12/30 21:50:46 giacomo Exp $
*/
public class <xsl:value-of select="@file-name"/> extends AbstractSitemap {
static final String LOCATION = "<xsl:value-of select="translate(@file-path,
'/', '.')"/>.<xsl:value-of select="@file-name"/>";
@@ -286,7 +291,7 @@
try {
<!-- configure well known components first -->
- load_component (Sitemap.GENERATOR, "!error-notifier!",
"org.apache.cocoon.sitemap.ErrorNotifier", new DefaultConfiguration("", LOCATION),
null);
+ load_component (Sitemap.GENERATOR, "!notifying-generator!",
"org.apache.cocoon.sitemap.NotifyingGenerator", new DefaultConfiguration("",
LOCATION), null);
load_component (Sitemap.GENERATOR, "!content-aggregator!",
"org.apache.cocoon.sitemap.ContentAggregator", new DefaultConfiguration("", LOCATION),
null);
load_component (Sitemap.TRANSFORMER, "!link-translator!",
"org.apache.cocoon.sitemap.LinkTranslator", new DefaultConfiguration("", LOCATION),
null);
@@ -630,6 +635,9 @@
XPath kind expressions in values of src attribute used with
generate and transform elements */
List listOfMaps = (List) new ArrayList();
+ //Adds Constants.NOTIFYING_OBJECTS to ObjectModel
+ //NKB FIXME add to ObjectModel?
+ environment.getObjectModel().put(Constants.NOTIFYING_OBJECTS, new
NotifyingObjects());
SitemapRedirector redirector = new SitemapRedirector(environment);
<!-- process the pipelines -->
<!-- for each pipeline element generate a try/catch block -->
@@ -734,13 +742,28 @@
eventPipeline =
(EventPipeline)this.manager.lookup(EventPipeline.ROLE);
pipeline = (StreamPipeline)this.manager.lookup(StreamPipeline.ROLE);
pipeline.setEventPipeline(eventPipeline);
+ pipeline.recompose(this.manager);
+ eventPipeline.recompose(this.manager);
List listOfMaps = (List)(new ArrayList());
Map map;
Parameters param;
- eventPipeline.setGenerator ("!error-notifier!", e.getMessage(),
Parameters.EMPTY_PARAMETERS, e);
+
+ // Create a Notifying out of this exception and stick it in the
object model Constants.NOTIFYING_OBJECTS
+ boolean de = getLogger().isDebugEnabled();
+ if(de)getLogger().debug("Starting to build Notifying");
+ NotifyingBuilder notifyingBuilder=
(NotifyingBuilder)this.manager.lookup(NotifyingBuilder.ROLE);
+ if(de)getLogger().debug("Got "+notifyingBuilder);
+ Notifying currentNotifying = notifyingBuilder.build(this, e);
+ if(de)getLogger().debug("Built "+currentNotifying);
+ NotifyingObjects notifyingObjects =
(NotifyingObjects)objectModel.get(Constants.NOTIFYING_OBJECTS);
+ if(de)getLogger().debug("Got "+notifyingObjects);
+ notifyingObjects.addNotifying(currentNotifying);
+ if(de)getLogger().debug("Added to "+notifyingObjects);
+ eventPipeline.setGenerator ("!notifying-generator!", e.getMessage(),
Parameters.EMPTY_PARAMETERS);
+
<xsl:apply-templates select="./*"/>
} catch (Exception ex) {
- if (getLogger().isErrorEnabled()) getLogger().error("error notifier
barfs", ex);
+ if (getLogger().isErrorEnabled())
getLogger().error("NotifyingGenerator was not able to notify the exception.", ex);
throw e;
} finally {
if(eventPipeline != null)
@@ -1919,3 +1942,4 @@
<xsl:template match="map:logicsheet|map:dependency|map:handle-errors"/>
</xsl:stylesheet>
+
1.1
xml-cocoon2/src/org/apache/cocoon/components/notification/DefaultNotifyingBuilder.java
Index: DefaultNotifyingBuilder.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
**************************************************************************** *
*/
package org.apache.cocoon.components.notification;
import org.apache.avalon.framework.CascadingThrowable;
import org.apache.avalon.framework.component.Component;
import org.xml.sax.SAXException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Map;
/**
* Generates an Notifying representation of widely used objects.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a>
* @created 24 August 2000
*/
public class DefaultNotifyingBuilder implements NotifyingBuilder, Component {
/** Builds a Notifying object (SimpleNotifyingBean in this case)
* that tries to explain what the Object o can reveal.
* @param sender who sent this Object.
* @param o the object to use when building the SimpleNotifyingBean
* @return the Notifying Object that was build
* @see org.apache.cocoon.components.notification.Notifying
*/
public Notifying build (Object sender, Object o) {
if (o instanceof Notifying) {
return (Notifying) o;
} else if (o instanceof Throwable) {
Throwable t = (Throwable) o;
SimpleNotifyingBean n = new SimpleNotifyingBean(sender);
n.setType("error");
n.setTitle("An error occurred");
if (t != null) {
n.setSource(t.getClass().getName());
n.setMessage(t.getMessage());
n.setDescription(t.toString());
Throwable rootT = getRootCause(t);
n.addExtraDescription("original message", rootT.toString());
// get the stacktrace: if the exception is a SAXException,
// the stacktrace of the embedded exception is used as the
// SAXException does not append it automatically
Throwable stackTraceException;
if (t instanceof SAXException && ((SAXException) t).getException() != null) {
stackTraceException = ((SAXException) t).getException();
} else {
stackTraceException = t;
}
//org.apache.avalon.framework.ExceptionUtil.captureStackTrace();
StringWriter sw = new StringWriter();
stackTraceException.printStackTrace(new PrintWriter(sw));
n.addExtraDescription("stacktrace", sw.toString());
// Add nested throwables description
sw = new StringWriter();
appendCauses(new PrintWriter(sw), stackTraceException);
String causes = sw.toString();
if (causes != null && causes.length() != 0) {
n.addExtraDescription("full exception chain stacktrace", causes);
}
}
return n;
} else {
SimpleNotifyingBean n = new SimpleNotifyingBean(sender);
n.setType("unknown");
n.setTitle("Object notification");
n.setSource(o.getClass().getName());
n.setMessage(o.toString());
n.setDescription("No details available.");
return n;
}
}
/** Builds a Notifying object (SimpleNotifyingBean in this case)
* that explains a notification.
* @param sender who sent this Object.
* @param o the object to use when building the SimpleNotifyingBean
* @param type see the Notifying apidocs
* @param title see the Notifying apidocs
* @param source see the Notifying apidocs
* @param message see the Notifying apidocs
* @param description see the Notifying apidocs
* @param extra see the Notifying apidocs
* @return the Notifying Object that was build
* @see org.apache.cocoon.components.notification.Notifying
*/
public Notifying build(Object sender, Object o, String type, String title,
String source, String message, String description, Map extra) {
//NKB Cast here is secure, the method is of this class
SimpleNotifyingBean n = (SimpleNotifyingBean) build (sender, o);
if (type != null)
n.setType(type);
if (title != null)
n.setTitle(title);
if (source != null)
n.setSource(source);
if (message != null)
n.setMessage(message);
if (description != null)
n.setDescription(description);
if (extra != null)
n.replaceExtraDescriptions(extra);
return n;
}
/**
* Print recursively all nested causes of a Throwable in a PrintWriter.
*/
private static void appendCauses (PrintWriter out, Throwable t) {
Throwable cause = null;
if (t instanceof CascadingThrowable) {
cause = ((CascadingThrowable) t).getCause();
} else if (t instanceof SAXException) {
cause = ((SAXException) t).getException();
} else if (t instanceof java.sql.SQLException) {
cause = ((java.sql.SQLException) t).getNextException();
}
if (cause != null) {
out.print("Original exception : ");
cause.printStackTrace(out);
out.println();
// Recurse
appendCauses(out, cause);
}
}
/**
* Get root Exception.
*/
private static Throwable getRootCause (Throwable t) {
Throwable cause = null;
if (t instanceof CascadingThrowable) {
cause = ((CascadingThrowable) t).getCause();
} else if (t instanceof SAXException) {
cause = ((SAXException) t).getException();
} else if (t instanceof java.sql.SQLException) {
cause = ((java.sql.SQLException) t).getNextException();
}
if (cause == null) {
return t;
} else {
// Recurse
return getRootCause(cause);
}
}
}
1.1
xml-cocoon2/src/org/apache/cocoon/components/notification/Notifier.java
Index: Notifier.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.cocoon.components.notification;
import org.apache.cocoon.Constants;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Map;
import java.util.Iterator;
/**
* Generates a representations of the specified Notifying Object.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a> Aisa
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
* @version CVS $Revision: 1.1 $ $Date: 2001/12/30 21:50:46 $
*/
public class Notifier {
/**
* Generate notification information as a response.
* The notification is directly written to the OutputStream.
* @param n The <code>Notifying</code> object
* @param outputStream The output stream the notification is written to
* This could be <code>null</code>.
* @return The content type for this notification
* (currently always text/html)
*/
public static String notify(Notifying n,
OutputStream outputStream) throws IOException {
StringBuffer sb = new StringBuffer();
sb.append("<html><head><title>").append(n.getTitle()).append("</title>");
sb.append("<STYLE><!--H1{font-family : sans-serif,Arial,Tahoma;color :
white;background-color : #0086b2;} ");
sb.append("BODY{font-family : sans-serif,Arial,Tahoma;color :
black;background-color : white;} ");
sb.append("B{color : white;background-color : #0086b2;} ");
sb.append("HR{color : #0086b2;} ");
sb.append("--></STYLE> ");
sb.append("</head><body>");
sb.append("<h1>Cocoon 2 - ").append(n.getTitle()).append("</h1>");
sb.append("<HR size=\"1\" noshade=\"noshade\">");
sb.append("<p><b>type</b> ").append(n.getType()).append("</p>");
sb.append("<p><b>message</b> <u>").append(n.getMessage()).append("</u></p>");
sb.append("<p><b>description</b>
<u>").append(n.getDescription()).append("</u></p>");
sb.append("<p><b>sender</b> ").append(n.getSender()).append("</p>");
sb.append("<p><b>source</b> ").append(n.getSource()).append("</p>");
Map extraDescriptions = n.getExtraDescriptions();
Iterator keyIter = extraDescriptions.keySet().iterator();
while (keyIter.hasNext()) {
String key = (String) keyIter.next();
sb.append("<p><b>").append(key).append("</b><pre>").append(
extraDescriptions.get(key)).append("</pre></p>");
}
sb.append("<HR size=\"1\" noshade>");
sb.append("</body></html>");
if (outputStream != null)
outputStream.write(sb.toString().getBytes());
// FIXME (SM) how can we send the error with the proper content type?
return "text/html";
}
/**
* Generate notification information in XML format.
*/
public static void notify(Notifying n, ContentHandler ch) throws SAXException {
final String PREFIX = Constants.ERROR_NAMESPACE_PREFIX;
final String URI = Constants.ERROR_NAMESPACE_URI;
// Start the document
ch.startDocument();
ch.startPrefixMapping(PREFIX, URI);
// Root element.
AttributesImpl atts = new AttributesImpl();
atts.addAttribute(URI, "type", PREFIX + ":type", "CDATA", n.getType());
atts.addAttribute(URI, "sender", PREFIX + ":sender", "CDATA", n.getSender());
ch.startElement(URI, "notify", PREFIX + ":notify", atts);
ch.startElement(URI, "title", PREFIX + ":title", new AttributesImpl());
ch.characters(n.getTitle().toCharArray(), 0, n.getTitle().length());
ch.endElement(URI, "title", PREFIX + ":title");
ch.startElement(URI, "source", PREFIX + ":source", new AttributesImpl());
ch.characters(n.getSource().toCharArray(), 0, n.getSource().length());
ch.endElement(URI, "source", PREFIX + ":source");
ch.startElement(URI, "message", PREFIX + ":message", new AttributesImpl());
if (n.getMessage() != null) {
ch.characters(n.getMessage().toCharArray(), 0, n.getMessage().length());
}
ch.endElement(URI, "message", PREFIX + ":message");
ch.startElement(URI, "description", PREFIX + ":description",
new AttributesImpl());
ch.characters(n.getDescription().toCharArray(), 0, n.getDescription().length());
ch.endElement(URI, "description", PREFIX + ":description");
Map extraDescriptions = n.getExtraDescriptions();
Iterator keyIter = extraDescriptions.keySet().iterator();
while (keyIter.hasNext()) {
String key = (String) keyIter.next();
atts = new AttributesImpl();
atts.addAttribute(URI, "description", PREFIX + ":description", "CDATA", key);
ch.startElement(URI, "extra", PREFIX + ":extra", atts);
ch.characters(extraDescriptions.get(key).toString().toCharArray(), 0,
(extraDescriptions.get(key).toString()).length());
ch.endElement(URI, "extra", PREFIX + ":extra");
}
// End root element.
ch.endElement(URI, "notify", PREFIX + ":notify");
// End the document.
ch.endPrefixMapping(PREFIX);
ch.endDocument();
}
}
1.1
xml-cocoon2/src/org/apache/cocoon/components/notification/Notifying.java
Index: Notifying.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.cocoon.components.notification;
import java.util.Map;
/**
* Interface for Objects that can notify something.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a>
* @created 24 August 2000
*/
public interface Notifying {
/**
* Proposed types of notifications
*/
public static final String UNKNOWN_NOTIFICATION = "unknown";
public static final String DEBUG_NOTIFICATION = "debug";
public static final String INFO_NOTIFICATION = "info" ;
public static final String WARN_NOTIFICATION = "warn" ;
public static final String ERROR_NOTIFICATION = "error";
public static final String FATAL_NOTIFICATION = "fatal";
/**
* Gets the Type of the Notifying object
*/
String getType();
/**
* Gets the Title of the Notifying object
*/
String getTitle();
/**
* Gets the Source of the Notifying object
*/
String getSource();
/**
* Gets the Sender of the Notifying object
*/
String getSender();
/**
* Gets the Message of the Notifying object
*/
String getMessage();
/**
* Gets the Description of the Notifying object
*/
String getDescription();
/**
* Gets the ExtraDescriptions of the Notifying object
*/
Map getExtraDescriptions();
}
1.1
xml-cocoon2/src/org/apache/cocoon/components/notification/NotifyingBuilder.java
Index: NotifyingBuilder.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.cocoon.components.notification;
import java.util.Map;
import org.apache.avalon.framework.component.Component;
/**
* Generates an Notifying representation of widely used objects.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a>
* @created 24 August 2000
*/
public interface NotifyingBuilder extends Component{
/**
* The role implemented by a <code>NotifyingBuilder</code>.
*/
String ROLE = "org.apache.cocoon.components.notification.NotifyingBuilder";
/** Builds a Notifying object (SimpleNotifyingObject in this case)
* that tries to explain what the Object o can reveal.
* @param sender who sent this Object.
* @param o the object to use when building the SimpleNotifyingObject
* @return the Notifying Object that was build
* @see org.apache.cocoon.components.notification.Notifying
*/
public Notifying build(Object sender, Object o);
/** Builds a Notifying object (SimpleNotifyingObject in this case)
* that explains a notification.
* @param sender who sent this Object.
* @param o the object to use when building the SimpleNotifyingObject
* @param type see the Notifying apidocs
* @param title see the Notifying apidocs
* @param source see the Notifying apidocs
* @param message see the Notifying apidocs
* @param description see the Notifying apidocs
* @param extra see the Notifying apidocs
* @return the Notifying Object that was build
* @see org.apache.cocoon.components.notification.Notifying
*/
public Notifying build(Object sender, Object o, String type, String title,
String source, String message, String description, Map extra);
}
1.1
xml-cocoon2/src/org/apache/cocoon/components/notification/NotifyingCascadingRuntimeException.java
Index: NotifyingCascadingRuntimeException.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.cocoon.components.notification;
import org.apache.avalon.framework.CascadingRuntimeException;
import java.util.Map;
import java.io.PrintStream;
import java.io.PrintWriter;
/**
* A CascadingRuntimeException that is also Notifying.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a>
* @created 7 December 2001
*/
public class NotifyingCascadingRuntimeException
extends CascadingRuntimeException
implements Notifying{
/**
* The Notifying Object used internally to keep Notifying fields
*/
Notifying n;
/**
* Construct a new <code>NotifyingCascadingRuntimeException</code> instance.
*/
public NotifyingCascadingRuntimeException(String message) {
super(message, null);
n = new DefaultNotifyingBuilder().build(this, message);
}
/**
* Creates a new <code>ProcessingException</code> instance.
*
* @param ex an <code>Exception</code> value
*/
public NotifyingCascadingRuntimeException(Exception ex) {
super(ex.getMessage(), ex);
n = new DefaultNotifyingBuilder().build(this, ex);
}
/**
* Construct a new <code>ProcessingException</code> that references
* a parent Exception.
*/
public NotifyingCascadingRuntimeException(String message, Throwable t) {
super(message, t);
n = new DefaultNotifyingBuilder().build(this, t);
}
/**
* Gets the Type attribute of the Notifying object
*/
public String getType() {
return n.getType();
}
/**
* Gets the Title attribute of the Notifying object
*/
public String getTitle() {
return n.getTitle();
}
/**
* Gets the Source attribute of the Notifying object
*/
public String getSource() {
return n.getSource();
}
/**
* Gets the Sender attribute of the Notifying object
*/
public String getSender() {
return n.getSender();
}
/**
* Gets the Message attribute of the Notifying object
*/
public String getMessage() {
return n.getMessage();
}
/**
* Gets the Description attribute of the Notifying object
*/
public String getDescription() {
return n.getDescription();
}
/**
* Gets the ExtraDescriptions attribute of the Notifying object
*/
public Map getExtraDescriptions() {
return n.getExtraDescriptions();
}
}
1.1
xml-cocoon2/src/org/apache/cocoon/components/notification/NotifyingObjects.java
Index: NotifyingObjects.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.cocoon.components.notification;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
/**
* Interface for a List of Objects that can notify something.
* NKB: FIXME The type checks are not complete.
* @author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a>
* @created 18 December 2001
*/
public class NotifyingObjects{
private ArrayList notifyingObjects;
public NotifyingObjects()
{
notifyingObjects = new ArrayList();
}
public synchronized void addNotifying(Notifying n)
{
notifyingObjects.add(n);
}
public synchronized Notifying getNotifying(int i)
{ //NKB cast is safe here
return (Notifying)notifyingObjects.get(i);
}
public synchronized Notifying getLastNotifying()
{ //NKB cast is safe here
return (Notifying)notifyingObjects.get(notifyingObjects.size()-1);
}
public Iterator iterator()
{
return notifyingObjects.iterator();
}
public int size()
{
return notifyingObjects.size();
}
}
1.1
xml-cocoon2/src/org/apache/cocoon/components/notification/SimpleNotifyingBean.java
Index: SimpleNotifyingBean.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.cocoon.components.notification;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Map;
import java.util.HashMap;
/**
* A simple bean implementation of Notifying.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a>
* @created 24 August 2000
*/
public class SimpleNotifyingBean implements Notifying {
/**
* The type of the notification. Examples can be "warning" or "error"
*/
private String type = "unknown";
/**
* The title of the notification.
*/
private String title = "";
/**
* The source that generates the notification.
*/
private String source = "";
/**
* The sender of the notification.
*/
private String sender = "";
/**
* The notification itself.
*/
private String message = "Message not known.";
/**
* A more detailed description of the notification.
*/
private String description = "No details available.";
/**
* A HashMap containing extra notifications
*/
private HashMap extraDescriptions = new HashMap();
public SimpleNotifyingBean(Object sender) {
this.sender = sender.getClass().getName();
setSource(this.getClass().getName());
setTitle("Generic notification");
}
/**
* Sets the Type of the SimpleNotifyingBean object
*
*@param type The new Type value
*/
public void setType(String type) {
this.type = type;
}
/**
* Sets the Title of the SimpleNotifyingBean object
*
*@param title The new Title value
*/
public void setTitle(String title) {
this.title = title;
}
/**
* Sets the Source of the SimpleNotifyingBean object
*
*@param source The new Source value
*/
public void setSource(String source) {
this.source = source;
}
/**
* Sets the Sender of the SimpleNotifyingBean object
*
*@param sender The new sender value
*/
private void setSender(Object sender) {
this.sender = sender.getClass().getName();
}
/**
* Sets the Sender of the SimpleNotifyingBean object
*
*@param sender The new sender value
*/
private void setSender(String sender) {
this.sender = sender;
}
/**
* Sets the Message of the SimpleNotifyingBean object
*
*@param message The new Message value
*/
public void setMessage(String message) {
this.message = message;
}
/**
* Sets the Description of the SimpleNotifyingBean object
*
*@param description The new Description value
*/
public void setDescription(String description) {
this.description = description;
}
/**
* Sets the ExtraDescriptions of the SimpleNotifyingBean object
*
*@param extraDescriptions The new ExtraDescriptions value
*/
public void addExtraDescription(String extraDescriptionDescription,
String extraDescription) {
this.extraDescriptions.put(extraDescriptionDescription, extraDescription);
}
/**
* replaces the ExtraDescriptions of the SimpleNotifyingBean object
*/
protected void replaceExtraDescriptions(Map extraDescriptions) {
this.extraDescriptions = new HashMap(extraDescriptions);
}
/**
* replaces the ExtraDescriptions of the SimpleNotifyingBean object
*/
protected void replaceExtraDescriptions(HashMap extraDescriptions) {
this.extraDescriptions = extraDescriptions;
}
/**
* Gets the Type of the SimpleNotifyingBean object
*/
public String getType() {
return type;
}
/**
* Gets the Title of the SimpleNotifyingBean object
*/
public String getTitle() {
return title;
}
/**
* Gets the Source of the SimpleNotifyingBean object
*/
public String getSource() {
return source;
}
/**
* Gets the Sender of the SimpleNotifyingBean object
*/
public String getSender() {
return sender;
}
/**
* Gets the Message of the SimpleNotifyingBean object
*/
public String getMessage() {
return message;
}
/**
* Gets the Description of the SimpleNotifyingBean object
*/
public String getDescription() {
return description;
}
/**
* Gets the ExtraDescriptions of the SimpleNotifyingBean object
*/
public Map getExtraDescriptions() {
return extraDescriptions;
}
}
1.19 +11 -9
xml-cocoon2/src/org/apache/cocoon/components/pipeline/AbstractEventPipeline.java
Index: AbstractEventPipeline.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/components/pipeline/AbstractEventPipeline.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- AbstractEventPipeline.java 10 Dec 2001 12:56:22 -0000 1.18
+++ AbstractEventPipeline.java 30 Dec 2001 21:50:46 -0000 1.19
@@ -17,7 +17,6 @@
import org.apache.cocoon.components.saxconnector.SAXConnector;
import org.apache.cocoon.environment.Environment;
import org.apache.cocoon.generation.Generator;
-import org.apache.cocoon.sitemap.ErrorNotifier;
import org.apache.cocoon.transformation.Transformer;
import org.apache.cocoon.xml.AbstractXMLProducer;
import org.apache.cocoon.xml.XMLConsumer;
@@ -31,8 +30,10 @@
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
* @author <a href="mailto:cziegeler@Carsten Ziegeler">Carsten Ziegeler</a>
- * @author <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a>
- * @version CVS $Revision: 1.18 $ $Date: 2001/12/10 12:56:22 $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a
+ * @author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Peter Royal</a>
+ * @version CVS $Revision: 1.19 $ $Date: 2001/12/30 21:50:46 $
*/
public abstract class AbstractEventPipeline
extends AbstractXMLProducer
@@ -69,14 +70,14 @@
this.newManager = manager;
}
+ /**
+ * @deprecated The NotifyingGenerator gets the Notificable from the objectModel
+ */
public void setGenerator (String role, String source, Parameters param,
Exception e)
throws Exception {
this.setGenerator (role, source, param);
- // FIXME(CZ) What can be done if this is not an ErrorNotifier?
- // (The sitemap uses this setGenerator() method only from inside
- // the error pipeline, when a ErrorNotifier is explicitly generated.)
- if (this.generator instanceof ErrorNotifier) {
- ((ErrorNotifier)this.generator).setException(e);
+ if (this.generator instanceof org.apache.cocoon.sitemap.ErrorNotifier) {
+
((org.apache.cocoon.sitemap.ErrorNotifier)this.generator).setThrowable(e);
}
}
@@ -85,7 +86,7 @@
if (this.generator != null) {
throw new ProcessingException ("Generator already set. You can only
select one Generator (" + role + ")");
}
- this.generatorSelector = (ComponentSelector)
this.newManager.lookup(Generator.ROLE + "Selector");
+ this.generatorSelector = (ComponentSelector)
this.newManager.lookup(Generator.ROLE + "Selector");
this.generator = (Generator) this.generatorSelector.select(role);
this.generatorSource = source;
this.generatorParam = param;
@@ -289,3 +290,4 @@
// Nothing here
}
}
+
1.59 +30 -22 xml-cocoon2/src/org/apache/cocoon/servlet/CocoonServlet.java
Index: CocoonServlet.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/servlet/CocoonServlet.java,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -r1.58 -r1.59
--- CocoonServlet.java 28 Dec 2001 17:59:35 -0000 1.58
+++ CocoonServlet.java 30 Dec 2001 21:50:46 -0000 1.59
@@ -16,8 +16,11 @@
import org.apache.avalon.framework.context.DefaultContext;
import org.apache.avalon.framework.logger.Loggable;
import org.apache.cocoon.Constants;
-import org.apache.cocoon.Notification;
-import org.apache.cocoon.Notifier;
+import org.apache.cocoon.components.notification.Notifying;
+import org.apache.cocoon.components.notification.SimpleNotifyingBean;
+import org.apache.cocoon.components.notification.NotifyingBuilder;
+import org.apache.cocoon.components.notification.DefaultNotifyingBuilder;
+import org.apache.cocoon.components.notification.Notifier;
import org.apache.cocoon.ResourceNotFoundException;
import org.apache.cocoon.ConnectionResetException;
import org.apache.cocoon.Cocoon;
@@ -50,6 +53,7 @@
import java.lang.reflect.Constructor;
import java.net.URL;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.StringTokenizer;
/**
@@ -58,13 +62,12 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a>
* (Apache Software Foundation, Exoffice Technologies)
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
- * @author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a> Aisa
+ * @author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Leo Sutic</a>
- * @version CVS $Revision: 1.58 $ $Date: 2001/12/28 17:59:35 $
+ * @version CVS $Revision: 1.59 $ $Date: 2001/12/30 21:50:46 $
*/
-
public class CocoonServlet extends HttpServlet {
protected Logger log;
@@ -730,14 +733,14 @@
if (this.cocoon == null) {
res.setStatus(res.SC_INTERNAL_SERVER_ERROR);
- Notification n = new Notification(this, this.exception);
- n.setType("internal-servlet-error");
+ SimpleNotifyingBean n= new SimpleNotifyingBean(this);
+ n.setType("fatal");
n.setTitle("Internal servlet error");
n.setSource("Cocoon servlet");
- n.setMessage("Internal servlet error");
- n.setDescription("Cocoon was not initialized.");
+ n.setMessage("Cocoon was not initialized.");
+ n.setDescription("Cocoon was not initialized. Cannot process request.");
n.addExtraDescription("request-uri", request.getRequestURI());
- res.setContentType(Notifier.notify(n, res.getOutputStream()));;
+ res.setContentType(Notifier.notify(n, res.getOutputStream()));
return;
}
@@ -792,14 +795,15 @@
if (this.cocoon.process(env)) {
contentType = env.getContentType();
} else {
+ // Should not get here!
// means SC_NOT_FOUND
res.sendError(res.SC_NOT_FOUND);
- Notification n = new Notification(this);
- n.setType("resource-not-found");
+ SimpleNotifyingBean n = new SimpleNotifyingBean(this);
+ n.setType("error");
n.setTitle("Resource not found");
n.setSource("Cocoon servlet");
- n.setMessage("Resource not found");
+ n.setMessage("The requested resource not found.");
n.setDescription("The requested URI \""
+ request.getRequestURI()
+ "\" was not found.");
@@ -815,7 +819,8 @@
}
res.sendError(res.SC_NOT_FOUND);
- Notification n = new Notification(this);
+
+ SimpleNotifyingBean n = new SimpleNotifyingBean(this);
n.setType("resource-not-found");
n.setTitle("Resource not found");
n.setSource("Cocoon servlet");
@@ -828,13 +833,14 @@
// send the notification but don't include it in the output stream
// as the status SC_NOT_FOUND is enough
res.setContentType(Notifier.notify(n, (OutputStream)null));
+
} catch (ConnectionResetException cre) {
if (log.isWarnEnabled()) {
log.warn("The connection was reset", cre);
}
- Notification n = new Notification(this);
- n.setType("resource-not-found");
+ SimpleNotifyingBean n = new SimpleNotifyingBean(this);
+ n.setType("error");
n.setTitle("Resource not found");
n.setSource("Cocoon servlet");
n.setMessage("Resource not found");
@@ -851,12 +857,14 @@
log.error("Problem with servlet", e);
}
//res.setStatus(res.SC_INTERNAL_SERVER_ERROR);
- Notification n = new Notification(this, e);
- n.setType("internal-server-error");
- n.setTitle("Internal server error");
- n.setSource("Cocoon servlet");
- n.addExtraDescription("request-uri", request.getRequestURI());
- n.addExtraDescription("path-info", uri);
+
+ HashMap extraDescriptions = new HashMap(2);
+ extraDescriptions.put("request-uri", request.getRequestURI());
+ extraDescriptions.put("path-info", uri);
+
+ Notifying n=new DefaultNotifyingBuilder().build(
+ this, e, "fatal","Internal server error","Cocoon
servlet",null,null,extraDescriptions);
+
res.setContentType(contentType = Notifier.notify(n,
res.getOutputStream()));
}
1.6 +41 -44 xml-cocoon2/src/org/apache/cocoon/sitemap/ErrorNotifier.java
Index: ErrorNotifier.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/sitemap/ErrorNotifier.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ErrorNotifier.java 11 Oct 2001 07:28:23 -0000 1.5
+++ ErrorNotifier.java 30 Dec 2001 21:50:46 -0000 1.6
@@ -8,62 +8,59 @@
package org.apache.cocoon.sitemap;
+import java.util.Map;
+import java.io.IOException;
+
import org.apache.avalon.excalibur.pool.Recyclable;
-import org.apache.cocoon.Notification;
-import org.apache.cocoon.Notifier;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.components.notification.Notifying;
+import org.apache.cocoon.components.notification.DefaultNotifyingBuilder;
import org.apache.cocoon.generation.ComposerGenerator;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.Constants;
+
import org.xml.sax.SAXException;
/**
* Generates an XML representation of the current notification.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a> Aisa
+ * @deprecated Now using NotifyingGenerator in sitemap
+ * @author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
* @created 31 July 2000
- * @version CVS $Revision: 1.5 $ $Date: 2001/10/11 07:28:23 $
+ * @version CVS $Revision: 1.6 $ $Date: 2001/12/30 21:50:46 $
*/
-public class ErrorNotifier extends ComposerGenerator implements Recyclable {
- /**
- * The <code>Notification</code> to report.
- */
- private Notification notification = null;
-
- /**
- * Set the Exception to report.
- *
- * @param exception The Exception to report
- */
- public void setException(Throwable throwable) {
- notification = new Notification(this, throwable);
- notification.setTitle("Error creating the resource");
- }
+public class ErrorNotifier extends NotifyingGenerator {
+ /**
+ * The <code>Notification</code> to report.
+ */
+ private Notifying notification = null;
- /**
- * Set the Notification to report.
- *
- * @param exception The Exception to report
- */
- public void setNotification(Object o) {
- notification = new Notification(this, o);
- notification.setTitle("Error creating the resource");
+ public void setup(SourceResolver resolver, Map objectModel, String src,
+ Parameters par) throws ProcessingException, SAXException, IOException {
+ try
+ {
+ super.setup(resolver, objectModel, src, par);
}
-
- /**
- * Generate the notification information in XML format.
- *
- * @exception SAXException Description of problem there is creating the
output SAX events.
- * @throws SAXException when there is a problem creating the
- * output SAX events.
- */
- public void generate() throws SAXException {
- Notifier.notify(notification, this.contentHandler);
+ catch(ProcessingException pe)
+ {
+ //do nothing, thrown by superclass that didn't find the object to notify
+ //it will be set in setThrowable in this class
}
+ }
- /**
- * Recycle
- */
- public void recycle() {
- super.recycle();
- this.notification = null;
+ /**
+ * Set the Notification to report.
+ * @deprecated Now it gets the Exception from the ObjectModel
+ * @param exception The Exception to report
+ */
+ public void setThrowable(Throwable throwable) {
+ if (throwable instanceof Notifying) {
+ this.notification = (Notifying) throwable;
+ } else {
+ notification = new DefaultNotifyingBuilder().build("@deprecated method
setThrowable() in ErrorNotifier", throwable);
}
+ }
+
}
+
1.7 +10 -2 xml-cocoon2/src/org/apache/cocoon/sitemap/sitemap.roles
Index: sitemap.roles
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/sitemap/sitemap.roles,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- sitemap.roles 10 Dec 2001 12:56:23 -0000 1.6
+++ sitemap.roles 30 Dec 2001 21:50:46 -0000 1.7
@@ -28,8 +28,11 @@
<role name="org.apache.cocoon.generation.GeneratorSelector"
shorthand="generator"
- default-class="org.apache.cocoon.sitemap.SitemapComponentSelector"/>
-
+ default-class="org.apache.cocoon.sitemap.SitemapComponentSelector">
+ <!--NKB doesnt load it - should be used instead of old error-notifier
+ <hint shorthand="!notifying-generator!"
class="org.apache.cocoon.sitemap.NotifyingGenerator"/>-->
+ </role>
+
<role name="org.apache.cocoon.transformation.TransformerSelector"
shorthand="transformer"
default-class="org.apache.cocoon.sitemap.SitemapComponentSelector"/>
@@ -41,4 +44,9 @@
<role name="org.apache.cocoon.reading.ReaderSelector"
shorthand="reader"
default-class="org.apache.cocoon.sitemap.SitemapComponentSelector"/>
+
+ <role name="org.apache.cocoon.components.notification.NotifyingBuilder"
+ shorthand="notifying-builder"
+
default-class="org.apache.cocoon.components.notification.DefaultNotifyingBuilder"/>
+
</role-list>
1.73 +1 -1 xml-cocoon2/webapp/sitemap.xmap
Index: sitemap.xmap
===================================================================
RCS file: /home/cvs/xml-cocoon2/webapp/sitemap.xmap,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -r1.72 -r1.73
--- sitemap.xmap 23 Dec 2001 09:48:40 -0000 1.72
+++ sitemap.xmap 30 Dec 2001 21:50:46 -0000 1.73
@@ -1096,7 +1096,7 @@
</map:match>
<map:handle-errors>
- <map:transform src="stylesheets/system/error2html.xsl"/>
+ <map:transform src="context://stylesheets/system/error2html.xsl"/>
<map:serialize status-code="500"/>
</map:handle-errors>
1.8 +4 -2 xml-cocoon2/webapp/protected/sitemap.xmap
Index: sitemap.xmap
===================================================================
RCS file: /home/cvs/xml-cocoon2/webapp/protected/sitemap.xmap,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- sitemap.xmap 22 Oct 2001 10:17:47 -0000 1.7
+++ sitemap.xmap 30 Dec 2001 21:50:47 -0000 1.8
@@ -94,11 +94,13 @@
</map:act>
</map:match>
+ <!-- Let parent sitemap treat it
<map:handle-errors>
- <map:transform src="stylesheets/system/error2html.xsl"/>
+ <map:transform src="context://stylesheets/system/error2html.xsl"/>
<map:serialize status-code="500"/>
</map:handle-errors>
-
+ -->
+
</map:pipeline>
</map:pipelines>
1.5 +1 -1 xml-cocoon2/webapp/stylesheets/simple-samples2html.xsl
Index: simple-samples2html.xsl
===================================================================
RCS file: /home/cvs/xml-cocoon2/webapp/stylesheets/simple-samples2html.xsl,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- simple-samples2html.xsl 14 Dec 2001 01:30:36 -0000 1.4
+++ simple-samples2html.xsl 30 Dec 2001 21:50:47 -0000 1.5
@@ -32,7 +32,7 @@
<table width="100%">
<tr>
- <td valign="top">
+ <td width="50%" valign="top">
<xsl:for-each select="group">
<xsl:variable name="group-position" select="position()"/>
<xsl:variable name="current-sample" select="1 + count(../group[position()
<= $group-position]/sample)"/>
1.6 +1 -1 xml-cocoon2/webapp/sub/stylesheets/error2html.xsl
Index: error2html.xsl
===================================================================
RCS file: /home/cvs/xml-cocoon2/webapp/sub/stylesheets/error2html.xsl,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- error2html.xsl 20 Dec 2001 15:14:34 -0000 1.5
+++ error2html.xsl 30 Dec 2001 21:50:47 -0000 1.6
@@ -22,7 +22,7 @@
<xsl:value-of select="translate(error:notify/error:extra[2],' ',' ')"/>
</pre>
<font face="Verdana" size="-2">
- Brought to you by <a href="http://xml.apache.org/cocoon/">Apache Cocoon</a>
in no time!
+ This special error layout is specified in the sub sitemap.
</font>
</body>
</html>
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]