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

📄 xmlwriter.java

📁 是一个JABBER的J2ME的实现
💻 JAVA
字号:
/* * Copyright 2004 Grzegorz Grasza groz@gryf.info * * This file is part of mobber. Mobber is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by the Free  * Software Foundation; either version 2 of the License, or (at your option) any later version. * Mobber 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 General Public License for more details. * You should have received a copy of the GNU General Public License along with mobber; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA . */package utils;import java.io.*;import java.util.*;public class XmlWriter extends OutputStreamWriter{	Stack tags;	boolean inside_tag;	public XmlWriter(OutputStream out) throws UnsupportedEncodingException	{		super(out, "UTF-8");		tags=new Stack();		inside_tag=false;	}		public void flush() throws IOException	{		if(inside_tag)		{			write('>'); // prevent Invalid XML fatal error			inside_tag=false;		}		super.flush();	}		public void startTag(String tag) throws IOException	{		if(inside_tag) write('>');				write('<');		write(tag);		tags.push(tag);		inside_tag=true;	}		public void attribute(String atr, String value) throws IOException	{		if(value==null) return;		write(' ');		write(atr);		write("=\'");		writeEscaped(value);		write('\'');	}	public void endTag() throws IOException {		try		{			String tagname=(String)tags.pop();			if(inside_tag)			{				write("/>");				inside_tag=false;			}			else			{				write("</");				write(tagname);				write('>');			}		}		catch(EmptyStackException e) {}	}		public void text(String str) throws IOException	{		if(inside_tag)		{			write('>');			inside_tag=false;		}		writeEscaped(str);	}		private void writeEscaped(String str) throws IOException	{		int index=0;		for(int i=0; i<str.length(); i++)		{			char c=str.charAt(i);			switch(c)			{				case '<': write("&lt;");				case '>': write("&gt;");				case '&': write("&amp;");				case '\'': write("&apos;");				case '"': write("&quot;");				default: write(c);			}		}	}};

⌨️ 快捷键说明

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