clime.messadmin.providers.spi.BaseTabularApplicationDataProvider Maven / Gradle / Ivy
/**
*
*/
package clime.messadmin.providers.spi;
import java.text.NumberFormat;
import javax.servlet.ServletContext;
/**
* Base implementation class for ApplicationDataProvider displaying tabular data.
* @author Cédrik LIME
*/
public abstract class BaseTabularApplicationDataProvider extends BaseTabularDataProvider implements ApplicationDataProvider {
/**
*
*/
public BaseTabularApplicationDataProvider() {
super();
}
/**
* @param context
* @return application-specific data labels for given Application, or null if it can be determined
*/
public abstract String[] getApplicationTabularDataLabels(final ServletContext context);
/**
* @param context
* @return application-specific data values for given Application, or null if it can be determined
*/
public abstract Object[][] getApplicationTabularData(final ServletContext context);
protected String getTableCaption(String[] labels, Object[][] values) {
NumberFormat numberFormatter = NumberFormat.getNumberInstance();
return ""+numberFormatter.format(values.length)+" application-specific attributes";
}
/**
* {@inheritDoc}
*/
public String getXHTMLApplicationData(ServletContext context) {
try {
String[] labels = getApplicationTabularDataLabels(context);
Object[][] values = getApplicationTabularData(context);
return buildXHTML(labels, values, "extraApplicationAttributesTable-"+getClass().getName(), getTableCaption(labels, values));
} catch (RuntimeException rte) {
return "Error in " + this.getClass().getName() + ": " + rte;
}
}
}