package org.richfaces.renderkit;

import javax.faces.FacesException;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;

import org.ajax4jsf.renderkit.HeaderResourcesRendererBase;
import org.richfaces.component.UIComponentControl;
import org.richfaces.component.util.HtmlUtil;


public class ComponentControlRendererBase  extends HeaderResourcesRendererBase {

	protected Class getComponentClass() {
		return UIComponentControl.class;
	}

	protected void checkValidity(String clientId, String name, String attachTiming, String forAttr, String operation) {

		if (  	! "onload".equals(attachTiming) &&
				! "immediate".equals(attachTiming) ) {
			throw new FacesException(
					"The attachTiming attribute of the controlComponent  (id='"+clientId+"') has an invalid value:'"+ attachTiming +
			"'. It may have only the following values: 'immediate', 'onload', 'onJScall'");
		}

		if (operation==null  || operation.trim().length() == 0) {
			throw new FacesException(
					"The operation attribute of the controlComponent (id='"+clientId+"') must be specified" );
		}


	}

	protected String replaceClientIds(FacesContext context, UIComponent component, String selector) {
		return HtmlUtil.expandIdSelector(HtmlUtil.idsToIdSelector(selector), component, context);
	}
}
