git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@649396 13f79535-47bb-0310-9956-ffa450edef68tags/fop-1_0
@@ -2,3 +2,4 @@ org.apache.fop.events.ValidationExceptionFactory | |||
org.apache.fop.events.PropertyExceptionFactory | |||
org.apache.fop.events.UnsupportedOperationExceptionFactory | |||
org.apache.fop.layoutmgr.LayoutException$LayoutExceptionFactory | |||
org.apache.fop.fo.pagination.PageProductionException$PageProductionExceptionFactory |
@@ -103,7 +103,7 @@ public class FOPException extends SAXException { | |||
* @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; |
@@ -31,6 +31,7 @@ import org.apache.fop.apps.FOPException; | |||
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 @@ public class RenderPagesModel extends AreaTreeModel { | |||
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. " |
@@ -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; | |||
} | |||
} | |||
} |
@@ -371,13 +371,13 @@ public class PageSequence extends AbstractPageSequence { | |||
* 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; |
@@ -189,14 +189,14 @@ public class PageSequenceMaster extends FObj { | |||
* @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) { |
@@ -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 @@ public interface SubSequenceSpecifier { | |||
* @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 |
@@ -21,9 +21,9 @@ package org.apache.fop.layoutmgr; | |||
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 @@ public interface BlockLevelEventProducer extends EventProducer { | |||
* @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 @@ public interface BlockLevelEventProducer extends EventProducer { | |||
* @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; | |||
} |
@@ -24,7 +24,6 @@ import java.util.List; | |||
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 @@ public class PageProvider implements Constants { | |||
} | |||
/** | |||
* | |||
* @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 @@ public class PageProvider implements Constants { | |||
} | |||
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; | |||
} | |||
} |