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

📄 node.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:   Node.java

package org.kxml.kdom;

import java.io.*;
import java.util.Vector;
import org.kxml.XmlIO;
import org.kxml.io.AbstractXmlWriter;
import org.kxml.io.XmlWriter;
import org.kxml.parser.AbstractXmlParser;
import org.kxml.parser.ParseEvent;

// Referenced classes of package org.kxml.kdom:
//			Element

public class Node
	implements XmlIO
{

	protected Vector children;
	protected StringBuffer types;

	public Node()
	{
	}

	public void addChild(int index, int type, Object child)
	{
		if (child == null)
			throw new NullPointerException();
		if (children == null)
		{
			children = new Vector();
			types = new StringBuffer();
		}
		if (type == 4)
		{
			if (!(child instanceof Element))
				throw new RuntimeException("Element obj expected)");
			((Element)child).setParent(this);
		} else
		if (!(child instanceof String))
			throw new RuntimeException("String expected");
		children.insertElementAt(child, index);
		types.insert(index, (char)type);
	}

	public void addChild(int type, Object child)
	{
		addChild(getChildCount(), type, child);
	}

	public Element createElement(String namespace, String name)
	{
		Element e = new Element();
		e.namespace = namespace != null ? namespace : "";
		e.name = name;
		return e;
	}

	public Object getChild(int index)
	{
		return children.elementAt(index);
	}

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

	public Element getElement(int index)
	{
		Object child = getChild(index);
		return (child instanceof Element) ? (Element)child : null;
	}

	public Element getElement(String name)
	{
		return getElement(getNamespace(), name);
	}

	public Element getElement(String namespace, String name)
	{
		int i = indexOf(namespace, name, 0);
		int j = indexOf(namespace, name, i + 1);
		if (i == -1 || j != -1)
			throw new RuntimeException("Element {" + namespace + "}" + name + (i != -1 ? " more than once in " : " not found in ") + getName());
		else
			return getElement(i);
	}

	public String getName()
	{
		return "#document-fragment";
	}

	public String getNamespace()
	{
		return "";
	}

	public String getText()
	{
		StringBuffer buf = new StringBuffer();
		int len = getChildCount();
		for (int i = 0; i < len; i++)
			if ((getType(i) & 0x180) != 0)
				buf.append(getText(i));
			else
			if (getType(i) == 4)
				throw new RuntimeException("not text-only content!");

		return buf.toString();
	}

	public String getText(int index)
	{
		return (getType(index) & 0x180) == 0 ? null : (String)getChild(index);
	}

	public int getType(int index)
	{
		return types.charAt(index);
	}

	public int indexOf(String name, int startIndex)
	{
		return indexOf(getNamespace(), name, startIndex);
	}

	public int indexOf(String namespace, String name, int startIndex)
	{
		int len = getChildCount();
		for (int i = startIndex; i < len; i++)
		{
			Element child = getElement(i);
			if (child != null && name.equals(child.getName()) && (namespace == null || namespace.equals(child.getNamespace())))
				return i;
		}

		return -1;
	}

	public void parse(AbstractXmlParser parser)
		throws IOException
	{
		boolean leave = false;
		do
		{
			ParseEvent event = parser.peek();
			switch (event.getType())
			{
			case 64: // '@'
				Element child = createElement(event.getNamespace(), event.getName());
				child.setAttributes(event.getAttributes());
				addChild(4, child);
				child.parse(parser);
				break;

			case 8: // '\b'
			case 16: // '\020'
				leave = true;
				break;

			default:
				addChild(event.getType(), event.getText());
				parser.read();
				break;
			}
		} while (!leave);
	}

	public void removeChild(int idx)
	{
		children.removeElementAt(idx);
		int n = types.length() - 1;
		for (int i = idx; i < n; i++)
			types.setCharAt(i, types.charAt(i + 1));

		types.setLength(n);
	}

	public String toString()
	{
		ByteArrayOutputStream bos;
		bos = new ByteArrayOutputStream();
		XmlWriter xw = new XmlWriter(new OutputStreamWriter(bos));
		write(xw);
		xw.close();
		return new String(bos.toByteArray());
		IOException e;
		e;
		throw new RuntimeException(e.toString());
	}

	public void write(AbstractXmlWriter writer)
		throws IOException
	{
		writeChildren(writer);
		writer.flush();
	}

	public void writeChildren(AbstractXmlWriter writer)
		throws IOException
	{
		if (children == null)
			return;
		int len = children.size();
		for (int i = 0; i < len; i++)
		{
			int type = getType(i);
			Object child = children.elementAt(i);
			switch (type)
			{
			case 4: // '\004'
				((Element)child).write(writer);
				break;

			case 128: 
			case 256: 
				writer.write((String)child);
				break;

			default:
				writer.writeLegacy(type, (String)child);
				break;
			}
		}

	}
}

⌨️ 快捷键说明

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