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

📄 outputformatter.java

📁 开发owl的API,提供了W3C规定标准接口,是目前比较少的API.
💻 JAVA
字号:
// The MIT License
//
// Copyright (c) 2004 Evren Sirin
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.

//The MIT License
//
//Copyright (c) 2003 Ron Alford, Mike Grove, Bijan Parsia, Evren Sirin
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to
//deal in the Software without restriction, including without limitation the
//rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
//sell copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in
//all copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
//FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
//IN THE SOFTWARE.

package org.mindswap.utils;


import java.io.PrintStream;
import java.io.PrintWriter;

/*
 * Created on Sep 3, 2003
 *
 */

/**
 * @author Evren Sirin
 *
 */
public class OutputFormatter {
	PrintWriter out = null;
	boolean formatHTML;

	public OutputFormatter() {
		this(false);
	}
		
	public OutputFormatter(boolean formatHTML) {
		this(System.out, formatHTML);
	}
	public OutputFormatter(PrintStream out, boolean formatHTML) {
		this(new PrintWriter(out), formatHTML);
	}
	public OutputFormatter(PrintWriter out, boolean formatHTML) {
		this.out = out;
		this.formatHTML = formatHTML;
	}
	public boolean isFormatHTML() {
		return formatHTML;
	}
	public PrintWriter getWriter() {
		return out;
	}
	public void flush() {
		out.flush();
	}
	public OutputFormatter print(String s) {
		out.print(s);
		return this;
	}
	public OutputFormatter print(Object o) {
		out.print(o);
		return this;
	}
	public OutputFormatter print(boolean b) {
		out.print(b);
		return this;
	}
	public OutputFormatter println(Object o) {
		print(o);
		println();
		return this;
	}	
	public OutputFormatter println(String s) {
		out.print(s);
		println();		
		return this;
	}	
	public OutputFormatter println() {
		printTag("<br>");
		out.println();	
		return this;
	}
	public OutputFormatter printParagraph() {
		if(formatHTML)
			out.println("<p>");
		else
			out.println();	
		return this;
	}

	public OutputFormatter printAnchor(String label) {
		if(formatHTML)
			printAnchor(label, label);
		else
			out.print(label);
		return this;	
	}
	
	public OutputFormatter printAnchor(String name, String label) {
		if(formatHTML) {
			out.print("<a name=\"");
			out.print(name);
			out.print("\">");
			out.print(label);
			out.print("</a>");
		}
		else
			out.print(label);
		
		return this;
	}
	
	public OutputFormatter printLink(String uri) {
		if(formatHTML)
			printLink(uri, uri);
		else
			out.print(uri);
		return this;	
	}
	
	public OutputFormatter printLink(String uri, String label) {
		if(formatHTML) {
			out.print("<a href=\"");
			out.print(uri);
			out.print("\">");
			out.print(label);
			out.print("</a>");
		}
		else
			out.print(label + " (" + uri + ")");
		
		return this;
	}
	
	public OutputFormatter printBold(String s) {
		return printInsideTag(s, "b");
	}	
	public OutputFormatter printItalic(String s) {
		return printInsideTag(s, "i");
	}	
	public OutputFormatter printInsideTag(String s, String tag) {
		if(formatHTML) {
			out.print("<"); out.print(tag); out.print(">");
			out.print(s);
			out.print("</"); out.print(tag); out.print(">");
		}
		else
			out.print(s);
		return this;	
	}
	public OutputFormatter printTab() {
		if(formatHTML) 
			out.print("&nbsp;&nbsp;&nbsp;");
		else
			out.print('\t');
		return this;	
	}	
	public OutputFormatter printTag( String tag) {
		if(formatHTML) 
			out.print(tag);
		return this;	
	}
	public OutputFormatter startTable() {
		return startTable(0);
	}
	public OutputFormatter startTable(int borderWidth) {
		printTag("<table border="+ borderWidth + ">");
		return this;
	}
	public OutputFormatter startRow() {
		printTag("<tr>");
		return this;
	}
	public OutputFormatter startCol() {
		printTag("<td>");
		return this;
	}
	public OutputFormatter endTable() {
		printTag("</table>");
		return this;
	}
	public OutputFormatter endRow() {
		printTag("</tr>");
		return this;
	}
	public OutputFormatter endCol() {
		printTag("</td>");
		return this;
	}
}

⌨️ 快捷键说明

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