You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by sy...@apache.org on 2005/09/13 21:15:14 UTC
svn commit: r280628 - in /cocoon/branches/BRANCH_2_1_X/src:
blocks/forms/java/org/apache/cocoon/forms/formmodel/
blocks/forms/java/org/apache/cocoon/forms/generation/
java/org/apache/cocoon/ java/org/apache/cocoon/components/flow/javascript/
java/org/a...
Author: sylvain
Date: Tue Sep 13 12:14:35 2005
New Revision: 280628
URL: http://svn.apache.org/viewcvs?rev=280628&view=rev
Log:
Refactor location stuff, allow for extensible location finders
Added:
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocationUtils.java (with props)
Removed:
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/ExceptionUtils.java
Modified:
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Widget.java
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/WidgetDefinition.java
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/WidgetDefinitionList.java
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java
cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/generation/jx-macros.xml
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/Cocoon.java
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/ProcessingException.java
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/LocationTrackingDebugger.java
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/fom_system.js
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/notification/DefaultNotifyingBuilder.java
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/DefaultTreeBuilder.java
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/generation/ExceptionGenerator.java
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/generation/JXTemplateGenerator.java
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/selection/ExceptionSelector.java
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/transformation/TraxTransformer.java
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatedException.java
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatedRuntimeException.java
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocationAttributes.java
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocationImpl.java
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/log/CocoonLogFormatter.java
cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/util/location/LocationTestCase.java
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java?rev=280628&r1=280627&r2=280628&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java Tue Sep 13 12:14:35 2005
@@ -26,6 +26,7 @@
import org.apache.cocoon.forms.event.CreateEvent;
import org.apache.cocoon.forms.event.WidgetEvent;
import org.apache.cocoon.forms.validation.WidgetValidator;
+import org.apache.cocoon.util.location.Location;
import org.apache.cocoon.xml.AttributesImpl;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
@@ -109,7 +110,7 @@
* @return the location-information (file, line and column) where this widget was
* configured.
*/
- public String getLocation() {
+ public Location getLocation() {
return getDefinition().getLocation();
}
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java?rev=280628&r1=280627&r2=280628&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java Tue Sep 13 12:14:35 2005
@@ -25,6 +25,7 @@
import org.apache.cocoon.forms.event.CreateListener;
import org.apache.cocoon.forms.event.WidgetEventMulticaster;
import org.apache.cocoon.forms.validation.WidgetValidator;
+import org.apache.cocoon.util.location.Location;
import org.apache.cocoon.xml.XMLUtils;
import org.apache.excalibur.xml.sax.XMLizable;
import org.xml.sax.ContentHandler;
@@ -40,7 +41,7 @@
protected WidgetDefinition parent;
//TODO consider final on these
- private String location = null;
+ private Location location = Location.UNKNOWN;
private String id;
/** the definition is mutable when being built */
private boolean mutable = true;
@@ -105,12 +106,12 @@
this.state = state;
}
- protected void setLocation(String location) {
+ protected void setLocation(Location location) {
checkMutable();
this.location = location;
}
- public String getLocation() {
+ public Location getLocation() {
return location;
}
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java?rev=280628&r1=280627&r2=280628&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java Tue Sep 13 12:14:35 2005
@@ -72,7 +72,7 @@
private void setCommonProperties(Element widgetElement, AbstractWidgetDefinition widgetDefinition) throws Exception {
// location
- widgetDefinition.setLocation(DomHelper.getLocation(widgetElement));
+ widgetDefinition.setLocation(DomHelper.getLocationObject(widgetElement));
// id
if (widgetDefinition instanceof FormDefinition) {
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java?rev=280628&r1=280627&r2=280628&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java Tue Sep 13 12:14:35 2005
@@ -25,6 +25,7 @@
import org.apache.cocoon.forms.event.WidgetEvent;
import org.apache.cocoon.forms.validation.ValidationError;
import org.apache.cocoon.forms.validation.ValidationErrorAware;
+import org.apache.cocoon.util.location.LocatedRuntimeException;
import org.apache.cocoon.xml.AttributesImpl;
import org.apache.cocoon.xml.XMLUtils;
import org.xml.sax.ContentHandler;
@@ -339,8 +340,8 @@
public void generateWidgetLabel(String widgetId, ContentHandler contentHandler) throws SAXException {
WidgetDefinition widgetDefinition = definition.getWidgetDefinition(widgetId);
if (widgetDefinition == null)
- throw new SAXException("Repeater \"" + getRequestParameterName() + "\" at " + this.getLocation()
- + " contains no widget with id \"" + widgetId + "\".");
+ throw new LocatedRuntimeException("Repeater \"" + getRequestParameterName()
+ + " contains no widget with id \"" + widgetId + "\".", this.getLocation());
widgetDefinition.generateLabel(contentHandler);
}
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Widget.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Widget.java?rev=280628&r1=280627&r2=280628&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Widget.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Widget.java Tue Sep 13 12:14:35 2005
@@ -18,6 +18,8 @@
import org.apache.cocoon.forms.FormContext;
import org.apache.cocoon.forms.validation.WidgetValidator;
import org.apache.cocoon.forms.event.WidgetEvent;
+import org.apache.cocoon.util.location.Locatable;
+import org.apache.cocoon.util.location.Location;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
@@ -51,7 +53,7 @@
*
* @version $Id$
*/
-public interface Widget {
+public interface Widget extends Locatable {
/**
* Widget-Separator used in path-like notations
@@ -69,7 +71,7 @@
/**
* @return the source location of this widget.
*/
- String getLocation();
+ Location getLocation();
/**
* @return the id of this widget. This should never be <code>null</code>
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/WidgetDefinition.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/WidgetDefinition.java?rev=280628&r1=280627&r2=280628&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/WidgetDefinition.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/WidgetDefinition.java Tue Sep 13 12:14:35 2005
@@ -15,6 +15,8 @@
*/
package org.apache.cocoon.forms.formmodel;
+import org.apache.cocoon.util.location.Locatable;
+import org.apache.cocoon.util.location.Location;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
@@ -26,7 +28,7 @@
*
* @version $Id$
*/
-public interface WidgetDefinition {
+public interface WidgetDefinition extends Locatable {
/**
* Gets the {@link FormDefinition}.
@@ -41,7 +43,7 @@
/**
* Gets source location of this widget definition.
*/
- String getLocation();
+ Location getLocation();
/**
* Gets id of this widget definition.
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/WidgetDefinitionList.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/WidgetDefinitionList.java?rev=280628&r1=280627&r2=280628&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/WidgetDefinitionList.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/WidgetDefinitionList.java Tue Sep 13 12:14:35 2005
@@ -22,6 +22,8 @@
import java.util.ListIterator;
import java.util.Map;
+import org.apache.cocoon.util.location.Location;
+
// TODO: Refine and i18n the exception messages.
/**
* Helper class for the Definition implementation of widgets containing
@@ -49,9 +51,9 @@
// Do not add NewDefinition id's hash.
if (!(widgetDefinition instanceof NewDefinition)) {
if (widgetDefinitionsById.containsKey(id)) {
- String duplicateLocation = widgetDefinition.getLocation();
- String containerLocation = containerDefinition.getLocation();
- String firstLocation = getWidgetDefinition(id).getLocation();
+ Location duplicateLocation = widgetDefinition.getLocation();
+ Location containerLocation = containerDefinition.getLocation();
+ Location firstLocation = getWidgetDefinition(id).getLocation();
throw new DuplicateIdException(
"Duplicate widget id \"" + id + "\" detected at " + duplicateLocation + ".\n" +
"Container widget \"" + containerDefinition.getId() + "\" at " + containerLocation + "\n" +
@@ -109,7 +111,7 @@
if (widgetDefinition instanceof UnionDefinition) break;
if (widgetDefinition instanceof RepeaterDefinition) break;
if (widgetDefinition == containerDefinition) {
- String location = containerDefinition.getLocation();
+ Location location = containerDefinition.getLocation();
if (parent instanceof FormDefinition) {
throw new Exception("Container: Non-terminating recursion detected in form definition (" + location + ")");
}
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java?rev=280628&r1=280627&r2=280628&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java Tue Sep 13 12:14:35 2005
@@ -182,7 +182,14 @@
}
public void generateRepeaterWidgetLabel(Widget widget, String id, String widgetId) throws SAXException {
- getRepeater(widget, id).generateWidgetLabel(widgetId, this.cocoonConsumer);
+ // a <fd:repeater-widget-label> can be placed either within a <ft:repeater> or outside a <ft:repeater-widget>
+ Repeater repeater;
+ if (widget instanceof Repeater) {
+ repeater = (Repeater)widget;
+ } else {
+ repeater = getRepeater(widget, id);
+ }
+ repeater.generateWidgetLabel(widgetId, this.cocoonConsumer);
}
public void generateRepeaterSize(Widget widget, String id) throws SAXException {
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/generation/jx-macros.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/generation/jx-macros.xml?rev=280628&r1=280627&r2=280628&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/generation/jx-macros.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/generation/jx-macros.xml Tue Sep 13 12:14:35 2005
@@ -216,7 +216,8 @@
<jx:macro name="repeater" targetNamespace="http://apache.org/cocoon/forms/1.0#template">
<jx:parameter name="id"/>
- <jx:set var="repeater" value="${cformsHelper.getWidget(widget, id)}"/>
+ <jx:set var="widget" value="${cformsHelper.getWidget(widget, id)}"/>
+ <jx:set var="repeater" value="${widget}"/>
<jx:if test="${cformsHelper.isVisible(widget)}">
<jx:choose>
<jx:when test="${cformsHelper.isModified(repeater)}">
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/Cocoon.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/Cocoon.java?rev=280628&r1=280627&r2=280628&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/Cocoon.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/Cocoon.java Tue Sep 13 12:14:35 2005
@@ -49,6 +49,9 @@
import org.apache.cocoon.environment.Session;
import org.apache.cocoon.util.ClassUtils;
import org.apache.cocoon.util.Deprecation;
+import org.apache.cocoon.util.location.Location;
+import org.apache.cocoon.util.location.LocationImpl;
+import org.apache.cocoon.util.location.LocationUtils;
import org.apache.commons.lang.SystemUtils;
import org.apache.excalibur.instrument.InstrumentManageable;
@@ -87,6 +90,55 @@
Contextualizable,
Composable,
InstrumentManageable {
+
+ // Register the location finder for Avalon configuration objects and exceptions
+ static {
+ LocationUtils.addFinder(new LocationUtils.LocationFinder() {
+
+ public Location getLocation(Object obj, String description) {
+ if (obj instanceof Configuration) {
+ Configuration config = (Configuration)obj;
+ String locString = config.getLocation();
+ Location result = LocationUtils.parse(locString);
+ if (LocationUtils.isKnown(result)) {
+ // Add description
+ StringBuffer desc = new StringBuffer().append('<');
+ // Unfortunately Configuration.getPrefix() is not public
+ try {
+ if (config.getNamespace().startsWith("http://apache.org/cocoon/sitemap/")) {
+ desc.append("map:");
+ }
+ } catch (ConfigurationException e) {
+ // no namespace: ignore
+ }
+ desc.append(config.getName()).append('>');
+ return new LocationImpl(desc.toString(), result);
+ } else {
+ return result;
+ }
+ }
+
+ if (obj instanceof Exception) {
+ // Many exceptions in Cocoon have a message like "blah blah at file://foo/bar.xml:12:1"
+ String msg = ((Exception)obj).getMessage();
+ if (msg == null) return null;
+
+ int pos = msg.lastIndexOf(" at ");
+ if (pos != -1) {
+ return LocationUtils.parse(msg.substring(pos + 4));
+ } else {
+ // Will try other finders
+ return null;
+ }
+ }
+
+ // Try next finders.
+ return null;
+ }
+ });
+
+ }
+
static Cocoon instance;
/** The root Cocoon logger */
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/ProcessingException.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/ProcessingException.java?rev=280628&r1=280627&r2=280628&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/ProcessingException.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/ProcessingException.java Tue Sep 13 12:14:35 2005
@@ -56,11 +56,21 @@
super(message, t);
}
+ /**
+ * Construct a new <code>ProcessingException</code> that has an associated location.
+ */
public ProcessingException(String message, Location location) {
super(message, location);
}
- public ProcessingException(String message, Throwable t, Location location) {
+ /**
+ * Construct a new <code>ProcessingException</code> that has a parent exception
+ * and an associated location.
+ * <p>
+ * This constructor is protected to enforce the use of {@link #throwLocated(String, Throwable, Location)}
+ * which limits exception nesting as far as possible.
+ */
+ protected ProcessingException(String message, Throwable t, Location location) {
super(message, t, location);
}
@@ -146,73 +156,4 @@
throw (ProcessingException)multiloc;
}
}
-
-
-// public String toString() {
-// StringBuffer s = new StringBuffer();
-// s.append(super.toString());
-// final Throwable t = getCause();
-// if(t!=null) {
-// s.append(": ");
-// // be more verbose try to get location info
-// s.append( extraInfo(t) );
-// s.append(t.toString());
-// }
-// return s.toString();
-// }
-//
-// /**
-// * Examine Throwable and try to figure out location information.
-// * <p>
-// * At the moment only SAXParseException, and TransformerException
-// * are considered.
-// * </p>
-// *
-// * @return String containing location information of the format
-// * <code>{file-name}:{line}:{column}:</code>, if no location info is
-// * available return empty string
-// */
-// private String extraInfo( Throwable t ) {
-// StringBuffer sb = new StringBuffer();
-// if (t instanceof SAXParseException) {
-// SAXParseException spe = (SAXParseException)t;
-// sb.append( String.valueOf(spe.getSystemId()));
-// sb.append( ":" );
-// sb.append( String.valueOf(spe.getLineNumber()));
-// sb.append( ":" );
-// sb.append( String.valueOf(spe.getColumnNumber()));
-// sb.append( ":" );
-// } else if (t instanceof TransformerException) {
-// TransformerException transformerException = (TransformerException) t;
-// SourceLocator sourceLocator = transformerException.getLocator();
-//
-// if( null != sourceLocator ) {
-// sb.append( String.valueOf(sourceLocator.getSystemId()));
-// sb.append( ":" );
-// sb.append( String.valueOf(sourceLocator.getLineNumber()));
-// sb.append( ":" );
-// sb.append( String.valueOf(sourceLocator.getColumnNumber()));
-// sb.append( ":" );
-// }
-// }
-// return sb.toString();
-// }
-//
-// public void printStackTrace() {
-// super.printStackTrace();
-// if(getCause()!=null)
-// getCause().printStackTrace();
-// }
-//
-// public void printStackTrace( PrintStream s ) {
-// super.printStackTrace(s);
-// if(getCause()!=null)
-// getCause().printStackTrace(s);
-// }
-//
-// public void printStackTrace( PrintWriter s ) {
-// super.printStackTrace(s);
-// if(getCause()!=null)
-// getCause().printStackTrace(s);
-// }
}
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/LocationTrackingDebugger.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/LocationTrackingDebugger.java?rev=280628&r1=280627&r2=280628&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/LocationTrackingDebugger.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/LocationTrackingDebugger.java Tue Sep 13 12:14:35 2005
@@ -19,10 +19,13 @@
import java.util.List;
import org.apache.cocoon.ProcessingException;
-import org.apache.cocoon.util.ExceptionUtils;
import org.apache.cocoon.util.location.Location;
import org.apache.cocoon.util.location.LocationImpl;
+import org.apache.cocoon.util.location.LocationUtils;
+import org.apache.commons.lang.exception.ExceptionUtils;
import org.mozilla.javascript.Context;
+import org.mozilla.javascript.EcmaError;
+import org.mozilla.javascript.JavaScriptException;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.debug.DebugFrame;
import org.mozilla.javascript.debug.DebuggableScript;
@@ -40,6 +43,34 @@
* @version $Id$
*/
public class LocationTrackingDebugger implements Debugger {
+
+ static {
+ // Register what's needed to analyze exceptions produced by Rhino
+ ExceptionUtils.addCauseMethodName("getWrappedException");
+ LocationUtils.addFinder(new LocationUtils.LocationFinder() {
+
+ public Location getLocation(Object obj, String description) {
+ if (obj instanceof EcmaError) {
+ EcmaError ex = (EcmaError)obj;
+ if (ex.getSourceName() != null) {
+ return new LocationImpl(ex.getName(), ex.getSourceName(), ex.getLineNumber(), ex.getColumnNumber());
+ } else {
+ return Location.UNKNOWN;
+ }
+
+ } else if (obj instanceof JavaScriptException) {
+ JavaScriptException ex = (JavaScriptException)obj;
+ if (ex.sourceName() != null) {
+ return new LocationImpl(description, ex.sourceName(), ex.lineNumber(), -1);
+ } else {
+ return Location.UNKNOWN;
+ }
+ }
+
+ return null;
+ }
+ });
+ }
private List locations;
private Throwable throwable;
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/fom_system.js
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/fom_system.js?rev=280628&r1=280627&r2=280628&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/fom_system.js (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/javascript/fom/fom_system.js Tue Sep 13 12:14:35 2005
@@ -42,7 +42,7 @@
* Exit the current flowscript invocation.
* <p>
* There are some flowscript use cases where we want to stop the current
- * flowscript without creating a continuation, as we don't want to the user
+ * flowscript without creating a continuation, as we don't want the user
* to go back to the script.
* <p>
* An example is a "login" function where the caller function expects this
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/notification/DefaultNotifyingBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/notification/DefaultNotifyingBuilder.java?rev=280628&r1=280627&r2=280628&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/notification/DefaultNotifyingBuilder.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/notification/DefaultNotifyingBuilder.java Tue Sep 13 12:14:35 2005
@@ -17,8 +17,8 @@
import org.apache.avalon.framework.component.Component;
-import org.apache.cocoon.util.ExceptionUtils;
import org.apache.commons.lang.SystemUtils;
+import org.apache.commons.lang.exception.ExceptionUtils;
import org.xml.sax.SAXParseException;
import javax.xml.transform.SourceLocator;
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java?rev=280628&r1=280627&r2=280628&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java Tue Sep 13 12:14:35 2005
@@ -228,12 +228,12 @@
try {
this.generatorSelector = (ComponentSelector) this.newManager.lookup(Generator.ROLE + "Selector");
} catch (ComponentException ce) {
- throw new ProcessingException("Lookup of generator selector failed", ce, getLocation(param));
+ throw ProcessingException.throwLocated("Lookup of generator selector failed", ce, getLocation(param));
}
try {
this.generator = (Generator) this.generatorSelector.select(role);
} catch (ComponentException ce) {
- throw new ProcessingException("Lookup of generator '" + role + "' failed", ce, getLocation(param));
+ throw ProcessingException.throwLocated("Lookup of generator '" + role + "' failed", ce, getLocation(param));
}
this.generatorSource = source;
this.generatorParam = param;
@@ -266,13 +266,13 @@
try {
selector = (ComponentSelector) this.newManager.lookup(Transformer.ROLE + "Selector");
} catch (ComponentException ce) {
- throw new ProcessingException("Lookup of transformer selector failed", ce, getLocation(param));
+ throw ProcessingException.throwLocated("Lookup of transformer selector failed", ce, getLocation(param));
}
try {
this.transformers.add(selector.select(role));
this.transformerSelectors.add(selector);
} catch (ComponentException ce) {
- throw new ProcessingException("Lookup of transformer '"+role+"' failed", ce, getLocation(param));
+ throw ProcessingException.throwLocated("Lookup of transformer '"+role+"' failed", ce, getLocation(param));
}
this.transformerSources.add(source);
this.transformerParams.add(param);
@@ -302,12 +302,12 @@
try {
this.serializerSelector = (OutputComponentSelector) this.newManager.lookup(Serializer.ROLE + "Selector");
} catch (ComponentException ce) {
- throw new ProcessingException("Lookup of serializer selector failed", ce, getLocation(param));
+ throw ProcessingException.throwLocated("Lookup of serializer selector failed", ce, getLocation(param));
}
try {
this.serializer = (Serializer)serializerSelector.select(role);
} catch (ComponentException ce) {
- throw new ProcessingException("Lookup of serializer '" + role + "' failed", ce, getLocation(param));
+ throw ProcessingException.throwLocated("Lookup of serializer '" + role + "' failed", ce, getLocation(param));
}
this.serializerSource = source;
this.serializerParam = param;
@@ -336,12 +336,12 @@
try {
this.readerSelector = (OutputComponentSelector) this.newManager.lookup(Reader.ROLE + "Selector");
} catch (ComponentException ce) {
- throw new ProcessingException("Lookup of reader selector failed", ce, getLocation(param));
+ throw ProcessingException.throwLocated("Lookup of reader selector failed", ce, getLocation(param));
}
try {
this.reader = (Reader)readerSelector.select(role);
} catch (ComponentException ce) {
- throw new ProcessingException("Lookup of reader '"+role+"' failed", ce, getLocation(param));
+ throw ProcessingException.throwLocated("Lookup of reader '"+role+"' failed", ce, getLocation(param));
}
this.readerSource = source;
this.readerParam = param;
@@ -424,7 +424,7 @@
// Connect next component.
producer.setConsumer(consumer);
}
-
+
/**
* Connect the XML pipeline.
*/
@@ -937,7 +937,7 @@
// Exception comes up from a deeper pipeline
throw (ConnectionResetException)e;
}
-
+
// Not a connection reset: add all location information
if (this.reader == null) {
// Add all locations in reverse order
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/DefaultTreeBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/DefaultTreeBuilder.java?rev=280628&r1=280627&r2=280628&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/DefaultTreeBuilder.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/DefaultTreeBuilder.java Tue Sep 13 12:14:35 2005
@@ -44,6 +44,7 @@
import org.apache.cocoon.sitemap.SitemapParameters;
import org.apache.cocoon.util.location.Location;
import org.apache.cocoon.util.location.LocationImpl;
+import org.apache.cocoon.util.location.LocationUtils;
import org.apache.excalibur.source.Source;
import java.util.ArrayList;
@@ -493,7 +494,7 @@
}
desc.append('>');
- Location rawLoc = LocationImpl.get(config);
+ Location rawLoc = LocationUtils.getLocation(config, null);
return new LocationImpl(desc.toString(), rawLoc.getURI(), rawLoc.getLineNumber(), rawLoc.getColumnNumber());
}
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/generation/ExceptionGenerator.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/generation/ExceptionGenerator.java?rev=280628&r1=280627&r2=280628&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/generation/ExceptionGenerator.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/generation/ExceptionGenerator.java Tue Sep 13 12:14:35 2005
@@ -23,12 +23,13 @@
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.SourceResolver;
-import org.apache.cocoon.util.ExceptionUtils;
import org.apache.cocoon.util.location.LocatableException;
import org.apache.cocoon.util.location.Location;
+import org.apache.cocoon.util.location.LocationUtils;
import org.apache.cocoon.util.location.MultiLocatable;
import org.apache.cocoon.xml.AttributesImpl;
import org.apache.commons.lang.SystemUtils;
+import org.apache.commons.lang.exception.ExceptionUtils;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
@@ -72,8 +73,8 @@
handler.startElement(EXCEPTION_NS, "exception-report", "ex:exception-report", attr);
// Root exception location
- Location loc = ExceptionUtils.getLocation(root);
- if (loc != null) {
+ Location loc = LocationUtils.getLocation(root);
+ if (LocationUtils.isKnown(loc)) {
attr.clear();
dumpLocation(loc, attr, handler);
}
@@ -87,8 +88,8 @@
handler.startElement(EXCEPTION_NS, "cocoon-stacktrace", "ex:cocoon-stacktrace", attr);
Throwable current = thr;
while (current != null) {
- loc = ExceptionUtils.getLocation(current);
- if (loc != null) {
+ loc = LocationUtils.getLocation(current);
+ if (LocationUtils.isKnown(loc)) {
// One or more locations: dump it
handler.startElement(EXCEPTION_NS, "exception", "ex:exception", attr);
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/generation/JXTemplateGenerator.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/generation/JXTemplateGenerator.java?rev=280628&r1=280627&r2=280628&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/generation/JXTemplateGenerator.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/generation/JXTemplateGenerator.java Tue Sep 13 12:14:35 2005
@@ -58,6 +58,7 @@
import org.apache.cocoon.util.location.LocatedRuntimeException;
import org.apache.cocoon.util.location.Location;
import org.apache.cocoon.util.location.LocationImpl;
+import org.apache.cocoon.util.location.LocationUtils;
import org.apache.cocoon.xml.IncludeXMLConsumer;
import org.apache.cocoon.xml.NamespacesTable;
import org.apache.cocoon.xml.RedundantNamespacesFilter;
@@ -128,10 +129,6 @@
JXTException(String message, Location loc, Throwable thr) {
super(message, thr, loc);
}
-
- static LocatedRuntimeException get(String message, Location loc, Throwable thr) {
- return LocatedRuntimeException.getLocatedException(message, thr, loc);
- }
}
private static final JXPathContextFactory jxpathContextFactory = JXPathContextFactory.newInstance();
@@ -696,7 +693,7 @@
try {
return compileExpr(expr);
} catch (Exception exc) {
- throw JXTException.get(errorPrefix + exc.getMessage(), location, exc);
+ throw new JXTException(errorPrefix + exc.getMessage(), location, exc);
}
}
@@ -949,7 +946,7 @@
compiledExpression = ExpressionFactory.createExpression(str);
}
} catch (Exception exc) {
- throw JXTException.get(exc.getMessage(), this.location, exc);
+ throw new JXTException(exc.getMessage(), this.location, exc);
}
substitutions.add(new JXTExpression(str, compiledExpression));
buf.setLength(0);
@@ -1150,7 +1147,7 @@
try {
compiledExpression = compile(str, xpath);
} catch (Exception exc) {
- throw JXTException.get(exc.getMessage(), location, exc);
+ throw new JXTException(exc.getMessage(), location, exc);
}
substEvents.add(compiledExpression);
buf.setLength(0);
@@ -1894,7 +1891,7 @@
private void addEvent(Event ev) throws SAXException {
if (ev != null) {
if (lastEvent == null) {
- lastEvent = startEvent = new StartDocument(LocationImpl.get(locator, "template"));
+ lastEvent = startEvent = new StartDocument(LocationUtils.getLocation(locator, "template"));
} else {
flushChars();
}
@@ -1921,14 +1918,14 @@
throws SAXException {
if (charBuf == null) {
charBuf = new StringBuffer(length);
- charLocation = LocationImpl.get(locator, "[text]");
+ charLocation = LocationUtils.getLocation(locator, "[text]");
}
charBuf.append(ch, start, length);
}
public void endDocument() throws SAXException {
StartDocument startDoc = (StartDocument)stack.pop();
- EndDocument endDoc = new EndDocument(LocationImpl.get(locator, "template"));
+ EndDocument endDoc = new EndDocument(LocationUtils.getLocation(locator, "template"));
startDoc.endDocument = endDoc;
addEvent(endDoc);
}
@@ -1938,7 +1935,7 @@
Event newEvent = null;
if (NS.equals(namespaceURI)) {
StartInstruction startInstruction = (StartInstruction)start;
- EndInstruction endInstruction = new EndInstruction(LocationImpl.get(locator, "<"+raw+">"), startInstruction);
+ EndInstruction endInstruction = new EndInstruction(LocationUtils.getLocation(locator, "<"+raw+">"), startInstruction);
newEvent = endInstruction;
if (start instanceof StartWhen) {
StartWhen startWhen = (StartWhen)start;
@@ -1959,7 +1956,7 @@
}
} else {
StartElement startElement = (StartElement)start;
- newEvent = startElement.endElement = new EndElement(LocationImpl.get(locator, "<"+raw+">"), startElement);
+ newEvent = startElement.endElement = new EndElement(LocationUtils.getLocation(locator, "<"+raw+">"), startElement);
}
addEvent(newEvent);
if (start instanceof StartDefine) {
@@ -1969,17 +1966,17 @@
}
public void endPrefixMapping(String prefix) throws SAXException {
- EndPrefixMapping endPrefixMapping = new EndPrefixMapping(LocationImpl.get(locator, null), prefix);
+ EndPrefixMapping endPrefixMapping = new EndPrefixMapping(LocationUtils.getLocation(locator, null), prefix);
addEvent(endPrefixMapping);
}
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
- Event ev = new IgnorableWhitespace(LocationImpl.get(locator, null), ch, start, length);
+ Event ev = new IgnorableWhitespace(LocationUtils.getLocation(locator, null), ch, start, length);
addEvent(ev);
}
public void processingInstruction(String target, String data) throws SAXException {
- Event pi = new ProcessingInstruction(LocationImpl.get(locator, null), target, data);
+ Event pi = new ProcessingInstruction(LocationUtils.getLocation(locator, null), target, data);
addEvent(pi);
}
@@ -1988,18 +1985,18 @@
}
public void skippedEntity(String name) throws SAXException {
- addEvent(new SkippedEntity(LocationImpl.get(locator, null), name));
+ addEvent(new SkippedEntity(LocationUtils.getLocation(locator, null), name));
}
public void startDocument() {
- startEvent = new StartDocument(LocationImpl.get(locator, null));
+ startEvent = new StartDocument(LocationUtils.getLocation(locator, null));
lastEvent = startEvent;
stack.push(lastEvent);
}
public void startElement(String namespaceURI, String localName, String qname, Attributes attrs) throws SAXException {
Event newEvent = null;
- Location locator = LocationImpl.get(this.locator, "<"+qname+">");
+ Location locator = LocationUtils.getLocation(this.locator, "<"+qname+">");
AttributesImpl elementAttributes = new AttributesImpl(attrs);
int attributeCount = elementAttributes.getLength();
for (int i = 0; i < attributeCount; i++) {
@@ -2210,7 +2207,7 @@
}
public void startPrefixMapping(String prefix, String uri) throws SAXException {
- addEvent(new StartPrefixMapping(LocationImpl.get(locator, null), prefix, uri));
+ addEvent(new StartPrefixMapping(LocationUtils.getLocation(locator, null), prefix, uri));
}
public void comment(char ch[], int start, int length) throws SAXException {
@@ -2218,27 +2215,27 @@
}
public void endCDATA() throws SAXException {
- addEvent(new EndCDATA(LocationImpl.get(locator, null)));
+ addEvent(new EndCDATA(LocationUtils.getLocation(locator, null)));
}
public void endDTD() throws SAXException {
- addEvent(new EndDTD(LocationImpl.get(locator, null)));
+ addEvent(new EndDTD(LocationUtils.getLocation(locator, null)));
}
public void endEntity(String name) throws SAXException {
- addEvent(new EndEntity(LocationImpl.get(locator, null), name));
+ addEvent(new EndEntity(LocationUtils.getLocation(locator, null), name));
}
public void startCDATA() throws SAXException {
- addEvent(new StartCDATA(LocationImpl.get(locator, null)));
+ addEvent(new StartCDATA(LocationUtils.getLocation(locator, null)));
}
public void startDTD(String name, String publicId, String systemId) throws SAXException {
- addEvent(new StartDTD(LocationImpl.get(locator, null), name, publicId, systemId));
+ addEvent(new StartDTD(LocationUtils.getLocation(locator, null), name, publicId, systemId));
}
public void startEntity(String name) throws SAXException {
- addEvent(new StartEntity(LocationImpl.get(locator, null), name));
+ addEvent(new StartEntity(LocationUtils.getLocation(locator, null), name));
}
}
@@ -2519,7 +2516,7 @@
Object val = getValue(expr, jexlContext, jxpathContext);
chars = val != null ? val.toString().toCharArray() : ArrayUtils.EMPTY_CHAR_ARRAY;
} catch (Exception e) {
- throw JXTException.get(e.getMessage(), event.location, e);
+ throw new JXTException(e.getMessage(), event.location, e);
}
}
handler.characters(chars, 0, chars.length);
@@ -2539,7 +2536,7 @@
try {
execute(consumer, jexlContext, jxpathContext, macroCall, startEvent, endEvent);
} catch (Exception exc) {
- throw JXTException.get(macroCall.localName + ": " + exc.getMessage(), location, exc);
+ throw new JXTException(macroCall.localName + ": " + exc.getMessage(), location, exc);
}
}
@@ -2623,7 +2620,7 @@
}
chars = val != null ? val.toString().toCharArray() : ArrayUtils.EMPTY_CHAR_ARRAY;
} catch (Exception e) {
- throw JXTException.get(e.getMessage(), ev.location, e);
+ throw new JXTException(e.getMessage(), ev.location, e);
}
}
consumer.characters(chars, 0, chars.length);
@@ -2656,7 +2653,7 @@
try {
val = getValue(startIf.test, jexlContext, jxpathContext, Boolean.TRUE);
} catch (Exception e) {
- throw JXTException.get(e.getMessage(), ev.location, e);
+ throw new JXTException(e.getMessage(), ev.location, e);
}
boolean result = false;
if (val instanceof Boolean) {
@@ -2726,7 +2723,7 @@
var = getStringValue(startForEach.var, jexlContext, jxpathContext);
varStatus = getStringValue(startForEach.varStatus, jexlContext, jxpathContext);
} catch (Exception exc) {
- throw JXTException.get(exc.getMessage(), ev.location, exc);
+ throw new JXTException(exc.getMessage(), ev.location, exc);
}
MyJexlContext localJexlContext = new MyJexlContext(jexlContext);
MyVariables localJXPathVariables = new MyVariables((MyVariables)jxpathContext.getVariables());
@@ -2757,7 +2754,7 @@
try {
value = ptr.getNode();
} catch (Exception exc) {
- throw JXTException.get(exc.getMessage(), ev.location, null);
+ throw new JXTException(exc.getMessage(), ev.location, null);
}
} else {
localJXPathContext = jxpathContextFactory.newContext(jxpathContext, value);
@@ -2794,7 +2791,7 @@
try {
val = getValue(startWhen.test, jexlContext, jxpathContext, Boolean.TRUE);
} catch (Exception e) {
- throw JXTException.get(e.getMessage(), ev.location, e);
+ throw new JXTException(e.getMessage(), ev.location, e);
}
boolean result;
if (val instanceof Boolean) {
@@ -2825,7 +2822,7 @@
value = getNode(startSet.value, jexlContext, jxpathContext);
}
} catch (Exception exc) {
- throw JXTException.get(exc.getMessage(), ev.location, exc);
+ throw new JXTException(exc.getMessage(), ev.location, exc);
}
if (value == null) {
NodeList nodeList = toDOMNodeList("set", startSet, jexlContext, macroCall);
@@ -2866,7 +2863,7 @@
try {
val = getNode(expr, jexlContext, jxpathContext);
} catch (Exception e) {
- throw JXTException.get(e.getMessage(), ev.location, e);
+ throw new JXTException(e.getMessage(), ev.location, e);
}
attributeValue = val != null ? val : "";
} else {
@@ -2883,7 +2880,7 @@
try {
val = getValue(expr, jexlContext, jxpathContext);
} catch (Exception e) {
- throw JXTException.get(e.getMessage(), ev.location, e);
+ throw new JXTException(e.getMessage(), ev.location, e);
}
buf.append(val != null ? val.toString() : "");
}
@@ -2945,7 +2942,7 @@
try {
val = getValue(expr, jexlContext, jxpathContext);
} catch (Exception e) {
- throw JXTException.get(e.getMessage(), ev.location, e);
+ throw new JXTException(e.getMessage(), ev.location, e);
}
buf.append(val != null ? val.toString() : "");
}
@@ -2964,7 +2961,7 @@
consumer.characters(chars, 0, chars.length);
}
} catch (Exception e) {
- throw JXTException.get(e.getMessage(), ev.location, e);
+ throw new JXTException(e.getMessage(), ev.location, e);
}
} else if (ev instanceof StartFormatDate) {
StartFormatDate startFormatDate = (StartFormatDate)ev;
@@ -2975,7 +2972,7 @@
consumer.characters(chars, 0, chars.length);
}
} catch (Exception e) {
- throw JXTException.get(e.getMessage(), ev.location, e);
+ throw new JXTException(e.getMessage(), ev.location, e);
}
} else if (ev instanceof StartPrefixMapping) {
StartPrefixMapping startPrefixMapping = (StartPrefixMapping)ev;
@@ -2993,7 +2990,7 @@
String str = XMLUtils.serializeNode(nodeList.item(i), omit);
buf.append(StringUtils.substringAfter(str, ">")); // cut the XML header
} catch (Exception e) {
- throw JXTException.get(e.getMessage(), startJXComment.location, e);
+ throw new JXTException(e.getMessage(), startJXComment.location, e);
}
}
char[] chars = new char[buf.length()];
@@ -3042,7 +3039,7 @@
consumer.characters(ch, 0, ch.length);
}
} catch (Exception e) {
- throw JXTException.get(e.getMessage(), ev.location, e);
+ throw new JXTException(e.getMessage(), ev.location, e);
}
} else if (ev instanceof StartTemplate) {
// EMPTY
@@ -3057,7 +3054,7 @@
StartElement call = (StartElement)val;
execute(consumer, jexlContext, jxpathContext, call, call.next, call.endElement);
} catch (Exception exc) {
- throw JXTException.get(exc.getMessage(), ev.location, exc);
+ throw new JXTException(exc.getMessage(), ev.location, exc);
}
ev = startEval.endInstruction.next;
continue;
@@ -3066,7 +3063,7 @@
try {
execute(consumer, jexlContext, jxpathContext, null, macroCall.next, macroCall.endElement);
} catch (Exception exc) {
- throw JXTException.get(exc.getMessage(), ev.location, exc);
+ throw new JXTException(exc.getMessage(), ev.location, exc);
}
ev = startEval.endInstruction.next;
continue;
@@ -3097,7 +3094,7 @@
try {
val = getValue(expr, jexlContext, jxpathContext);
} catch (Exception exc) {
- throw JXTException.get(exc.getMessage(), ev.location, exc);
+ throw new JXTException(exc.getMessage(), ev.location, exc);
}
buf.append(val != null ? val.toString() : "");
}
@@ -3144,7 +3141,7 @@
}
}
} catch (Exception exc) {
- throw JXTException.get(exc.getMessage(), ev.location, exc);
+ throw new JXTException(exc.getMessage(), ev.location, exc);
}
finally {
resolver.release(input);
@@ -3160,13 +3157,13 @@
selectJexl = new MyJexlContext(jexlContext);
fillContext(obj, selectJexl);
} catch (Exception exc) {
- throw JXTException.get(exc.getMessage(), ev.location, exc);
+ throw new JXTException(exc.getMessage(), ev.location, exc);
}
}
try {
execute(consumer, selectJexl, selectJXPath, macroCall, doc.next, doc.endDocument);
} catch (Exception exc) {
- throw JXTException.get("Exception occurred in imported template " + uri + ": "+ exc.getMessage(), ev.location, exc);
+ throw new JXTException("Exception occurred in imported template " + uri + ": "+ exc.getMessage(), ev.location, exc);
}
ev = startImport.endInstruction.next;
continue;
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/selection/ExceptionSelector.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/selection/ExceptionSelector.java?rev=280628&r1=280627&r2=280628&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/selection/ExceptionSelector.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/selection/ExceptionSelector.java Tue Sep 13 12:14:35 2005
@@ -23,7 +23,7 @@
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.util.ClassUtils;
-import org.apache.cocoon.util.ExceptionUtils;
+import org.apache.commons.lang.exception.ExceptionUtils;
/**
* In a <map:handle-errors>, selects depending on the exception that caused the error.
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/transformation/TraxTransformer.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/transformation/TraxTransformer.java?rev=280628&r1=280627&r2=280628&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/transformation/TraxTransformer.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/transformation/TraxTransformer.java Tue Sep 13 12:14:35 2005
@@ -48,8 +48,8 @@
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.Session;
import org.apache.cocoon.environment.SourceResolver;
-import org.apache.cocoon.util.ExceptionUtils;
import org.apache.cocoon.util.location.Location;
+import org.apache.cocoon.util.location.LocationUtils;
import org.apache.cocoon.xml.XMLConsumer;
import org.apache.commons.lang.BooleanUtils;
import org.apache.excalibur.source.Source;
@@ -209,14 +209,14 @@
public void warning(TransformerException ex) throws TransformerException {
if (getLogger().isWarnEnabled()) {
- Location loc = ExceptionUtils.getLocation(ex);
+ Location loc = LocationUtils.getLocation(ex);
getLogger().warn("Warning at " + loc == null ? inputSource.getURI() : loc.toString(), ex);
}
}
public void error(TransformerException ex) throws TransformerException {
if (getLogger().isWarnEnabled()) {
- Location loc = ExceptionUtils.getLocation(ex);
+ Location loc = LocationUtils.getLocation(ex);
getLogger().error("Error at " + loc == null ? inputSource.getURI() : loc.toString(), ex);
}
}
@@ -613,7 +613,7 @@
} catch(Exception e) {
if (transformerException != null) {
// Ignore the fake RuntimeException sent by Xalan
- Location loc = ExceptionUtils.getLocation(transformerException);
+ Location loc = LocationUtils.getLocation(transformerException);
if (loc == null) {
// No location: if it's just a wrapper, consider only the wrapped exception.
Throwable realEx = transformerException.getCause();
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatedException.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatedException.java?rev=280628&r1=280627&r2=280628&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatedException.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatedException.java Tue Sep 13 12:14:35 2005
@@ -19,8 +19,9 @@
import java.util.Collections;
import java.util.List;
-import org.apache.avalon.framework.CascadingException;
-import org.apache.cocoon.util.ExceptionUtils;
+import org.apache.commons.lang.exception.ExceptionUtils;
+import org.apache.commons.lang.exception.NestableException;
+
/**
* A cascading and located <code>Exception</code>. It is also {@link MultiLocatable} to easily build
@@ -29,7 +30,7 @@
* @since 2.1.8
* @version $Id$
*/
-public class LocatedException extends CascadingException implements LocatableException, MultiLocatable {
+public class LocatedException extends NestableException implements LocatableException, MultiLocatable {
private List locations;
@@ -63,7 +64,7 @@
* of locatable exceptions.
*
* @param self the current locatable exception
- * @param cause the cause of <code>self</code>
+ * @param cause a cause of <code>self</code>
*/
public static void addCauseLocations(MultiLocatable self, Throwable cause) {
if (cause == null || cause instanceof Locatable) {
@@ -73,9 +74,15 @@
// Add parent location first
addCauseLocations(self, ExceptionUtils.getCause(cause));
// then ourselve's
- Location loc = ExceptionUtils.getLocation(cause);
- if (loc != null) {
- loc = new LocationImpl("[cause location]", loc.getURI(), loc.getLineNumber(), loc.getColumnNumber());
+ Location loc = LocationUtils.getLocation(cause);
+ if (LocationUtils.isKnown(loc)) {
+ // Get the exception's short name
+ String name = cause.getClass().getName();
+ int pos = name.lastIndexOf('.');
+ if (pos != -1) {
+ name = name.substring(pos+1);
+ }
+ loc = new LocationImpl("[" + name + "]", loc.getURI(), loc.getLineNumber(), loc.getColumnNumber());
self.addLocation(loc);
}
}
@@ -119,7 +126,7 @@
}
public void addLocation(Location loc) {
- if (loc == null || loc.equals(Location.UNKNOWN))
+ if (LocationUtils.isUnknown(loc))
return;
if (locations == null) {
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatedRuntimeException.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatedRuntimeException.java?rev=280628&r1=280627&r2=280628&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatedRuntimeException.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatedRuntimeException.java Tue Sep 13 12:14:35 2005
@@ -19,34 +19,50 @@
import java.util.Collections;
import java.util.List;
-import org.apache.avalon.framework.CascadingRuntimeException;
+import org.apache.commons.lang.exception.NestableRuntimeException;
/**
* A cascading and located <code>RuntimeException</code>. It is also {@link MultiLocatable} to easily build
- * stack traces.
+ * location stack traces.
+ * <p>
+ * If a <code>LocatedRuntimeException</code> is built with a location and a cause which is also a
+ * <code>LocatedRuntimeException</code>, then the default behavior is to add the location to the cause
+ * exception and immediately rethrow the cause. This avoids exception nesting and builds a location
+ * stack.
*
* @since 2.1.8
* @version $Id$
*/
-public class LocatedRuntimeException extends CascadingRuntimeException implements LocatableException, MultiLocatable {
+public class LocatedRuntimeException extends NestableRuntimeException implements LocatableException, MultiLocatable {
private List locations;
public LocatedRuntimeException(String message) {
- this(message, null, null);
+ this(message, null, null, true);
}
- public LocatedRuntimeException(String message, Throwable cause) {
- this(message, cause, null);
+ public LocatedRuntimeException(String message, Throwable cause) throws LocatedRuntimeException {
+ this(message, cause, null, true);
}
public LocatedRuntimeException(String message, Location location) {
- this(message, null, location);
- addLocation(location);
+ this(message, null, location, true);
}
- public LocatedRuntimeException(String message, Throwable cause, Location location) {
+ public LocatedRuntimeException(String message, Throwable cause, Location location) throws LocatedRuntimeException {
+ this(message, cause, location, true);
+ }
+
+ public LocatedRuntimeException(String message, Throwable cause, Location location, boolean rethrowLocated)
+ throws LocatedRuntimeException {
super(message, cause);
+ if (rethrowLocated && cause instanceof LocatedRuntimeException) {
+ LocatedRuntimeException lreCause = (LocatedRuntimeException)cause;
+ lreCause.addLocation(location);
+ // Rethrow the cause
+ throw lreCause;
+ }
+
LocatedException.addCauseLocations(this, cause);
addLocation(location);
}
@@ -68,34 +84,12 @@
}
public void addLocation(Location loc) {
- if (loc == null || loc.equals(Location.UNKNOWN))
+ if (LocationUtils.isUnknown(loc))
return;
if (locations == null) {
this.locations = new ArrayList(1); // Start small
}
locations.add(LocationImpl.get(loc));
- }
-
- /**
- * Build a located exception given an existing exception and the location where
- * this exception was catched. If the exception is already a <code>LocatedRuntimeException</code>,
- * then the location is added to the original exception's location chain and the result is
- * the original exception (and <code>description</code> is ignored. Otherwise, a new
- * <code>LocatedRuntimeException</code> is built, wrapping the original exception.
- *
- * @param message a message (can be <code>null</code>)
- * @param thr the original exception (can be <code>null</code>)
- * @param location the location (can be <code>null</code>)
- * @return a located exception
- */
- public static LocatedRuntimeException getLocatedException(String message, Throwable thr, Location location) {
- if (thr instanceof LocatedRuntimeException) {
- LocatedRuntimeException re = (LocatedRuntimeException)thr;
- re.addLocation(location);
- return re;
- }
-
- return new LocatedRuntimeException(message, thr, location);
}
}
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocationAttributes.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocationAttributes.java?rev=280628&r1=280627&r2=280628&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocationAttributes.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocationAttributes.java Tue Sep 13 12:14:35 2005
@@ -15,7 +15,6 @@
*/
package org.apache.cocoon.util.location;
-import org.apache.cocoon.xml.AbstractXMLPipe;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.xml.sax.Attributes;
@@ -256,10 +255,12 @@
* @see org.apache.cocoon.util.location.LocationAttributes
* @since 2.1.8
*/
- public static class Pipe extends AbstractXMLPipe {
+ public static class Pipe implements ContentHandler {
private Locator locator;
+ private ContentHandler nextHandler;
+
/**
* Create a filter. It has to be chained to another handler to be really useful.
*/
@@ -271,27 +272,55 @@
* @param next the next handler in the chain.
*/
public Pipe(ContentHandler next) {
- setContentHandler(next);
+ nextHandler = next;
}
public void setDocumentLocator(Locator locator) {
this.locator = locator;
- super.setDocumentLocator(locator);
+ nextHandler.setDocumentLocator(locator);
}
public void startDocument() throws SAXException {
- super.startDocument();
- super.startPrefixMapping(LocationAttributes.PREFIX, LocationAttributes.URI);
+ nextHandler.startDocument();
+ nextHandler.startPrefixMapping(LocationAttributes.PREFIX, LocationAttributes.URI);
}
public void endDocument() throws SAXException {
endPrefixMapping(LocationAttributes.PREFIX);
- super.endDocument();
+ nextHandler.endDocument();
}
public void startElement(String uri, String loc, String raw, Attributes attrs) throws SAXException {
// Add location attributes to the element
- super.startElement(uri, loc, raw, LocationAttributes.addLocationAttributes(locator, attrs));
+ nextHandler.startElement(uri, loc, raw, LocationAttributes.addLocationAttributes(locator, attrs));
+ }
+
+ public void endElement(String arg0, String arg1, String arg2) throws SAXException {
+ nextHandler.endElement(arg0, arg1, arg2);
+ }
+
+ public void startPrefixMapping(String arg0, String arg1) throws SAXException {
+ nextHandler.startPrefixMapping(arg0, arg1);
+ }
+
+ public void endPrefixMapping(String arg0) throws SAXException {
+ nextHandler.endPrefixMapping(arg0);
+ }
+
+ public void characters(char[] arg0, int arg1, int arg2) throws SAXException {
+ nextHandler.characters(arg0, arg1, arg2);
+ }
+
+ public void ignorableWhitespace(char[] arg0, int arg1, int arg2) throws SAXException {
+ nextHandler.ignorableWhitespace(arg0, arg1, arg2);
+ }
+
+ public void processingInstruction(String arg0, String arg1) throws SAXException {
+ nextHandler.processingInstruction(arg0, arg1);
+ }
+
+ public void skippedEntity(String arg0) throws SAXException {
+ nextHandler.skippedEntity(arg0);
}
}
}
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocationImpl.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocationImpl.java?rev=280628&r1=280627&r2=280628&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocationImpl.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocationImpl.java Tue Sep 13 12:14:35 2005
@@ -17,9 +17,7 @@
import java.io.Serializable;
-import org.apache.avalon.framework.configuration.Configuration;
import org.apache.commons.lang.ObjectUtils;
-import org.xml.sax.Locator;
/**
* A simple immutable and serializable implementation of {@link Location}.
@@ -34,7 +32,7 @@
private final String description;
// Package private: outside this package, use Location.UNKNOWN.
- static final LocationImpl UNKNOWN = new LocationImpl(null, null);
+ static final LocationImpl UNKNOWN = new LocationImpl(null, null, -1, -1);
/**
* The string representation of an unknown location: "<code>[unknown location]</code>".
@@ -84,8 +82,15 @@
}
/**
+ * Create a location from an existing one, but with a different description
+ */
+ public LocationImpl(String description, Location location) {
+ this(description, location.getURI(), location.getLineNumber(), location.getColumnNumber());
+ }
+
+ /**
* Obtain a <code>LocationImpl</code> from a {@link Location}. If <code>location</code> is
- * alredy a <code>LocationImpl</code>, it is returned, otherwise it is copied.
+ * already a <code>LocationImpl</code>, it is returned, otherwise it is copied.
* <p>
* This method is useful when an immutable and serializable location is needed, such as in locatable
* exceptions.
@@ -101,88 +106,6 @@
} else {
return new LocationImpl(location);
}
- }
-
- /**
- * Parse a location string of the form "<code><em>uri</em>:<em>line</em>:<em>column</em></code>" (e.g.
- * "<code>path/to/file.xml:3:40</code>") to a Location object.
- *
- * @param text the text to parse
- * @return the location (possibly UNKNOWN if text was null or in an incorrect format)
- */
- public static LocationImpl get(String text) throws IllegalArgumentException {
- if (text == null || text.length() == 0) {
- return UNKNOWN;
- }
-
- // Do we have a description?
- String description;
- int uriStart = text.lastIndexOf(" - "); // lastIndexOf to allow the separator to be in the description
- if (uriStart > -1) {
- description = text.substring(0, uriStart);
- uriStart += 3; // strip " - "
- } else {
- description = null;
- uriStart = 0;
- }
-
- try {
- int colSep = text.lastIndexOf(':');
- if (colSep > -1) {
- int column = Integer.parseInt(text.substring(colSep + 1));
-
- int lineSep = text.lastIndexOf(':', colSep - 1);
- if (lineSep > -1) {
- int line = Integer.parseInt(text.substring(lineSep + 1, colSep));
- return new LocationImpl(description, text.substring(uriStart, lineSep), line, column);
- }
- } else {
- // unkonwn?
- if (text.endsWith(UNKNOWN_STRING)) {
- return new LocationImpl(description, null);
- }
- }
- } catch(Exception e) {
- // Ignore: handled below
- }
-
- return UNKNOWN;
- }
-
- /**
- * Returns the {@link Location} pointed to by a SAX <code>Locator</code>.
- *
- * @param locator the locator (can be null)
- * @param description a description for the location (can be null)
- * @return the location (possibly UNKNOWN)
- */
- public static LocationImpl get(Locator locator, String description) {
- if (locator == null || locator.getSystemId() == null) {
- return UNKNOWN;
- }
-
- return new LocationImpl(description, locator.getSystemId(), locator.getLineNumber(), locator.getColumnNumber());
- }
-
- /**
- * Returns the {@link Location} of an Avalon <code>Configuration</code> object.
- *
- *
- */
- public static LocationImpl get(Configuration config) {
- if (config == null) {
- return UNKNOWN;
- }
-
- // Why in hell is "if (config instanceof Locatable)" producing a compilation error???
- Object obj = config;
- // We may have a locatable implementation of configuration
- if (obj instanceof Locatable) {
- return get(((Locatable)obj).getLocation());
- }
-
- String locString = config.getLocation();
- return get(locString);
}
/**
Added: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocationUtils.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocationUtils.java?rev=280628&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocationUtils.java (added)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocationUtils.java Tue Sep 13 12:14:35 2005
@@ -0,0 +1,206 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.util.location;
+
+import javax.xml.transform.SourceLocator;
+import javax.xml.transform.TransformerException;
+
+import org.xml.sax.Locator;
+import org.xml.sax.SAXParseException;
+
+/**
+ * Location-related utility methods.
+ *
+ * @version $Id$
+ * @since 2.1.8
+ */
+public class LocationUtils {
+
+ private static LocationFinder[] finders = new LocationFinder[] {};
+
+ /**
+ * An finder or object locations
+ *
+ * @since 2.1.8
+ */
+ public interface LocationFinder {
+ /**
+ * Get the location of an object
+ * @param obj the object for which to find a location
+ * @param description and optional description to be added to the object's location
+ * @return the object's location or <code>null</code> if object's class isn't handled
+ * by this finder.
+ */
+ Location getLocation(Object obj, String description);
+ }
+
+ private LocationUtils() {
+ // Forbid instanciation
+ }
+
+ /**
+ * Parse a location string of the form "<code><em>uri</em>:<em>line</em>:<em>column</em></code>" (e.g.
+ * "<code>path/to/file.xml:3:40</code>") to a Location object. Additionally, a description may
+ * also optionally be present, separated with an hyphen (e.g. "<code>foo - path/to/file.xml:3.40</code>").
+ *
+ * @param text the text to parse
+ * @return the location (possibly <code>null</code> if text was null or in an incorrect format)
+ */
+ public static LocationImpl parse(String text) throws IllegalArgumentException {
+ if (text == null || text.length() == 0) {
+ return null;
+ }
+
+ // Do we have a description?
+ String description;
+ int uriStart = text.lastIndexOf(" - "); // lastIndexOf to allow the separator to be in the description
+ if (uriStart > -1) {
+ description = text.substring(0, uriStart);
+ uriStart += 3; // strip " - "
+ } else {
+ description = null;
+ uriStart = 0;
+ }
+
+ try {
+ int colSep = text.lastIndexOf(':');
+ if (colSep > -1) {
+ int column = Integer.parseInt(text.substring(colSep + 1));
+
+ int lineSep = text.lastIndexOf(':', colSep - 1);
+ if (lineSep > -1) {
+ int line = Integer.parseInt(text.substring(lineSep + 1, colSep));
+ return new LocationImpl(description, text.substring(uriStart, lineSep), line, column);
+ }
+ } else {
+ // unkonwn?
+ if (text.endsWith(LocationImpl.UNKNOWN_STRING)) {
+ return LocationImpl.UNKNOWN;
+ }
+ }
+ } catch(Exception e) {
+ // Ignore: handled below
+ }
+
+ return LocationImpl.UNKNOWN;
+ }
+
+ /**
+ * Checks if a location is known, i.e. it is not null nor equal to {@link Location#UNKNOWN}.
+ *
+ * @param location the location to check
+ * @return <code>true</code> if the location is known
+ */
+ public static boolean isKnown(Location location) {
+ return location != null && !Location.UNKNOWN.equals(location);
+ }
+
+ /**
+ * Checks if a location is unknown, i.e. it is either null or equal to {@link Location#UNKNOWN}.
+ *
+ * @param location the location to check
+ * @return <code>true</code> if the location is unknown
+ */
+ public static boolean isUnknown(Location location) {
+ return location == null || Location.UNKNOWN.equals(location);
+ }
+
+ /**
+ * Add a {@link LocationFinder} to the list of finders that will be queried for an object's
+ * location by {@link #getLocation(Object, String)}.
+ *
+ * @param finder the location finder to add
+ */
+ public static void addFinder(LocationFinder finder) {
+ if (finder == null) {
+ return;
+ }
+
+ synchronized(LocationUtils.class) {
+ int length = finders.length;
+ LocationFinder[] newFinders = new LocationFinder[length + 1];
+ System.arraycopy(finders, 0, newFinders, 0, length);
+ newFinders[length] = finder;
+ finders = newFinders;
+ }
+ }
+
+ /**
+ * Get the location of an object. Some well-known located classes built in the JDK are handled
+ * by this method. Handling of other located classes can be handled by adding new location finders.
+ *
+ * @param obj the object of which to get the location
+ * @return the object's location, or {@link Location#UNKNOWN} if no location could be found
+ */
+ public static Location getLocation(Object obj) {
+ return getLocation(obj, null);
+ }
+
+ /**
+ * Get the location of an object. Some well-known located classes built in the JDK are handled
+ * by this method. Handling of other located classes can be handled by adding new location finders.
+ *
+ * @param obj the object of which to get the location
+ * @param description an optional description of the object's location, used if a Location object
+ * has to be created.
+ * @return the object's location, or {@link Location#UNKNOWN} if no location could be found
+ */
+ public static Location getLocation(Object obj, String description) {
+ if (obj instanceof Locatable) {
+ return ((Locatable)obj).getLocation();
+ }
+
+ // Check some well-known locatable exceptions
+ if (obj instanceof SAXParseException) {
+ SAXParseException spe = (SAXParseException)obj;
+ if (spe.getSystemId() != null) {
+ return new LocationImpl(description, spe.getSystemId(), spe.getLineNumber(), spe.getColumnNumber());
+ } else {
+ return Location.UNKNOWN;
+ }
+ }
+
+ if (obj instanceof TransformerException) {
+ TransformerException ex = (TransformerException)obj;
+ SourceLocator locator = ex.getLocator();
+ if (locator != null && locator.getSystemId() != null) {
+ return new LocationImpl(description, locator.getSystemId(), locator.getLineNumber(), locator.getColumnNumber());
+ } else {
+ return Location.UNKNOWN;
+ }
+ }
+
+ if (obj instanceof Locator) {
+ Locator locator = (Locator)obj;
+ if (locator.getSystemId() != null) {
+ return new LocationImpl(description, locator.getSystemId(), locator.getLineNumber(), locator.getColumnNumber());
+ } else {
+ return Location.UNKNOWN;
+ }
+ }
+
+ Location result;
+ LocationFinder[] currentFinders = finders;
+ for (int i = 0; i < currentFinders.length; i++) {
+ result = currentFinders[i].getLocation(obj, description);
+ if (result != null) {
+ return result;
+ }
+ }
+
+ return Location.UNKNOWN;
+ }
+}
Propchange: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocationUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocationUtils.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/log/CocoonLogFormatter.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/log/CocoonLogFormatter.java?rev=280628&r1=280627&r2=280628&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/log/CocoonLogFormatter.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/log/CocoonLogFormatter.java Tue Sep 13 12:14:35 2005
@@ -20,9 +20,9 @@
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
-import org.apache.cocoon.util.ExceptionUtils;
import org.apache.commons.lang.ClassUtils;
+import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.commons.lang.time.FastDateFormat;
import org.apache.log.ContextMap;
import org.apache.log.LogEvent;
Modified: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/util/location/LocationTestCase.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/util/location/LocationTestCase.java?rev=280628&r1=280627&r2=280628&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/util/location/LocationTestCase.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/util/location/LocationTestCase.java Tue Sep 13 12:14:35 2005
@@ -32,7 +32,7 @@
public void testParse() throws Exception {
String str = "<map:generate> - path/to/file.xml:1:40";
- Location loc = LocationImpl.get(str);
+ Location loc = LocationUtils.parse(str);
assertEquals("<map:generate>", loc.getDescription());
assertEquals("URI", "path/to/file.xml", loc.getURI());
@@ -42,7 +42,7 @@
}
public void testEquals() throws Exception {
- Location loc1 = LocationImpl.get(str);
+ Location loc1 = LocationUtils.parse(str);
Location loc2 = new LocationImpl(null, "path/to/file.xml", 1, 40);
assertEquals("locations", loc1, loc2);