?? xmlwriter.java
字號(hào):
/* * 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("<"); case '>': write(">"); case '&': write("&"); case '\'': write("'"); case '"': write("""); default: write(c); } } }};
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -