You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2008/03/06 15:38:32 UTC

svn commit: r634280 - in /xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java: META-INF/services/ org/apache/fop/events/ org/apache/fop/fo/ org/apache/fop/fo/flow/table/

Author: jeremias
Date: Thu Mar  6 06:38:30 2008
New Revision: 634280

URL: http://svn.apache.org/viewvc?rev=634280&view=rev
Log:
ExceptionFactory is now dynamically registered.
More table warnings and errors switch to events.

Added:
    xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/META-INF/services/org.apache.fop.events.EventExceptionManager$ExceptionFactory
    xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/PropertyExceptionFactory.java   (with props)
    xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/ValidationExceptionFactory.java   (with props)
Modified:
    xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/EventExceptionManager.java
    xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/EventFormatter.xml
    xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/PropertyList.java
    xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/table/TableCellContainer.java
    xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/table/TableColumn.java
    xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/table/TableEventProducer.java

Added: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/META-INF/services/org.apache.fop.events.EventExceptionManager$ExceptionFactory
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/META-INF/services/org.apache.fop.events.EventExceptionManager%24ExceptionFactory?rev=634280&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/META-INF/services/org.apache.fop.events.EventExceptionManager$ExceptionFactory (added)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/META-INF/services/org.apache.fop.events.EventExceptionManager$ExceptionFactory Thu Mar  6 06:38:30 2008
@@ -0,0 +1,2 @@
+org.apache.fop.events.ValidationExceptionFactory
+org.apache.fop.events.PropertyExceptionFactory

Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/EventExceptionManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/EventExceptionManager.java?rev=634280&r1=634279&r2=634280&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/EventExceptionManager.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/EventExceptionManager.java Thu Mar  6 06:38:30 2008
@@ -19,12 +19,10 @@
 
 package org.apache.fop.events;
 
-import java.util.Locale;
+import java.util.Iterator;
 import java.util.Map;
 
-import org.xml.sax.Locator;
-
-import org.apache.fop.fo.ValidationException;
+import org.apache.xmlgraphics.util.Service;
 
 /**
  * This class is reponsible for converting events into exceptions.
@@ -34,9 +32,12 @@
     private static final Map EXCEPTION_FACTORIES = new java.util.HashMap();
     
     static {
-        //TODO Replace with dynamic registration if more than two different exceptions are needed.
-        EXCEPTION_FACTORIES.put(ValidationException.class.getName(),
-                new ValidationExceptionFactory());
+        Iterator iter;
+        iter = Service.providers(ExceptionFactory.class, true);
+        while (iter.hasNext()) {
+            ExceptionFactory factory = (ExceptionFactory)iter.next();
+            EXCEPTION_FACTORIES.put(factory.getExceptionClass().getName(), factory);
+        }
     }
     
     /**
@@ -46,34 +47,36 @@
      * @throws Throwable this happens always
      */
     public static void throwException(Event event, String exceptionClass) throws Throwable {
-        
-        //TODO Complain if there's no ExceptionFactory for the given exceptionClass
-        
         ExceptionFactory factory = (ExceptionFactory)EXCEPTION_FACTORIES.get(exceptionClass);
         if (factory != null) {
             throw factory.createException(event);
         } else {
+            throw new IllegalArgumentException(
+                    "No such ExceptionFactory available: " + exceptionClass);
+            /*
             String msg = EventFormatter.format(event);
             throw new RuntimeException(msg);
+            */
         }
     }
     
