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/08/13 00:14:53 UTC
svn commit: r232400 [2/2] - in /cocoon/branches/BRANCH_2_1_X/src:
java/org/apache/cocoon/ java/org/apache/cocoon/components/flow/javascript/
java/org/apache/cocoon/components/pipeline/
java/org/apache/cocoon/components/treeprocessor/ java/org/apache/co...
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/ExceptionUtils.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/ExceptionUtils.java?rev=232400&r1=232399&r2=232400&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/ExceptionUtils.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/ExceptionUtils.java Fri Aug 12 15:14:26 2005
@@ -15,15 +15,14 @@
*/
package org.apache.cocoon.util;
-import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.util.Vector;
import javax.xml.transform.SourceLocator;
import javax.xml.transform.TransformerException;
import org.apache.cocoon.util.location.Locatable;
import org.apache.cocoon.util.location.Location;
+import org.apache.cocoon.util.location.LocationImpl;
import org.mozilla.javascript.EcmaError;
import org.mozilla.javascript.JavaScriptException;
import org.xml.sax.SAXParseException;
@@ -34,6 +33,7 @@
* to handle exception chains, with additional heuristics to unroll exceptions, and other Cocoon-specific stuff
* such as getting the {@link Location} of an exception.
*
+ * @since 2.1.8
* @version $Id$
*/
public class ExceptionUtils extends org.apache.commons.lang.exception.ExceptionUtils {
@@ -115,7 +115,7 @@
} else if (thr instanceof SAXParseException) {
SAXParseException spe = (SAXParseException)thr;
if (spe.getSystemId() != null) {
- return new Location(spe.getSystemId(), spe.getLineNumber(), spe.getColumnNumber());
+ return new LocationImpl(null, spe.getSystemId(), spe.getLineNumber(), spe.getColumnNumber());
} else {
return null;
}
@@ -124,7 +124,7 @@
TransformerException ex = (TransformerException)thr;
SourceLocator locator = ex.getLocator();
if (locator != null && locator.getSystemId() != null) {
- return new Location(locator.getSystemId(), locator.getLineNumber(), locator.getColumnNumber());
+ return new LocationImpl(null, locator.getSystemId(), locator.getLineNumber(), locator.getColumnNumber());
} else {
return null;
}
@@ -132,7 +132,7 @@
} else if (thr instanceof EcmaError) {
EcmaError ex = (EcmaError)thr;
if (ex.getSourceName() != null) {
- return new Location(ex.getSourceName(), ex.getLineNumber(), ex.getColumnNumber());
+ return new LocationImpl(ex.getName(), ex.getSourceName(), ex.getLineNumber(), ex.getColumnNumber());
} else {
return null;
}
@@ -140,14 +140,7 @@
} else if (thr instanceof JavaScriptException) {
JavaScriptException ex = (JavaScriptException)thr;
if (ex.sourceName() != null) {
- return new Location(ex.sourceName(), ex.lineNumber(), -1);
-// Vector stackTrace = ex.getJSStackTrace();
-// if (stackTrace != null) {
-// // see JavaScriptException.getMessage()
-// int i = stackTrace.size() - 1;
-// String sourceName = (String)stackTrace.elementAt(i-2);
-// int lineNum = ((Integer)stackTrace.elementAt(i)).intValue();
-// return new Location(sourceName, lineNum, -1);
+ return new LocationImpl(null, ex.sourceName(), ex.lineNumber(), -1);
} else {
return null;
}
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/Locatable.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/Locatable.java?rev=232400&r1=232399&r2=232400&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/Locatable.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/Locatable.java Fri Aug 12 15:14:26 2005
@@ -19,6 +19,7 @@
* A interface that should be implemented by objects knowning their location (i.e. where they
* have been created from).
*
+ * @since 2.1.8
* @version $Id$
*/
public interface Locatable {
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatableException.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatableException.java?rev=232400&r1=232399&r2=232400&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatableException.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatableException.java Fri Aug 12 15:14:26 2005
@@ -22,10 +22,12 @@
* a {@link Locatable} exception should return a concatenation of the raw message (given in the
* constructor) and the exception's location, e.g. "<code>foo failed (file.xml:12:3)</code>". However,
* {@link Locatable}-aware classes will want to handle the raw message (i.e. "<code>foo failed</code>")
- * and location separately.
+ * and location separately. This interface gives access to the raw message.
* <p>
- * This interface gives access to the raw message.
+ * <strong>Note:</strong> care should be taken for locatable exceptions to use only immutable and
+ * serializable implementations of {@link Location} ({@see org.apache.cocoon.util.location.LocationImpl#get(Location)}).
*
+ * @since 2.1.8
* @version $Id$
*/
public interface LocatableException extends Locatable {
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=232400&r1=232399&r2=232400&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 Fri Aug 12 15:14:26 2005
@@ -16,6 +16,7 @@
package org.apache.cocoon.util.location;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import org.apache.avalon.framework.CascadingException;
@@ -24,6 +25,7 @@
* A cascading and located <code>Exception</code>. It is also {@link MultiLocatable} to easily build
* stack traces.
*
+ * @since 2.1.8
* @version $Id$
*/
public class LocatedException extends CascadingException implements LocatableException, MultiLocatable {
@@ -53,7 +55,7 @@
}
public List getLocations() {
- return locations;
+ return locations == null ? Collections.EMPTY_LIST : locations;
}
public String getRawMessage() {
@@ -93,6 +95,6 @@
if (locations == null) {
this.locations = new ArrayList(1); // Start small
}
- locations.add(loc);
+ locations.add(LocationImpl.get(loc));
}
}
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=232400&r1=232399&r2=232400&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 Fri Aug 12 15:14:26 2005
@@ -16,6 +16,7 @@
package org.apache.cocoon.util.location;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import org.apache.avalon.framework.CascadingRuntimeException;
@@ -24,6 +25,7 @@
* A cascading and located <code>RuntimeException</code>. It is also {@link MultiLocatable} to easily build
* stack traces.
*
+ * @since 2.1.8
* @version $Id$
*/
public class LocatedRuntimeException extends CascadingRuntimeException implements LocatableException, MultiLocatable {
@@ -53,7 +55,7 @@
}
public List getLocations() {
- return locations;
+ return locations == null ? Collections.EMPTY_LIST : locations;
}
public String getRawMessage() {
@@ -71,21 +73,28 @@
if (locations == null) {
this.locations = new ArrayList(1); // Start small
}
- locations.add(loc);
+ locations.add(LocationImpl.get(loc));
}
/**
- * A convenience method to get a located exception for an existing <code>Throwable</code>.
- * If the throwable already is {@link MultiLocatable}, the location is added to its location
- * list. Otherwise, a new <code>LocatedRuntimeException</code> is created.
+ * 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 description, Throwable thr, Location location) {
+ 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(description, thr, location);
+ return new LocatedRuntimeException(message, thr, location);
}
}
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/Location.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/Location.java?rev=232400&r1=232399&r2=232400&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/Location.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/Location.java Fri Aug 12 15:14:26 2005
@@ -15,154 +15,48 @@
*/
package org.apache.cocoon.util.location;
-import java.io.Serializable;
/**
* A location in a resource. The location is composed of the URI of the resource, and
- * the line and column numbers within that resource (when available).
+ * the line and column numbers within that resource (when available), along with a description.
* <p>
- * Locations are mostly used by {@link Locatable}s objects.
+ * Locations are mostly provided by {@link Locatable}s objects.
*
+ * @since 2.1.8
* @version $Id$
*/
-public class Location implements Serializable {
- private final String uri;
- private final int line;
- private final int column;
- private transient String stringValue;
+public interface Location {
/**
* Constant for unknown locations.
*/
- public static final Location UNKNOWN = new Location();
+ public static final Location UNKNOWN = new LocationImpl(null, null);
/**
- * The string representation of an {@link #UNKNOWN unknown location}: "<code>[unknown location]</code>".
- */
- public static final String UNKNOWN_STRING = "[unknown location]";
-
- private Location() {
- // Null location
- uri = "";
- line = -1;
- column = -1;
- stringValue = UNKNOWN_STRING;
- }
-
- /**
- * Build a location for a given URI, with unknown line and column numbers.
- *
- * @param uri the resource URI
- */
- public Location(String uri) {
- this(uri, -1, -1);
- }
-
- /**
- * Build a location for a given URI and line and columb numbers.
+ * Get the description of this location
*
- * @param uri the resource URI
- * @param line the line number (starts at 1)
- * @param column the column number (starts at 1)
+ * @return the description (can be <code>null</code>)
*/
- public Location(String uri, int line, int column) {
- this.uri = uri;
- this.line = line;
- this.column = column;
- }
-
- /**
- * 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
- */
- public static Location parse(String text) throws Exception {
- if (text == null || text.equals(UNKNOWN_STRING)) {
- return UNKNOWN;
- }
-
- 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 Location(text.substring(0, lineSep), line, column);
- }
- }
- } catch(Exception e) {
- // Ignore: we throw another one below
- }
-
- throw new IllegalArgumentException("Invalid location string: " + text);
- }
+ public String getDescription();
/**
* Get the URI of this location
*
- * @return the URI (empty string if unknown).
+ * @return the URI (<code>null</code> if unknown).
*/
- public String getURI() {
- return this.uri;
- }
-
+ public String getURI();
/**
* Get the line number of this location
*
* @return the line number (<code>-1</code> if unknown)
*/
- public int getLine() {
- return this.line;
- }
+ public int getLineNumber();
/**
* Get the column number of this location
*
* @return the column number (<code>-1</code> if unknown)
*/
- public int getColumn() {
- return this.column;
- }
-
- public boolean equals(Object obj) {
- if (obj == this) {
- return true;
- }
+ public int getColumnNumber();
- if (obj instanceof Location) {
- Location other = (Location)obj;
- return this.line == other.line && other.column == other.column && this.uri.equals(other.uri);
- }
-
- return false;
- }
-
- public int hashCode() {
- return uri.hashCode() ^ line ^ column;
- }
-
- /**
- * Builds a string representation of the location, in the "<code><em>uri</em>:<em>line</em>:<em>column</em></code>"
- * format (e.g. "<code>path/to/file.xml:3:40</code>"). For {@link #UNKNOWN an unknown location}, returns
- * {@link #UNKNOWN_STRING}.
- *
- * @return the string representation
- */
- public String toString() {
- if (stringValue == null) {
- stringValue = uri + ":" + Integer.toString(line) + ":" + Integer.toString(column);
- }
- return stringValue;
- }
-
- /**
- * Ensure serialized unknown location resolve to {@link UNKNOWN}.
- */
- private Object readResolve() {
- return this.equals(UNKNOWN) ? UNKNOWN : this;
- }
}
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=232400&r1=232399&r2=232400&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 Fri Aug 12 15:14:26 2005
@@ -26,6 +26,7 @@
* These attributes are typically setup using {@link LocatorToAttributesPipe}
*
* @see LocatorToAttributesPipe
+ * @since 2.1.8
* @version $Id$
*/
public class LocationAttributes {
@@ -81,29 +82,31 @@
* 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
*/
- public static Location getLocation(Locator locator) {
+ public static Location getLocation(Locator locator, String description) {
if (locator == null || locator.getSystemId() == null) {
return Location.UNKNOWN;
}
- return new Location(locator.getSystemId(), locator.getLineNumber(), locator.getColumnNumber());
+ return new LocationImpl(description, locator.getSystemId(), locator.getLineNumber(), locator.getColumnNumber());
}
/**
* Returns the {@link Location} of an element (SAX flavor).
*
* @param attrs the element's attributes that hold the location information
+ * @param description a description for the location (can be null)
* @return a {@link Location} object
*/
- public static Location getLocation(Attributes attrs) {
+ public static Location getLocation(Attributes attrs, String description) {
String src = attrs.getValue(URI, SRC_ATTR);
if (src == null) {
return Location.UNKNOWN;
}
- return new Location(src, getLine(attrs), getColumn(attrs));
+ return new LocationImpl(description, src, getLine(attrs), getColumn(attrs));
}
/**
@@ -117,7 +120,7 @@
public static String getLocationString(Attributes attrs) {
String src = attrs.getValue(URI, SRC_ATTR);
if (src == null) {
- return Location.UNKNOWN_STRING;
+ return LocationImpl.UNKNOWN_STRING;
}
return src + ":" + attrs.getValue(URI, LINE_ATTR) + ":" + attrs.getValue(URI, COL_ATTR);
@@ -132,7 +135,7 @@
*/
public static String getURI(Attributes attrs) {
String src = attrs.getValue(URI, SRC_ATTR);
- return src != null ? src : Location.UNKNOWN_STRING;
+ return src != null ? src : LocationImpl.UNKNOWN_STRING;
}
/**
@@ -163,16 +166,26 @@
* Returns the {@link Location} of an element (DOM flavor).
*
* @param attrs the element that holds the location information
+ * @param description a description for the location (if <code>null</code>, the element's name is used)
* @return a {@link Location} object
*/
- public static Location getLocation(Element elem) {
+ public static Location getLocation(Element elem, String description) {
Attr srcAttr = elem.getAttributeNodeNS(URI, SRC_ATTR);
if (srcAttr == null) {
return Location.UNKNOWN;
}
-
- return new Location(srcAttr.getValue(), getLine(elem), getColumn(elem));
+
+ return new LocationImpl(description == null ? elem.getNodeName() : description,
+ srcAttr.getValue(), getLine(elem), getColumn(elem));
+ }
+
+ /**
+ * Same as <code>getLocation(elem, null)</code>.
+ */
+ public static Location getLocation(Element elem) {
+ return getLocation(elem, null);
}
+
/**
* Returns the location of an element that has been processed by this pipe (DOM flavor).
@@ -185,7 +198,7 @@
public static String getLocationString(Element elem) {
Attr srcAttr = elem.getAttributeNodeNS(URI, SRC_ATTR);
if (srcAttr == null) {
- return Location.UNKNOWN_STRING;
+ return LocationImpl.UNKNOWN_STRING;
}
return srcAttr.getValue() + ":" + elem.getAttributeNS(URI, LINE_ATTR) + ":" + elem.getAttributeNS(URI, COL_ATTR);
@@ -200,7 +213,7 @@
*/
public static String getURI(Element elem) {
Attr attr = elem.getAttributeNodeNS(URI, SRC_ATTR);
- return attr != null ? attr.getValue() : Location.UNKNOWN_STRING;
+ return attr != null ? attr.getValue() : LocationImpl.UNKNOWN_STRING;
}
/**
Added: 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=232400&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocationImpl.java (added)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocationImpl.java Fri Aug 12 15:14:26 2005
@@ -0,0 +1,242 @@
+/*
+ * 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 java.io.Serializable;
+
+import org.apache.commons.lang.ObjectUtils;
+
+/**
+ * A simple immutable and serializable implementation of {@link Location}.
+ *
+ * @since 2.1.8
+ * @version $Id$
+ */
+public class LocationImpl implements Location, Serializable {
+ private final String uri;
+ private final int line;
+ private final int column;
+ private final String description;
+
+ /**
+ * The string representation of an unknown location: "<code>[unknown location]</code>".
+ */
+ public static final String UNKNOWN_STRING = "[unknown location]";
+
+ /**
+ * Build a location for a given URI, with unknown line and column numbers.
+ *
+ * @param uri the resource URI
+ */
+ public LocationImpl(String description, String uri) {
+ this(description, uri, -1, -1);
+ }
+
+ /**
+ * Build a location for a given URI and line and columb numbers.
+ *
+ * @param uri the resource URI
+ * @param line the line number (starts at 1)
+ * @param column the column number (starts at 1)
+ */
+ public LocationImpl(String description, String uri, int line, int column) {
+ if (uri == null || uri.length() == 0) {
+ this.uri = null;
+ this.line = -1;
+ this.column = -1;
+ } else {
+ this.uri = uri;
+ this.line = line;
+ this.column = column;
+ }
+
+ if (description != null && description.length() == 0) {
+ description = null;
+ }
+ this.description = description;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param location the location to be copied
+ */
+ public LocationImpl(Location location) {
+ this(location.getDescription(), 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.
+ * <p>
+ * This method is useful when an immutable and serializable location is needed, such as in locatable
+ * exceptions.
+ *
+ * @param location the location
+ * @return an immutable and serializable version of <code>location</code>
+ */
+ public static LocationImpl get(Location location) {
+ if (location instanceof LocationImpl) {
+ return (LocationImpl)location;
+ } else if (location == null) {
+ return (LocationImpl)Location.UNKNOWN;
+ } 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
+ */
+ public static LocationImpl valueOf(String text) {
+ if (text == null || text.length() == 0) {
+ return (LocationImpl)Location.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: we throw another one below
+ }
+
+ throw new IllegalArgumentException("Invalid location string: " + text);
+ }
+
+ /**
+ * Get the description of this location
+ *
+ * @return the description (can be <code>null</code>)
+ */
+ public String getDescription() {
+ return this.description;
+ }
+
+ /**
+ * Get the URI of this location
+ *
+ * @return the URI (<code>null</code> if unknown).
+ */
+ public String getURI() {
+ return this.uri;
+ }
+
+ /**
+ * Get the line number of this location
+ *
+ * @return the line number (<code>-1</code> if unknown)
+ */
+ public int getLineNumber() {
+ return this.line;
+ }
+
+ /**
+ * Get the column number of this location
+ *
+ * @return the column number (<code>-1</code> if unknown)
+ */
+ public int getColumnNumber() {
+ return this.column;
+ }
+
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+
+ if (obj instanceof Location) {
+ Location other = (Location)obj;
+ return this.line == other.getLineNumber() && this.column == other.getColumnNumber()
+ && ObjectUtils.equals(this.uri, other.getURI())
+ && ObjectUtils.equals(this.description, other.getDescription());
+ }
+
+ return false;
+ }
+
+ public int hashCode() {
+ int hash = line ^ column;
+ if (uri != null) hash ^= uri.hashCode();
+ if (description != null) hash ^= description.hashCode();
+
+ return hash;
+ }
+
+ public String toString() {
+ return toString(this);
+ }
+
+ /**
+ * Builds a string representation of a location, in the
+ * "<code><em>descripton</em> - <em>uri</em>:<em>line</em>:<em>column</em></code>"
+ * format (e.g. "<code>path/to/file.xml:3:40</code>"). For {@link Location#UNKNOWN an unknown location}, returns
+ * {@link #UNKNOWN_STRING}.
+ *
+ * @return the string representation
+ */
+ public static String toString(Location location) {
+ StringBuffer result = new StringBuffer();
+
+ String description = location.getDescription();
+ if (description != null) {
+ result.append(description).append(" - ");
+ }
+
+ String uri = location.getURI();
+ if (uri != null) {
+ result.append(uri).append(':').append(location.getLineNumber()).append(':').append(location.getColumnNumber());
+ } else {
+ result.append(UNKNOWN_STRING);
+ }
+
+ return result.toString();
+ }
+
+ /**
+ * Ensure serialized unknown location resolve to {@link Location#UNKNOWN}.
+ */
+ private Object readResolve() {
+ return this.equals(Location.UNKNOWN) ? Location.UNKNOWN : this;
+ }
+}
Propchange: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocationImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocationImpl.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatorToAttributesPipe.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatorToAttributesPipe.java?rev=232400&r1=232399&r2=232400&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatorToAttributesPipe.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatorToAttributesPipe.java Fri Aug 12 15:14:26 2005
@@ -39,6 +39,7 @@
* attributes point to the same string.
*
* @see org.apache.cocoon.util.location.LocationAttributes
+ * @since 2.1.8
* @version $Id$
*/
public class LocatorToAttributesPipe extends AbstractXMLPipe {
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/MultiLocatable.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/MultiLocatable.java?rev=232400&r1=232399&r2=232400&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/MultiLocatable.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/MultiLocatable.java Fri Aug 12 15:14:26 2005
@@ -13,6 +13,7 @@
* location of this stack. This is consistent with the need for <code>getLocation()</code> to
* return the most precise location.
*
+ * @since 2.1.8
* @version $Id$
*/
public interface MultiLocatable extends Locatable {
@@ -20,8 +21,19 @@
/**
* Return the list of locations.
*
- * @return a list of locations, or <code>null</code> if there are no locations.
+ * @return a list of locations, possibly empty but never null.
*/
public List getLocations();
+
+ /**
+ * Add a location to the current list of locations.
+ * <p>
+ * Implementations are free to filter locations that can be added (e.g. {@link Location#UNKNOWN}),
+ * and there is therefore no guarantee that the given location will actually be added to the list.
+ * Filtered locations are silently ignored.
+ *
+ * @param location the location to be added.
+ */
+ public void addLocation(Location location);
}
Modified: cocoon/branches/BRANCH_2_1_X/src/webapp/stylesheets/system/exception2html.xslt
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/webapp/stylesheets/system/exception2html.xslt?rev=232400&r1=232399&r2=232400&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/webapp/stylesheets/system/exception2html.xslt (original)
+++ cocoon/branches/BRANCH_2_1_X/src/webapp/stylesheets/system/exception2html.xslt Fri Aug 12 15:14:26 2005
@@ -29,7 +29,7 @@
<!-- let sitemap override default page title -->
<xsl:param name="pageTitle">An error has occured</xsl:param>
- <xsl:template match="ex:exception">
+ <xsl:template match="ex:exception-report">
<html>
<head>
<title>
@@ -42,6 +42,9 @@
p.description { padding: 10px 30px 20px 30px; border-width: 0px 0px 1px 0px; border-style: solid; border-color: #336699;}
p.topped { padding-top: 10px; border-width: 1px 0px 0px 0px; border-style: solid; border-color: #336699; }
pre { font-size: 120%; }
+ .row-1 { background-color: #F0F0F0;}
+ table { border-collapse: collapse; margin-top: 0.3em; }
+ td { padding: 0.1em; }
</style>
<script src="{$contextPath}/scripts/main.js" type="text/javascript"/>
</head>
@@ -60,22 +63,37 @@
<xsl:value-of select="."/>
</xsl:if>
</xsl:for-each>
- <xsl:if test="@uri">
- <br/><span style="font-weight: normal"><xsl:call-template name="dump-location"/></span>
+ <xsl:if test="ex:location">
+ <br/><span style="font-weight: normal"><xsl:apply-templates select="ex:location"/></span>
</xsl:if>
</p>
- <xsl:if test="count(ex:locations/*)">
- <p><span class="description">Cocoon stacktrace</span>
- <span class="switch" id="locations-switch" onclick="toggle('locations')">[hide]</span>
- </p>
- <div id="locations">
- <xsl:for-each select="ex:locations/*">
- <xsl:sort select="position()" order="descending"/>
- <xsl:apply-templates select="."/>
- </xsl:for-each>
- </div>
- </xsl:if>
+ <p><span class="description">Cocoon stacktrace</span>
+ <span class="switch" id="locations-switch" onclick="toggle('locations')">[hide]</span>
+ </p>
+ <div id="locations">
+ <xsl:for-each select="ex:cocoon-stacktrace/ex:exception">
+ <strong>
+ <xsl:for-each select="str:split(ex:message, ' ')">
+ <xsl:if test="normalize-space(.)">
+ <xsl:value-of select="."/>
+ <br/>
+ </xsl:if>
+ </xsl:for-each>
+ </strong>
+ <table>
+ <xsl:for-each select="ex:locations/*">
+ <!--xsl:sort select="position()" order="descending"/-->
+ <tr class="row-{position() mod 2}">
+ <td><xsl:call-template name="print-location"/></td>
+ <td><em><xsl:value-of select="."/></em></td>
+ </tr>
+ <!--xsl:apply-templates select="."/><br/-->
+ </xsl:for-each>
+ </table>
+ <br/>
+ </xsl:for-each>
+ </div>
<xsl:apply-templates select="ex:stacktrace"/>
<xsl:apply-templates select="ex:full-stacktrace"/>
@@ -130,37 +148,7 @@
</body>
</html>
</xsl:template>
-
- <xsl:template match="ex:location">
- <p>
- <strong>
- <xsl:for-each select="str:split(., ' ')">
- <xsl:if test="normalize-space(.)">
- <xsl:value-of select="."/>
- </xsl:if>
- </xsl:for-each>
- </strong>
- <br/>
- <xsl:call-template name="dump-location"/>
- </p>
- </xsl:template>
- <xsl:template match="ex:location-list">
- <p>
- <strong>
- <xsl:for-each select="str:split(ex:description, ' ')">
- <xsl:if test="normalize-space(.)">
- <xsl:value-of select="."/>
- </xsl:if>
- </xsl:for-each>
- </strong>
- <xsl:for-each select="ex:location">
- <br/>
- <xsl:call-template name="dump-location"/>
- </xsl:for-each>
- </p>
- </xsl:template>
-
<xsl:template match="ex:stacktrace|ex:full-stacktrace">
<p class="stacktrace">
<span class="description">Java <xsl:value-of select="translate(local-name(), '-', ' ')"/></span>
@@ -171,18 +159,26 @@
</p>
</xsl:template>
- <xsl:template name="dump-location">
- <xsl:choose>
- <xsl:when test="contains(@uri, $realPath)">
- <xsl:text>context:/</xsl:text>
- <xsl:value-of select="substring-after(@uri, $realPath)"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="@uri"/>
- </xsl:otherwise>
- </xsl:choose>
- <xsl:text> - </xsl:text>
- <xsl:value-of select="@line"/>:<xsl:value-of select="@column"/>
+ <xsl:template match="ex:location">
+ <xsl:if test="string-length(.) > 0">
+ <em><xsl:value-of select="."/></em>
+ <xsl:text> - </xsl:text>
+ </xsl:if>
+ <xsl:call-template name="print-location"/>
+ </xsl:template>
+
+ <xsl:template name="print-location">
+ <xsl:choose>
+ <xsl:when test="contains(@uri, $realPath)">
+ <xsl:text>context:/</xsl:text>
+ <xsl:value-of select="substring-after(@uri, $realPath)"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="@uri"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ <xsl:text> - </xsl:text>
+ <xsl:value-of select="@line"/>:<xsl:value-of select="@column"/>
</xsl:template>
</xsl:stylesheet>