From 969fb8ff2be739e6b2d25841e090aafee1afa604 Mon Sep 17 00:00:00 2001 From: Peter Bernard West Date: Wed, 27 Nov 2002 02:43:58 +0000 Subject: [PATCH] Added error checking for getEnumIndex() and getEnumText(). git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP_0-20-0_Alt-Design@195630 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/fop/fo/properties/ActiveState.java | 15 +++++++++--- .../fop/fo/properties/AlignmentAdjust.java | 15 +++++++++--- .../fop/fo/properties/AlignmentBaseline.java | 15 +++++++++--- .../fop/fo/properties/BorderCommonStyle.java | 15 +++++++++--- .../apache/fop/fo/properties/BreakCommon.java | 15 +++++++++--- .../apache/fop/fo/properties/CaptionSide.java | 15 +++++++++--- src/org/apache/fop/fo/properties/Clear.java | 15 +++++++++--- .../fo/properties/ColorNonTransparent.java | 15 +++++++++--- .../fop/fo/properties/ColorTransparent.java | 16 ++++++++++--- .../fop/fo/properties/DominantBaseline.java | 15 +++++++++--- src/org/apache/fop/fo/properties/Float.java | 15 +++++++++--- .../apache/fop/fo/properties/FontStretch.java | 15 +++++++++--- .../fop/fo/properties/ForcePageCount.java | 15 +++++++++--- .../fop/fo/properties/PageBreakCommon.java | 24 ++++++++++++------- .../apache/fop/fo/properties/RegionName.java | 15 +++++++++--- .../fop/fo/properties/RenderingIntent.java | 15 +++++++++--- .../apache/fop/fo/properties/RuleStyle.java | 15 +++++++++--- .../apache/fop/fo/properties/TextAlign.java | 15 +++++++++--- .../fop/fo/properties/TextAlignLast.java | 15 +++++++++--- .../fop/fo/properties/VerticalAlign.java | 15 +++++++++--- .../fo/properties/WhiteSpaceTreatment.java | 15 +++++++++--- .../apache/fop/fo/properties/WritingMode.java | 15 +++++++++--- 22 files changed, 268 insertions(+), 72 deletions(-) diff --git a/src/org/apache/fop/fo/properties/ActiveState.java b/src/org/apache/fop/fo/properties/ActiveState.java index 04fce63a5..480dd3e3d 100644 --- a/src/org/apache/fop/fo/properties/ActiveState.java +++ b/src/org/apache/fop/fo/properties/ActiveState.java @@ -38,10 +38,19 @@ public class ActiveState extends Property { } } - public int getEnumIndex(String enum) { - return ((Integer)(rwEnumHash.get(enum))).intValue(); + public int getEnumIndex(String enum) + throws PropertyException + { + Integer ii = (Integer)(rwEnumHash.get(enum)); + if (ii == null) + throw new PropertyException("Unknown enum value: " + enum); + return ii.intValue(); } - public String getEnumText(int index) { + public String getEnumText(int index) + throws PropertyException + { + if (index < 1 || index >= rwEnums.length) + throw new PropertyException("index out of range: " + index); return rwEnums[index]; } diff --git a/src/org/apache/fop/fo/properties/AlignmentAdjust.java b/src/org/apache/fop/fo/properties/AlignmentAdjust.java index df60ffdcf..146fb3ff9 100644 --- a/src/org/apache/fop/fo/properties/AlignmentAdjust.java +++ b/src/org/apache/fop/fo/properties/AlignmentAdjust.java @@ -51,10 +51,19 @@ public class AlignmentAdjust extends Property { } } - public int getEnumIndex(String enum) { - return ((Integer)(rwEnumHash.get(enum))).intValue(); + public int getEnumIndex(String enum) + throws PropertyException + { + Integer ii = (Integer)(rwEnumHash.get(enum)); + if (ii == null) + throw new PropertyException("Unknown enum value: " + enum); + return ii.intValue(); } - public String getEnumText(int index) { + public String getEnumText(int index) + throws PropertyException + { + if (index < 1 || index >= rwEnums.length) + throw new PropertyException("index out of range: " + index); return rwEnums[index]; } diff --git a/src/org/apache/fop/fo/properties/AlignmentBaseline.java b/src/org/apache/fop/fo/properties/AlignmentBaseline.java index 9fad8be62..b2ab29bae 100644 --- a/src/org/apache/fop/fo/properties/AlignmentBaseline.java +++ b/src/org/apache/fop/fo/properties/AlignmentBaseline.java @@ -50,10 +50,19 @@ public class AlignmentBaseline extends Property { } } - public int getEnumIndex(String enum) { - return ((Integer)(rwEnumHash.get(enum))).intValue(); + public int getEnumIndex(String enum) + throws PropertyException + { + Integer ii = (Integer)(rwEnumHash.get(enum)); + if (ii == null) + throw new PropertyException("Unknown enum value: " + enum); + return ii.intValue(); } - public String getEnumText(int index) { + public String getEnumText(int index) + throws PropertyException + { + if (index < 1 || index >= rwEnums.length) + throw new PropertyException("index out of range: " + index); return rwEnums[index]; } diff --git a/src/org/apache/fop/fo/properties/BorderCommonStyle.java b/src/org/apache/fop/fo/properties/BorderCommonStyle.java index 2edbc00ad..da0f406fd 100644 --- a/src/org/apache/fop/fo/properties/BorderCommonStyle.java +++ b/src/org/apache/fop/fo/properties/BorderCommonStyle.java @@ -43,10 +43,19 @@ public class BorderCommonStyle extends Property { } } - public int getEnumIndex(String enum) { - return ((Integer)(rwEnumHash.get(enum))).intValue(); + public int getEnumIndex(String enum) + throws PropertyException + { + Integer ii = (Integer)(rwEnumHash.get(enum)); + if (ii == null) + throw new PropertyException("Unknown enum value: " + enum); + return ii.intValue(); } - public String getEnumText(int index) { + public String getEnumText(int index) + throws PropertyException + { + if (index < 1 || index >= rwEnums.length) + throw new PropertyException("index out of range: " + index); return rwEnums[index]; } diff --git a/src/org/apache/fop/fo/properties/BreakCommon.java b/src/org/apache/fop/fo/properties/BreakCommon.java index 154f3e7de..888ea347e 100644 --- a/src/org/apache/fop/fo/properties/BreakCommon.java +++ b/src/org/apache/fop/fo/properties/BreakCommon.java @@ -29,10 +29,19 @@ public class BreakCommon extends Property { } } - public int getEnumIndex(String enum) { - return ((Integer)(rwEnumHash.get(enum))).intValue(); + public int getEnumIndex(String enum) + throws PropertyException + { + Integer ii = (Integer)(rwEnumHash.get(enum)); + if (ii == null) + throw new PropertyException("Unknown enum value: " + enum); + return ii.intValue(); } - public String getEnumText(int index) { + public String getEnumText(int index) + throws PropertyException + { + if (index < 1 || index >= rwEnums.length) + throw new PropertyException("index out of range: " + index); return rwEnums[index]; } diff --git a/src/org/apache/fop/fo/properties/CaptionSide.java b/src/org/apache/fop/fo/properties/CaptionSide.java index 04f8a0a57..75af3dc09 100644 --- a/src/org/apache/fop/fo/properties/CaptionSide.java +++ b/src/org/apache/fop/fo/properties/CaptionSide.java @@ -53,10 +53,19 @@ public class CaptionSide extends Property { (Object) Ints.consts.get(i)); } } - public int getEnumIndex(String enum) { - return ((Integer)(rwEnumHash.get(enum))).intValue(); + public int getEnumIndex(String enum) + throws PropertyException + { + Integer ii = (Integer)(rwEnumHash.get(enum)); + if (ii == null) + throw new PropertyException("Unknown enum value: " + enum); + return ii.intValue(); } - public String getEnumText(int index) { + public String getEnumText(int index) + throws PropertyException + { + if (index < 1 || index >= rwEnums.length) + throw new PropertyException("index out of range: " + index); return rwEnums[index]; } } diff --git a/src/org/apache/fop/fo/properties/Clear.java b/src/org/apache/fop/fo/properties/Clear.java index d57844eca..273ab8610 100644 --- a/src/org/apache/fop/fo/properties/Clear.java +++ b/src/org/apache/fop/fo/properties/Clear.java @@ -38,10 +38,19 @@ public class Clear extends Property { (Object) Ints.consts.get(i)); } } - public int getEnumIndex(String enum) { - return ((Integer)(rwEnumHash.get(enum))).intValue(); + public int getEnumIndex(String enum) + throws PropertyException + { + Integer ii = (Integer)(rwEnumHash.get(enum)); + if (ii == null) + throw new PropertyException("Unknown enum value: " + enum); + return ii.intValue(); } - public String getEnumText(int index) { + public String getEnumText(int index) + throws PropertyException + { + if (index < 1 || index >= rwEnums.length) + throw new PropertyException("index out of range: " + index); return rwEnums[index]; } } diff --git a/src/org/apache/fop/fo/properties/ColorNonTransparent.java b/src/org/apache/fop/fo/properties/ColorNonTransparent.java index 03c169170..f5d0057f8 100644 --- a/src/org/apache/fop/fo/properties/ColorNonTransparent.java +++ b/src/org/apache/fop/fo/properties/ColorNonTransparent.java @@ -25,10 +25,19 @@ public class ColorNonTransparent extends ColorCommon { } } - public int getEnumIndex(String enum) { - return ((Integer)(rwEnumHash.get(enum))).intValue(); + public int getEnumIndex(String enum) + throws PropertyException + { + Integer ii = (Integer)(rwEnumHash.get(enum)); + if (ii == null) + throw new PropertyException("Unknown enum value: " + enum); + return ii.intValue(); } - public String getEnumText(int index) { + public String getEnumText(int index) + throws PropertyException + { + if (index < 1 || index >= rwEnums.length) + throw new PropertyException("index out of range: " + index); return rwEnums[index]; } diff --git a/src/org/apache/fop/fo/properties/ColorTransparent.java b/src/org/apache/fop/fo/properties/ColorTransparent.java index 8ce728325..ac476fb91 100644 --- a/src/org/apache/fop/fo/properties/ColorTransparent.java +++ b/src/org/apache/fop/fo/properties/ColorTransparent.java @@ -25,10 +25,20 @@ public class ColorTransparent extends ColorCommon { } } - public int getEnumIndex(String enum) { - return ((Integer)(rwEnumHash.get(enum))).intValue(); + public int getEnumIndex(String enum) + throws PropertyException + { + Integer ii = (Integer)(rwEnumHash.get(enum)); + if (ii == null) + throw new PropertyException("Unknown enum value: " + enum); + return ii.intValue(); } - public String getEnumText(int index) { + + public String getEnumText(int index) + throws PropertyException + { + if (index < 1 || index >= rwEnums.length) + throw new PropertyException("index out of range: " + index); return rwEnums[index]; } diff --git a/src/org/apache/fop/fo/properties/DominantBaseline.java b/src/org/apache/fop/fo/properties/DominantBaseline.java index 4746401ee..5505321de 100644 --- a/src/org/apache/fop/fo/properties/DominantBaseline.java +++ b/src/org/apache/fop/fo/properties/DominantBaseline.java @@ -47,10 +47,19 @@ public class DominantBaseline extends Property { (Object) Ints.consts.get(i)); } } - public int getEnumIndex(String enum) { - return ((Integer)(rwEnumHash.get(enum))).intValue(); + public int getEnumIndex(String enum) + throws PropertyException + { + Integer ii = (Integer)(rwEnumHash.get(enum)); + if (ii == null) + throw new PropertyException("Unknown enum value: " + enum); + return ii.intValue(); } - public String getEnumText(int index) { + public String getEnumText(int index) + throws PropertyException + { + if (index < 1 || index >= rwEnums.length) + throw new PropertyException("index out of range: " + index); return rwEnums[index]; } } diff --git a/src/org/apache/fop/fo/properties/Float.java b/src/org/apache/fop/fo/properties/Float.java index 7d7c63769..64c0e483d 100644 --- a/src/org/apache/fop/fo/properties/Float.java +++ b/src/org/apache/fop/fo/properties/Float.java @@ -36,10 +36,19 @@ public class Float extends Property { (Object) Ints.consts.get(i)); } } - public int getEnumIndex(String enum) { - return ((Integer)(rwEnumHash.get(enum))).intValue(); + public int getEnumIndex(String enum) + throws PropertyException + { + Integer ii = (Integer)(rwEnumHash.get(enum)); + if (ii == null) + throw new PropertyException("Unknown enum value: " + enum); + return ii.intValue(); } - public String getEnumText(int index) { + public String getEnumText(int index) + throws PropertyException + { + if (index < 1 || index >= rwEnums.length) + throw new PropertyException("index out of range: " + index); return rwEnums[index]; } } diff --git a/src/org/apache/fop/fo/properties/FontStretch.java b/src/org/apache/fop/fo/properties/FontStretch.java index 77a01fb4d..5c41ca912 100644 --- a/src/org/apache/fop/fo/properties/FontStretch.java +++ b/src/org/apache/fop/fo/properties/FontStretch.java @@ -58,10 +58,19 @@ public class FontStretch extends Property { (Object) Ints.consts.get(i)); } } - public int getEnumIndex(String enum) { - return ((Integer)(rwEnumHash.get(enum))).intValue(); + public int getEnumIndex(String enum) + throws PropertyException + { + Integer ii = (Integer)(rwEnumHash.get(enum)); + if (ii == null) + throw new PropertyException("Unknown enum value: " + enum); + return ii.intValue(); } - public String getEnumText(int index) { + public String getEnumText(int index) + throws PropertyException + { + if (index < 1 || index >= rwEnums.length) + throw new PropertyException("index out of range: " + index); return rwEnums[index]; } } diff --git a/src/org/apache/fop/fo/properties/ForcePageCount.java b/src/org/apache/fop/fo/properties/ForcePageCount.java index e71d200b8..10f4c1eb0 100644 --- a/src/org/apache/fop/fo/properties/ForcePageCount.java +++ b/src/org/apache/fop/fo/properties/ForcePageCount.java @@ -37,10 +37,19 @@ public class ForcePageCount extends Property { (Object) Ints.consts.get(i)); } } - public int getEnumIndex(String enum) { - return ((Integer)(rwEnumHash.get(enum))).intValue(); + public int getEnumIndex(String enum) + throws PropertyException + { + Integer ii = (Integer)(rwEnumHash.get(enum)); + if (ii == null) + throw new PropertyException("Unknown enum value: " + enum); + return ii.intValue(); } - public String getEnumText(int index) { + public String getEnumText(int index) + throws PropertyException + { + if (index < 1 || index >= rwEnums.length) + throw new PropertyException("index out of range: " + index); return rwEnums[index]; } } diff --git a/src/org/apache/fop/fo/properties/PageBreakCommon.java b/src/org/apache/fop/fo/properties/PageBreakCommon.java index 1f9cf448f..6f43c4e72 100644 --- a/src/org/apache/fop/fo/properties/PageBreakCommon.java +++ b/src/org/apache/fop/fo/properties/PageBreakCommon.java @@ -42,10 +42,19 @@ public class PageBreakCommon extends Property { (Object) Ints.consts.get(i)); } } - public int getEnumIndex(String enum) { - return ((Integer)(rwEnumHash.get(enum))).intValue(); + public int getEnumIndex(String enum) + throws PropertyException + { + Integer ii = (Integer)(rwEnumHash.get(enum)); + if (ii == null) + throw new PropertyException("Unknown enum value: " + enum); + return ii.intValue(); } - public String getEnumText(int index) { + public String getEnumText(int index) + throws PropertyException + { + if (index < 1 || index >= rwEnums.length) + throw new PropertyException("index out of range: " + index); return rwEnums[index]; } @@ -73,8 +82,7 @@ public class PageBreakCommon extends Property { previousNext = PropNames.KEEP_WITH_NEXT; break; default: - throw new PropertyException - ("Unknown property in PageBreakCommon: " + throw new PropertyException("Unknown property in PageBreakCommon: " + PropNames.getPropertyName(property)); } if (value instanceof Inherit | @@ -91,8 +99,7 @@ public class PageBreakCommon extends Property { try { enum = new EnumType(value.getProperty(), ncname); } catch (PropertyException e) { - throw new PropertyException - ("Unrecognized NCName in page-break-after: " + ncname); + throw new PropertyException ("Unrecognized NCName in page-break-after: " + ncname); } PropertyValueList list = new PropertyValueList(property); switch (enum.getEnumValue()) { @@ -115,8 +122,7 @@ public class PageBreakCommon extends Property { } } - throw new PropertyException - ("Invalid value for '" + PropNames.getPropertyName(property) + throw new PropertyException ("Invalid value for '" + PropNames.getPropertyName(property) + "': " + value.getClass().getName()); } } diff --git a/src/org/apache/fop/fo/properties/RegionName.java b/src/org/apache/fop/fo/properties/RegionName.java index 616e42bb4..e991ecdb9 100644 --- a/src/org/apache/fop/fo/properties/RegionName.java +++ b/src/org/apache/fop/fo/properties/RegionName.java @@ -40,10 +40,19 @@ public class RegionName extends Property { (Object) Ints.consts.get(i)); } } - public int getEnumIndex(String enum) { - return ((Integer)(rwEnumHash.get(enum))).intValue(); + public int getEnumIndex(String enum) + throws PropertyException + { + Integer ii = (Integer)(rwEnumHash.get(enum)); + if (ii == null) + throw new PropertyException("Unknown enum value: " + enum); + return ii.intValue(); } - public String getEnumText(int index) { + public String getEnumText(int index) + throws PropertyException + { + if (index < 1 || index >= rwEnums.length) + throw new PropertyException("index out of range: " + index); return rwEnums[index]; } } diff --git a/src/org/apache/fop/fo/properties/RenderingIntent.java b/src/org/apache/fop/fo/properties/RenderingIntent.java index 9492714d0..4386e6411 100644 --- a/src/org/apache/fop/fo/properties/RenderingIntent.java +++ b/src/org/apache/fop/fo/properties/RenderingIntent.java @@ -34,10 +34,19 @@ public class RenderingIntent extends Property { (Object) Ints.consts.get(i)); } } - public int getEnumIndex(String enum) { - return ((Integer)(rwEnumHash.get(enum))).intValue(); + public int getEnumIndex(String enum) + throws PropertyException + { + Integer ii = (Integer)(rwEnumHash.get(enum)); + if (ii == null) + throw new PropertyException("Unknown enum value: " + enum); + return ii.intValue(); } - public String getEnumText(int index) { + public String getEnumText(int index) + throws PropertyException + { + if (index < 1 || index >= rwEnums.length) + throw new PropertyException("index out of range: " + index); return rwEnums[index]; } } diff --git a/src/org/apache/fop/fo/properties/RuleStyle.java b/src/org/apache/fop/fo/properties/RuleStyle.java index b34cc15f3..fcf684169 100644 --- a/src/org/apache/fop/fo/properties/RuleStyle.java +++ b/src/org/apache/fop/fo/properties/RuleStyle.java @@ -46,10 +46,19 @@ public class RuleStyle extends Property { (Object) Ints.consts.get(i)); } } - public int getEnumIndex(String enum) { - return ((Integer)(rwEnumHash.get(enum))).intValue(); + public int getEnumIndex(String enum) + throws PropertyException + { + Integer ii = (Integer)(rwEnumHash.get(enum)); + if (ii == null) + throw new PropertyException("Unknown enum value: " + enum); + return ii.intValue(); } - public String getEnumText(int index) { + public String getEnumText(int index) + throws PropertyException + { + if (index < 1 || index >= rwEnums.length) + throw new PropertyException("index out of range: " + index); return rwEnums[index]; } } diff --git a/src/org/apache/fop/fo/properties/TextAlign.java b/src/org/apache/fop/fo/properties/TextAlign.java index 92d6a3d73..6f450c287 100644 --- a/src/org/apache/fop/fo/properties/TextAlign.java +++ b/src/org/apache/fop/fo/properties/TextAlign.java @@ -51,10 +51,19 @@ public class TextAlign extends Property { (Object) Ints.consts.get(i)); } } - public int getEnumIndex(String enum) { - return ((Integer)(rwEnumHash.get(enum))).intValue(); + public int getEnumIndex(String enum) + throws PropertyException + { + Integer ii = (Integer)(rwEnumHash.get(enum)); + if (ii == null) + throw new PropertyException("Unknown enum value: " + enum); + return ii.intValue(); } - public String getEnumText(int index) { + public String getEnumText(int index) + throws PropertyException + { + if (index < 1 || index >= rwEnums.length) + throw new PropertyException("index out of range: " + index); return rwEnums[index]; } } diff --git a/src/org/apache/fop/fo/properties/TextAlignLast.java b/src/org/apache/fop/fo/properties/TextAlignLast.java index 842f31017..7cab9b94b 100644 --- a/src/org/apache/fop/fo/properties/TextAlignLast.java +++ b/src/org/apache/fop/fo/properties/TextAlignLast.java @@ -53,10 +53,19 @@ public class TextAlignLast extends Property { (Object) Ints.consts.get(i)); } } - public int getEnumIndex(String enum) { - return ((Integer)(rwEnumHash.get(enum))).intValue(); + public int getEnumIndex(String enum) + throws PropertyException + { + Integer ii = (Integer)(rwEnumHash.get(enum)); + if (ii == null) + throw new PropertyException("Unknown enum value: " + enum); + return ii.intValue(); } - public String getEnumText(int index) { + public String getEnumText(int index) + throws PropertyException + { + if (index < 1 || index >= rwEnums.length) + throw new PropertyException("index out of range: " + index); return rwEnums[index]; } } diff --git a/src/org/apache/fop/fo/properties/VerticalAlign.java b/src/org/apache/fop/fo/properties/VerticalAlign.java index 0bee65bf8..7a98a1bb4 100644 --- a/src/org/apache/fop/fo/properties/VerticalAlign.java +++ b/src/org/apache/fop/fo/properties/VerticalAlign.java @@ -50,10 +50,19 @@ public class VerticalAlign extends Property { (Object) Ints.consts.get(i)); } } - public int getEnumIndex(String enum) { - return ((Integer)(rwEnumHash.get(enum))).intValue(); + public int getEnumIndex(String enum) + throws PropertyException + { + Integer ii = (Integer)(rwEnumHash.get(enum)); + if (ii == null) + throw new PropertyException("Unknown enum value: " + enum); + return ii.intValue(); } - public String getEnumText(int index) { + public String getEnumText(int index) + throws PropertyException + { + if (index < 1 || index >= rwEnums.length) + throw new PropertyException("index out of range: " + index); return rwEnums[index]; } } diff --git a/src/org/apache/fop/fo/properties/WhiteSpaceTreatment.java b/src/org/apache/fop/fo/properties/WhiteSpaceTreatment.java index 8871799da..47598d4b5 100644 --- a/src/org/apache/fop/fo/properties/WhiteSpaceTreatment.java +++ b/src/org/apache/fop/fo/properties/WhiteSpaceTreatment.java @@ -43,10 +43,19 @@ public class WhiteSpaceTreatment extends Property { (Object) Ints.consts.get(i)); } } - public int getEnumIndex(String enum) { - return ((Integer)(rwEnumHash.get(enum))).intValue(); + public int getEnumIndex(String enum) + throws PropertyException + { + Integer ii = (Integer)(rwEnumHash.get(enum)); + if (ii == null) + throw new PropertyException("Unknown enum value: " + enum); + return ii.intValue(); } - public String getEnumText(int index) { + public String getEnumText(int index) + throws PropertyException + { + if (index < 1 || index >= rwEnums.length) + throw new PropertyException("index out of range: " + index); return rwEnums[index]; } } diff --git a/src/org/apache/fop/fo/properties/WritingMode.java b/src/org/apache/fop/fo/properties/WritingMode.java index 88885ea60..5d7bbc51c 100644 --- a/src/org/apache/fop/fo/properties/WritingMode.java +++ b/src/org/apache/fop/fo/properties/WritingMode.java @@ -45,10 +45,19 @@ public class WritingMode extends Property { (Object) Ints.consts.get(i)); } } - public int getEnumIndex(String enum) { - return ((Integer)(rwEnumHash.get(enum))).intValue(); + public int getEnumIndex(String enum) + throws PropertyException + { + Integer ii = (Integer)(rwEnumHash.get(enum)); + if (ii == null) + throw new PropertyException("Unknown enum value: " + enum); + return ii.intValue(); } - public String getEnumText(int index) { + public String getEnumText(int index) + throws PropertyException + { + if (index < 1 || index >= rwEnums.length) + throw new PropertyException("index out of range: " + index); return rwEnums[index]; } } -- 2.39.5