import java.util.TreeMap;
import jxl.Cell;
+import jxl.CellType;
import jxl.FormulaCell;
import jxl.JXLException;
+import jxl.LabelCell;
+import jxl.NumberCell;
import jxl.Sheet;
import jxl.Workbook;
+import jxl.WorkbookSettings;
import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
private ClassLoader classLoader = getClass().getClassLoader();
private ApplicationContext applicationContext;
+ private List<Class<?>> additionalClasses = new ArrayList<Class<?>>();
private Map<Class<?>, Map<Object, Object>> model = new HashMap<Class<?>, Map<Object, Object>>();
private List<Resource> workbooks = new ArrayList<Resource>();
+ private Integer charset = 0;
+
public void afterPropertiesSet() throws Exception {
+ init();
+ }
+
+ public void init() {
+ // used to resolve inner references
+ Map<String, List<Object>> tempRefs = new HashMap<String, List<Object>>();
+
+ List<Reference> references = new ArrayList<Reference>();
+
for (Resource res : workbooks) {
InputStream in = null;
try {
in = res.getInputStream();
- load(in);
+ load(in, references, tempRefs);
+ } catch (Exception e) {
+ throw new ArgeoServerException("Cannot load stream", e);
} finally {
IOUtils.closeQuietly(in);
}
}
+ // Inject references
+ for (Reference ref : references) {
+ injectReference(ref, tempRefs);
+ }
+ if (log.isDebugEnabled())
+ log.debug(references.size() + " references linked");
}
- public void load(InputStream in) {
- try {
- // used to resolve inner references
- Map<String, List<Object>> tempRefs = new HashMap<String, List<Object>>();
-
- List<Reference> references = new ArrayList<Reference>();
-
- Workbook workbook = Workbook.getWorkbook(in);
+ public List<Class<?>> getSupportedClasses() {
+ List<Class<?>> res = new ArrayList<Class<?>>();
+ res.addAll(additionalClasses);
+ res.addAll(model.keySet());
+ return res;
+ }
+ public void load(InputStream in, List<Reference> references,
+ Map<String, List<Object>> tempRefs) {
+ try {
+ WorkbookSettings workbookSettings = new WorkbookSettings();
+ workbookSettings.setCharacterSet(charset);
+ Workbook workbook = Workbook.getWorkbook(in, workbookSettings);
for (Sheet sheet : workbook.getSheets()) {
loadSheet(sheet, references, tempRefs);
}
-
- for (Reference ref : references) {
- injectReference(ref, tempRefs);
- }
- if (log.isDebugEnabled())
- log.debug(references.size() + " references linked");
-
} catch (Exception e) {
throw new ArgeoServerException("Cannot load workbook", e);
}
if (cell instanceof FormulaCell) {
String formula = ((FormulaCell) cell).getFormula();
int index = formula.indexOf('!');
+ if (index < 0)
+ throw new ArgeoServerException("Cannot interpret formula "
+ + formula);
+ ;
String targetSheet = formula.substring(0, index);
// assume no double letters!!
String targetRowStr = formula.substring(index + 2);
+ ", targetRow=" + targetRow);
} else {
String contents = cell.getContents();
+
+// if (cell.getType() == CellType.LABEL) {
+// LabelCell lc = (LabelCell) cell;
+// contents = lc.getString();
+// } else if (cell.getType() == CellType.NUMBER) {
+// NumberCell nc = (NumberCell) cell;
+// contents = new Double(nc.getValue()).toString();
+// } else {
+// contents = cell.getContents();
+// }
+
if (propertyName.equals(keyProperty)
&& !StringUtils.hasText(contents)) {
// auto allocate key column if empty
this.classLoader = classLoader;
}
+ public List<Class<?>> getAdditionalClasses() {
+ return additionalClasses;
+ }
+
+ public void setAdditionalClasses(List<Class<?>> additionalClasses) {
+ this.additionalClasses = additionalClasses;
+ }
+
+ public void setCharset(Integer charset) {
+ this.charset = charset;
+ }
+
public static class Reference {
private Object object;
private String property;