1 17 18 19 20 package org.apache.fop.fo.properties; 21 22 import org.apache.fop.datatypes.CompoundDatatype; 23 import org.apache.fop.fo.Constants; 24 import org.apache.fop.fo.FObj; 25 import org.apache.fop.fo.PropertyList; 26 import org.apache.fop.fo.expr.PropertyException; 27 28 34 37 public class CompoundPropertyMaker extends PropertyMaker { 38 41 private PropertyMaker[] subproperties = 42 new PropertyMaker[Constants.COMPOUND_COUNT]; 43 44 47 private PropertyMaker shorthandMaker = null; 48 49 53 public CompoundPropertyMaker(int propId) { 54 super(propId); 55 } 56 57 60 public void useGeneric(PropertyMaker generic) { 61 super.useGeneric(generic); 62 if (generic instanceof CompoundPropertyMaker) { 63 CompoundPropertyMaker compoundGeneric = (CompoundPropertyMaker) generic; 64 for (int i = 0; i < Constants.COMPOUND_COUNT; i++) { 65 PropertyMaker submaker = compoundGeneric.subproperties[i]; 66 if (submaker != null) { 67 addSubpropMaker((PropertyMaker) submaker.clone()); 68 } 69 } 70 } 71 } 72 73 77 public void addSubpropMaker(PropertyMaker subproperty) { 78 subproperty.propId &= Constants.COMPOUND_MASK; 80 subproperty.propId |= propId; 81 82 subproperties[getSubpropIndex(subproperty.getPropId())] = subproperty; 83 84 if (shorthandMaker == null && subproperty.setByShorthand) { 87 shorthandMaker = subproperty; 88 } 89 } 90 91 92 102 public PropertyMaker getSubpropMaker(int subpropertyId) { 103 return subproperties[getSubpropIndex(subpropertyId)]; 104 } 105 106 113 private int getSubpropIndex(int subpropertyId) { 114 return ((subpropertyId & Constants.COMPOUND_MASK) >> 115 Constants.COMPOUND_SHIFT)-1; 116 } 117 118 125 protected Property checkEnumValues(String value) { 126 Property result = null; 127 if (shorthandMaker != null) { 128 result = shorthandMaker.checkEnumValues(value); 129 } 130 if (result == null) { 131 result = super.checkEnumValues(value); 132 } 133 return result; 134 } 135 136 147 public Property get(int subpropertyId, PropertyList propertyList, 148 boolean tryInherit, boolean tryDefault) 149 throws PropertyException 150 { 151 Property p = super.get(subpropertyId, propertyList, tryInherit, tryDefault); 152 if (subpropertyId != 0 && p != null) { 153 p = getSubprop(p, subpropertyId); 154 } 155 return p; 156 } 157 158 169 protected Property convertProperty(Property p, 170 PropertyList propertyList, 171 FObj fo) throws PropertyException { 172 p = shorthandMaker.convertProperty(p, propertyList, fo); 174 175 if (p != null) { 176 Property prop = makeCompound(propertyList, fo); 177 CompoundDatatype pval = (CompoundDatatype) prop.getObject(); 178 for (int i = 0; i < Constants.COMPOUND_COUNT; i++) { 179 PropertyMaker submaker = subproperties[i]; 180 if (submaker != null && submaker.setByShorthand) { 181 pval.setComponent(submaker.getPropId() & Constants.COMPOUND_MASK, p, false); 182 } 183 } 184 return prop; 185 } 186 return null; 187 } 188 189 195 public Property make(PropertyList propertyList) throws PropertyException { 196 if (defaultValue != null) { 197 return make(propertyList, defaultValue, propertyList.getParentFObj()); 198 } else { 199 return makeCompound(propertyList, propertyList.getParentFObj()); 200 } 201 } 202 203 211 public Property make(PropertyList propertyList, String value, 212 FObj fo) throws PropertyException { 213 Property p = super.make(propertyList, value, fo); 214 p = convertProperty(p, propertyList, fo); 215 return p; 216 } 217 218 232 public Property make(Property baseProperty, int subpropertyId, 233 PropertyList propertyList, String value, 234 FObj fo) throws PropertyException { 235 if (baseProperty == null) { 236 baseProperty = makeCompound(propertyList, fo); 237 } 238 239 PropertyMaker spMaker = getSubpropMaker(subpropertyId); 240 241 if (spMaker != null) { 242 Property p = spMaker.make(propertyList, value, fo); 243 if (p != null) { 244 return setSubprop(baseProperty, subpropertyId & Constants.COMPOUND_MASK, p); 245 } 246 } else { 247 } 250 return baseProperty; 251 } 252 253 262 protected Property makeCompound(PropertyList propertyList, FObj parentFO) 263 throws PropertyException { 264 Property p = makeNewProperty(); 265 CompoundDatatype data = (CompoundDatatype) p.getObject(); 266 for (int i = 0; i < Constants.COMPOUND_COUNT; i++) { 267 PropertyMaker subpropertyMaker = subproperties[i]; 268 if (subpropertyMaker != null) { 269 Property subproperty = subpropertyMaker.make(propertyList); 270 data.setComponent(subpropertyMaker.getPropId() & Constants.COMPOUND_MASK, subproperty, true); 271 } 272 } 273 return p; 274 } 275 } 276 | Popular Tags |