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/04/18 09:44:33 UTC

svn commit: r649396 - in /xmlgraphics/fop/trunk/src/java: META-INF/services/ org/apache/fop/apps/ org/apache/fop/area/ org/apache/fop/fo/pagination/ org/apache/fop/layoutmgr/

Author: jeremias
Date: Fri Apr 18 00:44:32 2008
New Revision: 649396

URL: http://svn.apache.org/viewvc?rev=649396&view=rev
Log:
Introduced PageProductionException and fixed exception throwing for the event related to this exception. It's a RuntimeException descendant as making it a checked exception would have made changes necessary to at least a dozen more classes. Our overall exception style is still not so good.

Added:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageProductionException.java   (with props)
Modified:
    xmlgraphics/fop/trunk/src/java/META-INF/services/org.apache.fop.events.EventExceptionManager$ExceptionFactory
    xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOPException.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/area/RenderPagesModel.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageSequence.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageProvider.java

Modified: xmlgraphics/fop/trunk/src/java/META-INF/services/org.apache.fop.events.EventExceptionManager$ExceptionFactory
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/META-INF/services/org.apache.fop.events.EventExceptionManager%24ExceptionFactory?rev=649396&r1=649395&r2=649396&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/META-INF/services/org.apache.fop.events.EventExceptionManager$ExceptionFactory (original)
+++ xmlgraphics/fop/trunk/src/java/META-INF/services/org.apache.fop.events.EventExceptionManager$ExceptionFactory Fri Apr 18 00:44:32 2008
@@ -2,3 +2,4 @@
 org.apache.fop.events.PropertyExceptionFactory
 org.apache.fop.events.UnsupportedOperationExceptionFactory
 org.apache.fop.layoutmgr.LayoutException$LayoutExceptionFactory
+org.apache.fop.fo.pagination.PageProductionException$PageProductionExceptionFactory

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOPException.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOPException.java?rev=649396&r1=649395&r2=649396&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOPException.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOPException.java Fri Apr 18 00:44:32 2008
@@ -103,7 +103,7 @@
      * @param systemId the system id of the FO document which is associated with the exception;
      *                 may be null.
      * @param line line number in the FO document which is associated with the exception.
