1 51 package org.apache.fop.fo; 52 53 import org.apache.fop.messaging.MessageHandler; 54 import org.apache.fop.fo.properties.WritingMode; 55 import org.apache.fop.apps.FOPException; 56 57 import java.util.HashMap ; 58 59 60 public class PropertyList extends HashMap { 61 62 private byte[] wmtable = null; public static final int LEFT = 0; 64 public static final int RIGHT = 1; 65 public static final int TOP = 2; 66 public static final int BOTTOM = 3; 67 public static final int HEIGHT = 4; 68 public static final int WIDTH = 5; 69 70 public static final int START = 0; 71 public static final int END = 1; 72 public static final int BEFORE = 2; 73 public static final int AFTER = 3; 74 public static final int BLOCKPROGDIM = 4; 75 public static final int INLINEPROGDIM = 5; 76 77 private static final String [] sAbsNames = new String [] { 78 "left", "right", "top", "bottom", "height", "width" 79 }; 80 81 private static final String [] sRelNames = new String [] { 82 "start", "end", "before", "after", "block-progression-dimension", 83 "inline-progression-dimension" 84 }; 85 86 private static final byte[][] wmtables; 87 static{ 88 int i = Math.max( Math.max( WritingMode.LR_TB, WritingMode.RL_TB), WritingMode.TB_RL)+1; 89 wmtables = new byte[i][]; 90 wmtables[ WritingMode.LR_TB] = 91 new byte[] { 92 START, END, BEFORE, AFTER, BLOCKPROGDIM, INLINEPROGDIM 93 }; 94 wmtables[ WritingMode.RL_TB] = 95 new byte[] { 96 END, START, BEFORE, AFTER, BLOCKPROGDIM, INLINEPROGDIM 97 }; 98 wmtables[ WritingMode.TB_RL] = 99 new byte[] { 100 AFTER, BEFORE, START, END, INLINEPROGDIM, BLOCKPROGDIM 101 }; 102 } 103 104 private PropertyListBuilder builder; 105 private PropertyList parentPropertyList = null; 106 String namespace = ""; 107 String element = ""; 108 FObj fobj = null; 109 110 public PropertyList(PropertyList parentPropertyList, String space, 111 String el) { 112 this.parentPropertyList = parentPropertyList; 113 this.namespace = space; 114 this.element = el; 115 } 116 117 public void setFObj(FObj fobj) { 118 this.fobj = fobj; 119 } 120 121 public FObj getFObj() { 122 return this.fobj; 123 } 124 125 public FObj getParentFObj() { 126 if (parentPropertyList != null) { 127 return parentPropertyList.getFObj(); 128 } else 129 return null; 130 } 131 132 139 public Property getExplicitOrShorthand(String propertyName) { 140 141 int sepchar = propertyName.indexOf('.'); 142 String baseName; 143 if (sepchar > -1) { 144 baseName = propertyName.substring(0, sepchar); 145 } else 146 baseName = propertyName; 147 Property p = getExplicitBaseProp(baseName); 148 if (p == null) { 149 p = builder.getShorthand(this, namespace, element, baseName); 150 } 151 if (p != null && sepchar > -1) { 152 return builder.getSubpropValue(namespace, element, baseName, p, 153 propertyName.substring(sepchar 154 + 1)); 155 } 156 return p; 157 } 158 159 165 public Property getExplicit(String propertyName) { 166 167 int sepchar = propertyName.indexOf('.'); 168 if (sepchar > -1) { 169 String baseName = propertyName.substring(0, sepchar); 170 Property p = getExplicitBaseProp(baseName); 171 if (p != null) { 172 return this.builder.getSubpropValue(namespace, element, 173 baseName, p, 174 propertyName.substring(sepchar 175 + 1)); 176 } else 177 return null; 178 } 179 return (Property)super.get(propertyName); 180 } 181 182 187 public Property getExplicitBaseProp(String propertyName) { 188 return (Property)super.get(propertyName); 189 } 190 191 198 public Property getInherited(String propertyName) { 199 if (builder != null) { 200 if (parentPropertyList != null 201 && builder.isInherited(namespace, element, 202 propertyName)) { 203 return parentPropertyList.get(propertyName); 204 } else { 205 try { 207 return builder.makeProperty(this, namespace, element, 208 propertyName); 209 } catch (org.apache.fop.apps.FOPException e) { 210 MessageHandler.errorln("Exception in getInherited(): property=" 211 + propertyName + " : " + e); 212 } 213 } 214 } 215 return null; } 217 218 226 private Property findProperty(String propertyName, boolean bTryInherit) { 227 Property p = null; 228 if (builder.isCorrespondingForced(this, namespace, element, 229 propertyName)) { 230 p = builder.computeProperty(this, namespace, element, 231 propertyName); 232 } else { 233 p = getExplicitBaseProp(propertyName); 234 if (p == null) { 235 p = this.builder.computeProperty(this, namespace, element, 236 propertyName); 237 } 238 if (p == null) { p = builder.getShorthand(this, namespace, element, 240 propertyName); 241 } 242 if (p == null 243 && bTryInherit) { if (this.parentPropertyList != null 245 && builder.isInherited(namespace, element, 246 propertyName)) { 247 p = parentPropertyList.findProperty(propertyName, true); 248 } 249 } 250 } 251 return p; 252 } 253 254 255 259 public Property getSpecified(String propertyName) { 260 return get(propertyName, false, false); 261 } 262 263 264 270 public Property get(String propertyName) { 271 return get(propertyName, true, true); 272 } 273 274 280 private Property get(String propertyName, boolean bTryInherit, 281 boolean bTryDefault) { 282 283 if (builder == null) 284 MessageHandler.errorln("OH OH, builder has not been set"); 285 286 287 int sepchar = propertyName.indexOf('.'); 288 String subpropName = null; 289 if (sepchar > -1) { 290 subpropName = propertyName.substring(sepchar + 1); 291 propertyName = propertyName.substring(0, sepchar); 292 } 293 294 Property p = findProperty(propertyName, bTryInherit); 295 if (p == null && bTryDefault) { try { 297 p = this.builder.makeProperty(this, namespace, element, 298 propertyName); 299 } catch (FOPException e) { 300 } 302 } 303 313 if (subpropName != null && p != null) { 314 return this.builder.getSubpropValue(namespace, element, 315 propertyName, p, subpropName); 316 } else 317 return p; 318 } 319 320 public void setBuilder(PropertyListBuilder builder) { 321 this.builder = builder; 322 } 323 324 public String getNameSpace() { 325 return namespace; 326 } 327 328 public String getElement() { 329 return element; 330 } 331 332 339 public Property getNearestSpecified(String propertyName) { 340 Property p = null; 341 for (PropertyList plist = this; p == null && plist != null; 342 plist = plist.parentPropertyList) { 343 p = plist.getExplicit(propertyName); 344 } 345 if (p == null) { 346 try { 348 p = this.builder.makeProperty(this, namespace, element, 349 propertyName); 350 } catch (FOPException e) { 351 MessageHandler.errorln("Exception in getNearestSpecified(): property=" 352 + propertyName + " : " + e); 353 } 354 } 355 return p; 356 } 357 358 365 public Property getFromParent(String propertyName) { 366 if (parentPropertyList != null) { 367 return parentPropertyList.get(propertyName); 368 } else if (builder != null) { 369 try { 371 return builder.makeProperty(this, namespace, element, 372 propertyName); 373 } catch (org.apache.fop.apps.FOPException e) { 374 MessageHandler.errorln("Exception in getFromParent(): property=" 375 + propertyName + " : " + e); 376 } 377 } 378 return null; } 380 381 386 public String wmAbsToRel(int absdir) { 387 if (wmtable != null) { 388 return sRelNames[wmtable[absdir]]; 389 } else 390 return ""; 391 } 392 393 398 public String wmRelToAbs(int reldir) { 399 if (wmtable != null) { 400 for (int i = 0; i < wmtable.length; i++) { 401 if (wmtable[i] == reldir) 402 return sAbsNames[i]; 403 } 404 } 405 return ""; 406 } 407 408 411 public void setWritingMode(int writingMode) { 412 this.wmtable = wmtables[writingMode]; 413 } 414 415 } 416 417 | Popular Tags |