clime.messadmin.providers.spi.BaseTabularDataProvider Maven / Gradle / Ivy
/**
*
*/
package clime.messadmin.providers.spi;
/**
* Base implementation class for DataProvider displaying tabular data.
* @author Cédrik LIME
*/
public abstract class BaseTabularDataProvider {
/**
*
*/
public BaseTabularDataProvider() {
super();
}
// /**
// * @param object
// * @return specific data labels for given object, or null if it can be determined
// */
// public abstract String[] getTabularDataLabels(final Object object);
// /**
// * @param object
// * @return specific data values for given object, or null if it can be determined
// */
// public abstract Object[][] getTabularData(final Object object);
//
// protected abstract String getTableCaption(String[] labels, Object[][] data);
//
// protected String getXHTMLData(Object object) {
// try {
// String[] labels = getTabularDataLabels(object);
// Object[][] values = getTabularData(object);
// return buildXHTML(labels, values, tableId, getTableCaption(labels, values));
// } catch (RuntimeException rte) {
// return "Error in " + this.getClass().getName() + ": " + rte;
// }
// }
protected String buildXHTML(String[] labels, Object[][] values, String tableId, String tableCaption) {
if (labels == null || values == null || labels.length == 0 || values.length == 0) {
return "";
}
StringBuffer buff = new StringBuffer(1024);
buff.append("\n");
buff.append("").append(tableCaption).append(" \n");
buff.append("\n");
for (int i = 0; i < labels.length; ++i) {
String label = labels[i];
buff.append("").append(label).append(" \n");
}
buff.append(" \n");
for (int i = 0; i < values.length; ++i) {
Object[] raw = values[i];
buff.append("\n");
for (int j = 0; j < raw.length; ++j) {
Object value = raw[j];
buff.append("");
if (value != null) {
buff.append("");
buff.append(value);
buff.append("");
}
buff.append(" ");
}
buff.append(" \n");
}
buff.append("
\n");
return buff.toString();
}
}