1 23 24 package tests.org.enhydra.xml.xhtml.dominfo; 25 26 import java.util.HashMap ; 27 import java.util.Iterator ; 28 import java.util.Map ; 29 import java.util.Set ; 30 import java.util.TreeMap ; 31 32 36 class Relations { 37 38 public static final int HTML_INTERFACE_IDX = 0; 39 public static final int XHTML_INTERFACE_IDX = 1; 40 public static final int XHTML_IMPLEMENTATION_IDX = 2; 41 public static final int NUM_DOM_CLASS_TYPES = 3; 42 43 46 public class TagRelation { 47 48 private final String fTagName; 49 50 51 private final DTDInfo.ElementInfo fElementInfo; 52 53 54 private DOMInfo.ElementClass[] fElementClassInfo = new DOMInfo.ElementClass[NUM_DOM_CLASS_TYPES]; 55 56 60 private Map fAttrRelations = new TreeMap (); 61 62 63 public TagRelation(DTDInfo.ElementInfo elementInfo) { 64 fTagName = elementInfo.getRawName(); 65 fElementInfo = elementInfo; 66 67 Iterator attrNames = elementInfo.getAttrNames().iterator(); 69 while (attrNames.hasNext()) { 70 addDTDAttrInfo(elementInfo.getAttr((String )attrNames.next())); 71 } 72 } 73 74 75 public TagRelation(String tagName) { 76 fTagName = tagName; 77 fElementInfo = null; 78 } 79 80 81 private void addDTDAttrInfo(DTDInfo.AttrInfo attrInfo) { 82 AttrRelation attrRelation = new AttrRelation(this, attrInfo); 84 if (fAttrRelations.containsKey(attrRelation.getAttrName())) { 85 throw new Error ("attribute \"" + attrRelation.getAttrName() + "\" already exists"); 86 } 87 fAttrRelations.put(attrRelation.getAttrName(), attrRelation); 88 } 89 90 91 92 private void addElementProperties(int domIdx, 93 DOMInfo.ElementClass elementClassInfo) { 94 Iterator props = elementClassInfo.getPropertyNames().iterator(); 95 while (props.hasNext()) { 96 addElementProperty(domIdx, elementClassInfo.getProperty((String )props.next())); 97 } 98 } 99 100 101 public Set getAttrRelationNames() { 102 return fAttrRelations.keySet(); 103 } 104 105 106 public AttrRelation getAttrRelation(String name) { 107 return (AttrRelation)fAttrRelations.get(name); 108 } 109 110 111 public String getTagName() { 112 return fTagName; 113 } 114 115 116 public DTDInfo.ElementInfo getElementInfo() { 117 return fElementInfo; 118 } 119 120 121 public DOMInfo.ElementClass getElementClassInfo(int domIdx) { 122 return fElementClassInfo[domIdx]; 123 } 124 125 126 public void setElementClassInfo(int domIdx, 127 DOMInfo.ElementClass elementClassInfo) { 128 fElementClassInfo[domIdx] = elementClassInfo; 129 addElementProperties(domIdx, elementClassInfo); 131 } 132 133 134 private void addElementProperty(int domIdx, 135 DOMInfo.ElementProperty prop) { 136 String attrName = prop.getAttrName(); 137 if (fSpecialPropertyAttrMap.containsKey(attrName)) { 138 attrName = (String )fSpecialPropertyAttrMap.get(attrName); 139 } 140 141 AttrRelation attrRelHead = (AttrRelation)fAttrRelations.get(attrName); 142 if (attrRelHead == null) { 143 attrRelHead = new AttrRelation(this, prop.getAttrName()); 145 fAttrRelations.put(attrRelHead.getAttrName(), attrRelHead); 146 } 147 148 AttrRelation attrRel = attrRelHead; 150 while ((attrRel != null) && (attrRel.getElementPropertyInfo(domIdx) != null)) { 151 attrRel = attrRel.getNextAttrRelation(); 152 } 153 if (attrRel == null) { 154 DTDInfo.AttrInfo attrInfo = attrRelHead.getAttrInfo(); 156 if (attrInfo != null) { 157 attrRel = new AttrRelation(this, attrInfo); 158 } else { 159 attrRel = new AttrRelation(this, prop.getAttrName()); 160 } 161 attrRelHead.addAttrRelation(attrRel); 162 } 163 attrRel.setElementPropertyInfo(domIdx, prop); 164 } 165 } 166 167 171 public class AttrRelation { 172 173 private final TagRelation fTagRelation; 174 175 176 private final String fAttrName; 177 178 179 private final DTDInfo.AttrInfo fAttrInfo; 180 181 182 private DOMInfo.ElementProperty[] fElementPropertyInfo = new DOMInfo.ElementProperty[NUM_DOM_CLASS_TYPES]; 183 184 189 private AttrRelation fNext; 190 191 192 public AttrRelation(TagRelation tagRelation, 193 DTDInfo.AttrInfo attrInfo) { 194 fTagRelation = tagRelation; 195 fAttrName = attrInfo.getRawName().toLowerCase(); 196 fAttrInfo = attrInfo; 197 } 199 200 201 public AttrRelation(TagRelation tagRelation, 202 String attrNameLower) { 203 fTagRelation = tagRelation; 204 fAttrName = attrNameLower; 205 fAttrInfo = null; 206 } 208 209 210 public TagRelation getTagRelation() { 211 return fTagRelation; 212 } 213 214 215 public String getAttrName() { 216 return fAttrName; 217 } 218 219 220 public DTDInfo.AttrInfo getAttrInfo() { 221 return fAttrInfo; 222 } 223 224 225 public DOMInfo.ElementProperty getElementPropertyInfo(int domIdx) { 226 return fElementPropertyInfo[domIdx]; 227 } 228 229 230 public void setElementPropertyInfo(int domIdx, 231 DOMInfo.ElementProperty elementPropertyInfo) { 232 fElementPropertyInfo[domIdx] = elementPropertyInfo; 233 } 234 235 239 public void addAttrRelation(AttrRelation next) { 240 if (fNext == null) { 241 fNext = next; 242 } else { 243 fNext.addAttrRelation(next); 244 } 245 } 246 247 250 public AttrRelation getNextAttrRelation() { 251 return fNext; 252 } 253 } 254 255 256 257 private DTDInfo fDTDInfo; 258 259 260 private DOMInfo[] fDOMInfos = new DOMInfo[NUM_DOM_CLASS_TYPES]; 261 262 266 private Set [] fPendingElementClasses = new Set [NUM_DOM_CLASS_TYPES]; 267 268 269 private Map fTags = new TreeMap (); 270 271 272 private static final String [][] SPECIAL_PROPERTY_ATTR_MAP = { 273 {"ClassName", "class"}, 274 {"ChOff", "charoff"}, 275 {"Ch", "char"} 276 }; 277 private static final HashMap fSpecialPropertyAttrMap = new HashMap (); 278 279 static { 280 for (int idx =
|