home *** CD-ROM | disk | FTP | other *** search
- package com.ibm.xml.parser;
-
- import java.util.Enumeration;
- import java.util.Vector;
- import org.w3c.dom.Attr;
- import org.w3c.dom.CDATASection;
- import org.w3c.dom.DOMException;
- import org.w3c.dom.Element;
- import org.w3c.dom.NamedNodeMap;
- import org.w3c.dom.Node;
- import org.w3c.dom.NodeList;
- import org.w3c.dom.Text;
-
- public class TXElement extends Parent implements Element, Namespace {
- static final long serialVersionUID = 1851699621748517673L;
- public static final String S_XMLNS = "xmlns";
- public static final String S_XMLNAMESPACEURI = "http://www.w3.org/XML/1998/namespace";
- String name;
- TXAttributeList attributes;
- boolean isPreserveSpace = false;
-
- public TXElement(String var1) {
- this.setTagName(var1);
- }
-
- public synchronized Object clone() {
- TXElement var1 = this.cloneWithoutChildren();
- var1.children.ensureCapacity(super.children.getLength());
-
- for(int var2 = 0; var2 < super.children.getLength(); ++var2) {
- ((Parent)var1).insertBefore(super.children.item(var2).cloneNode(true), (Node)null);
- }
-
- return var1;
- }
-
- public synchronized TXElement cloneWithoutChildren() {
- ((Child)this).checkFactory();
- TXElement var1 = (TXElement)super.factory.createElement(this.getTagName());
- ((Child)var1).setFactory(((Child)this).getFactory());
- var1.setPreserveSpace(this.isPreserveSpace);
- if (this.attributes != null) {
- for(int var2 = 0; var2 < this.attributes.getLength(); ++var2) {
- var1.setAttributeNode((TXAttribute)this.attributes.item(var2).cloneNode(true));
- }
- }
-
- return var1;
- }
-
- public Node cloneNode(boolean var1) {
- return (Node)(var1 ? (Node)this.clone() : this.cloneWithoutChildren());
- }
-
- public boolean equals(Node var1, boolean var2) {
- if (var1 == null) {
- return false;
- } else if (!(var1 instanceof TXElement)) {
- return false;
- } else {
- TXElement var3 = (TXElement)var1;
- if (!var3.getTagName().equals(this.getTagName())) {
- return false;
- } else {
- NamedNodeMap var4 = var3.getAttributes();
- NamedNodeMap var5 = this.getAttributes();
- if (var4.getLength() != var5.getLength()) {
- return false;
- } else {
- for(int var6 = 0; var6 < var4.getLength(); ++var6) {
- Attr var7 = (Attr)var4.item(var6);
- Attr var8 = (Attr)var5.getNamedItem(var7.getName());
- if (var8 == null || !((Child)var7).equals(var8, true)) {
- return false;
- }
- }
-
- if (var2 && !var3.children.equals(super.children, var2)) {
- return false;
- } else {
- return true;
- }
- }
- }
- }
- }
-
- public short getNodeType() {
- return 1;
- }
-
- public String getNodeName() {
- return this.getTagName();
- }
-
- public String getTagName() {
- return this.name;
- }
-
- /** @deprecated */
- public String getName() {
- return this.getTagName();
- }
-
- public void setTagName(String var1) {
- this.name = var1;
- ((Child)this).clearDigest();
- }
-
- public String getAttribute(String var1) {
- if (this.attributes != null) {
- TXAttribute var2 = (TXAttribute)this.attributes.getNamedItem(var1);
- return var2 == null ? "" : var2.getValue();
- } else {
- return "";
- }
- }
-
- String getAttributeOrNull(String var1) {
- if (this.attributes != null) {
- TXAttribute var2 = (TXAttribute)this.attributes.getNamedItem(var1);
- return var2 == null ? null : var2.getValue();
- } else {
- return null;
- }
- }
-
- public Attr getAttributeNode(String var1) {
- return this.attributes != null ? (Attr)this.attributes.getNamedItem(var1) : null;
- }
-
- public void setAttribute(String var1, String var2) throws DOMException {
- ((Child)this).checkFactory();
- Attr var3 = this.getAttributeNode(var1);
- if (var3 == null) {
- var3 = super.factory.createAttribute(var1);
- this.setAttributeNode(var3);
- var3.setValue(var2);
- } else {
- var3.setValue(var2);
- ((Child)this).clearDigest();
- }
- }
-
- /** @deprecated */
- public void setAttribute(TXAttribute var1) {
- this.makeAttributeList();
- this.attributes.setNamedItem(var1);
- }
-
- public Attr setAttributeNode(Attr var1) {
- this.makeAttributeList();
- return (Attr)this.attributes.setNamedItem(var1);
- }
-
- public void removeAttribute(String var1) {
- if (this.attributes != null) {
- this.attributes.removeNamedItem(var1);
- }
-
- this.resetDefaultAttribute(var1);
- }
-
- public Attr removeAttributeNode(Attr var1) {
- Attr var2 = null;
- if (this.attributes != null) {
- String var3 = this.getAttributeOrNull(var1.getName());
- if (var3 != null && var3.equals(var1.getValue())) {
- var2 = (Attr)this.attributes.removeNamedItem(var1.getName());
- }
- }
-
- this.resetDefaultAttribute(var1.getName());
- return var2;
- }
-
- protected void resetDefaultAttribute(String var1) {
- TXDocument var2 = (TXDocument)((Child)this).getOwnerDocument();
- DTD var3 = (DTD)var2.getDoctype();
- if (var3 != null) {
- AttDef var4 = var3.getAttributeDeclaration(this.getNodeName(), var1);
- if (var4 != null) {
- switch (var4.getDefaultType()) {
- case 0:
- case 2:
- case 3:
- default:
- return;
- case 1:
- if (!var2.isAddFixedAttributes()) {
- return;
- }
- case -1:
- Attr var5 = var2.createAttribute(var1);
- var5.setNodeValue(var4.getDefaultStringValue());
- ((TXAttribute)var5).setSpecified(false);
- this.setAttributeNode(var5);
- }
- }
- }
- }
-
- public NamedNodeMap getAttributes() {
- this.makeAttributeList();
- return this.attributes;
- }
-
- public TXAttribute[] getAttributeArray() {
- return this.attributes == null ? new TXAttribute[0] : this.attributes.makeArray();
- }
-
- public Enumeration attributeElements() {
- this.makeAttributeList();
- return this.attributes.elements();
- }
-
- public String getNSLocalName() {
- return getLocalNameForQName(this.getNodeName());
- }
-
- public String getNSName() {
- return this.getNamespaceForQName(this.getNodeName());
- }
-
- /** @deprecated */
- public String getUniversalName() {
- String var1 = this.getNSName();
- return var1 == null ? this.getNSLocalName() : var1 + ":" + this.getNSLocalName();
- }
-
- public String createExpandedName() {
- String var1 = this.getNSName();
- return var1 != null && var1.length() != 0 ? var1 + ((Child)this).getFactory().expandedNameSeparator + this.getNSLocalName() : this.getNSLocalName();
- }
-
- /** @deprecated */
- public boolean isEmpty() {
- return super.children.getLength() == 0;
- }
-
- public boolean isPreserveSpace() {
- return this.isPreserveSpace;
- }
-
- public void setPreserveSpace(boolean var1) {
- this.isPreserveSpace = var1;
- }
-
- public String getLanguage() {
- String var1 = this.getAttributeOrNull("xml:lang");
- if (var1 != null) {
- return var1;
- } else {
- if (super.parent != null) {
- if (super.parent instanceof TXElement) {
- return ((TXElement)super.parent).getLanguage();
- }
-
- if (super.parent instanceof GeneralReference) {
- return ((GeneralReference)super.parent).getLanguage();
- }
- }
-
- return null;
- }
- }
-
- public void normalize() {
- normalize(this, this.isPreserveSpace());
- }
-
- private static void normalize(Node var0, boolean var1) {
- Node var2 = var0.getFirstChild();
- if (var2 != null) {
- if (var2.getNodeType() == 1) {
- normalize(var2, ((TXElement)var2).isPreserveSpace());
- } else if (var2.getNodeType() == 5) {
- normalize(var2, var1);
- }
-
- Node var3;
- for(; (var3 = var2.getNextSibling()) != null; var2 = var3) {
- short var4 = var3.getNodeType();
- if (var4 == 3 && var2.getNodeType() == 3) {
- ((Text)var3).setData(var2.getNodeValue() + var3.getNodeValue());
- var0.removeChild(var2);
- if (!var1 && Util.checkAllSpace(var3.getNodeValue())) {
- Node var5 = var3.getPreviousSibling();
- Node var6 = var3.getNextSibling();
- if ((var5 == null || var5.getNodeType() != 3) && (var6 == null || var6.getNodeType() != 3)) {
- ((TXText)var3).setIsIgnorableWhitespace(true);
- }
- }
- } else if (var4 == 1) {
- normalize(var3, ((TXElement)var3).isPreserveSpace());
- } else if (var4 == 5) {
- normalize(var3, var1);
- }
- }
-
- }
- }
-
- public void addTextElement(TXText var1) {
- if (var1 != null) {
- if (var1 instanceof CDATASection) {
- ((Parent)this).appendChild(var1);
- } else {
- Node var2 = ((Parent)this).getLastChild();
- if (var2 == null) {
- ((Parent)this).appendChild(var1);
- } else if (var2.getNodeType() != 3) {
- ((Parent)this).appendChild(var1);
- } else {
- ((Text)var2).appendData(((TXCharacterData)var1).getData());
- if (!var1.getIsIgnorableWhitespace() || !((TXText)var2).getIsIgnorableWhitespace()) {
- ((TXText)var2).setIsIgnorableWhitespace(false);
- }
-
- }
- }
- }
- }
-
- public TXElement searchDescendants(String var1) {
- return this.searchDescendants(0, (String)null, var1);
- }
-
- public TXElement searchDescendants(int var1, String var2, String var3) {
- for(Child var4 = (Child)((Parent)this).getFirstChild(); var4 != null; var4 = (Child)var4.getNextSibling()) {
- if (var4 instanceof TXElement) {
- if (Match.matchName((TXElement)var4, var1, var2, var3)) {
- return (TXElement)var4;
- }
-
- TXElement var5 = ((TXElement)var4).searchDescendants(var1, var2, var3);
- if (var5 != null) {
- return var5;
- }
- }
- }
-
- return null;
- }
-
- public TXElement getElementNamed(String var1) {
- return this.getNthElementNamed(0, 0, (String)null, var1);
- }
-
- public TXElement getElementNamed(String var1, String var2) {
- return this.getNthElementNamed(0, 2, var1, var2);
- }
-
- public TXElement getElementNamed(int var1, String var2, String var3) {
- return this.getNthElementNamed(0, var1, var2, var3);
- }
-
- public TXElement getNthElementNamed(int var1, String var2) {
- return this.getNthElementNamed(var1, 0, (String)null, var2);
- }
-
- public TXElement getNthElementNamed(int var1, String var2, String var3) {
- return this.getNthElementNamed(var1, 2, var2, var3);
- }
-
- public TXElement getNthElementNamed(int var1, int var2, String var3, String var4) {
- for(Node var5 = ((Parent)this).getFirstChild(); var5 != null; var5 = var5.getNextSibling()) {
- if (var5 instanceof TXElement) {
- TXElement var6 = (TXElement)var5;
- if (Match.matchName(var6, var2, var3, var4)) {
- if (var1 == 0) {
- return var6;
- }
-
- --var1;
- }
- }
- }
-
- return null;
- }
-
- public TXElement[] searchChildrenAll(String var1) {
- Vector var2 = new Vector();
-
- for(Node var3 = ((Parent)this).getFirstChild(); var3 != null; var3 = var3.getNextSibling()) {
- if (var3 instanceof Element && Match.matchName((Namespace)var3, 0, (String)null, var1)) {
- var2.addElement(var3);
- }
- }
-
- TXElement[] var4 = new TXElement[var2.size()];
- var2.copyInto(var4);
- return var4;
- }
-
- public NodeList getElementsByTagName(String var1) {
- return new TXNodeList.VectorNodeList(this.realSearchDescendantsAll(0, (String)null, var1));
- }
-
- public TXElement[] searchDescendantsAll(String var1) {
- return this.searchDescendantsAll(0, (String)null, var1);
- }
-
- public TXElement[] searchDescendantsAll(int var1, String var2, String var3) {
- Vector var4 = this.realSearchDescendantsAll(var1, var2, var3);
- TXElement[] var5 = new TXElement[var4.size()];
- var4.copyInto(var5);
- return var5;
- }
-
- public NodeList getElementsNamed(String var1) {
- return this.getElementsNamed(0, (String)null, var1);
- }
-
- public NodeList getElementsNamed(String var1, String var2) {
- return this.getElementsNamed(2, var1, var2);
- }
-
- public NodeList getElementsNamed(int var1, String var2, String var3) {
- Vector var4 = new Vector();
-
- for(Node var5 = ((Parent)this).getFirstChild(); var5 != null; var5 = var5.getNextSibling()) {
- if (var5 instanceof Element && Match.matchName((Namespace)var5, var1, var2, var3)) {
- var4.addElement(var5);
- }
- }
-
- return new TXNodeList.VectorNodeList(var4);
- }
-
- public void acceptPre(Visitor var1) throws Exception {
- var1.visitElementPre(this);
- }
-
- public void acceptPost(Visitor var1) throws Exception {
- var1.visitElementPost(this);
- }
-
- private Vector realSearchDescendantsAll(int var1, String var2, String var3) {
- Vector var4 = new Vector();
- SearchElementVisitor var5 = new SearchElementVisitor(var4, var1, var2, var3);
-
- try {
- (new NonRecursivePreorderTreeTraversal(var5)).traverse(this);
- } catch (Exception var6) {
- }
-
- return var4;
- }
-
- private void makeAttributeList() {
- if (this.attributes == null) {
- ((Child)this).checkFactory();
- this.attributes = new TXAttributeList();
- this.attributes.setParent(this);
- }
-
- }
-
- protected void checkChildType(Node var1) throws DOMException {
- switch (var1.getNodeType()) {
- case 1:
- case 3:
- case 4:
- case 5:
- case 7:
- case 8:
- case 23:
- return;
- default:
- throw new TXDOMException((short)3, "Specified node type (" + var1.getNodeType() + ") can't be a child of Element.");
- }
- }
-
- public String getNamespaceForPrefix(String var1) {
- if (var1.equals("xml")) {
- return "http://www.w3.org/XML/1998/namespace";
- } else if (var1.equals("xmlns")) {
- return var1;
- } else {
- String var2 = var1.length() == 0 ? "xmlns" : "xmlns:" + var1;
- Object var3 = this;
-
- do {
- String var4 = ((TXElement)var3).getAttributeOrNull(var2);
- if (var4 != null) {
- return var4;
- }
-
- short var5;
- do {
- var3 = ((Node)var3).getParentNode();
- if (var3 == null) {
- if (var2 == "xmlns") {
- return "";
- }
-
- return null;
- }
-
- var5 = ((Node)var3).getNodeType();
- } while(var5 == 5);
-
- if (var5 != 1) {
- if (var2 == "xmlns") {
- return "";
- }
-
- return null;
- }
- } while(var3 != null);
-
- return null;
- }
- }
-
- public String getNamespaceForQName(String var1) {
- int var2 = var1.indexOf(58);
- String var3 = var2 < 0 ? "" : var1.substring(0, var2).intern();
- return this.getNamespaceForPrefix(var3);
- }
-
- public static String getLocalNameForQName(String var0) {
- int var1 = var0.indexOf(58);
- return var1 < 0 ? var0 : var0.substring(var1 + 1).intern();
- }
-
- public void collectNamespaceAttributes() {
- this.collectNamespaceAttributes(((Child)this).getParentNode());
- }
-
- public void collectNamespaceAttributes(Node var1) {
- if (((Child)this).getFactory().isProcessNamespace()) {
- short var2;
- for(; var1 != null && ((var2 = var1.getNodeType()) == 1 || var2 == 5); var1 = var1.getParentNode()) {
- if (var2 == 1) {
- NamedNodeMap var3 = var1.getAttributes();
-
- for(int var4 = 0; var4 < var3.getLength(); ++var4) {
- Node var5 = var3.item(var4);
- String var6 = var5.getNodeName();
- if ((var6.equals("xmlns") || var6.startsWith("xmlns:")) && this.getAttributeNode(var6) == null) {
- this.setAttribute(var6, var5.getNodeValue());
- }
- }
- }
- }
-
- }
- }
-
- public void removeOverlappedNamespaceAttributes() {
- if (((Child)this).getFactory().isProcessNamespace()) {
- Vector var1 = new Vector();
- NamedNodeMap var2 = this.getAttributes();
-
- for(int var3 = 0; var3 < var2.getLength(); ++var3) {
- Node var4 = var2.item(var3);
- String var5 = var4.getNodeName();
- short var7;
- if (var5.equals("xmlns") || var5.startsWith("xmlns:")) {
- for(Node var6 = ((Child)this).getParentNode(); var6 != null && ((var7 = var6.getNodeType()) == 1 || var7 == 5); var6 = var6.getParentNode()) {
- if (var7 == 1) {
- TXElement var8 = (TXElement)var6;
- String var9 = var8.getAttributeOrNull(var5);
- if (var9 != null && var9.equals(var4.getNodeValue())) {
- var1.addElement(var5);
- }
- }
- }
- }
- }
-
- for(int var10 = 0; var10 < var1.size(); ++var10) {
- this.removeAttribute((String)var1.elementAt(var10));
- }
-
- }
- }
- }
-