org.ajax4jsf.ajax.UILoadBundle Maven / Gradle / Ivy
/**
*
*/
package org.ajax4jsf.ajax;
import java.io.IOException;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import javax.faces.component.UIComponentBase;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import org.ajax4jsf.framework.util.message.Messages;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* @author shura
*
*/
public abstract class UILoadBundle extends UIComponentBase {
public static final String COMPONENT_FAMILY = "org.ajax4jsf.Bundle";
public static final String COMPONENT_TYPE = "org.ajax4jsf.ajax.Bundle";
private static final Log _log = LogFactory.getLog(UILoadBundle.class);
/*
* (non-Javadoc)
*
* @see javax.faces.component.UIComponent#getFamily()
*/
public String getFamily() {
// TODO Auto-generated method stub
return COMPONENT_FAMILY;
}
/*
* (non-Javadoc)
*
* @see javax.faces.component.UIComponentBase#encodeBegin(javax.faces.context.FacesContext)
*/
public void encodeBegin(FacesContext context) throws IOException {
UIViewRoot viewRoot = context.getViewRoot();
Locale locale = viewRoot.getLocale();
if (locale == null) {
locale = context.getApplication().getDefaultLocale();
}
ResourceBundle bundle;
try {
bundle = ResourceBundle.getBundle(getBasename(), locale, Thread
.currentThread().getContextClassLoader());
} catch (MissingResourceException e) {
_log.error(Messages.getMessage(Messages.COULD_NOT_LOAD_RESOURCE_BUNDLE, getBasename()));
return;
}
context.getExternalContext().getRequestMap().put(getVar(),
new ResourceBundleMap(bundle));
}
/*
* (non-Javadoc)
*
* @see javax.faces.component.UIComponentBase#getRendererType()
*/
public String getRendererType() {
// TODO Auto-generated method stub
return null;
}
/**
* @return Returns the basename.
*/
public abstract String getBasename();
/**
* @param basename
* The basename to set.
*/
public abstract void setBasename(String basename);
/**
* @return Returns the var.
*/
public abstract String getVar();
/**
* @param var
* The var to set.
*/
public abstract void setVar(String var);
}