org.ajax4jsf.tag.MediaOutputHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ajax4jsf Show documentation
Show all versions of ajax4jsf Show documentation
Ajax4jsf is an open source extension to the JavaServer Faces standard that adds AJAX capability to JSF applications without requiring the writing of any JavaScript.
The newest version!
/**
* Licensed under the Common Development and Distribution License,
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.sun.com/cddl/
*
* 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.ajax4jsf.tag;
import java.io.OutputStream;
import org.ajax4jsf.ajax.resource.UIMediaOutput;
import com.sun.facelets.FaceletContext;
import com.sun.facelets.el.LegacyMethodBinding;
import com.sun.facelets.tag.MetaRule;
import com.sun.facelets.tag.MetaRuleset;
import com.sun.facelets.tag.Metadata;
import com.sun.facelets.tag.MetadataTarget;
import com.sun.facelets.tag.TagAttribute;
import com.sun.facelets.tag.jsf.ComponentConfig;
import com.sun.facelets.tag.jsf.ComponentHandler;
/**
* @author shura (latest modification by $Author: alexsmirnov $)
* @version $Revision: 1.1 $ $Date: 2006/07/19 12:36:10 $
*
*/
public class MediaOutputHandler extends ComponentHandler {
private static final MetaRule mmediaMetaRule = new MMediaMetaRule();
/**
* @param config
*/
public MediaOutputHandler(ComponentConfig config) {
super(config);
}
/* (non-Javadoc)
* @see org.ajax4jsf.tag.AjaxComponentHandler#createMetaRuleset(java.lang.Class)
*/
protected MetaRuleset createMetaRuleset(Class type) {
MetaRuleset metaRules = super.createMetaRuleset(type);
metaRules.addRule(mmediaMetaRule);
return metaRules;
}
/**
* @author shura (latest modification by $Author: alexsmirnov $)
* @version $Revision: 1.1 $ $Date: 2006/07/19 12:36:10 $
*
*/
static class MMediaMetaRule extends MetaRule{
/**
*
*/
public MMediaMetaRule() {
super();
}
/* (non-Javadoc)
* @see com.sun.facelets.tag.MetaRule#applyRule(java.lang.String, com.sun.facelets.tag.TagAttribute, com.sun.facelets.tag.MetadataTarget)
*/
public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget meta) {
if (meta.isTargetInstanceOf(UIMediaOutput.class)) {
if ("createContent".equals(name)) {
return new MMediaActionMapper(attribute);
}
}
return null;
}
}
/**
* @author shura (latest modification by $Author: alexsmirnov $)
* @version $Revision: 1.1 $ $Date: 2006/07/19 12:36:10 $
*
*/
static class MMediaActionMapper extends Metadata {
private static final Class[] MMEDIA_ACTION_SIG = new Class[] {OutputStream.class,Object.class};
private final TagAttribute _send;
/**
* @param attribute
*/
public MMediaActionMapper(TagAttribute attribute) {
_send = attribute;
}
/* (non-Javadoc)
* @see com.sun.facelets.tag.Metadata#applyMetadata(com.sun.facelets.FaceletContext, java.lang.Object)
*/
public void applyMetadata(FaceletContext ctx, Object instance) {
((UIMediaOutput) instance)
.setCreateContent(new LegacyMethodBinding(this._send
.getMethodExpression(ctx, null,
MMEDIA_ACTION_SIG)));
}
}
}