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

📄 xmlwriter.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:   XmlWriter.java

package org.kxml.io;

import java.io.IOException;
import java.io.Writer;
import org.kxml.PrefixMap;
import org.kxml.Xml;

// Referenced classes of package org.kxml.io:
//			AbstractXmlWriter, State

public class XmlWriter extends AbstractXmlWriter
{

	protected Writer writer;
	boolean pending;
	int indentLevel;
	int noIndent;
	static char indent[] = {
		'\r', '\n', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 
		' ', ' ', ' ', ' ', ' ', ' '
	};

	public XmlWriter(Writer writer)
	{
		pending = false;
		indentLevel = 0;
		noIndent = 0x7fffffff;
		this.writer = writer;
	}

	protected void checkPending()
		throws IOException
	{
		if (pending)
		{
			writer.write(62);
			pending = false;
		}
	}

	public void close()
		throws IOException
	{
		flush();
		writer.close();
	}

	public void flush()
		throws IOException
	{
		checkPending();
		writer.flush();
	}

	public void write(char c)
		throws IOException
	{
		checkPending();
		if (noIndent > indentLevel)
			noIndent = indentLevel;
		switch (c)
		{
		case 60: // '<'
			writer.write("&lt;");
			break;

		case 62: // '>'
			writer.write("&gt;");
			break;

		case 38: // '&'
			writer.write("&amp;");
			break;

		default:
			writer.write(c);
			break;
		}
	}

	public void write(char buf[], int start, int len)
		throws IOException
	{
		checkPending();
		if (noIndent > indentLevel)
			noIndent = indentLevel;
		int end = start + len;
		do
		{
			int i;
			for (i = start; i < end && "<>&".indexOf(buf[i]) == -1; i++);
			writer.write(buf, start, i - start);
			if (i == end)
				break;
			write(buf[i]);
			start = i + 1;
		} while (start < end);
	}

	public void writeIndent()
		throws IOException
	{
		int l = indentLevel + 2;
		if (l < 2)
			l = 2;
		else
		if (l > indent.length)
			l = indent.length;
		checkPending();
		writer.write(indent, 0, l);
	}

	public void attribute(String name, String value)
		throws IOException
	{
		if (!pending)
			throw new RuntimeException("can write attr only immediately after a startTag");
		writer.write(32);
		writer.write(name);
		writer.write("=\"");
		writer.write(Xml.encode(value, 1));
		writer.write(34);
		if (name.equals("xml:space") && value.equals("preserve"))
			noIndent = indentLevel;
	}

	protected void startTag(PrefixMap prefixMap, String tag)
		throws IOException
	{
		super.current = new State(super.current, prefixMap, tag);
		checkPending();
		if (indentLevel < noIndent)
			writeIndent();
		indentLevel++;
		writer.write(60);
		writer.write(tag);
		pending = true;
	}

	public void endTag()
		throws IOException
	{
		indentLevel--;
		if (pending)
		{
			writer.write(" />");
			pending = false;
		} else
		{
			if (indentLevel + 1 < noIndent)
				writeIndent();
			writer.write("</");
			writer.write(super.current.tag);
			writer.write(">");
		}
		if (indentLevel + 1 == noIndent)
			noIndent = 0x7fffffff;
		super.current = super.current.prev;
		if (super.current == null)
			throw new RuntimeException("too many closing tags!");
		else
			return;
	}

	public void writeLegacy(int type, String content)
		throws IOException
	{
		checkPending();
		switch (type)
		{
		case 1: // '\001'
			writer.write("<!--");
			writer.write(content);
			writer.write("-->");
			break;

		case 2: // '\002'
			writer.write("<!DOCTYPE ");
			writer.write(content);
			writer.write(">");
			break;

		case 32: // ' '
			writer.write("<?");
			writer.write(content);
			writer.write("?>");
			break;
		}
	}

	public void writeRaw(String s)
		throws IOException
	{
		checkPending();
		writer.write(s);
	}

}

⌨️ 快捷键说明

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