-    private interface ExceptionFactory {
+    /**
+     * This interface is implementation by exception factories that can create exceptions from
+     * events.
+     */
+    public interface ExceptionFactory {
+        
+        /**
+         * Creates an exception from an event.
+         * @param event the event
+         * @return the newly created exception
+         */
         Throwable createException(Event event);
-    }
-    
-    //TODO Move me out of here as I'm FOP-dependent!
-    private static class ValidationExceptionFactory implements ExceptionFactory {
-
-        public Throwable createException(Event event) {
-            Locator loc = (Locator)event.getParam("loc");
-            String msg = EventFormatter.format(event, Locale.ENGLISH);
-            ValidationException ex = new ValidationException(msg, loc);
-            if (!Locale.ENGLISH.equals(Locale.getDefault())) {
-                ex.setLocalizedMessage(EventFormatter.format(event));
-            }
-            return ex;
-        }
         
+        /**
+         * Returns the {@link Exception} class created by this factory.
+         * @return the exception class
+         */
+        Class getExceptionClass();
     }
 }

Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/EventFormatter.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/EventFormatter.xml?rev=634280&r1=634279&r2=634280&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/EventFormatter.xml (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/EventFormatter.xml Thu Mar  6 06:38:30 2008
@@ -36,4 +36,7 @@
   <message key="org.apache.fop.fo.flow.table.TableEventProducer.noMixRowsAndCells">Either fo:table-rows or fo:table-cells may be children of an {elementName} but not both.{{locator}}</message>
   <message key="org.apache.fop.fo.flow.table.TableEventProducer.footerOrderCannotRecover">This table uses the collapsing border model. In order to resolve borders in an efficient way the table-footer must be known before any table-body is parsed. Either put the footer at the correct place or switch to the separate border model.{{locator}}</message>
   <message key="org.apache.fop.fo.flow.table.TableEventProducer.startEndRowUnderTableRowWarning">starts-row/ends-row for fo:table-cells non-applicable for children of an fo:table-row.{{locator}}</message>
+  <message key="org.apache.fop.fo.flow.table.TableEventProducer.tooManyCells">The column-number or number of cells in the row overflows the number of fo:table-columns specified for the table.{{locator}}</message>
+  <message key="org.apache.fop.fo.flow.table.TableEventProducer.valueMustBeBiggerGtEqOne">{propName} must be 1 or bigger, but got {actualValue}{{locator}}</message>
+  <message key="org.apache.fop.fo.flow.table.TableEventProducer.warnImplicitColumns">table-layout=\"fixed\" and column-width unspecified => falling back to proportional-column-width(1){{locator}}</message>
 </catalogue>

Added: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/PropertyExceptionFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/PropertyExceptionFactory.java?rev=634280&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/PropertyExceptionFactory.java (added)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/PropertyExceptionFactory.java Thu Mar  6 06:38:30 2008
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.events;
+
+import java.util.Locale;
+
+import org.apache.fop.events.EventExceptionManager.ExceptionFactory;
+import org.apache.fop.fo.expr.PropertyException;
+
+/**
+ * Exception factory for {@link PropertyException}.
+ */
+public class PropertyExceptionFactory implements ExceptionFactory {
+
+    /** {@inheritDoc} */
+    public Throwable createException(Event event) {
+        String msg = EventFormatter.format(event, Locale.ENGLISH);
+        PropertyException ex = new PropertyException(msg);
+        if (!Locale.ENGLISH.equals(Locale.getDefault())) {
+            ex.setLocalizedMessage(EventFormatter.format(event));
+        }
+        return ex;
+    }
+    
+    /** {@inheritDoc} */
+    public Class getExceptionClass() {
+        return PropertyException.class;
+    }
+    
+}
\ No newline at end of file

Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/PropertyExceptionFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/PropertyExceptionFactory.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/ValidationExceptionFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/ValidationExceptionFactory.java?rev=634280&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/ValidationExceptionFactory.java (added)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/ValidationExceptionFactory.java Thu Mar  6 06:38:30 2008
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.events;
+
+import java.util.Locale;
+
+import org.xml.sax.Locator;
+
+import org.apache.fop.events.EventExceptionManager.ExceptionFactory;
+import org.apache.fop.fo.ValidationException;
+
+/**
+ * Exception factory for {@link ValidationException}.
+ */
+public class ValidationExceptionFactory implements ExceptionFactory {
+
+    /** {@inheritDoc} */
+    public Throwable createException(Event event) {
+        Locator loc = (Locator)event.getParam("loc");
+        String msg = EventFormatter.format(event, Locale.ENGLISH);
+        ValidationException ex = new ValidationException(msg, loc);
+        if (!Locale.ENGLISH.equals(Locale.getDefault())) {
+            ex.setLocalizedMessage(EventFormatter.format(event));
+        }
+        return ex;
+    }
+    
+    /** {@inheritDoc} */
+    public Class getExceptionClass() {
+        return ValidationException.class;
+    }
+    
+    
+}
\ No newline at end of file

Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/ValidationExceptionFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/events/ValidationExceptionFactory.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/PropertyList.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/PropertyList.java?rev=634280&r1=634279&r2=634280&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/PropertyList.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/PropertyList.java Thu Mar  6 06:38:30 2008
@@ -149,7 +149,7 @@
      * the default value.
      * @param propId The Constants ID of the property whose value is desired.
      * @return the Property corresponding to that name
-     * @throws PropertyException ...
+     * @throws PropertyException if there is a problem evaluating the property 
      */
     public Property get(int propId) throws PropertyException {
         return get(propId, true, true);
@@ -165,7 +165,7 @@
      *                      value is needed
      * @param bTryDefault   true when the default value may be used as a last resort
      * @return the property
-     * @throws PropertyException ...
+     * @throws PropertyException if there is a problem evaluating the property 
      */
     public Property get(int propId, boolean bTryInherit,
                          boolean bTryDefault) throws PropertyException {

Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/table/TableCellContainer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/table/TableCellContainer.java?rev=634280&r1=634279&r2=634280&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/table/TableCellContainer.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/table/TableCellContainer.java Thu Mar  6 06:38:30 2008
@@ -24,7 +24,6 @@
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.datatypes.Length;
 import org.apache.fop.fo.FONode;
-import org.apache.fop.fo.ValidationException;
 
 /**
  * A common class for fo:table-body and fo:table-row which both can contain fo:table-cell.
@@ -47,9 +46,9 @@
         Table t = getTable();
         if (t.hasExplicitColumns()) {
             if (colNumber + colSpan - 1 > t.getNumberOfColumns()) {
-                throw new ValidationException(FONode.errorText(locator) + "column-number or "
-                        + "number of cells in the row overflows the number of fo:table-column "
-                        + "specified for the table.");
+                TableEventProducer eventProducer = TableEventProducer.Factory.create(
+                        getUserAgent().getEventBroadcaster());
+                eventProducer.tooManyCells(this, getLocator());
             }
         } else {
             t.ensureColumnNumber(colNumber + colSpan - 1);

Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/table/TableColumn.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/table/TableColumn.java?rev=634280&r1=634279&r2=634280&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/table/TableColumn.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/table/TableColumn.java Thu Mar  6 06:38:30 2008
@@ -82,12 +82,16 @@
         super.bind(pList);
 
         if (numberColumnsRepeated <= 0) {
-            throw new PropertyException("number-columns-repeated must be 1 or bigger, "
-                    + "but got " + numberColumnsRepeated);
+            TableEventProducer eventProducer = TableEventProducer.Factory.create(
+                    getUserAgent().getEventBroadcaster());
+            eventProducer.valueMustBeBiggerGtEqOne(this,
+                    "number-columns-repeated", numberColumnsRepeated, getLocator());
         }
         if (numberColumnsSpanned <= 0) {
-            throw new PropertyException("number-columns-spanned must be 1 or bigger, "
-                    + "but got " + numberColumnsSpanned);
+            TableEventProducer eventProducer = TableEventProducer.Factory.create(
+                    getUserAgent().getEventBroadcaster());
+            eventProducer.valueMustBeBiggerGtEqOne(this,
+                    "number-columns-spanned", numberColumnsSpanned, getLocator());
         }
 
         /* check for unspecified width and replace with default of
@@ -96,8 +100,9 @@
          */
         if (columnWidth.getEnum() == EN_AUTO) {
             if (!this.implicitColumn && !getTable().isAutoLayout()) {
-                log.warn("table-layout=\"fixed\" and column-width unspecified "
-                        + "=> falling back to proportional-column-width(1)");
+                TableEventProducer eventProducer = TableEventProducer.Factory.create(
+                        getUserAgent().getEventBroadcaster());
+                eventProducer.warnImplicitColumns(this, getLocator());
             }
             columnWidth = new TableColLength(1.0, this);
         }
@@ -240,7 +245,7 @@
      * 
      * @param propId    the id for the property to retrieve
      * @return the requested Property
-     * @throws PropertyException
+     * @throws PropertyException if there is a problem evaluating the property 
      */
     public Property getProperty(int propId) throws PropertyException {
         return this.pList.get(propId);

Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/table/TableEventProducer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/table/TableEventProducer.java?rev=634280&r1=634279&r2=634280&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/table/TableEventProducer.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fo/flow/table/TableEventProducer.java Thu Mar  6 06:38:30 2008
@@ -24,6 +24,7 @@
 import org.apache.fop.events.EventBroadcaster;
 import org.apache.fop.events.EventProducer;
 import org.apache.fop.fo.ValidationException;
+import org.apache.fop.fo.expr.PropertyException;
 
 /**
  * Event producer interface for table-specific XSL-FO validation messages.
@@ -92,6 +93,37 @@
      * @event.severity WARN
      */
     void startEndRowUnderTableRowWarning(Object source, Locator loc);
+
+    /**
+     * Column-number or number of cells in the row overflows the number of fo:table-column 
+     * specified for the table.
+     * @param source the event source
+     * @param loc the location of the error or null
+     * @throws ValidationException the validation error provoked by the method call
+     * @event.severity FATAL
+     */
+    void tooManyCells(Object source, Locator loc) throws ValidationException;
+
+    /**
+     * Property value must be 1 or bigger.
+     * @param source the event source
+     * @param propName the property name
+     * @param actualValue the actual value
+     * @param loc the location of the error or null
+     * @throws PropertyException the validation error provoked by the method call
+     * @event.severity FATAL
+     */
+    void valueMustBeBiggerGtEqOne(Object source, String propName,
+            int actualValue, Locator loc) throws PropertyException;
+
+    /**
+     * table-layout=\"fixed\" and column-width unspecified
+     * => falling back to proportional-column-width(1)
+     * @param source the event source
+     * @param loc the location of the error or null
+     * @event.severity WARN
+     */
+    void warnImplicitColumns(Object source, Locator loc);
 
     
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org