1 57 58 package com.sun.org.apache.xerces.internal.dom; 59 60 import org.w3c.dom.DocumentType ; 61 import org.w3c.dom.EntityReference ; 62 import org.w3c.dom.NamedNodeMap ; 63 import org.w3c.dom.Node ; 64 65 120 public class EntityReferenceImpl 121 extends ParentNode 122 implements EntityReference { 123 124 128 129 static final long serialVersionUID = -7381452955687102062L; 130 131 135 136 protected String name; 137 138 protected String baseURI; 139 140 141 142 144 145 147 151 152 public EntityReferenceImpl(CoreDocumentImpl ownerDoc, String name) { 153 super(ownerDoc); 154 this.name = name; 155 isReadOnly(true); 156 needsSyncChildren(true); 157 } 158 159 163 167 public short getNodeType() { 168 return Node.ENTITY_REFERENCE_NODE; 169 } 170 171 174 public String getNodeName() { 175 if (needsSyncData()) { 176 synchronizeData(); 177 } 178 return name; 179 } 180 181 182 public Node cloneNode(boolean deep) { 183 EntityReferenceImpl er = (EntityReferenceImpl)super.cloneNode(deep); 184 er.setReadOnly(true, deep); 185 return er; 186 } 187 188 192 public String getBaseURI() { 193 if (needsSyncData()) { 194 synchronizeData(); 195 } 196 if (baseURI == null) { 197 DocumentType doctype; 198 NamedNodeMap entities; 199 EntityImpl entDef; 200 if (null != (doctype = getOwnerDocument().getDoctype()) && 201 null != (entities = doctype.getEntities())) { 202 203 entDef = (EntityImpl)entities.getNamedItem(getNodeName()); 204 if (entDef !=null) { 205 return entDef.getBaseURI(); 206 } 207 } 208 } 209 return baseURI; 210 } 211 212 213 214 public void setBaseURI(String uri){ 215 if (needsSyncData()) { 216 synchronizeData(); 217 } 218 baseURI = uri; 219 } 220 221 228 protected String getEntityRefValue (){ 229 if (needsSyncChildren()){ 230 synchronizeChildren(); 231 } 232 233 String value = ""; 234 if (firstChild != null){ 235 if (firstChild.getNodeType() == Node.ENTITY_REFERENCE_NODE){ 236 value = ((EntityReferenceImpl)firstChild).getEntityRefValue(); 237 } 238 else if (firstChild.getNodeType() == Node.TEXT_NODE){ 239 value = firstChild.getNodeValue(); 240 } 241 else { 242 return null; 244 } 245 246 if (firstChild.nextSibling == null){ 247 return value; 248 } 249 else { 250 StringBuffer buff = new StringBuffer (value); 251 ChildNode next = firstChild.nextSibling; 252 while (next != null){ 253 254 if (next.getNodeType() == Node.ENTITY_REFERENCE_NODE){ 255 value = ((EntityReferenceImpl)next).getEntityRefValue(); 256 } 257 else if (next.getNodeType() == Node.TEXT_NODE){ 258 value = next.getNodeValue(); 259 } 260 else { 261 return null; 263 } 264 buff.append(value); 265 next = next.nextSibling; 266 267 } 268 return buff.toString(); 269 } 270 } 271 return ""; 272 } 273 274 280 protected void synchronizeChildren() { 281 needsSyncChildren(false); 283 284 DocumentType doctype; 285 NamedNodeMap entities; 286 EntityImpl entDef; 287 if (null != (doctype = getOwnerDocument().getDoctype()) && 288 null != (entities = doctype.getEntities())) { 289 290 entDef = (EntityImpl)entities.getNamedItem(getNodeName()); 291 292 if (entDef == null) 294 return; 295 296 isReadOnly(false); 298 for (Node defkid = entDef.getFirstChild(); 299 defkid != null; 300 defkid = defkid.getNextSibling()) { 301 Node newkid = defkid.cloneNode(true); 302 insertBefore(newkid, null); 303 } 304 setReadOnly(true, true); 305 } 306 } 307 308 309 314 public void setReadOnly(boolean readOnly, boolean deep) { 315 316 if (needsSyncData()) { 317 synchronizeData(); 318 } 319 if (deep) { 320 321 if (needsSyncChildren()) { 322 synchronizeChildren(); 323 } 324 for (ChildNode mykid = firstChild; 326 mykid != null; 327 mykid = mykid.nextSibling) { 328 329 mykid.setReadOnly(readOnly,true); 330 331 } 332 } 333 isReadOnly(readOnly); 334 } 336 337 346 347 373 423 424 425 } | Popular Tags |