📄 headpadfilter.java
字号:
/*
Jacson
Copyright (C) 2004 Patrick Carl, pcs_org at users.sf.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
*/
package de.spieleck.app.jacson.filter;
import de.spieleck.app.jacson.JacsonConfigException;
import de.spieleck.app.jacson.JacsonException;
import de.spieleck.app.jacson.JacsonRegistry;
import de.spieleck.config.ConfigNode;
import de.spieleck.config.ConfigVerify.Acceptor;
/**
* <h2>HeadPadFilter</h2>
* <h3>Description</h3>
* <p>Filter class which either adds a configurable token as first chunk
* or prepends the token to the first chunk. This allows something like
* awk's begin.</p>
* <h3>Parameters</h3>
* <table border="1" cellpadding="2" cellspacing="0">
* <tr>
* <td valign="top"><b>Attribute</b></td>
* <td valign="top"><b>Description</b></td>
* <td align="center" valign="top"><b>Required</b></td>
* </tr>
* <tr>
* <td valign="top">pre</td>
* <td valign="top">The token to add at the beginning</td>
* <td valign="top" align="center">Yes</td>
* </tr>
* <tr>
* <td valign="top">separatechunk</td>
* <td valign="top">Determines if the token is added as separated chunk or
* if the token is prepended to the first chunk</td>
* <td valign="top" align="center">No, default is false</td>
* </tr>
* </table>
* @version $Id: HeadPadFilter.java 35 2005-10-03 22:08:55Z pcs $
* @author pcs
* @since 0.90
*/
public class HeadPadFilter extends FilterBase
implements FilterNames, Acceptor{
public static final String PRE_NODE = "pre";
private String preText;
public static final String SEPARATE_CHUNK_NODE = "separatechunk";
public static final boolean SEPARATE_CHUNK_DEFAULT = false;
private boolean ownChunk;
private boolean done = false;
/**
* string to add is configured via node "pre"
*/
public void init(ConfigNode snr, JacsonRegistry registry) throws JacsonConfigException {
preText = snr.getString(PRE_NODE, null);
if(preText == null)
throw new JacsonConfigException("HeadPadFilter needs a text to preprend");
ownChunk = snr.getBoolean(SEPARATE_CHUNK_NODE, SEPARATE_CHUNK_DEFAULT);
}
/**
* adds the configured text to the first chunk
*/
public void putChunk(String ch) throws JacsonException {
if(!done){
if(ownChunk){
drain.putChunk(preText);
drain.putChunk(ch);
} else
drain.putChunk(preText + ch);
done= true;
}
else
drain.putChunk(ch);
}
public boolean accept(ConfigNode node) {
String name = node.getName();
return name.equals(PRE_NODE) || name.equals(SEPARATE_CHUNK_NODE);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -