📄 printingreport.java
字号:
package de.spieleck.app.jacson.report;
import de.spieleck.app.jacson.JacsonConfigException;
import de.spieleck.app.jacson.JacsonPrintReport;
import de.spieleck.app.jacson.JacsonState;
import de.spieleck.app.jacson.util.ConfigUtil;
import de.spieleck.config.ConfigNode;
import de.spieleck.config.ConfigVerify.Acceptor;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.LinkedList;
/**
* Report that prints out everything in the property file format.
* Also (ab)used as the baseclass of all reports that write to a file.
* @author fsn
* @author Patrick Carl
*/
public class PrintingReport
implements JacsonPrintReport, Acceptor
{
public final static String FILENAME_NODE = "filename";
protected PrintWriter pw;
protected LinkedList begins = new LinkedList();
private JacsonState state;
public PrintingReport() { }
public void init(ConfigNode config)
throws JacsonConfigException
{
begins.clear();
useFilename(config);
ConfigUtil.verify(config, this);
}
protected void useFilename(ConfigNode config)
throws JacsonConfigException
{
useFilename(this, config);
}
/**
* use a Filename but be able to give a default output stream
*/
protected static void useFilename(JacsonPrintReport rep, ConfigNode conf,
OutputStream defaultOut) throws JacsonConfigException{
String fName = conf.getString(FILENAME_NODE, null);
try
{
if ( fName != null ){
rep.setOutputStream(new FileOutputStream(fName));
}
else
rep.setOutputStream(defaultOut);
}
catch ( IOException e )
{
throw new JacsonConfigException("Error on outputfile <"+fName+">",e);
}
}
/*package*/ static void useFilename(JacsonPrintReport rep, ConfigNode conf)
throws JacsonConfigException
{
useFilename(rep, conf, System.out);
}
public boolean accept(ConfigNode cn)
{
return cn.getName().equals(FILENAME_NODE);
}
public void setOutputStream(OutputStream os)
{
setPrintWriter(new PrintWriter(os));
}
public void setPrintWriter(PrintWriter pw)
{
this.pw = pw;
}
protected PrintWriter getPrintWriter()
{
return pw;
}
public void begin(String id)
{
begins.addLast(id);
}
public void report(String localName, String value)
{
Iterator it = begins.iterator();
while ( it.hasNext() )
{
pw.print((String)it.next());
pw.print('.');
}
pw.println(localName+"="+value);
pw.flush();
}
public void end()
{
begins.removeLast();
}
public void finish()
{
finish(true);
}
public void finish(boolean close)
{
if ( close )
pw.close();
else
pw.flush();
}
public void registerState(JacsonState state)
{
this.state = state;
}
public JacsonState getRegState()
{
return state;
}
}
//
// Jacson - Text Filtering with Java.
// Copyright (C) 2002 Frank S. Nestel (nestefan -at- users.sourceforge.net)
//
// 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
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -