cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anathan...@apache.org
Subject svn commit: r349094 - in /cocoon/branches/BRANCH_2_1_X: ./ src/blocks/xsp/java/org/apache/cocoon/components/language/markup/ src/blocks/xsp/java/org/apache/cocoon/components/language/markup/xsp/
Date Sat, 26 Nov 2005 07:18:27 GMT
Author: anathaniel
Date: Fri Nov 25 23:18:20 2005
New Revision: 349094

URL: http://svn.apache.org/viewcvs?rev=349094&view=rev
Log:
XSP block: Instrument {#expr} interpolation to produce Cocoon stacktrace for parse errors.

Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/markup/LogicsheetFilter.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/markup/xsp/XSPExpressionFilter.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/markup/xsp/XSPExpressionParser.java
    cocoon/branches/BRANCH_2_1_X/status.xml

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/markup/LogicsheetFilter.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/markup/LogicsheetFilter.java?rev=349094&r1=349093&r2=349094&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/markup/LogicsheetFilter.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/markup/LogicsheetFilter.java
Fri Nov 25 23:18:20 2005
@@ -15,6 +15,7 @@
  */
 package org.apache.cocoon.components.language.markup;
 
+import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
 import org.xml.sax.XMLReader;
 import org.xml.sax.helpers.XMLFilterImpl;
@@ -30,7 +31,20 @@
  * @version $Id$
  */
 public class LogicsheetFilter extends XMLFilterImpl {
+
+    protected Locator locator;
+
     private Map namespaces;
+
+    /**
+     * Receive an object for locating the origin of SAX document events.
+     *
+     * @param locator An object that can return the location of any SAX
+     *                document event.
+     */
+    public void setDocumentLocator(Locator locator) {
+        this.locator = locator;
+    }
 
     /**
      * The filter needs an initialized <code>Map</code> object where it

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/markup/xsp/XSPExpressionFilter.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/markup/xsp/XSPExpressionFilter.java?rev=349094&r1=349093&r2=349094&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/markup/xsp/XSPExpressionFilter.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/markup/xsp/XSPExpressionFilter.java
Fri Nov 25 23:18:20 2005
@@ -24,6 +24,7 @@
 import org.apache.commons.lang.StringUtils;
 import org.xml.sax.Attributes;
 import org.xml.sax.ContentHandler;
+import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
 import org.xml.sax.ext.LexicalHandler;
 
@@ -61,6 +62,11 @@
         public void setLexicalHandler(LexicalHandler handler) {
             additionalFilter.setLexicalHandler(handler);
         }
+
+        public void setDocumentLocator(Locator locator) {
+            additionalFilter.setDocumentLocator(locator);
+            expressionFilter.setDocumentLocator(locator);
+        }
     }
 
 
@@ -109,7 +115,7 @@
      */
     public void startElement(String namespaceURI, String localName, String qName, Attributes
attribs)
     throws SAXException {
-        expressionParser.flush();
+        expressionParser.flush(locator, "...<"+qName+">");
 
         // Check template for interpolation flags
         attribs = pushInterpolationStack(attribs);
@@ -149,11 +155,12 @@
                     addAttribute(elemAttribs, "prefix", StringUtils.left(qname, qname.indexOf(':')));
                 }
 
-                addAttribute(elemAttribs, "name", dynamicAttribs.getLocalName(i));
+                String attrName = dynamicAttribs.getLocalName(i);
+                addAttribute(elemAttribs, "name", attrName);
 
                 super.startElement(markupURI, "attribute", markupPrefix + ":attribute", elemAttribs);
                 expressionParser.consume(dynamicAttribs.getValue(i));
-                expressionParser.flush();
+                expressionParser.flush(locator, "<"+qName+" "+attrName+"=\"...\">");
                 super.endElement(markupURI, "attribute", markupPrefix + ":attribute");
             }
         } else {
@@ -205,7 +212,7 @@
      * Flush the current expression.
      */
     public void endElement(String uri, String loc, String raw) throws SAXException {
-        expressionParser.flush();
+        expressionParser.flush(locator, "...</"+raw+">");
         super.endElement(uri, loc, raw);
 
         // Pop stack of interpolation settings.

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/markup/xsp/XSPExpressionParser.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/markup/xsp/XSPExpressionParser.java?rev=349094&r1=349093&r2=349094&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/markup/xsp/XSPExpressionParser.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/java/org/apache/cocoon/components/language/markup/xsp/XSPExpressionParser.java
Fri Nov 25 23:18:20 2005
@@ -15,6 +15,10 @@
  */
 package org.apache.cocoon.components.language.markup.xsp;
 
+import org.apache.cocoon.util.location.LocatedException;
+import org.apache.cocoon.util.location.LocationUtils;
+
+import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
 
 /**
@@ -320,12 +324,21 @@
     /**
      * Flushes the parser
      * 
+     * @param locator The SAX locator to determine the current parse position
+     * @param description The description of the current parse context
      * @throws SAXException If there is an error in the parsed text.
+     *         A wrapped LocatedException contains the location of the parse error.
      */
-    public void flush() throws SAXException {
-        state.done(this);
-        bufSize = 0;
-        state = TEXT_STATE;
+    public void flush(Locator locator, String description) throws SAXException {
+        try {
+            state.done(this);
+            bufSize = 0;
+            state = TEXT_STATE;
+        }
+        catch(SAXException ex) {
+            throw new SAXException(new LocatedException(ex.getMessage(), ex,
+                                                        LocationUtils.getLocation(locator,
description)));
+        }
     }
 
     protected State getState() {

Modified: cocoon/branches/BRANCH_2_1_X/status.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/status.xml?rev=349094&r1=349093&r2=349094&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml Fri Nov 25 23:18:20 2005
@@ -179,6 +179,9 @@
   <release version="@version@" date="@date@">
 -->
   <release version="2.1.9" date="TBD">
+    <action dev="AN" type="add">
+      XSP block: Instrument {#expr} interpolation to produce Cocoon stacktrace for parse
errors.
+    </action>
     <action dev="CZ" type="fix">
       Portal block: Fix possible encoding problems with JSR 168 portlets.
     </action>



Mime
View raw message