maven-doxia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r385397 - in /maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia: macro/ macro/snippet/ module/apt/ parser/
Date Mon, 13 Mar 2006 00:52:25 GMT
Author: brett
Date: Sun Mar 12 16:52:22 2006
New Revision: 385397

URL: http://svn.apache.org/viewcvs?rev=385397&view=rev
Log:
[DOXIA-56] clean up macro exception handling

Added:
    maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/MacroExecutionException.java
  (with props)
Modified:
    maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/EchoMacro.java
    maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/Macro.java
    maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetMacro.java
    maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/apt/AptParseException.java
    maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java
    maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractParser.java

Modified: maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/EchoMacro.java
URL: http://svn.apache.org/viewcvs/maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/EchoMacro.java?rev=385397&r1=385396&r2=385397&view=diff
==============================================================================
--- maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/EchoMacro.java
(original)
+++ maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/EchoMacro.java
Sun Mar 12 16:52:22 2006
@@ -28,7 +28,6 @@
     extends AbstractMacro
 {
     public void execute( Sink sink, MacroRequest request )
-        throws Exception
     {
         sink.verbatim( true );
 

Modified: maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/Macro.java
URL: http://svn.apache.org/viewcvs/maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/Macro.java?rev=385397&r1=385396&r2=385397&view=diff
==============================================================================
--- maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/Macro.java (original)
+++ maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/Macro.java Sun
Mar 12 16:52:22 2006
@@ -27,6 +27,6 @@
     String ROLE = Macro.class.getName();
 
     void execute( Sink sink, MacroRequest request )
-        throws Exception;
+        throws MacroExecutionException;
 
 }

Added: maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/MacroExecutionException.java
URL: http://svn.apache.org/viewcvs/maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/MacroExecutionException.java?rev=385397&view=auto
==============================================================================
--- maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/MacroExecutionException.java
(added)
+++ maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/MacroExecutionException.java
Sun Mar 12 16:52:22 2006
@@ -0,0 +1,31 @@
+package org.apache.maven.doxia.macro;
+
+/*
+ * Copyright 2001-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.
+ */
+
+/**
+ * Warp an exception that occurs during the execution of a Doxia macro.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public class MacroExecutionException
+    extends Exception
+{
+    public MacroExecutionException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+}

Propchange: maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/MacroExecutionException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/MacroExecutionException.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetMacro.java
URL: http://svn.apache.org/viewcvs/maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetMacro.java?rev=385397&r1=385396&r2=385397&view=diff
==============================================================================
--- maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetMacro.java
(original)
+++ maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetMacro.java
Sun Mar 12 16:52:22 2006
@@ -17,6 +17,7 @@
  */
 
 import org.apache.maven.doxia.macro.AbstractMacro;
+import org.apache.maven.doxia.macro.MacroExecutionException;
 import org.apache.maven.doxia.macro.MacroRequest;
 import org.apache.maven.doxia.sink.Sink;
 
@@ -44,7 +45,7 @@
     private boolean debug = false;
 
     public void execute( Sink sink, MacroRequest request )
-        throws Exception
+        throws MacroExecutionException
     {
         String id = (String) request.getParameter( "id" );
 
@@ -67,7 +68,15 @@
 
         String lang = (String) request.getParameter( "lang" );
 
-        StringBuffer snippet = getSnippet( url, id );
+        StringBuffer snippet = null;
+        try
+        {
+            snippet = getSnippet( url, id );
+        }
+        catch ( IOException e )
+        {
+            throw new MacroExecutionException( "Error reading snippet", e );
+        }
 
         sink.verbatim( true );
 

Modified: maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/apt/AptParseException.java
URL: http://svn.apache.org/viewcvs/maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/apt/AptParseException.java?rev=385397&r1=385396&r2=385397&view=diff
==============================================================================
--- maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/apt/AptParseException.java
(original)
+++ maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/apt/AptParseException.java
Sun Mar 12 16:52:22 2006
@@ -26,6 +26,11 @@
         super( null, message, source.getName(), source.getLineNumber() );
     }
 
+    public AptParseException( String message, AptSource source, Exception e )
+    {
+        super( e, message, source.getName(), source.getLineNumber() );
+    }
+
     public AptParseException( String message )
     {
         super( message );

Modified: maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java
URL: http://svn.apache.org/viewcvs/maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java?rev=385397&r1=385396&r2=385397&view=diff
==============================================================================
--- maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java
(original)
+++ maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java
Sun Mar 12 16:52:22 2006
@@ -16,7 +16,9 @@
  * limitations under the License.
  */
 
+import org.apache.maven.doxia.macro.MacroExecutionException;
 import org.apache.maven.doxia.macro.MacroRequest;
+import org.apache.maven.doxia.macro.manager.MacroNotFoundException;
 import org.apache.maven.doxia.parser.AbstractParser;
 import org.apache.maven.doxia.sink.Sink;
 import org.apache.maven.doxia.sink.SinkAdapter;
@@ -84,9 +86,6 @@
 
     private AptSource source;
 
-    /**
-     * @ignore
-     */
     private Sink sink;
 
     private String line;
@@ -2134,7 +2133,18 @@
 
             MacroRequest request = new MacroRequest( parameters );
 
-            AptParser.this.executeMacro( macroId, request, sink );
+            try
+            {
+                AptParser.this.executeMacro( macroId, request, sink );
+            }
+            catch ( MacroExecutionException e )
+            {
+                throw new AptParseException( "Unable to execute macro in the APT document",
source, e );
+            }
+            catch ( MacroNotFoundException e )
+            {
+                throw new AptParseException( "Unable to find macro used in the APT document",
source, e );
+            }
         }
     }
 

Modified: maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractParser.java
URL: http://svn.apache.org/viewcvs/maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractParser.java?rev=385397&r1=385396&r2=385397&view=diff
==============================================================================
--- maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractParser.java
(original)
+++ maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractParser.java
Sun Mar 12 16:52:22 2006
@@ -17,6 +17,7 @@
  */
 
 import org.apache.maven.doxia.macro.Macro;
+import org.apache.maven.doxia.macro.MacroExecutionException;
 import org.apache.maven.doxia.macro.MacroRequest;
 import org.apache.maven.doxia.macro.manager.MacroManager;
 import org.apache.maven.doxia.macro.manager.MacroNotFoundException;
@@ -38,25 +39,10 @@
     // Made public right now because of the structure of the APT parser and
     // all its inner classes.
     public void executeMacro( String macroId, MacroRequest request, Sink sink )
+        throws MacroExecutionException, MacroNotFoundException
     {
-        try
-        {
-            Macro macro = macroManager.getMacro( macroId );
+        Macro macro = macroManager.getMacro( macroId );
 
-            try
-            {
-                macro.execute( sink, request );
-            }
-            catch ( Exception e )
-            {
-                // TODO: this is not right
-                e.printStackTrace();
-            }
-        }
-        catch ( MacroNotFoundException e )
-        {
-            // TODO: this should probably be thrown out somewhere
-            System.out.println( "The requested macro with id = " + macroId + " cannot be
found." );
-        }
+        macro.execute( sink, request );
     }
 }



Mime
View raw message