-     * @param column clolumn number in the line which is associated with the exception.
+     * @param column column number in the line which is associated with the exception.
      */
     public void setLocation(String systemId, int line, int column) {
         this.systemId = systemId;

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/area/RenderPagesModel.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/area/RenderPagesModel.java?rev=649396&r1=649395&r2=649396&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/area/RenderPagesModel.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/area/RenderPagesModel.java Fri Apr 18 00:44:32 2008
@@ -31,6 +31,7 @@
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.render.Renderer;
+import org.apache.fop.render.RendererEventProducer;
 
 /**
  * This uses the AreaTreeModel to store the pages
@@ -115,8 +116,12 @@
                 String err = "Error while rendering page " + page.getPageNumberString(); 
                 log.error(err, re);
                 throw re;
-            } catch (Exception e) {
-                //TODO use error handler to handle this FOP or IO Exception or propagate exception
+            } catch (IOException ioe) {
+                RendererEventProducer eventProducer = RendererEventProducer.Provider.get(
+                        renderer.getUserAgent().getEventBroadcaster());
+                eventProducer.ioError(this, ioe);
+            } catch (FOPException e) {
+                //TODO use error handler to handle this FOPException or propagate exception
                 String err = "Error while rendering page " + page.getPageNumberString(); 
                 log.error(err, e);
                 throw new IllegalStateException("Fatal error occurred. Cannot continue. " 

Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageProductionException.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageProductionException.java?rev=649396&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageProductionException.java (added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageProductionException.java Fri Apr 18 00:44:32 2008
@@ -0,0 +1,106 @@
+/*
+ * 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.fo.pagination;
+
+import java.util.Locale;
+
+import org.xml.sax.Locator;
+import org.xml.sax.helpers.LocatorImpl;
+
+import org.apache.fop.events.Event;
+import org.apache.fop.events.EventFormatter;
+import org.apache.fop.events.EventExceptionManager.ExceptionFactory;
+
+/**
+ * Exception thrown by FOP if there is a problem while producing new pages.
+ */
+public class PageProductionException extends RuntimeException {
+
+    private static final long serialVersionUID = -5126033718398975158L;
+
+    private String localizedMessage;
+    private Locator locator;
+    
+    /**
+     * Creates a new PageProductionException.
+     * @param message the message
+     * @param locator the optional locator that points to the error in the source file
+     */
+    public PageProductionException(String message, Locator locator) {
+        super(message);
+        setLocator(locator);
+    }
+    
+    /**
+     * Set a location associated with the exception.
+     * @param locator the locator holding the location.
+     */
+    public void setLocator(Locator locator) {
+        this.locator = new LocatorImpl(locator);
+    }
+
+
+    /**
+     * Returns the locattion associated with the exception.
+     * @return the locator or null if the location information is not available
+     */
+    public Locator getLocator() {
+        return this.locator;
+    }
+    
+    /**
+     * Sets the localized message for this exception.
+     * @param msg the localized message
+     */
+    public void setLocalizedMessage(String msg) {
+        this.localizedMessage = msg;
+    }
+
+    /** {@inheritDoc} */
+    public String getLocalizedMessage() {
+        if (this.localizedMessage != null) {
+            return this.localizedMessage;
+        } else {
+            return super.getLocalizedMessage();
+        }
+    }
+    
+    /** Exception factory for {@link PageProductionException}. */
+    public static class PageProductionExceptionFactory implements ExceptionFactory {
+
+        /** {@inheritDoc} */
+        public Throwable createException(Event event) {
+            Object obj = event.getParam("loc");
+            Locator loc = (obj instanceof Locator ? (Locator)obj : null);
+            String msg = EventFormatter.format(event, Locale.ENGLISH);
+            PageProductionException ex = new PageProductionException(msg, loc);
+            if (!Locale.ENGLISH.equals(Locale.getDefault())) {
+                ex.setLocalizedMessage(EventFormatter.format(event));
+            }
+            return ex;
+        }
+        
+        /** {@inheritDoc} */
+        public Class getExceptionClass() {
+            return PageProductionException.class;
+        }
+        
+    }    
+}

Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageProductionException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageProductionException.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageSequence.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageSequence.java?rev=649396&r1=649395&r2=649396&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageSequence.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageSequence.java Fri Apr 18 00:44:32 2008
@@ -371,13 +371,13 @@
      *      page sequence
      * @param isBlank indicator whether the page will be blank
      * @return the SimplePageMaster to use for this page
-     * @throws FOPException if there's a problem determining the page master
+     * @throws PageProductionException if there's a problem determining the page master
      */
     public SimplePageMaster getNextSimplePageMaster(int page, 
             boolean isFirstPage,  
             boolean isLastPage,  
             boolean isOnlyPage,
-            boolean isBlank) throws FOPException {
+            boolean isBlank) throws PageProductionException {
 
         if (pageSequenceMaster == null) {
             return simplePageMaster;

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java?rev=649396&r1=649395&r2=649396&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java Fri Apr 18 00:44:32 2008
@@ -189,14 +189,14 @@
      * @param isOnlyPage True if the next page is the only page
      * @param isBlankPage True if the next page is blank
      * @return the requested page master
-     * @throws FOPException if there's a problem determining the next page master
+     * @throws PageProductionException if there's a problem determining the next page master
      */
     public SimplePageMaster getNextSimplePageMaster(boolean isOddPage,
                                                     boolean isFirstPage,
                                                     boolean isLastPage,
                                                     boolean isOnlyPage,
                                                     boolean isBlankPage)
-                                                      throws FOPException {
+                                                      throws PageProductionException {
         if (currentSubSequence == null) {
             currentSubSequence = getNextSubSequence();
             if (currentSubSequence == null) {

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java?rev=649396&r1=649395&r2=649396&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java Fri Apr 18 00:44:32 2008
@@ -19,7 +19,6 @@
  
 package org.apache.fop.fo.pagination;
 
-import org.apache.fop.apps.FOPException;
 
 /**
  * Classes that implement this interface can be added to a PageSequenceMaster,
@@ -35,14 +34,14 @@
      * @param isOnlyPage True if the next page is the only page
      * @param isBlankPage True if the next page is blank
      * @return the page master name
-     * @throws FOPException if there's a problem determining the next page master
+     * @throws PageProductionException if there's a problem determining the next page master
      */
     String getNextPageMasterName(boolean isOddPage,
                                  boolean isFirstPage,
                                  boolean isLastPage,
                                  boolean isOnlyPage,
                                  boolean isBlankPage)
-                                    throws FOPException;
+                                    throws PageProductionException;
 
     /**
      * Called before a new page sequence is rendered so subsequences can reset

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.java?rev=649396&r1=649395&r2=649396&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.java Fri Apr 18 00:44:32 2008
@@ -21,9 +21,9 @@
 
 import org.xml.sax.Locator;
 
-import org.apache.fop.apps.FOPException;
 import org.apache.fop.events.EventBroadcaster;
 import org.apache.fop.events.EventProducer;
+import org.apache.fop.fo.pagination.PageProductionException;
 
 /**
  * Event producer interface for block-level layout managers.
@@ -136,22 +136,22 @@
      * @param pageSequenceMasterName the name of the page sequence master
      * @param canRecover indicates whether FOP can recover from this problem and continue working
      * @param loc the location of the error or null
-     * @throws FOPException the error provoked by the method call
+     * @throws PageProductionException the error provoked by the method call
      * @event.severity FATAL
      */
     void pageSequenceMasterExhausted(Object source, String pageSequenceMasterName,
-            boolean canRecover, Locator loc) throws FOPException;
+            boolean canRecover, Locator loc) throws PageProductionException;
 
     /**
      * No subsequences in page sequence master.
      * @param source the event source
      * @param pageSequenceMasterName the name of the page sequence master
      * @param loc the location of the error or null
-     * @throws FOPException the error provoked by the method call
+     * @throws PageProductionException the error provoked by the method call
      * @event.severity FATAL
      */
     void missingSubsequencesInPageSequenceMaster(Object source, String pageSequenceMasterName,
-            Locator loc) throws FOPException;
+            Locator loc) throws PageProductionException;
     
     /**
      * No single-page-master matching in page sequence master.
@@ -159,10 +159,10 @@
      * @param pageSequenceMasterName the name of the page sequence master
      * @param pageMasterName the name of the page master not matching
      * @param loc the location of the error or null
-     * @throws FOPException the error provoked by the method call
+     * @throws PageProductionException the error provoked by the method call
      * @event.severity FATAL
      */
     void noMatchingPageMaster(Object source, String pageSequenceMasterName,
-            String pageMasterName, Locator loc) throws FOPException;
+            String pageMasterName, Locator loc) throws PageProductionException;
     
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageProvider.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageProvider.java?rev=649396&r1=649395&r2=649396&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageProvider.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageProvider.java Fri Apr 18 00:44:32 2008
@@ -24,7 +24,6 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import org.apache.fop.apps.FOPException;
 import org.apache.fop.area.AreaTreeHandler;
 import org.apache.fop.fo.Constants;
 import org.apache.fop.fo.pagination.PageSequence;
@@ -196,10 +195,10 @@
     }
     
     /**
-     * 
-     * @param isBlank   true if the Page should be a blank one
+     * Returns a Page.
+     * @param isBlank true if the Page should be a blank one
      * @param index the Page's index
-     * @return  a Page instance
+     * @return a Page instance
      */
     protected Page getPage(boolean isBlank, int index) {
         boolean isLastPage = (lastPageIndex >= 0) && (index == lastPageIndex);
@@ -251,31 +250,25 @@
     }
     
     private Page cacheNextPage(int index, boolean isBlank, boolean isLastPage) {
-        try {
-            String pageNumberString = pageSeq.makeFormattedPageNumber(index);
-            SimplePageMaster spm = pageSeq.getNextSimplePageMaster(
-                    index, (startPageOfPageSequence == index), isLastPage, false, isBlank);
-                
-            Region body = spm.getRegion(FO_REGION_BODY);
-            if (!pageSeq.getMainFlow().getFlowName().equals(body.getRegionName())) {
-                // this is fine by the XSL Rec (fo:flow's flow-name can be mapped to
-                // any region), but we don't support it yet.
-                BlockLevelEventProducer eventProducer = BlockLevelEventProducer.Provider.get(
-                        pageSeq.getUserAgent().getEventBroadcaster());
-                eventProducer.flowNotMappingToRegionBody(this,
-                        pageSeq.getMainFlow().getFlowName(), spm.getMasterName(), spm.getLocator());
-            }
-            Page page = new Page(spm, index, pageNumberString, isBlank);
-            //Set unique key obtained from the AreaTreeHandler
-            page.getPageViewport().setKey(areaTreeHandler.generatePageViewportKey());
-            page.getPageViewport().setForeignAttributes(spm.getForeignAttributes());
-            cachedPages.add(page);
-            return page;
-        } catch (FOPException e) {
-            //TODO Maybe improve. It'll mean to propagate this exception up several
-            //methods calls.
-            throw new IllegalStateException(e.getMessage());
-        }
+        String pageNumberString = pageSeq.makeFormattedPageNumber(index);
+        SimplePageMaster spm = pageSeq.getNextSimplePageMaster(
+                index, (startPageOfPageSequence == index), isLastPage, false, isBlank);
+            
+        Region body = spm.getRegion(FO_REGION_BODY);
+        if (!pageSeq.getMainFlow().getFlowName().equals(body.getRegionName())) {
+            // this is fine by the XSL Rec (fo:flow's flow-name can be mapped to
+            // any region), but we don't support it yet.
+            BlockLevelEventProducer eventProducer = BlockLevelEventProducer.Provider.get(
+                    pageSeq.getUserAgent().getEventBroadcaster());
+            eventProducer.flowNotMappingToRegionBody(this,
+                    pageSeq.getMainFlow().getFlowName(), spm.getMasterName(), spm.getLocator());
+        }
+        Page page = new Page(spm, index, pageNumberString, isBlank);
+        //Set unique key obtained from the AreaTreeHandler
+        page.getPageViewport().setKey(areaTreeHandler.generatePageViewportKey());
+        page.getPageViewport().setForeignAttributes(spm.getForeignAttributes());
+        cachedPages.add(page);
+        return page;
     }
-    
+
 }



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