1 17 package org.apache.fop.fo.properties; 18 19 import java.util.Iterator ; 20 import java.util.List ; 21 22 import org.apache.fop.fo.Constants; 23 import org.apache.fop.fo.FObj; 24 import org.apache.fop.fo.PropertyList; 25 import org.apache.fop.fo.expr.NCnameProperty; 26 import org.apache.fop.fo.expr.PropertyException; 27 28 31 public class TextDecorationProperty extends ListProperty { 32 33 36 public static class Maker extends PropertyMaker { 37 38 41 public Maker(int propId) { 42 super(propId); 43 } 44 45 48 public Property convertProperty(Property p, 49 PropertyList propertyList, FObj fo) 50 throws PropertyException { 51 if (p instanceof TextDecorationProperty) { 52 return p; 53 } else { 54 if (p instanceof ListProperty) { 55 ListProperty lst = (ListProperty)p; 56 lst = checkEnums(lst); 57 return new TextDecorationProperty((ListProperty)p); 58 } else if (p instanceof EnumProperty) { 59 ListProperty lst = new ListProperty(p); 60 return new TextDecorationProperty(lst); 61 } else { 62 throw new PropertyException("Cannot convert anything other " 63 + "than a list property, got a " + p.getClass().getName()); 64 } 65 } 66 } 67 68 private ListProperty checkEnums(ListProperty lst) throws PropertyException { 69 List l = lst.getList(); 70 for (int i = 0; i < l.size(); i++) { 71 Property prop = (Property)l.get(i); 72 if (prop instanceof EnumProperty) { 73 } else if (prop instanceof NCnameProperty) { 75 Property prop_enum = checkEnumValues(((NCnameProperty)prop).getString()); 76 if (prop_enum == null) { 77 throw new PropertyException("Illegal enum value: " + prop.getString()); 78 } 79 l.set(i, prop_enum); 80 } else { 81 throw new PropertyException("Invalid content for text-decoration " 82 + "property: " + prop); 83 } 84 } 85 return lst; 86 } 87 88 } 89 90 95 public TextDecorationProperty(ListProperty listProp) throws PropertyException { 96 List lst = listProp.getList(); 97 boolean none = false; 98 boolean under = false; 99 boolean over = false; 100 boolean through = false; 101 boolean blink = false; 102 Iterator i = lst.iterator(); 103 while (i.hasNext()) { 104 Property prop = (Property)i.next(); 105 switch (prop.getEnum()) { 106 case Constants.EN_NONE: 107 if (under | over | through | blink) { 108 throw new PropertyException( 109 "Invalid combination of values"); 110 } 111 none = true; 112 break; 113 case Constants.EN_UNDERLINE: 114 case Constants.EN_NO_UNDERLINE: 115 if (none) { 116 throw new PropertyException("'none' specified, no additional values allowed"); 117 } 118 if (under) { 119 throw new PropertyException("Invalid combination of values"); 120 } 121 under = true; 122 break; 123 case Constants.EN_OVERLINE: 124 case Constants.EN_NO_OVERLINE: 125 if (none) { 126 throw new PropertyException("'none' specified, no additional values allowed"); 127 } 128 if (over) { 129 throw new PropertyException("Invalid combination of values"); 130 } 131 over = true; 132 break; 133 case Constants.EN_LINE_THROUGH: 134 case Constants.EN_NO_LINE_THROUGH: 135 if (none) { 136 throw new PropertyException("'none' specified, no additional values allowed"); 137 } 138 if (through) { 139 throw new PropertyException("Invalid combination of values"); 140 } 141 through = true; 142 break; 143 case Constants.EN_BLINK: 144 case Constants.EN_NO_BLINK: 145 if (none) { 146 throw new PropertyException("'none' specified, no additional values allowed"); 147 } 148 if (blink) { 149 throw new PropertyException("Invalid combination of values"); 150 } 151 blink = true; 152 break; 153 default: 154 throw new PropertyException("Invalid value specified: " + prop); 155 } 156 addProperty(prop); 157 } 158 } 159 160 } 161 | Popular Tags |