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 ac...@apache.org on 2008/04/18 12:06:23 UTC

svn commit: r649444 - in /xmlgraphics/fop/branches/Temp_AFPGOCAResources: ./ examples/embedding/java/embedding/ src/java/META-INF/services/ src/java/org/apache/fop/apps/ src/java/org/apache/fop/area/ src/java/org/apache/fop/fo/pagination/ src/java/org/...

Author: acumiskey
Date: Fri Apr 18 03:06:07 2008
New Revision: 649444

URL: http://svn.apache.org/viewvc?rev=649444&view=rev
Log:
Merged revisions 649279,649283,649285,649393,649396,649420 via svnmerge from 
https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk

........
  r649279 | jeremias | 2008-04-17 22:23:15 +0100 (Thu, 17 Apr 2008) | 1 line
  
  clone() did not propagate the page's page index.
........
  r649283 | jeremias | 2008-04-17 22:25:02 +0100 (Thu, 17 Apr 2008) | 1 line
  
  Throw a useful exception when the user agent isn't set on the renderer. This has been a problem for more than one person setting up their own renderer using FOUserAgent.setRendererOverride().
........
  r649285 | jeremias | 2008-04-17 22:27:46 +0100 (Thu, 17 Apr 2008) | 2 lines
  
  Split PrintRenderer into PageableRenderer and PrintRenderer (extends PageableRenderer). This allows the use of FOP with JPS. A new example illustrates how this is done.
  Removed the code that sets start/end/copies from system properties (now done through renderer options).
........
  r649393 | jeremias | 2008-04-18 08:40:27 +0100 (Fri, 18 Apr 2008) | 1 line
  
  Forgot to include in commit for revision 649285.
........
  r649396 | jeremias | 2008-04-18 08:44:32 +0100 (Fri, 18 Apr 2008) | 1 line
  
  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.
........
  r649420 | jeremias | 2008-04-18 10:16:28 +0100 (Fri, 18 Apr 2008) | 1 line
  
  Fixed build problem. FOPException is no longer thrown there.
........

Added:
    xmlgraphics/fop/branches/Temp_AFPGOCAResources/examples/embedding/java/embedding/ExampleFO2JPSPrint.java
      - copied unchanged from r649420, xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleFO2JPSPrint.java
    xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/fo/pagination/PageProductionException.java
      - copied unchanged from r649420, xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageProductionException.java
    xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/print/PageableRenderer.java
      - copied unchanged from r649420, xmlgraphics/fop/trunk/src/java/org/apache/fop/render/print/PageableRenderer.java
Modified:
    xmlgraphics/fop/branches/Temp_AFPGOCAResources/   (props changed)
    xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/META-INF/services/org.apache.fop.events.EventExceptionManager$ExceptionFactory
    xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/apps/FOPException.java
    xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/area/PageViewport.java
    xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/area/RenderPagesModel.java
    xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/fo/pagination/PageSequence.java
    xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java
    xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java
    xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.java
    xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/layoutmgr/PageProvider.java
    xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/AbstractRenderer.java
    xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
    xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/print/PrintRenderer.java
    xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/rtf/RTFHandler.java
    xmlgraphics/fop/branches/Temp_AFPGOCAResources/status.xml

Propchange: xmlgraphics/fop/branches/Temp_AFPGOCAResources/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Fri Apr 18 03:06:07 2008
@@ -1 +1 @@
-/xmlgraphics/fop/trunk:1-649169
+/xmlgraphics/fop/trunk:1-649432

Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/META-INF/services/org.apache.fop.events.EventExceptionManager$ExceptionFactory
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/META-INF/services/org.apache.fop.events.EventExceptionManager%24ExceptionFactory?rev=649444&r1=649443&r2=649444&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/META-INF/services/org.apache.fop.events.EventExceptionManager$ExceptionFactory (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/META-INF/services/org.apache.fop.events.EventExceptionManager$ExceptionFactory Fri Apr 18 03:06:07 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/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/apps/FOPException.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/apps/FOPException.java?rev=649444&r1=649443&r2=649444&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/apps/FOPException.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/apps/FOPException.java Fri Apr 18 03:06:07 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/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/area/PageViewport.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/area/PageViewport.java?rev=649444&r1=649443&r2=649444&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/area/PageViewport.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/area/PageViewport.java Fri Apr 18 03:06:07 2008
@@ -124,6 +124,7 @@
         if (original.extensionAttachments != null) {
             this.extensionAttachments = new java.util.ArrayList(original.extensionAttachments);
         }
+        this.pageIndex = original.pageIndex;
         this.pageNumber = original.pageNumber;
         this.pageNumberString = original.pageNumberString;
         this.page = (Page)original.page.clone();

Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/area/RenderPagesModel.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/area/RenderPagesModel.java?rev=649444&r1=649443&r2=649444&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/area/RenderPagesModel.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/area/RenderPagesModel.java Fri Apr 18 03:06:07 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. " 

Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/fo/pagination/PageSequence.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/fo/pagination/PageSequence.java?rev=649444&r1=649443&r2=649444&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/fo/pagination/PageSequence.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/fo/pagination/PageSequence.java Fri Apr 18 03:06:07 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/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java?rev=649444&r1=649443&r2=649444&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java Fri Apr 18 03:06:07 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/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java?rev=649444&r1=649443&r2=649444&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java Fri Apr 18 03:06:07 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/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.java?rev=649444&r1=649443&r2=649444&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/layoutmgr/BlockLevelEventProducer.java Fri Apr 18 03:06:07 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/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/layoutmgr/PageProvider.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/layoutmgr/PageProvider.java?rev=649444&r1=649443&r2=649444&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/layoutmgr/PageProvider.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/layoutmgr/PageProvider.java Fri Apr 18 03:06:07 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;
     }
