/** * Copyright 2011 meltmedia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.xchain.namespaces.sax; import org.apache.commons.jxpath.JXPathContext; import org.xchain.Command; import org.xchain.annotations.Attribute; import org.xchain.annotations.AttributeType; import org.xchain.annotations.Element; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * <p><sax:parameter/> elements are placed inside <sax:transfromer/> elements to set parameters on a transformer.</p> * * <code class="source"> * <sax:pipeline xmlns:sax="http://www.xchain.org/sax/1.0"> * <sax:source .../> * ... * <sax:transformer system-id="'relative-uri-of-template'"> * <sax:parameter name="'name'" value="'value'"/> * </sax:transformer> * ... * <sax:result .../> * </sax:pipeline> * </code> * * @author Mike Moulton * @author Christian Trimble * @author Devon Tackett * @author Josh Kennedy */ @Element(localName="parameter") public abstract class ParameterCommand implements Command { /** The log for this class. */ private static Logger log = LoggerFactory.getLogger(ParameterCommand.class); /** * <p>The name of the parameter to set.</p> * @param context the JXPathContext to evaluate against. */ @Attribute(localName="name", type=AttributeType.JXPATH_VALUE) public abstract String getName( JXPathContext context ) throws Exception; /** * <p>The value of the parameter to set.</p> * @param context the JXPathContext to evaluate against. */ @Attribute(localName="value", type=AttributeType.JXPATH_VALUE) public abstract String getValue( JXPathContext context ) throws Exception; public ParameterCommand() { if( log.isDebugEnabled() ) { log.debug("Parameter command created."); } } /** * <p>Gets the name and value for the context and sets a parameter for them on the current transformer.</p> * @param context the JXPathContext to evaluate against. */ public boolean execute( JXPathContext context ) throws Exception { String name = getName( context ); Object value = getValue( context ); if( log.isDebugEnabled() ) { log.debug("Name: "+name+" Value:"+value); } TransformerCommand.getCurrentTransformer().setParameter(name, value); return false; } }