home *** CD-ROM | disk | FTP | other *** search
- package com.sun.xml.tree;
-
- import java.io.CharArrayWriter;
- import java.io.IOException;
- import java.io.Writer;
- import org.w3c.dom.Attr;
- import org.w3c.dom.DOMException;
- import org.w3c.dom.Element;
- import org.w3c.dom.NamedNodeMap;
- import org.w3c.dom.Node;
-
- public class ElementNode extends ParentNode implements ElementEx {
- private String tag;
- private AttributeSet attributes;
- private String idAttributeName;
- private Object userObject;
- private static final char[] tagStart = new char[]{'<', '/'};
- private static final char[] tagEnd = new char[]{' ', '/', '>'};
-
- void checkChildType(int var1) throws DOMException {
- switch (var1) {
- case 1:
- case 3:
- case 4:
- case 5:
- case 7:
- case 8:
- return;
- case 2:
- case 6:
- default:
- throw new DomEx((short)3);
- }
- }
-
- public Node cloneNode(boolean var1) {
- try {
- ElementNode var2 = (ElementNode)((NodeBase)this).getOwnerDocument().createElement(this.tag);
- if (this.attributes != null) {
- var2.setAttributes(new AttributeSet(this.attributes, true));
- }
-
- if (var1) {
- int var3 = 0;
-
- while(true) {
- Node var4 = ((ParentNode)this).item(var3);
- if (var4 == null) {
- break;
- }
-
- ((ParentNode)var2).appendChild(var4.cloneNode(true));
- ++var3;
- }
- }
-
- return var2;
- } catch (DOMException var5) {
- throw new RuntimeException(((NodeBase)this).getMessage("EN-001"));
- }
- }
-
- public String getAttribute(String var1) {
- return this.attributes == null ? "" : this.attributes.getValue(var1);
- }
-
- public String getAttribute(String var1, String var2) {
- if (this.attributes == null) {
- return "";
- } else {
- Attr var3 = this.getAttributeNode(var1, var2);
- return var3 == null ? "" : var3.getValue();
- }
- }
-
- public Attr getAttributeNode(String var1) {
- return this.attributes != null ? (Attr)this.attributes.getNamedItem(var1) : null;
- }
-
- public Attr getAttributeNode(String var1, String var2) {
- if (var2 == null) {
- return null;
- } else if (this.attributes != null) {
- int var3 = 0;
-
- while(true) {
- AttributeNode var4 = (AttributeNode)this.attributes.item(var3);
- if (var4 == null) {
- return null;
- }
-
- if (var2.equals(var4.getName())) {
- String var5 = var4.getNamespace();
- if (var5 != null && var5.equals(var1)) {
- return var4;
- }
- }
-
- ++var3;
- }
- } else {
- return null;
- }
- }
-
- public NamedNodeMap getAttributes() {
- if (this.attributes == null) {
- this.attributes = new AttributeSet(this);
- }
-
- return this.attributes;
- }
-
- public String getIdAttributeName() {
- return this.idAttributeName;
- }
-
- public String getLocalName() {
- int var1 = this.tag.indexOf(58);
- return var1 < 0 ? this.tag : this.tag.substring(var1 + 1);
- }
-
- public String getNamespace() {
- String var1;
- if ((var1 = this.getPrefix()) == null) {
- return ((NodeBase)this).getInheritedAttribute("xmlns");
- } else if (!"xml".equals(var1) && !"xmlns".equals(var1)) {
- String var2 = ((NodeBase)this).getInheritedAttribute("xmlns:" + var1);
- if (var2 == null) {
- throw new IllegalStateException(((NodeBase)this).getMessage("EN-000", new Object[]{var1}));
- } else {
- return var2;
- }
- } else {
- return null;
- }
- }
-
- public String getNodeName() {
- return this.tag;
- }
-
- public short getNodeType() {
- return 1;
- }
-
- public String getPrefix() {
- int var1 = this.tag.indexOf(58);
- return var1 < 0 ? null : this.tag.substring(0, var1);
- }
-
- public String getTagName() {
- return this.tag;
- }
-
- public Object getUserObject() {
- return this.userObject;
- }
-
- public void normalize() {
- boolean var2 = false;
- boolean var3 = false;
- if (super.readonly) {
- throw new DomEx((short)7);
- } else {
- Node var1;
- for(int var4 = 0; (var1 = ((ParentNode)this).item(var4)) != null; ++var4) {
- switch (var1.getNodeType()) {
- case 1:
- ((Element)var1).normalize();
- case 2:
- default:
- break;
- case 3:
- Node var5 = ((ParentNode)this).item(var4 + 1);
- if (var5 != null && var5.getNodeType() == 3) {
- ((TextNode)var1).joinNextText();
- --var4;
- } else {
- if (!var3) {
- var2 = "preserve".equals(((NodeBase)this).getInheritedAttribute("xml:space"));
- var3 = true;
- }
-
- if (!var2) {
- char[] var6 = ((TextNode)var1).data;
- if (var6 != null && var6.length != 0) {
- int var7 = this.removeWhiteSpaces(var6);
- if (var7 != var6.length) {
- char[] var8 = new char[var7];
- System.arraycopy(var6, 0, var8, 0, var7);
- ((TextNode)var1).data = var8;
- }
- } else {
- ((ParentNode)this).removeChild(var1);
- --var4;
- }
- }
- }
- }
- }
-
- }
- }
-
- public void removeAttribute(String var1) throws DOMException {
- if (super.readonly) {
- throw new DomEx((short)7);
- } else if (this.attributes == null) {
- throw new DomEx((short)8);
- } else {
- this.attributes.removeNamedItem(var1);
- }
- }
-
- public Attr removeAttributeNode(Attr var1) throws DOMException {
- if (((NodeBase)this).isReadonly()) {
- throw new DomEx((short)7);
- } else {
- Attr var2 = this.getAttributeNode(var1.getNodeName());
- if (var2 == null) {
- throw new DomEx((short)8);
- } else {
- this.removeAttribute(var2.getNodeName());
- return var2;
- }
- }
- }
-
- public int removeWhiteSpaces(char[] var1) {
- int var2 = 0;
- int var3 = 0;
-
- while(var3 < var1.length) {
- boolean var4 = false;
- char var5 = var1[var3++];
- if (var5 == ' ' || var5 == '\t' || var5 == '\n' || var5 == '\r') {
- var5 = ' ';
- var4 = true;
- }
-
- var1[var2++] = var5;
- if (var4) {
- while(var3 < var1.length) {
- var5 = var1[var3];
- if (var5 != ' ' && var5 != '\t' && var5 != '\n' && var5 != '\r') {
- break;
- }
-
- ++var3;
- }
- }
- }
-
- return var2;
- }
-
- public void setAttribute(String var1, String var2) throws DOMException {
- if (super.readonly) {
- throw new DomEx((short)7);
- } else {
- if (this.attributes == null) {
- this.attributes = new AttributeSet(this);
- }
-
- AttributeNode var3;
- if ((var3 = (AttributeNode)this.attributes.getNamedItem(var1)) != null) {
- var3.setNodeValue(var2);
- } else {
- var3 = new AttributeNode(var1, var2, true, (String)null);
- ((NodeBase)var3).setOwnerDocument((XmlDocument)((NodeBase)this).getOwnerDocument());
- this.attributes.setNamedItem(var3);
- }
-
- }
- }
-
- public Attr setAttributeNode(Attr var1) throws DOMException {
- if (super.readonly) {
- throw new DomEx((short)7);
- } else if (!(var1 instanceof AttributeNode)) {
- throw new DomEx((short)4);
- } else {
- if (this.attributes == null) {
- this.attributes = new AttributeSet(this);
- }
-
- return (Attr)this.attributes.setNamedItem(var1);
- }
- }
-
- void setAttributes(AttributeSet var1) {
- AttributeSet var2 = this.attributes;
- if (var2 != null && var2.isReadonly()) {
- throw new DomEx((short)7);
- } else {
- if (var1 != null) {
- var1.setNameScope(this);
- }
-
- this.attributes = var1;
- if (var2 != null) {
- var2.setNameScope((ElementNode)null);
- }
-
- }
- }
-
- public void setIdAttributeName(String var1) {
- if (super.readonly) {
- throw new DomEx((short)7);
- } else {
- this.idAttributeName = var1;
- }
- }
-
- public void setPrefix(String var1) {
- int var2 = this.tag.indexOf(58);
- if (var1 == null) {
- if (var2 >= 0) {
- this.tag = this.tag.substring(var2 + 1);
- }
- } else {
- StringBuffer var3 = new StringBuffer(var1);
- var3.append(':');
- if (var2 < 0) {
- var3.append(this.tag);
- } else {
- var3.append(this.tag.substring(var2 + 1));
- }
-
- this.tag = var3.toString();
- }
- }
-
- public void setReadonly(boolean var1) {
- if (this.attributes != null) {
- this.attributes.setReadonly();
- }
-
- super.setReadonly(var1);
- }
-
- protected void setTag(String var1) {
- this.tag = var1;
- }
-
- public void setUserObject(Object var1) {
- this.userObject = var1;
- }
-
- public String toString() {
- try {
- CharArrayWriter var1 = new CharArrayWriter();
- XmlWriteContext var2 = new XmlWriteContext(var1);
- this.writeXml(var2);
- return var1.toString();
- } catch (Exception var3) {
- return super.toString();
- }
- }
-
- public void trimToSize() {
- super.trimToSize();
- if (this.attributes != null) {
- this.attributes.trimToSize();
- }
-
- }
-
- public void write(Writer var1) throws IOException {
- this.writeXml(new XmlWriteContext(var1));
- }
-
- public void writeXml(XmlWriteContext var1) throws IOException {
- Writer var2 = var1.getWriter();
- if (this.tag == null) {
- throw new IllegalStateException(((NodeBase)this).getMessage("EN-002"));
- } else {
- var2.write(tagStart, 0, 1);
- var2.write(this.tag);
- if (this.attributes != null) {
- this.attributes.writeXml(var1);
- }
-
- if (!((ParentNode)this).hasChildNodes()) {
- var2.write(tagEnd, 0, 3);
- } else {
- var2.write(tagEnd, 2, 1);
- ((ParentNode)this).writeChildrenXml(var1);
- var2.write(tagStart, 0, 2);
- var2.write(this.tag);
- var2.write(tagEnd, 2, 1);
- }
-
- }
- }
- }
-