1 20 package com.nilostep.xlsql.database.excel; 21 22 import com.nilostep.xlsql.database.*; 23 24 import java.io.*; 25 26 import jxl.*; 27 28 import jxl.write.*; 29 30 31 36 public class xlFolderXls extends xlFolder implements FilenameFilter { 37 private static final String XLS = ".xls"; 38 39 46 public xlFolderXls(File dir) throws xlException { 47 super(dir); 48 } 49 50 protected void readSubFolders(File dir) throws xlException { 51 directory = dir; 52 53 File[] f = dir.listFiles(this); 54 55 if (f == null) { 56 throw new xlException("xlSQL: invalid directory"); 57 } 58 59 for (int i = 0; i < f.length; i++) { 60 try { 61 Workbook workbook = Workbook.getWorkbook(f[i]); 62 String name = f[i].getName() 63 .substring(0, f[i].getName().lastIndexOf('.')); 64 xlSubFolder obj = new xlWorkbook(directory, name); 65 subfolders.put(name.toUpperCase(), obj); 66 } catch (jxl.read.biff.BiffException jxle) { 67 logger.info(f[i] + " contains no xls data"); 68 69 continue; } catch (IOException ioe) { 71 logger.warning("io error while reading " + f[i]); 72 73 continue; } 75 } 76 } 77 78 83 public void addSchema(String workbook) { 84 String workbookU = workbook.toUpperCase(); 86 87 if (subfolders.containsKey(workbookU)) { 88 xlSubFolder wb = (xlSubFolder) subfolders.get(workbookU); 89 wb.setDirty(UPDATE, true); 90 } else { 91 xlSubFolder obj = new xlWorkbook(directory, workbook, true); 92 subfolders.put(workbookU, obj); 93 } 94 } 95 96 104 public void addTable(String workbook, String sheet) { 105 String workbookU = workbook.toUpperCase(); 107 String sheetU = sheet.toUpperCase(); 108 109 if (subfolders.containsKey(workbookU)) { 110 xlSubFolder wb = (xlSubFolder) subfolders.get(workbookU); 111 112 if (wb.getFiles().containsKey(sheetU)) { 113 xlFile sh = (xlFile) wb.getFiles().get(sheetU); 114 sh.setIsChanged(UPDATE, true); 115 } else { 116 xlFile obj = new xlSheet(directory, wb.getSubFolderName(), 117 sheet, true); 118 wb.getFiles().put(sheetU, obj); 119 wb.getValidFiles().put(sheetU, obj); 120 } 121 } else { 122 throw new IllegalArgumentException (NOARGS); 123 } 124 } 125 126 135 public boolean accept(File dir, String name) { 136 String ext = ""; 137 138 if (name.length() > 3) { 139 ext = name.substring(name.length() - 4, name.length()); 140 } 141 142 return (ext.equalsIgnoreCase(XLS)); 143 } 144 }
| Popular Tags
|