-    
+
 }

Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/AbstractRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/AbstractRenderer.java?rev=649444&r1=649443&r2=649444&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/AbstractRenderer.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/AbstractRenderer.java Fri Apr 18 03:06:07 2008
@@ -124,12 +124,19 @@
 
     /** {@inheritDoc} */
     public FOUserAgent getUserAgent() {
+        if (userAgent == null) {
+            throw new IllegalStateException("FOUserAgent has not been set on Renderer");
+        }
         return userAgent;
     }
 
     /** {@inheritDoc} */
     public void startRenderer(OutputStream outputStream)
-        throws IOException { }
+            throws IOException {
+        if (userAgent == null) {
+            throw new IllegalStateException("FOUserAgent has not been set on Renderer");
+        }
+    }
 
     /** {@inheritDoc} */
     public void stopRenderer()

Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/java2d/Java2DRenderer.java?rev=649444&r1=649443&r2=649444&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/java2d/Java2DRenderer.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/java2d/Java2DRenderer.java Fri Apr 18 03:06:07 2008
@@ -198,6 +198,7 @@
 
     /** {@inheritDoc} */
     public void startRenderer(OutputStream out) throws IOException {
+        super.startRenderer(out);
         // do nothing by default
     }
 
@@ -232,7 +233,9 @@
     }
 
     /**
+     * Returns the number of pages available. This method is also part of the Pageable interface.
      * @return The 0-based total number of rendered pages
+     * @see java.awt.print.Pageable
      */
     public int getNumberOfPages() {
         return pageViewportList.size();
@@ -250,7 +253,7 @@
     /**
      * This method override only stores the PageViewport in a List. No actual
      * rendering is performed here. A renderer override renderPage() to get the
-     * freshly produced PageViewport, and rendere them on the fly (producing the
+     * freshly produced PageViewport, and render them on the fly (producing the
      * desired BufferedImages by calling getPageImage(), which lazily starts the
      * rendering process).
      *
@@ -260,12 +263,23 @@
      * @see org.apache.fop.render.Renderer
      */
     public void renderPage(PageViewport pageViewport) throws IOException {
-        // TODO clone?
-        pageViewportList.add(pageViewport.clone());
+        rememberPage((PageViewport)pageViewport.clone());
+        //The clone() call is necessary as we store the page for later. Otherwise, the
+        //RenderPagesModel calls PageViewport.clear() to release memory as early as possible.
         currentPageNumber++;
     }
 
     /**
+     * Stores the pageViewport in a list of page viewports so they can be rendered later.
+     * Subclasses can override this method to filter pages, for example.
+     * @param pageViewport the page viewport
+     */
+    protected void rememberPage(PageViewport pageViewport) {
+        assert pageViewport.getPageIndex() >= 0;
+        pageViewportList.add(pageViewport);
+    }
+    
+    /**
      * Generates a desired page from the renderer's page viewport list.
      *
      * @param pageViewport the PageViewport to be rendered
@@ -362,17 +376,17 @@
     
     /**
      * Returns a page viewport.
-     * @param pageNum the page number
+     * @param pageIndex the page index (zero-based)
      * @return the requested PageViewport instance
      * @exception FOPException If the page is out of range.
      */
-    public PageViewport getPageViewport(int pageNum) throws FOPException {
-        if (pageNum < 0 || pageNum >= pageViewportList.size()) {
-            throw new FOPException("Requested page number is out of range: " + pageNum
+    public PageViewport getPageViewport(int pageIndex) throws FOPException {
+        if (pageIndex < 0 || pageIndex >= pageViewportList.size()) {
+            throw new FOPException("Requested page number is out of range: " + pageIndex
                      + "; only " + pageViewportList.size()
                      + " page(s) available.");
         }
-        return (PageViewport) pageViewportList.get(pageNum);
+        return (PageViewport) pageViewportList.get(pageIndex);
     }
 
     /**

Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/print/PrintRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/print/PrintRenderer.java?rev=649444&r1=649443&r2=649444&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/print/PrintRenderer.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/print/PrintRenderer.java Fri Apr 18 03:06:07 2008
@@ -19,20 +19,12 @@
 
 package org.apache.fop.render.print;
 
-import java.awt.geom.Rectangle2D;
-import java.awt.print.PageFormat;
-import java.awt.print.Pageable;
-import java.awt.print.Paper;
-import java.awt.print.Printable;
 import java.awt.print.PrinterException;
 import java.awt.print.PrinterJob;
 import java.io.IOException;
 import java.util.Map;
-import java.util.Vector;
 
-import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.render.java2d.Java2DRenderer;
 
 /**
  * Renderer that prints through java.awt.PrintJob.
@@ -40,7 +32,7 @@
  * since both PrintRenderer and AWTRenderer need to
  * support printing.
  */
-public class PrintRenderer extends Java2DRenderer implements Pageable {
+public class PrintRenderer extends PageableRenderer {
 
     /**
      * Printing parameter: the preconfigured PrinterJob to use,
@@ -49,45 +41,21 @@
     public static final String PRINTER_JOB = "printerjob";
   
     /**
-     * Printing parameter: the pages to be printed (all, even or odd),
-     * datatype: the strings "all", "even" or "odd" or one of PagesMode.*
-     */
-    public static final String PAGES_MODE = "even-odd";
-
-    /**
-     * Printing parameter: the page number (1-based) of the first page to be printed,
-     * datatype: a positive Integer
-     */
-    public static final String START_PAGE = "start-page";
-
-    /**
-     * Printing parameter: the page number (1-based) of the last page to be printed,
-     * datatype: a positive Integer
-     */
-    public static final String END_PAGE = "end-page";
-    
-    /**
      * Printing parameter: the number of copies of the document to be printed,
      * datatype: a positive Integer
      */
     public static final String COPIES = "copies";
     
     
-    private int startNumber = 0;
-    private int endNumber = -1;
-
-    private PagesMode mode = PagesMode.ALL;
-
     private int copies = 1;
 
     private PrinterJob printerJob;
 
     /**
-     * Creates a new PrintRenderer with the options set from system properties if a custom
+     * Creates a new PrintRenderer with the options set through the renderer options if a custom
      * PrinterJob is not given in FOUserAgent's renderer options.
      */
     public PrintRenderer() {
-        setupFromSystemProperties();
     }
     
     /**
@@ -117,18 +85,6 @@
         }
     }
 
-    private void setupFromSystemProperties() {
-        //TODO Remove me! This is not a beautiful way to do this.
-        // read from command-line options
-        copies = getIntProperty("copies", 1);
-        startNumber = getIntProperty("start", 1);
-        endNumber = getIntProperty("end", -1);
-        String str = System.getProperty("even");
-        if (str != null) {
-            mode = Boolean.valueOf(str).booleanValue() ? PagesMode.EVEN : PagesMode.ODD;
-        }
-    }
-    
     /** {@inheritDoc} */
     public void setUserAgent(FOUserAgent agent) {
         super.setUserAgent(agent);
@@ -146,53 +102,13 @@
             printerJob = (PrinterJob)printerJobO;
             printerJob.setPageable(this);
         }
-        Object o = rendererOptions.get(PrintRenderer.PAGES_MODE);
-        if (o != null) {
-            if (o instanceof PagesMode) {
-                this.mode = (PagesMode)o;
-            } else if (o instanceof String) {
-                this.mode = PagesMode.byName((String)o);
-            } else {
-                throw new IllegalArgumentException(
-                        "Renderer option " + PrintRenderer.PAGES_MODE
-                        + " must be an 'all', 'even', 'odd' or a PagesMode instance.");
-            }
-        }
-        
-        o = rendererOptions.get(PrintRenderer.START_PAGE);
-        if (o != null) {
-            this.startNumber = getPositiveInteger(o);
-        }
-        o = rendererOptions.get(PrintRenderer.END_PAGE);
-        if (o != null) {
-            this.endNumber = getPositiveInteger(o);
-        }
-        if (this.endNumber >= 0 && this.endNumber < this.endNumber) {
-            this.endNumber = this.startNumber;
-        }
-        o = rendererOptions.get(PrintRenderer.COPIES);
+        Object o = rendererOptions.get(PrintRenderer.COPIES);
         if (o != null) {
             this.copies = getPositiveInteger(o);
         }
         initializePrinterJob();
     }
 
-    private int getPositiveInteger(Object o) {
-        if (o instanceof Integer) {
-            Integer i = (Integer)o;
-            if (i.intValue() < 1) {
-                throw new IllegalArgumentException(
-                        "Value must be a positive Integer");
-            }
-            return i.intValue();
-        } else if (o instanceof String) {
-            return Integer.parseInt((String)o);
-        } else {
-            throw new IllegalArgumentException(
-                    "Value must be a positive integer");
-        }
-    }
-    
     /** @return the PrinterJob instance that this renderer prints to */
     public PrinterJob getPrinterJob() {
         return this.printerJob;
@@ -228,17 +144,6 @@
     public void stopRenderer() throws IOException {
         super.stopRenderer();
 
-        if (endNumber == -1) {
-            // was not set on command line
-            endNumber = getNumberOfPages();
-        }
-
-        Vector numbers = getInvalidPageNumbers();
-        for (int i = numbers.size() - 1; i > -1; i--) {
-            int page = ((Integer)numbers.elementAt(i)).intValue();
-            pageViewportList.remove(page - 1);
-        }
-
         try {
             printerJob.print();
         } catch (PrinterException e) {
@@ -249,79 +154,4 @@
         clearViewportList();
     }
 
-    private static int getIntProperty(String name, int def) {
-        String propValue = System.getProperty(name);
-        if (propValue != null) {
-            try {
-                return Integer.parseInt(propValue);
-            } catch (Exception e) {
-                return def;
-            }
-        } else {
-            return def;
-        }
-    }
-
-    private Vector getInvalidPageNumbers() {
-        Vector vec = new Vector();
-        int max = getNumberOfPages();
-        boolean isValid;
-        for (int i = 1; i <= max; i++) {
-            isValid = true;
-            if (i < startNumber || i > endNumber) {
-                isValid = false;
-            } else if (mode != PagesMode.ALL) {
-                if (mode == PagesMode.EVEN && (i % 2 != 0)) {
-                    isValid = false;
-                } else if (mode == PagesMode.ODD && (i % 2 == 0)) {
-                    isValid = false;
-                }
-            }
-
-            if (!isValid) {
-                vec.add(new Integer(i));
-            }
-        }
-        return vec;
-    }
-
-    /** {@inheritDoc} */
-    public PageFormat getPageFormat(int pageIndex)
-            throws IndexOutOfBoundsException {
-        try {
-            if (pageIndex >= getNumberOfPages()) {
-                return null;
-            }
-    
-            PageFormat pageFormat = new PageFormat();
-    
-            Paper paper = new Paper();
-    
-            Rectangle2D dim = getPageViewport(pageIndex).getViewArea();
-            double width = dim.getWidth();
-            double height = dim.getHeight();
-    
-            // if the width is greater than the height assume lanscape mode
-            // and swap the width and height values in the paper format
-            if (width > height) {
-                paper.setImageableArea(0, 0, height / 1000d, width / 1000d);
-                paper.setSize(height / 1000d, width / 1000d);
-                pageFormat.setOrientation(PageFormat.LANDSCAPE);
-            } else {
-                paper.setImageableArea(0, 0, width / 1000d, height / 1000d);
-                paper.setSize(width / 1000d, height / 1000d);
-                pageFormat.setOrientation(PageFormat.PORTRAIT);
-            }
-            pageFormat.setPaper(paper);
-            return pageFormat;
-        } catch (FOPException fopEx) {
-            throw new IndexOutOfBoundsException(fopEx.getMessage());
-        }
-    }
-
-    /** {@inheritDoc} */
-    public Printable getPrintable(int pageIndex)
-            throws IndexOutOfBoundsException {
-        return this;
-    }
 }

Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/rtf/RTFHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/rtf/RTFHandler.java?rev=649444&r1=649443&r2=649444&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/rtf/RTFHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/rtf/RTFHandler.java Fri Apr 18 03:06:07 2008
@@ -242,9 +242,6 @@
             bFooterSpecified = false;
         } catch (IOException ioe) {
             handleIOTrouble(ioe);
-        } catch (FOPException fope) {
-            // TODO could we throw Exception in all FOEventHandler events?
-            log.error("startPageSequence: " + fope.getMessage(), fope);
         }
     }
 

Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/status.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/status.xml?rev=649444&r1=649443&r2=649444&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/status.xml (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/status.xml Fri Apr 18 03:06:07 2008
@@ -59,6 +59,10 @@
       <action context="Renderers" dev="AC" importance="high" type="add">
         Added de-duplication and externalization support for IOCA and GOCA data resource objects.
       </action>
+      <action context="Renderers" dev="JM" type="add">
+        Added support for rendering pages using JPS (Java Printing System). See new example:
+        examples/embedding/java/ExamplesFO2JPSPrint.java
+      </action>
       <action context="Renderers" dev="JM" type="add" fixes-bug="41687">
         Restored ability to specify from/to and odd/even pages as well as the number of copies
         for printing from the command-line.



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