📄 parameterselect.java
字号:
//
// 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
//
package de.spieleck.app.jacson.select;
// import java.util.Iterator;
// import java.util.Set;
// import org.apache.log4j.Logger;
import de.spieleck.config.ConfigNode;
import de.spieleck.config.ConfigVerify.Acceptor;
import de.spieleck.app.jacson.SelectionResult;
import de.spieleck.app.jacson.JacsonSelect;
import de.spieleck.app.jacson.JacsonStately;
import de.spieleck.app.jacson.JacsonState;
import de.spieleck.app.jacson.JacsonRegistry;
import de.spieleck.app.jacson.JacsonConfigException;
import de.spieleck.app.jacson.util.ConfigUtil;
/**
* Select a chunk into some parameter.
* You could compare this behaviour with:
* <xsl:param name="foo">
* <xsl:value-of select="node"/>
* <xsl:param />
*
* The difference to jacson ParameterSelect is the node order.
* With jacson you decide first, what (chunk) to select. Second
* is, where you send it (the chunk) to.
* In this case the previously read/generated chunk is selected
* into a parameter - and stored for later reusage.
* The parameter should be initialized earlier (in a parent block).
* If you don't do so, the parameter is created within the
* current select block and gets lost after leaving it...
* (At least, that's what I'd expect it to be :-))
*
* <select param="foo" />
*
* @author brenck (Dirk.Brenckmann@gmx.de)
* @author fsn
*/
public class ParameterSelect
// extends PluginBase
implements JacsonSelect, Acceptor, JacsonStately
{
/**
* log4j logger - debugging is lame :-)
*/
// private static final Logger L = Logger.getLogger( ParameterSelect.class.getName());
/**
* Accept sub-node "param"
*/
public static final String PARAMETER_NODE = "param";
/**
* Parameter (key) which is to be set.
*/
private String parameter = null;
/**
* Current chunk
*/
protected String curChunk = null;
/**
* The state we live with
*/
protected JacsonState state;
/**
* Default Constructor.
* Guarantee it's existence for Bean usage, introspection etc.
*/
public ParameterSelect() { }
/**
* Overwritten init method
*/
public void init(ConfigNode config, JacsonRegistry registry)
throws JacsonConfigException
{
// if ( L.isDebugEnabled())
// {
// L.debug( "Initialization by config: \"" + config + "\" and registry \"" + registry + "\"" );
// }
parameter = config.getString( PARAMETER_NODE, this.getClass().getName() + "." + "param.default" );
ConfigUtil.verify(config, this);
}
/**
* Overwritten accept method.
* Choose which childnodes are to be accepted and which will be
* denied.
*/
public boolean accept(ConfigNode cn)
{
// if ( L.isDebugEnabled())
// {
// L.debug( "Request for acceptance of " + cn + " with" + (( cn.getParent() != null ) ? "out " : " " ) + "parent." );
// }
return cn.getName().equals(PARAMETER_NODE);
}
/**
* Register the surrounding state
*/
public void registerState(JacsonState state)
{
this.state = state;
}
/**
* Feed the node with a chunk and reset match counter.
*/
public void setChunk(String chunk)
{
// if ( L.isDebugEnabled())
// {
// L.debug( "Setting chunk to " + this.getClass().getName());
// }
state.put(parameter, chunk);
}
/**
* Called by a filter, to access the SelectionResult(s).
* The returned values depend on the current state of
* this object.
* <i>Calls to this class are threadsave by default, because
* no value will be returned!</i>
*/
public SelectionResult getNextSelection()
{
// if ( L.isDebugEnabled())
// {
// L.debug( "Found request for next selection." + getClass().getName());
// StringBuffer out = new StringBuffer();
// Set keys = state.getKeySet();
// Iterator it = keys.iterator();
// while ( it.hasNext())
// {
// // XXX Is this cast safe in the context of Jacson, where the
// state is a wrapped Project?
// String key = (String) it.next();
// Object val = state.get(key);
// out.append("\n\t\t").append(key).append('=').append(val);
// }
// L.debug( "Current parameter map:" + out );
// }
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -