⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 element.java

📁 Mofire的JAR压缩包
💻 JAVA
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   Element.java

package org.kxml.kdom;

import java.io.IOException;
import java.util.Vector;
import org.kxml.Attribute;
import org.kxml.PrefixMap;
import org.kxml.io.AbstractXmlWriter;
import org.kxml.parser.*;

// Referenced classes of package org.kxml.kdom:
//			Node, Document

public class Element extends Node
{

	protected String namespace;
	protected String name;
	protected Vector attributes;
	protected Node parent;
	protected PrefixMap prefixMap;

	public Element()
	{
	}

	/**
	 * @deprecated Method init is deprecated
	 */

	public Element init(Node parent, String namespace, String name, Vector attributes)
	{
		this.parent = parent;
		return this;
	}

	public void clear()
	{
		setAttributes(new Vector());
		for (int i = getChildCount() - 1; i >= 0; i--)
			removeChild(i);

	}

	public Element createElement(String namespace, String name)
	{
		return parent != null ? parent.createElement(namespace, name) : super.createElement(namespace, name);
	}

	public Attribute getAttribute(int index)
	{
		return (Attribute)attributes.elementAt(index);
	}

	public Attribute getAttribute(String name)
	{
		return getAttribute("", name);
	}

	public Attribute getAttribute(String namespace, String name)
	{
		int len = getAttributeCount();
		for (int i = 0; i < len; i++)
		{
			Attribute attr = getAttribute(i);
			if (name.equals(attr.getName()) && (namespace == null || namespace.equals(attr.getNamespace())))
				return attr;
		}

		return null;
	}

	public int getAttributeCount()
	{
		return attributes != null ? attributes.size() : 0;
	}

	public Vector getAttributes()
	{
		return attributes;
	}

	public Document getDocument()
	{
		if (parent instanceof Document)
			return (Document)parent;
		if (parent instanceof Element)
			return ((Element)parent).getDocument();
		else
			return null;
	}

	public String getName()
	{
		return name;
	}

	public String getNamespace()
	{
		return namespace;
	}

	public Node getParent()
	{
		return parent;
	}

	public Element getParentElement()
	{
		return (parent instanceof Element) ? (Element)parent : null;
	}

	public PrefixMap getPrefixMap()
	{
		return prefixMap;
	}

	public String getValue(String name)
	{
		Attribute attr = getAttribute("", name);
		return attr != null ? attr.getValue() : null;
	}

	public String getValueDefault(String name, String dflt)
	{
		Attribute attr = getAttribute("", name);
		return attr != null ? attr.getValue() : dflt;
	}

	public void parse(AbstractXmlParser parser)
		throws IOException
	{
		StartTag startTag = (StartTag)parser.read();
		name = startTag.getName();
		namespace = startTag.getNamespace();
		attributes = startTag.getAttributes();
		setPrefixMap(startTag.getPrefixMap());
		super.parse(parser);
		if (startTag != null && !startTag.getDegenerated() && getChildCount() == 0)
			addChild(256, "");
		parser.read(16, startTag.getNamespace(), startTag.getName());
	}

	public void removeAttribute(int index)
	{
		attributes.removeElementAt(index);
	}

	public void setAttributes(Vector attributes)
	{
		this.attributes = attributes;
	}

	public void setAttribute(Attribute attribute)
	{
		if (attributes == null)
		{
			attributes = new Vector();
		} else
		{
			for (int i = attributes.size() - 1; i >= 0; i--)
			{
				Attribute attr = (Attribute)attributes.elementAt(i);
				if (attr.getName().equals(attribute.getName()) && attr.getNamespace().equals(attribute.getNamespace()))
				{
					attributes.setElementAt(attribute, i);
					return;
				}
			}

		}
		attributes.addElement(attribute);
	}

	public void setValue(String name, String value)
	{
		setAttribute(new Attribute(name, value));
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public void setNamespace(String namespace)
	{
		this.namespace = namespace != null ? namespace : "";
	}

	protected void setParent(Node parent)
	{
		this.parent = parent;
		if (init(parent, namespace, name, attributes) != this)
			throw new RuntimeException("init must return this");
		else
			return;
	}

	public void setPrefixMap(PrefixMap prefixMap)
	{
		this.prefixMap = prefixMap;
	}

	public void write(AbstractXmlWriter writer)
		throws IOException
	{
		writer.startTag(getPrefixMap(), getNamespace(), getName());
		int len = getAttributeCount();
		for (int i = 0; i < len; i++)
		{
			Attribute attr = getAttribute(i);
			writer.attribute(attr.getNamespace(), attr.getName(), attr.getValue());
		}

		writeChildren(writer);
		writer.endTag();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -