diff options
author | Maximilian Berger <maxberger@apache.org> | 2009-09-15 12:50:47 +0000 |
---|---|---|
committer | Maximilian Berger <maxberger@apache.org> | 2009-09-15 12:50:47 +0000 |
commit | 0a0a566c5d86b5894acb47f10ab18c6994652e15 (patch) | |
tree | 0c80e45081cd3246d9fa347f7fe4c64b15227e32 /src/java/org/apache/fop/render/intermediate | |
parent | d5911c9e9a5f3a19f1ae1ecc3b51676a4f9f2afa (diff) | |
download | xmlgraphics-fop-0a0a566c5d86b5894acb47f10ab18c6994652e15.tar.gz xmlgraphics-fop-0a0a566c5d86b5894acb47f10ab18c6994652e15.zip |
Add safeguards for getter not to return null
fixes an NPE with disfunctional links.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@815301 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/render/intermediate')
-rw-r--r-- | src/java/org/apache/fop/render/intermediate/extensions/GoToXYAction.java | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/src/java/org/apache/fop/render/intermediate/extensions/GoToXYAction.java b/src/java/org/apache/fop/render/intermediate/extensions/GoToXYAction.java index 7efb82a12..a2b4f31b6 100644 --- a/src/java/org/apache/fop/render/intermediate/extensions/GoToXYAction.java +++ b/src/java/org/apache/fop/render/intermediate/extensions/GoToXYAction.java @@ -71,18 +71,34 @@ public class GoToXYAction extends AbstractAction implements DocumentNavigationEx /** * Returns the page index of the target page. + * <p> + * This function will always return a valid value for safety. Use + * {@link #isComplete()} to check if the link is actually complete. + * * @return the page index (0-based) */ public int getPageIndex() { - return this.pageIndex; + if (this.pageIndex >= 0) { + return this.pageIndex; + } else { + return 0; + } } /** * Returns the absolute coordinates of the target location on the page. + * <p> + * This function will always return a valid value for safety. Use + * {@link #isComplete()} to check if the link is actually complete. + * * @return the target location (coordinates in millipoints) */ public Point getTargetLocation() { - return this.targetLocation; + if (this.targetLocation == null) { + return new Point(0, 0); + } else { + return this.targetLocation; + } } /** @@ -93,9 +109,13 @@ public class GoToXYAction extends AbstractAction implements DocumentNavigationEx this.targetLocation = location; } + private boolean isCompleteExceptTargetLocation() { + return (getPageIndex() >= 0); + } + /** {@inheritDoc} */ public boolean isComplete() { - return (getPageIndex() >= 0) && (getTargetLocation() != null); + return this.isCompleteExceptTargetLocation() && (this.targetLocation != null); } /** {@inheritDoc} */ @@ -107,10 +127,10 @@ public class GoToXYAction extends AbstractAction implements DocumentNavigationEx return false; } GoToXYAction otherAction = (GoToXYAction)other; - if (getPageIndex() != otherAction.getPageIndex()) { + if (this.pageIndex != otherAction.pageIndex) { return false; } - if (getTargetLocation() == null || otherAction.getTargetLocation() == null) { + if (this.targetLocation == null || otherAction.targetLocation == null) { return false; } if (!getTargetLocation().equals(otherAction.getTargetLocation())) { @@ -121,16 +141,16 @@ public class GoToXYAction extends AbstractAction implements DocumentNavigationEx /** {@inheritDoc} */ public void toSAX(ContentHandler handler) throws SAXException { - if (getTargetLocation() == null) { - setTargetLocation(new Point(0, 0)); - } AttributesImpl atts = new AttributesImpl(); - if (isComplete()) { + if (this.isCompleteExceptTargetLocation()) { + final Point reportedTargetLocation = this.getTargetLocation(); atts.addAttribute(null, "id", "id", XMLUtil.CDATA, getID()); atts.addAttribute(null, "page-index", "page-index", XMLUtil.CDATA, Integer.toString(pageIndex)); - atts.addAttribute(null, "x", "x", XMLUtil.CDATA, Integer.toString(targetLocation.x)); - atts.addAttribute(null, "y", "y", XMLUtil.CDATA, Integer.toString(targetLocation.y)); + atts.addAttribute(null, "x", "x", XMLUtil.CDATA, + Integer.toString(reportedTargetLocation.x)); + atts.addAttribute(null, "y", "y", XMLUtil.CDATA, + Integer.toString(reportedTargetLocation.y)); } else { atts.addAttribute(null, "idref", "idref", XMLUtil.CDATA, getID()); } |