1 16 package org.ccil.cowan.tagsoup; 17 import java.util.HashMap ; 18 19 23 24 public abstract class Schema { 25 26 public static final int M_ANY = 0xFFFFFFFF; 27 public static final int M_EMPTY = 0; 28 public static final int M_PCDATA = 1 << 30; 29 public static final int M_ROOT = 1 << 31; 30 31 32 public static final int F_RESTART = 1; 33 public static final int F_CDATA = 2; 34 public static final int F_NOFORCE = 4; 35 36 private HashMap theEntities = 37 new HashMap (); private HashMap theElementTypes = 39 new HashMap (); 41 private String theURI = ""; 42 private String thePrefix = ""; 43 44 51 52 public void elementType(String name, int model, int memberOf, int flags) { 53 ElementType e = new ElementType(name, model, memberOf, flags, this); 54 theElementTypes.put(name, e); 55 } 56 57 64 65 public void attribute(String elemName, String attrName, 66 String type, String value) { 67 ElementType e = getElementType(elemName); 68 if (e == null) { 69 throw new Error ("Attribute " + attrName + 70 " specified for unknown element type " + 71 elemName); 72 } 73 e.setAttribute(attrName, type, value); 74 } 75 76 81 82 public void parent(String name, String parentName) { 83 ElementType child = getElementType(name); 84 ElementType parent = getElementType(parentName); 85 if (child == null) { 86 throw new Error ("No child " + name + " for parent " + parentName); 87 } 88 if (parent == null) { 89 throw new Error ("No parent " + parentName + " for child " + name); 90 } 91 child.setParent(parent); 92 } 93 94 99 100 public void entity(String name, char value) { 101 theEntities.put(name, new Character (value)); 102 } 103 104 109 110 public ElementType getElementType(String name) { 111 return (ElementType)(theElementTypes.get(name)); 112 } 113 114 119 120 public char getEntity(String name) { 121 if (name.length() == 0) return 0; 123 if (name.charAt(0) == '#') { 124 if (name.length() > 1 && name.charAt(1) == 'x') { 125 try { 126 return (char)Integer.parseInt(name.substring(2), 16); 127 } 128 catch (NumberFormatException e) { return 0; } 129 } 130 try { 131 return (char)Integer.parseInt(name.substring(1)); 132 } 133 catch (NumberFormatException e) { return 0; } 134 } 135 Character c = (Character )theEntities.get(name); 136 if (c == null) { 137 return 0; 138 } 139 return c.charValue(); 140 } 141 142 145 146 public String getURI() { 147 return theURI; 148 } 149 150 153 154 public String getPrefix() { 155 return thePrefix; 156 } 157 158 161 162 public void setURI(String uri) { 163 theURI = uri; 164 } 165 166 169 170 public void setPrefix(String prefix) { 171 thePrefix = prefix; 172 } 173 174 } 175 | Popular Tags |