List of usage examples for org.apache.poi.hssf.usermodel HSSFWorkbook getSheet
@Override
public HSSFSheet getSheet(String name)
From source file:org.hsh.bfr.db.imports.custom.LieferkettenImporterEFSA.java
License:Open Source License
private int[] doImportStandard(HSSFWorkbook wb, JProgressBar progress, String filename) { int numSuccess = 0; int numFails = 0; HSSFSheet transactionSheet = wb.getSheet("Transactions"); boolean isSimpleFormat = transactionSheet != null && isSimple(transactionSheet.getRow(0)); boolean isNewFormat = transactionSheet == null && wb.getSheet("NewTransactions") != null || isNew(transactionSheet.getRow(0)); if (isNewFormat && !isSimpleFormat) { doImportNewFormat(wb, progress); } else {// ww w . ja v a2 s .c o m boolean isBvl = isBVL(transactionSheet.getRow(0)); HSSFSheet businessSheet = wb.getSheet("Business_List"); int numRows = transactionSheet.getLastRowNum() + 1; progress.setMaximum(numRows); progress.setValue(0); for (int i = isBvl ? 6 : 1; i < numRows; i++) { HSSFRow row = transactionSheet.getRow(i); if (row != null) { String serial = getStrVal(row.getCell(0)); // Serial_number String BL0 = getStrVal(row.getCell(1)); // Contact_Region String KP = getStrVal(row.getCell(2)); // Contact_person String idRec = getStrVal(row.getCell(3)); // ID_Address String adressRec = getStrVal(row.getCell(4)); // Address if ((serial == null || serial.trim().isEmpty()) && (adressRec == null || adressRec.trim().isEmpty())) { continue;//break; } if (serials.containsKey(serial)) { String msg = "Row: " + (i + 1) + "\tSerial '" + serial + "' already defined in file '" + serials.get(serial) + "' -> not importing this row!"; System.err.println(msg); logMessages += msg + "\n"; continue; } serials.put(serial, filename); String activityRec = getStrVal(row.getCell(5)); // Activity String nameRec = adressRec; String streetRec = null; String streetNoRec = null; String zipRec = null; String cityRec = null; String countyRec = null; String countryRec = null; String vatRec = null; HSSFRow busRow = getRow(businessSheet, idRec, 0); if (busRow != null) { nameRec = getStrVal(busRow.getCell(1)); // streetRec = getStrVal(busRow.getCell(2)); // streetNoRec = getStrVal(busRow.getCell(3), 10); // zipRec = getStrVal(busRow.getCell(4), 10); // cityRec = getStrVal(busRow.getCell(5)); // countyRec = getStrVal(busRow.getCell(6), 30); countryRec = getStrVal(busRow.getCell(7)); // vatRec = getStrVal(busRow.getCell(8)); // if (!adressRec.toUpperCase().startsWith(nameRec.toUpperCase())) { String msg = "Row: " + (i + 1) + "\tId issue on recs...\t" + nameRec + " <> " + adressRec; System.err.println(msg); logMessages += msg + "\n"; } } else if (idRec != null) { String msg = "Row: " + (i + 1) + "\tbusiness not there???\tidReceived: " + idRec; System.err.println(msg); logMessages += msg + "\n"; } else { String msg = "Row: " + (i + 1) + "\tidRec is null???\t" + adressRec + (adressRec != null ? "" : " -> Station not defined"); System.err.println(msg); logMessages += msg + "\n"; } String prodNameOut = getStrVal(row.getCell(6)); // ProductName String prodNumOut = getStrVal(row.getCell(7)); // ProductNo String dayOut = getStrVal(row.getCell(8)); // Day String monthOut = getStrVal(row.getCell(9)); // Month String yearOut = getStrVal(row.getCell(10)); // Year String amountKG_Out = getStrVal(row.getCell(11)); // amountKG String typePUOut = getStrVal(row.getCell(12)); // typePU String numPUOut = getStrVal(row.getCell(13)); // numPU String lotNo_Out = getStrVal(row.getCell(14)); // String dayMHDOut = getStrVal(row.getCell(15)); String monthMHDOut = getStrVal(row.getCell(16)); String yearMHDOut = getStrVal(row.getCell(17)); // String dayPDOut = getStrVal(row.getCell(18)); String monthPDOut = getStrVal(row.getCell(19)); String yearPDOut = getStrVal(row.getCell(20)); //Date dateOut = getDate(dayOut, monthOut, yearOut); //Date dateMHDOut = getDate(dayMHDOut, monthMHDOut, yearMHDOut); //Date datePDOut = getDate(dayPDOut, monthPDOut, yearPDOut); String idInsp = getStrVal(row.getCell(21)); // ID_Address String adressInsp = getStrVal(row.getCell(22)); // Address String activityInsp = getStrVal(row.getCell(23)); // Activity String nameInsp = adressInsp; String streetInsp = null; String streetNoInsp = null; String zipInsp = null; String cityInsp = null; String countyInsp = null; String countryInsp = null; String vatInsp = null; busRow = getRow(businessSheet, idInsp, 0); if (busRow != null) { nameInsp = getStrVal(busRow.getCell(1)); // streetInsp = getStrVal(busRow.getCell(2)); // streetNoInsp = getStrVal(busRow.getCell(3), 10); // zipInsp = getStrVal(busRow.getCell(4), 10); // cityInsp = getStrVal(busRow.getCell(5)); // countyInsp = getStrVal(busRow.getCell(6), 30); countryInsp = getStrVal(busRow.getCell(7)); // vatInsp = getStrVal(busRow.getCell(8)); // if (!adressInsp.toUpperCase().startsWith(nameInsp.toUpperCase())) { String msg = "Row: " + (i + 1) + "\tId issue on insps...\t" + nameInsp + " <> " + adressInsp; System.err.println(msg); logMessages += msg + "\n"; } } else if (idInsp != null) { String msg = "Row: " + (i + 1) + "\tbusiness not there???\tidInspected: " + idInsp; System.err.println(msg); logMessages += msg + "\n"; } else { String msg = "Row: " + (i + 1) + "\tidInsp is null???\t" + adressInsp + (adressInsp != null ? "" : " -> Station not defined"); System.err.println(msg); logMessages += msg + "\n"; } String oc = ""; String cqr = ""; if (!isSimpleFormat) { oc = getStrVal(row.getCell(44)); // OriginCountry cqr = getStrVal(row.getCell(45)); // Contact_Questions_Remarks } Integer c1 = null; if (nameInsp != null && !nameInsp.trim().isEmpty()) { Integer[] c = getCharge_Lieferung(idInsp, nameInsp, streetInsp, streetNoInsp, zipInsp, cityInsp, countyInsp, countryInsp, activityInsp, vatInsp, prodNameOut, prodNumOut, null, lotNo_Out, dayMHDOut, monthMHDOut, yearMHDOut, dayPDOut, monthPDOut, yearPDOut, oc, dayOut, monthOut, yearOut, amountKG_Out, typePUOut, numPUOut, idRec, nameRec, streetRec, streetNoRec, zipRec, cityRec, countyRec, countryRec, activityRec, vatRec, serial, cqr, null, null, null, null); if (c != null) c1 = c[2]; } if (isSimpleFormat) continue; String prodNameIn = getStrVal(row.getCell(24)); // ProductName String prodNumIn = getStrVal(row.getCell(25)); // ProductNo String dayIn = getStrVal(row.getCell(26)); // Day String monthIn = getStrVal(row.getCell(27)); // Month String yearIn = getStrVal(row.getCell(28)); // Year String amountKG_In = getStrVal(row.getCell(29)); // amountKG String typePUIn = getStrVal(row.getCell(30)); // typePU String numPUIn = getStrVal(row.getCell(31)); // numPU String lotNo_In = getStrVal(row.getCell(32)); // String dayMHDIn = getStrVal(row.getCell(33)); String monthMHDIn = getStrVal(row.getCell(34)); String yearMHDIn = getStrVal(row.getCell(35)); // String dayPDIn = getStrVal(row.getCell(36)); String monthPDIn = getStrVal(row.getCell(37)); String yearPDIn = getStrVal(row.getCell(38)); //Date dateIn = getDate(dayIn, monthIn, yearIn); //Date dateMHDIn = getDate(dayMHDIn, monthMHDIn, yearMHDIn); //Date datePDIn = getDate(dayPDIn, monthPDIn, yearPDIn); String idSup = getStrVal(row.getCell(39)); // ID_Address String adressSup = getStrVal(row.getCell(40)); // Address String activitySup = getStrVal(row.getCell(41)); // Activity String nameSup = adressSup; String streetSup = null; String streetNoSup = null; String zipSup = null; String citySup = null; String countySup = null; String countrySup = null; String vatSup = null; busRow = getRow(businessSheet, idSup, 0); if (busRow != null) { nameSup = getStrVal(busRow.getCell(1)); // streetSup = getStrVal(busRow.getCell(2)); // streetNoSup = getStrVal(busRow.getCell(3), 10); // zipSup = getStrVal(busRow.getCell(4), 10); // citySup = getStrVal(busRow.getCell(5)); // countySup = getStrVal(busRow.getCell(6), 30); countrySup = getStrVal(busRow.getCell(7)); // vatSup = getStrVal(busRow.getCell(8)); // if (!adressSup.toUpperCase().startsWith(nameSup.toUpperCase())) { String msg = "Row: " + (i + 1) + "\tId issue on sups...\t" + nameSup + " <> " + adressSup; System.err.println(msg); logMessages += msg + "\n"; } } else if (idSup != null) { String msg = "Row: " + (i + 1) + "\tbusiness not there???\tidSupplier: " + idSup; System.err.println(msg); logMessages += msg + "\n"; } else { String msg = "Row: " + (i + 1) + "\tidSup is null???\t" + adressSup + (adressSup != null ? "" : " -> Station not defined"); System.err.println(msg); logMessages += msg + "\n"; } String ec = getStrVal(row.getCell(42)); // EndChain String ece = getStrVal(row.getCell(43)); // Explanation_EndChain String ft = getStrVal(row.getCell(46)); // Further_Traceback String ms = getStrVal(row.getCell(47)); // MicrobiologicalSample //if (amountKG_Out != null && amountKG_In != null && Integer.parseInt(amountKG_Out) > Integer.parseInt(amountKG_In)) System.err.println("amountOut > aomountIn!!! Row " + i + "; amountKG_Out: " + amountKG_Out + "; amountKG_In: " + amountKG_In); if (is1SurelyNewer(dayIn, monthIn, yearIn, dayOut, monthOut, yearOut)) { String msg = "Row: " + (i + 1) + "\tDates not in temporal order, dateOut < dateIn!!! , KP: " + KP + ", BL0: " + BL0 + "; dateOut: " + sdfFormat(dayOut, monthOut, yearOut) + "; dateIn: " + sdfFormat(dayIn, monthIn, yearIn); System.err.println(msg); logMessages += msg + "\n"; } Integer c2 = null; if (nameSup != null && !nameSup.trim().isEmpty()) { Integer[] c = getCharge_Lieferung(idSup, nameSup, streetSup, streetNoSup, zipSup, citySup, countySup, countrySup, activitySup, vatSup, prodNameIn, prodNumIn, null, lotNo_In, dayMHDIn, monthMHDIn, yearMHDIn, dayPDIn, monthPDIn, yearPDIn, oc, dayIn, monthIn, yearIn, amountKG_In, typePUIn, numPUIn, idInsp, nameInsp, streetInsp, streetNoInsp, zipInsp, cityInsp, countyInsp, countryInsp, activityInsp, vatInsp, serial, cqr, ec, ece, ft, ms); if (c != null) c2 = c[3]; } if (c1 == null) { // Chargen String msg = "Row: " + (i + 1) + "\tError Type 1 (Batches)!!"; // Fehlerchenchen_1 System.err.println(msg); logMessages += msg + "\n"; numFails++; } else if (c2 == null) { // Lieferungen String msg = "Row: " + (i + 1) + "\tError Type 2 (Deliveries)!! E.g. Station not defined?"; // Fehlerchenchen_2 System.err.println(msg); logMessages += msg + "\n"; /* * getCharge_Lieferung(nameSup, streetSup, streetNoSup, * zipSup, citySup, countySup, countrySup, activitySup, * vatSup, prodNameIn, prodNumIn, lotNo_In, dateMHDIn, * datePDIn, oc, dateIn, amountKG_In, typePUIn, numPUIn, * nameSup, streetSup, streetNoSup, zipSup, citySup, * countySup, countrySup, activityInsp, vatInsp, comment, * false); */ numFails++; } else { if (c2 != null) { Integer cvID = getID("ChargenVerbindungen", new String[] { "Zutat", "Produkt" }, new String[] { c2.toString(), c1.toString() }, null, null); if (cvID == null) { String msg = "Row: " + (i + 1) + "\tError Type 4 (Links)!!"; // Fehlerchenchen_4 System.err.println(msg); logMessages += msg + "\n"; numFails++; } else { numSuccess++; } } } } } } return new int[] { numSuccess, numFails }; }
From source file:org.jfree.chart.demo.LineChartDemo1.java
License:Open Source License
public void addChartToExcel(JFreeChart chart, HSSFWorkbook wb) throws Exception { final BufferedImage buffer = chart.createBufferedImage(WIDTH, HIGH); //final FileOutputStream file = new FileOutputStream(excel+".xls"); ByteArrayOutputStream img_bytes = new ByteArrayOutputStream(); ImageIO.write(buffer, "png", img_bytes); img_bytes.flush();/*from w w w.j a v a 2 s . co m*/ /*Esta es la parte para agregar todo lo gneraod al excel*/ /*Esta es la parte para agregar todo lo gneraod al excel*/ /*Esta es la parte para agregar todo lo gneraod al excel*/ //HSSFWorkbook wb = new HSSFWorkbook(); //wb.createSheet(SHEET_NAME); HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) POSITION_X, POSITION_Y, (short) CHART_WIDTH, CHART_HIGH); int index = wb.addPicture(img_bytes.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG); HSSFSheet sheet = wb.getSheet(SHEET_NAME); HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); patriarch.createPicture(anchor, index); //wb.write(file); //file.close(); }
From source file:org.lisapark.octopus.util.json.JsonUtils.java
License:Open Source License
public String jsonStringFromSSbyName(HSSFWorkbook workbook, String name) throws JSONException, FileNotFoundException, IOException { // Get Sheet by index. Sheet sheet = workbook.getSheet(name); return jsonFromSS(sheet, 2); }
From source file:org.neo4art.colour.write.WriteFileCsv.java
License:Apache License
public void savePixel(Color[] c) { try {//from w w w . j a v a2s. co m int i = 0; FileInputStream inp = new FileInputStream(csv); HSSFWorkbook workbook = new HSSFWorkbook(inp); HSSFSheet worksheet = workbook.getSheet("Pixel image"); while (i < c.length) { HSSFRow row = worksheet.createRow(worksheet.getLastRowNum() + 1); CellStyle cellStyle = workbook.createCellStyle(); cellStyle.setAlignment(CellStyle.ALIGN_CENTER); HSSFCell cell1 = row.createCell(0); cell1.setCellStyle(cellStyle); HSSFCell cell2 = row.createCell(1); cell2.setCellStyle(cellStyle); HSSFCell cell3 = row.createCell(2); cell3.setCellStyle(cellStyle); cell1.setCellValue(c[i].getRed()); cell2.setCellValue(c[i].getGreen()); cell3.setCellValue(c[i].getBlue()); FileOutputStream fileOut = new FileOutputStream(csv); workbook.write(fileOut); i++; } workbook.close(); } catch (Exception e) { } }
From source file:org.neo4art.colour.write.WriteFileCsv.java
License:Apache License
public void saveReport(ColourAnalysis image) { try {//w w w . j a v a 2s . c o m Color[] temp = new Color[3]; FileInputStream inp = new FileInputStream(csv); HSSFWorkbook workbook = new HSSFWorkbook(inp); HSSFSheet worksheet = workbook.getSheet("Report"); CellStyle cellStyle = workbook.createCellStyle(); cellStyle.setAlignment(CellStyle.ALIGN_CENTER); HSSFRow row = worksheet.createRow((short) 7); HSSFRow row1 = worksheet.createRow((short) 9); HSSFRow row3 = worksheet.createRow((short) 11); HSSFRow row4 = worksheet.createRow((short) 13); HSSFCell cell1 = row.createCell(0); cell1.setCellStyle(cellStyle); HSSFCell cell3 = row1.createCell(0); cell3.setCellStyle(cellStyle); HSSFCell cell4 = row3.createCell(0); cell4.setCellStyle(cellStyle); HSSFCell cell5 = row4.createCell(0); cell5.setCellStyle(cellStyle); cell1.setCellValue(image.getAverageClosestColour().getName()); cell3.setCellValue(image.getMaximumClosestColour().getName()); cell4.setCellValue(image.getMinimumClosestColour().getName()); cell5.setCellValue(image.getIncrement()); temp[0] = image.getAverageColour(); temp[1] = image.getMinimumColour(); temp[2] = image.getMaximumColour(); int j = 1; for (int i = 0; i < 3; i++) { Color c = temp[i]; HSSFRow row2 = worksheet.createRow((short) j); HSSFCell cell1a = row2.createCell(0); cell1a.setCellStyle(cellStyle); HSSFCell cell2a = row2.createCell(1); cell2a.setCellStyle(cellStyle); HSSFCell cell3a = row2.createCell(2); cell3a.setCellStyle(cellStyle); cell1a.setCellValue(c.getRed()); cell2a.setCellValue(c.getGreen()); cell3a.setCellValue(c.getBlue()); FileOutputStream fileOut = new FileOutputStream(csv); workbook.write(fileOut); workbook.close(); j = j + 2; } } catch (Exception e) { } }
From source file:org.newcashel.meta.model.ElasticAlias.java
License:Apache License
public static void load(HSSFWorkbook wb, LaunchParms launchParm) throws Exception { // load the sheet HSSFSheet sheet = wb.getSheet("Aliases"); if (sheet == null) { throw new Exception("The Aliases sheet was not found in BootBook, terminate load process"); }/*from w ww . java2s . co m*/ NCClass ncCls = NCClass.getNCClass("ElasticAlias"); Row row = null; try { for (int i = 1; i <= sheet.getLastRowNum(); i++) { if ((row = sheet.getRow(i)) != null && POIUtil.getCellValue(row, 0) != null && POIUtil.getCellValue(row, 0).length() > 0) { String mode = POIUtil.getCellValue(row, 0); if (mode == null || mode.length() < 1) { String msg = "deploy mode must be specified for Alias entries "; logger.error(msg); throw new Exception(msg); } String version = POIUtil.getCellValue(row, 1); // if version is set but not the specified launch version, skip it if (version != null && version.length() > 0) { if (!(launchParm.getVersion().equals(version))) { continue; } } ElasticAlias alias = new ElasticAlias(POIUtil.getCellValue(row, 2), POIUtil.getCellValue(row, 3), POIUtil.getCellValue(row, 4), POIUtil.getCellValue(row, 5), POIUtil.getCellValue(row, 6)); elasticAliases.put(alias.getName(), alias); } } } catch (Exception e) { logger.error("exception in GroupAssign load " + e.toString()); } }
From source file:org.newcashel.meta.model.ElasticIndex.java
License:Apache License
public static void load(HSSFWorkbook wb, LaunchParms launchParm) throws Exception { // load the sheet HSSFSheet sheet = wb.getSheet("Indexes"); if (sheet == null) { throw new Exception("The Indexes sheet was not found in BootBook, terminate load process"); }//from www . j av a 2 s .co m NCClass ncCls = NCClass.getNCClass("ElasticIndex"); Row row = null; try { for (int i = 1; i <= sheet.getLastRowNum(); i++) { if ((row = sheet.getRow(i)) != null && POIUtil.getCellValue(row, 0) != null && POIUtil.getCellValue(row, 0).length() > 0) { String mode = POIUtil.getCellValue(row, 0); if (mode == null || mode.length() < 1) { String msg = "deploy mode must be specified for Index entries "; logger.error(msg); throw new Exception(msg); } String version = POIUtil.getCellValue(row, 1); // if version is set but not the specified launch version, skip it if (version != null && version.length() > 0) { if (!(launchParm.getVersion().equals(version))) { continue; } } ElasticIndex index = new ElasticIndex(POIUtil.getCellValue(row, 2), POIUtil.getCellValue(row, 3), POIUtil.getCellValue(row, 4), POIUtil.getCellValue(row, 5), POIUtil.getCellValue(row, 6), POIUtil.getCellValue(row, 7), POIUtil.getCellValue(row, 8), POIUtil.getCellValue(row, 9), POIUtil.getCellValue(row, 10)); elasticIndexes.put(index.getName(), index); } } } catch (Exception e) { logger.error("exception in GroupAssign load " + e.toString()); } }
From source file:org.newcashel.meta.model.LaunchParms.java
License:Apache License
public static LaunchParms load(HSSFWorkbook wb) throws Exception { // load the sheet HSSFSheet sheet = wb.getSheet("LaunchParms"); if (sheet == null) { throw new Exception("The LaunchParms sheet was not found in BootBook, terminate load process"); }/* www . jav a 2 s. c om*/ Row row = null; // the first and only LaunchConfig marked with Current = true will be loaded and assigned to a static instance try { for (int i = 1; i <= 1; i++) { if ((row = sheet.getRow(i)) != null && POIUtil.getCellValue(row, 0) != null && POIUtil.getCellValue(row, 0).length() > 0) { // skip all but the first row that is current // NOTE, if the Sheet columns are changed, change the column offset if (!(UTIL.convertBoolean(POIUtil.getCellValue(row, 2)))) continue; return new LaunchParms(POIUtil.getCellValue(row, 0), POIUtil.getCellValue(row, 1), POIUtil.getCellValue(row, 2), POIUtil.getCellValue(row, 3), POIUtil.getCellValue(row, 4), POIUtil.getCellValue(row, 5), POIUtil.getCellValue(row, 6)); } } String msg = "No launch configuration marked as current, server cannot start"; logger.error(msg); throw new Exception(msg); } catch (Exception e) { String msg = "exception in LaunchParms load " + e.toString(); logger.error(msg); throw new Exception(msg); } }
From source file:org.newcashel.meta.model.NCClass.java
License:Apache License
public static void load(HSSFWorkbook wb, LaunchParms launchParm) throws Exception { // load the sheet Sheet sheet = wb.getSheet("ClassAttributes"); if (sheet == null) { throw new Exception("The ClassAttributes sheet was not found in the MetaBook, terminate load process"); }/*ww w . ja v a 2 s .co m*/ //String[] fieldNames = POIUtil.getFirstRowVals(sheet); Class cls = Class.forName("org.newcashel.meta.model.NCClass"); Class[] parmString = new Class[1]; Row row = null; try { for (int i = 1; i <= sheet.getLastRowNum(); i++) { // skip blank rows between class attributes row = sheet.getRow(i); if (row != null && (POIUtil.getCellValue(row, ATTRIBUTE_OFFSET) == null || POIUtil.getCellValue(row, TYPE_OFFSET).length() < 1)) continue; // get the size of the cell, the length will be the number of atbs in the class // determine if the next Cell to the left is a separate Cell or part of a CellRangeAddress Cell cell = row.getCell(0, Row.RETURN_BLANK_AS_NULL); if (cell == null) { continue; } CellRangeAddress cra = getCellRangeAddress(sheet, row.getRowNum(), 0); if (cra == null) { return; } // instantiate the NCClass instance NCClass ncClass = new NCClass(); ncClass.setClassName(POIUtil.getCellValue(row, CLASSNAME_OFFSET)); //logger.info("loading NCClass " + ncClass.getClassName()); ncClass.setSuperClassName(POIUtil.getCellValue(row, SUPERCLASS_NAME_OFFSET)); ncClass.setClassParent(POIUtil.getCellValue(row, PARENTCLASS_OFFSET)); ncClass.setPrimaryKey(POIUtil.getCellValue(row, PRIMARYKEY_OFFSET)); ncClass.setPercolate(new Boolean(POIUtil.getCellValue(row, PERCOLATE_OFFSET))); ncClass.setGroupConstrain(new Boolean(POIUtil.getCellValue(row, GROUP_CONSTRAIN_OFFSET))); // not throwing java class errors, may not be significant to load context // TODO, if NO_VERIFY_JAVA_CLASS is true, skip validation // TODO, if NO_VERF true and blank String javaClassName = POIUtil.getCellValue(row, JAVA_CLASS_OFFSET); if (javaClassName.endsWith("Person.class")) { System.out.println("OKK"); } Class<?> javaCls = null; if (javaClassName != null && javaClassName.length() > 0) { ncClass.setJavaClassName(javaClassName); try { javaCls = Class.forName(javaClassName); } catch (Exception e) { logger.error("Java class specified but cannot be loaded for " + ncClass.getClassName() + ", " + javaClassName); } } else { logger.info("no java class specified for class " + ncClass.getClassName()); } classes.put(ncClass.getClassName(), ncClass); logger.info("Adding class " + ncClass.getClassName()); // loop for all the rows in the cell range for (i = cra.getFirstRow(); i <= cra.getLastRow(); i++) { row = sheet.getRow(i); if (row == null) { return; // range iteration complete } cell = row.getCell(ATTRIBUTE_OFFSET, Row.RETURN_BLANK_AS_NULL); if (cell == null) continue; String atbName = POIUtil.getCellValue(row, ATTRIBUTE_OFFSET); String version = POIUtil.getCellValue(row, VERSION_OFFSET); // if no version id and the atb has not been set, then set it // if a version and it matches the build version, set/overwrite the value Attribute atb = null; // if version id is set and matches the launchParm setting, use it else skip // a non-versioned atb may be encountered first, reuse it if received a versioned one if (version != null && version.length() > 0) { if (!(launchParm.getVersion().equals(version))) { continue; } logger.debug("add version specific atb " + ncClass.getClassName() + ", " + atbName + ", " + version); // if a default version has already been established, use it else create one atb = ncClass.getAttribute(atbName); if (atb == null) { atb = new Attribute(); } } else { // no version, use existing if already set to the current version atb = ncClass.getAttribute(atbName); if (atb == null) { atb = new Attribute(); } else continue; // already established a version specific atb, ignore non-versioned entry } // create the Attributes and add to the class instance // TODO, verify not null on these required values, user may override Excel edits atb.setName(POIUtil.getCellValue(row, ATTRIBUTE_OFFSET)); atb.setType(POIUtil.getCellValue(row, TYPE_OFFSET)); atb.setLabel(POIUtil.getCellValue(row, LABEL_OFFSET)); atb.setIndexName(POIUtil.getPopulatedCellValue(row, INDEXNAME_OFFSET)); //logger.info("added NCClass atb " + ncClass.getClassName() + ", " + atb.getName()); // defaults to false atb.setStore(UTIL.convertBoolean(POIUtil.getCellValue(row, STORE_OFFSET))); /* String storeVal = POIUtil.getPopulatedCellValue(row, STORE_OFFSET); if (storeVal != null) { atb.setStore(new Boolean(storeVal)); } */ // analyzed is default value, will tokenize field String indexVal = POIUtil.getPopulatedCellValue(row, INDEX_OFFSET); if (indexVal != null) { atb.setIndex(indexVal); } // default is true, don't set unless value is not String includeInAll = POIUtil.getPopulatedCellValue(row, INCLUDEINALL_OFFSET); if (includeInAll != null && includeInAll.equalsIgnoreCase("no")) { atb.setIncludeInAll(false); } // default varies, based on the numeric type // TODO, verify numeric field String precision = POIUtil.getPopulatedCellValue(row, PRECISIONSTEP_OFFSET); if (precision != null) { atb.setPrecision(new Integer(precision)); } String dateFormat = POIUtil.getPopulatedCellValue(row, DATEFORMAT_OFFSET); if (dateFormat != null) { atb.setDateFormat(dateFormat); } String fieldDataFormat = POIUtil.getPopulatedCellValue(row, FIELDDATAFORMAT_OFFSET); if (fieldDataFormat != null) { atb.setFieldDataFormat(fieldDataFormat); } atb.setDocValues(UTIL.convertBoolean(POIUtil.getCellValue(row, DOCVALUES_OFFSET))); String boost = POIUtil.getPopulatedCellValue(row, BOOST_OFFSET); if (boost != null) { atb.setBoost(new Double(boost)); } // defaults to not adding the field to the JSON string String nullVal = POIUtil.getPopulatedCellValue(row, NULLVALUE_OFFSET); if (nullVal != null) { atb.setNullValue(nullVal); } String termVector = POIUtil.getPopulatedCellValue(row, TERMVECTOR_OFFSET); if (termVector != null) { atb.setTermVector(termVector); } String analyzer = POIUtil.getPopulatedCellValue(row, ANALYZER_OFFSET); if (analyzer != null) { atb.setAnalyzer(analyzer); } String indexAnalyzer = POIUtil.getPopulatedCellValue(row, INDEX_ANALYZER_OFFSET); if (indexAnalyzer != null) { atb.setIndexAnalyzer(indexAnalyzer); } String searchAnalyzer = POIUtil.getPopulatedCellValue(row, SEARCH_ANALYZER_OFFSET); if (searchAnalyzer != null) { atb.setSearchAnalyzer(searchAnalyzer); } atb.setIgnoreAbove(UTIL.convertAnyNumberToInt(POIUtil.getCellValue(row, IGNOREABOVE_OFFSET))); atb.setPositionOffset( UTIL.convertAnyNumberToInt(POIUtil.getCellValue(row, POSITIONGAP_OFFSET))); atb.setIgnoreMalformed(UTIL.convertBoolean(POIUtil.getCellValue(row, IGNOREMALFORMED_OFFSET))); atb.setCoerceNumber(UTIL.convertBoolean(POIUtil.getCellValue(row, COERCENUMBER_OFFSET))); atb.setBinaryCompress(UTIL.convertBoolean(POIUtil.getCellValue(row, BINARYCOMPRESS_OFFSET))); atb.setCompressThreshold( UTIL.convertAnyNumberToInt(POIUtil.getCellValue(row, COMPRESSTHRESHOLD_OFFSET))); // TODO, all all the others //atb.setStore(UTIL.convertBoolean(POIUtil.getCellValue(row, STORE_OFFSET))); if (atb.getType().equalsIgnoreCase("SubType")) { subTypes.put(atb.getName(), atb.getLabel()); } else { // save the attribute ncClass.attributes.put(atb.getName(), atb); ncClass.labels.put(atb.getLabel(), atb); // if java class, verify the field accessibility if (javaCls != null) { Field field = null; Class<?> current = javaCls; while (!(current.getName().equals("java.lang.Object"))) { try { field = current.getDeclaredField(atb.getName()); atb.setField(field); //atb.setField(current.getDeclaredField(atb.getName())); break; } catch (Exception e) { //System.out.println("java reflection warning, class/field not found, checking super class " + cls.getName() + ", " + atb.getName()); current = current.getSuperclass(); continue; } } if (field != null) { field.setAccessible(true); } } } } i--; // continue the loop on the prior row } } catch (Exception e) { String msg = "exception in NCClass load " + e.toString(); logger.error(msg); throw new Exception(msg); } }
From source file:org.newcashel.meta.model.River.java
License:Apache License
public static void load(HSSFWorkbook wb) throws Exception { // load the sheet HSSFSheet sheet = wb.getSheet("Rivers"); if (sheet == null) { throw new Exception("The River sheet was not found in MetaBook, terminate load process"); }// w w w .j a v a2s .co m NCClass ncCls = NCClass.getNCClass("River"); Row row = null; try { for (int i = 1; i <= sheet.getLastRowNum(); i++) { if ((row = sheet.getRow(i)) != null && POIUtil.getCellValue(row, 0) != null && POIUtil.getCellValue(row, 0).length() > 0) { String mode = POIUtil.getCellValue(row, 0); if (mode == null || mode.length() < 1) { String msg = "deploy mode must be specified for River entries "; logger.error(msg); throw new Exception(msg); } River river = new River(POIUtil.getCellValue(row, 0), POIUtil.getCellValue(row, 1), POIUtil.getCellValue(row, 2)); rivers.put(river.getName(), river); } } } catch (Exception e) { logger.error("exception in GroupAssign load " + e.toString()); } }