1 17 18 19 20 package org.apache.fop.fotreetest.ext; 21 22 23 import org.apache.fop.apps.FOPException; 24 import org.apache.fop.fo.FONode; 25 import org.apache.fop.fo.FOPropertyMapping; 26 import org.apache.fop.fo.PropertyList; 27 import org.apache.fop.fo.properties.KeepProperty; 28 import org.apache.fop.fo.properties.LengthPairProperty; 29 import org.apache.fop.fo.properties.LengthRangeProperty; 30 import org.apache.fop.fo.properties.Property; 31 import org.apache.fop.fo.properties.SpaceProperty; 32 import org.apache.fop.fotreetest.ResultCollector; 33 34 import org.xml.sax.Attributes ; 35 import org.xml.sax.Locator ; 36 37 40 public class AssertElement extends TestObj { 41 42 45 public AssertElement(FONode parent) { 46 super(parent); 47 } 48 49 52 public void processNode(String elementName, 53 Locator locator, 54 Attributes attlist, 55 PropertyList propertyList) throws FOPException { 56 58 ResultCollector collector = ResultCollector.getInstance(); 59 String propName = attlist.getValue("property"); 60 String component = null; 61 int dotIndex = propName.indexOf('.'); 62 if (dotIndex >= 0) { 63 component = propName.substring(dotIndex + 1); 64 propName = propName.substring(0, dotIndex); 65 } 66 int propID = FOPropertyMapping.getPropertyId(propName); 67 if (propID < 0) { 68 collector.notifyException(new IllegalArgumentException ( 69 "Property not found: " + propName)); 70 } else { 71 Property prop; 72 prop = propertyList.getParentPropertyList().get(propID); 73 if (component != null) { 74 Property mainProp = prop; 76 prop = null; 77 LengthPairProperty lpp = mainProp.getLengthPair(); 78 if (lpp != null) { 79 prop = lpp.getComponent(FOPropertyMapping.getSubPropertyId(component)); 80 } 81 LengthRangeProperty lrp = mainProp.getLengthRange(); 82 if (lrp != null) { 83 prop = lrp.getComponent(FOPropertyMapping.getSubPropertyId(component)); 84 } 85 KeepProperty kp = mainProp.getKeep(); 86 if (kp != null) { 87 prop = kp.getComponent(FOPropertyMapping.getSubPropertyId(component)); 88 } 89 SpaceProperty sp = mainProp.getSpace(); 90 if (sp != null) { 91 prop = sp.getComponent(FOPropertyMapping.getSubPropertyId(component)); 92 } 93 } 94 String s = String.valueOf(prop); 95 String expected = attlist.getValue("expected"); 96 if (!expected.equals(s)) { 97 collector.notifyException( 98 new IllegalStateException (locator.getSystemId() 99 + "\nProperty '" + propName 100 + "' expected to evaluate to '" + expected 101 + "' but got '" + s 102 + "'\n(test:assert in " 103 + propertyList.getParentFObj().getName() 104 + " at line #" + locator.getLineNumber() 105 + ", column #" + locator.getColumnNumber() + ")\n")); 106 } 107 } 108 109 } 110 111 112 public String getLocalName() { 113 return "assert"; 114 } 115 116 } 117 118 | Popular Tags |