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

📄 tinysaxwriter.java

📁 免疫遗传算法java语言版源程序
💻 JAVA
字号:
/**
 * IgaLib -> String
 * Copyright (C) 2001  Tosiki IGA , IgaLib project member
 *   (http://homepage2.nifty.com/igat/igapyon/index.html)
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package jp.ne.nifty.iga.tosiki.string;

import java.io.*;

/**
 * 挻彫偝偄SAX彂偒弌偟Writer僋儔僗<BR>
 * 彫偝偄偺偩偗偑庢傝暱偺SAX彂偒弌偟僋儔僗偱偡丅
 * 摿偵巊偄彑庤偼柍偄偱偟傚偆丅
 *
 * @author Tosiki IGA
 */
public class TinySaxWriter
{
	protected BufferedWriter writer=null;
	protected int indent=0;
	protected boolean isPastStart=true;

	/**
	 * 挻彫偝偄SAX彂偒弌偟Writer僋儔僗偺僐儞僗僩儔僋僞
	 *
	 * @param BufferedWriter writer 楢寢偡傞尦偺Writer
	 */
	public TinySaxWriter(BufferedWriter writer)
	{
		this.writer=writer;
	}

	public void startDocument()
		throws IOException
	{
		writer.write("<?xml version=\"1.0\" encoding=\"Shift_JIS\" standalone=\"yes\"?>");
		writer.newLine();
	}

	public void endDocument()
		throws IOException
	{
		
	}

	/**
	 * String偺攝楍傪 Object攝楍偱擖傟偰偔偩偝偄丅
	 */
	public void startElement(String name,java.util.ArrayList attributes)
		throws IOException
	{
		if(isPastStart)
		{
			writer.newLine();
		}
		isPastStart=true;

		writer.write(MojiUtil.padLeft("",indent*2,' '));
		writer.write('<');
		writer.write(name);

		if(attributes!=null)
		{
			for(int index=0;index<attributes.size();index++)
			{
				String[] param=(String[])attributes.get(index);
				writer.write(' ');
				writer.write(param[0]);
				writer.write('=');
				writer.write('"');
				writer.write(param[1]);
				writer.write('"');
			}
		}

		writer.write('>');

		indent++;
	}

	public void endElement(String name)
		throws IOException
	{
		indent--;

		if(isPastStart==false)
		{
			writer.write(MojiUtil.padLeft("",indent*2,' '));
		}
		isPastStart=false;

		writer.write('<');
		writer.write('/');
		writer.write(name);
		writer.write('>');
		writer.newLine();
	}

	public void characters(String strLine)
		throws IOException
	{
		writer.write(strLine);
	}


	/**
	 * Writer傪僼儔僢僔儏偟傑偡
	 *
	 * @throws IOException 壗偐偟傜偺I/O椺奜偺敪惗
	 */
	public final void flush()
		throws IOException
	{
		if(writer!=null)
		{
			writer.flush();
		}
	}

	/**
	 * Writer傪僋儘乕僘偟傑偡
	 *
	 * @throws IOException 壗偐偟傜偺I/O椺奜偺敪惗
	 */
	public final void close()
		throws IOException
	{
		if(writer!=null)
		{
			writer.close();
			writer=null;
		}
	}
}

⌨️ 快捷键说明

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