All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ajax4jsf.framework.renderer.compiler.PutAttributesRule Maven / Gradle / Ivy

Go to download

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.framework.renderer.compiler;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.apache.commons.digester.Digester;
import org.apache.commons.digester.Rule;
import org.xml.sax.Attributes;

/**
 * @author [email protected] (latest modification by $Author: sergeysmirnov $)
 * @version $Revision: 1.1 $ $Date: 2006/04/28 02:04:21 $
 *
 */
public class PutAttributesRule extends Rule {

	private List toSkip = Collections.EMPTY_LIST;
	private String methodName = "put";
	/**
	 * @param digestr
	 * @param toSkip
	 */
	public PutAttributesRule(Digester digestr, String[] toSkip) {
		// TODO Auto-generated constructor stub
		this.digester = digestr;
//		Arrays.asList(toSkip);
		this.toSkip = Arrays.asList(toSkip);
	}

	/**
	 * @param digestr
	 * @param methodName
	 */
	public PutAttributesRule(Digester digestr, String methodName) {
		// TODO Auto-generated constructor stub
		this.digester = digestr;
//		Arrays.asList(toSkip);
		this.methodName = methodName;
	}
	
	/**
	 * @param digestr
	 * @param methodName
	 * @param toSkip
	 */
	public PutAttributesRule(Digester digestr, String methodName, String[] toSkip) {
		// TODO Auto-generated constructor stub
		this.digester = digestr;
		this.methodName = methodName;
		this.toSkip = Arrays.asList(toSkip);
	}
	/* (non-Javadoc)
	 * @see org.apache.commons.digester.Rule#begin(java.lang.String, java.lang.String, org.xml.sax.Attributes)
	 */
	public void begin(String namespace, String element, Attributes attrs) throws Exception {
		Object top = digester.peek();
		if(null != top){
			Method put = top.getClass().getDeclaredMethod(methodName,new Class[]{Object.class,Object.class});
			for (int i = 0; i < attrs.getLength(); i++) {
				String qName = attrs.getQName(i);
				String value = attrs.getValue(i);
				if (!toSkip.contains(qName)) {
					put.invoke(top,new Object[]{qName,value});
				}
			}
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy