List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet getLastRowNum
@Override public int getLastRowNum()
From source file:de.jwic.ecolib.tableviewer.export.ExcelExportControl.java
License:Apache License
@SuppressWarnings({ "unchecked", "rawtypes" }) protected void renderRows(Iterator<?> iter, int level, TableModel model, HSSFSheet sheet, HSSFCellStyle styleDate) {// w ww . ja va2s. co m while (iter.hasNext()) { short col = 0; Object inputObj = iter.next(); HSSFRow row = sheet.createRow(sheet.getLastRowNum() + 1); IContentProvider contentProvider = model.getContentProvider(); for (Iterator<TableColumn> it = model.getColumnIterator(); it.hasNext();) { ; TableColumn column = it.next(); if (!isColumnVisible(column)) { // skip column, it's not visible! continue; } // call the label provider's getCellLabel method to get the // CellLabel object CellLabel label = null; String rowKey = contentProvider.getUniqueKey(inputObj); boolean expanded = model.isExpanded(rowKey); HSSFCell cell = row.createCell(col++); try { label = tableViewer.getTableLabelProvider().getCellLabel(inputObj, column, new RowContext(expanded, level)); Object obj = label.object; // set cell text and style if (obj != null) { // identify special style for Date and Number if (obj instanceof Number) { cell.setCellValue(((Number) obj).doubleValue()); continue; } else if (obj instanceof Date) { cell.setCellValue((Date) obj); cell.setCellStyle(styleDate); continue; } else if (obj instanceof Boolean) { cell.setCellValue((Boolean) obj ? "Y" : "N"); continue; } } String columnText = label.text; cell.setCellValue(columnText); } catch (Throwable t) { cell.setCellValue(t.getMessage()); log.error("Error rendering column " + column.getTitle(), t); } } // render children if (contentProvider.hasChildren(inputObj)) { Iterator children = contentProvider.getChildren(inputObj); renderRows(children, level + 1, model, sheet, styleDate); } } }
From source file:eafit.cdei.asignacion.input.ReadCurrentCourses.java
public List<Teacher> loadCurrentOffering() throws Exception { try {//www. j av a 2s .co m FileInputStream fileInputStream = new FileInputStream("current_classes.xls"); HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream); HSSFSheet worksheet = workbook.getSheet("currentOffering"); boolean keepDoing = true; for (int i = 0; i < worksheet.getLastRowNum() + 1; i++) { HSSFRow row1 = worksheet.getRow(i); HSSFCell cellF1 = row1.getCell((short) 5); String f1Val = ((int) cellF1.getNumericCellValue()) + ""; HSSFCell cellW1 = row1.getCell((short) 22); String w1Val = cellW1.getStringCellValue(); HSSFCell cellX1 = row1.getCell((short) 23); String x1Val = cellX1.getStringCellValue(); HSSFCell cellY1 = row1.getCell((short) 24); String y1Val = cellY1.getStringCellValue(); HSSFCell cellAU1 = row1.getCell((short) 46); String au1Val = ((int) cellAU1.getNumericCellValue()) + ""; HSSFCell cellAW1 = row1.getCell((short) 48); String aw1Val = cellAW1.getStringCellValue(); if (f1Val == null || f1Val.length() == 0 || f1Val.equals("0")) { keepDoing = false; } Course c = new Course(); c.setHourStart(f1Val); c.setHourEnd(au1Val); c.setDowList(generateDaysList(aw1Val)); c.setNameCourse(x1Val); c.setCodeCourse(w1Val); c.setCodeCourse(y1Val); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HHmm"); if (au1Val.length() == 3) { au1Val = "0" + au1Val; } if (f1Val.length() == 3) { f1Val = "0" + f1Val; } c.setHourEndLocal(LocalTime.parse(au1Val, dtf)); c.setHourStartLocal(LocalTime.parse(f1Val, dtf)); c.setDateStartLocal(LocalTime.parse(au1Val, dtf)); c.setDateEndLocal(LocalTime.parse(aw1Val, dtf)); System.out.println(c); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:eafit.cdei.asignacion.input.ReadCurrentOffering.java
public List<Teacher> loadCurrentOffering() throws Exception { try {/*from ww w . jav a2s. c o m*/ FileInputStream fileInputStream = new FileInputStream("currentOffering.xls"); HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream); HSSFSheet worksheet = workbook.getSheet("currentOffering"); boolean keepDoing = true; for (int i = 0; i < worksheet.getLastRowNum() + 1; i++) { HSSFRow row1 = worksheet.getRow(i); HSSFCell cellF1 = row1.getCell((short) 5); String f1Val = ((int) cellF1.getNumericCellValue()) + ""; HSSFCell cellW1 = row1.getCell((short) 22); String w1Val = cellW1.getStringCellValue(); HSSFCell cellX1 = row1.getCell((short) 23); String x1Val = cellX1.getStringCellValue(); HSSFCell cellY1 = row1.getCell((short) 24); String y1Val = cellY1.getStringCellValue(); HSSFCell cellAU1 = row1.getCell((short) 46); String au1Val = ((int) cellAU1.getNumericCellValue()) + ""; HSSFCell cellAW1 = row1.getCell((short) 48); String aw1Val = cellAW1.getStringCellValue(); HSSFCell cellAB = row1.getCell((short) 27); String abVal = cellAB.getStringCellValue(); HSSFCell cellAC = row1.getCell((short) 28); String acVal = cellAC.getStringCellValue(); if (f1Val == null || f1Val.length() == 0 || f1Val.equals("0")) { keepDoing = false; } Course c = new Course(); c.setHourStart(f1Val); c.setHourEnd(au1Val); c.setDowList(generateDaysList(aw1Val)); c.setNameCourse(x1Val); c.setCodeCourse(w1Val); c.setCodeCourse(y1Val); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HHmm"); if (au1Val.length() == 3) { au1Val = "0" + au1Val; } if (f1Val.length() == 3) { f1Val = "0" + f1Val; } c.setHourEndLocal(LocalTime.parse(au1Val, dtf)); c.setHourStartLocal(LocalTime.parse(f1Val, dtf)); DateTimeFormatter dtf1 = DateTimeFormatter.ofPattern("yyyyMMdd"); //c.setDateStart(LocalDate.parse(abVal,dtf1)); //c.setHourStartLocal(LocalTime.parse(f1Val,dtf)); System.out.println(c); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:eafit.cdei.asignacion.input.ReadTeacherAvailability.java
@Override public List<Teacher> loadTeacherAvailability() throws Exception { try {/*from w w w . jav a 2 s .c o m*/ FileInputStream fileInputStream = new FileInputStream("googleDoc.xls"); HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream); HSSFSheet worksheet = workbook.getSheet("Form Responses 1"); boolean keepDoing = true; for (int i = 1; i < worksheet.getLastRowNum() + 1; i++) { HSSFRow row1 = worksheet.getRow(i); HSSFCell cellB1 = row1.getCell((short) 1); String b1Val = cellB1.getStringCellValue() + ""; HSSFCell cellG1 = row1.getCell((short) 6); String g1Val = cellG1.getStringCellValue() + ""; HSSFCell cellH1 = row1.getCell((short) 7); String h1Val = cellH1.getStringCellValue() + ""; HSSFCell cellJ1 = row1.getCell((short) 8); String j1Val = cellJ1.getStringCellValue() + ""; HSSFCell cellK1 = row1.getCell((short) 9); String k1Val = cellK1.getStringCellValue() + ""; HSSFCell cellI1 = row1.getCell((short) 10); String i1Val = cellI1.getStringCellValue() + ""; HSSFCell cellL1 = row1.getCell((short) 11); String l1Val = cellL1.getStringCellValue() + ""; HSSFCell cellM1 = row1.getCell((short) 12); String m1Val = cellM1.getStringCellValue() + ""; HSSFCell cellN1 = row1.getCell((short) 13); String n1Val = cellN1.getStringCellValue() + ""; HSSFCell cellO1 = row1.getCell((short) 14); String o1Val = cellO1.getStringCellValue() + ""; HSSFCell cellP1 = row1.getCell((short) 15); String p1Val = cellP1.getStringCellValue() + ""; HSSFCell cellQ1 = row1.getCell((short) 16); String q1Val = cellQ1.getStringCellValue() + ""; HSSFCell cellR1 = row1.getCell((short) 17); String r1Val = cellR1.getStringCellValue() + ""; HSSFCell cellS1 = row1.getCell((short) 18); String s1Val = cellS1.getStringCellValue() + ""; HSSFCell cellT1 = row1.getCell((short) 19); String t1Val = cellT1.getStringCellValue() + ""; HSSFCell cellU1 = row1.getCell((short) 20); String u1Val = cellU1.getStringCellValue() + ""; HSSFCell cellV1 = row1.getCell((short) 21); String v1Val = cellV1.getStringCellValue() + ""; HSSFCell cellW1 = row1.getCell((short) 22); String w1Val = cellW1.getStringCellValue() + ""; HSSFCell cellX1 = row1.getCell((short) 23); String x1Val = cellX1.getStringCellValue() + ""; HSSFCell cellY1 = row1.getCell((short) 24); String y1Val = cellY1.getStringCellValue() + ""; HSSFCell cellZ1 = row1.getCell((short) 25); String z1Val = cellZ1.getStringCellValue() + ""; HSSFCell cellAA1 = row1.getCell((short) 26); String aa1Val = cellAA1.getStringCellValue() + ""; HSSFCell cellAB1 = row1.getCell((short) 27); String ab1Val = cellAB1.getStringCellValue() + ""; if (b1Val.length() == 0) { keepDoing = false; } else { Teacher t = new Teacher(); t.setFullName(b1Val); t.addCourseAvaliability(generateMTF(getAnswer(g1Val), "06", "08")); t.addCourseAvaliability(generateMTF(getAnswer(h1Val), "08", "10")); t.addCourseAvaliability(generateMTF(getAnswer(i1Val), "10", "12")); t.addCourseAvaliability(generateMTF(getAnswer(j1Val), "12", "14")); t.addCourseAvaliability(generateMTF(getAnswer(k1Val), "14", "16")); t.addCourseAvaliability(generateMWF(getAnswer(l1Val), "06", "08")); t.addCourseAvaliability(generateMWF(getAnswer(n1Val), "08", "10")); t.addCourseAvaliability(generateMWF(getAnswer(m1Val), "10", "12")); t.addCourseAvaliability(generateMWF(getAnswer(o1Val), "12", "14")); t.addCourseAvaliability(generateMWF(getAnswer(p1Val), "14", "16")); t.addCourseAvaliability(generateMTT(getAnswer(q1Val), "18", "15", "20", "45")); t.addCourseAvaliability(generateMTW(getAnswer(r1Val), "18", "30", "20", "30")); t.addCourseAvaliability(generateTTT(getAnswer(s1Val), "10", "12")); t.addCourseAvaliability(generateTTT(getAnswer(t1Val), "12", "14")); t.addCourseAvaliability(generateTTT(getAnswer(u1Val), "14", "16")); t.addCourseAvaliability(generateTTT(getAnswer(v1Val), "18", "30", "20", "30")); t.addCourseAvaliability(generateTTT(getAnswer(w1Val), "06", "09")); t.addCourseAvaliability(generateTTT(getAnswer(x1Val), "09", "12")); t.addCourseAvaliability(generateWF(getAnswer(y1Val), "06", "09")); t.addCourseAvaliability(generateWF(getAnswer(z1Val), "07", "00", "08", "30")); t.addCourseAvaliability(generateTTT(getAnswer(aa1Val), "12", "00", "13", "30")); t.addCourseAvaliability(generateTTT(getAnswer(ab1Val), "07", "00", "08", "30")); System.out.println(t); } } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:eafit.cdei.asignacion.input.ReadTeacherPreferences.java
public List<Teacher> loadTeacherPreferences() throws Exception { try {/* w w w .j a v a 2 s . co m*/ FileInputStream fileInputStream = new FileInputStream("TeacherPreferences.xls"); HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream); HSSFSheet worksheet = workbook.getSheet("Preferences"); boolean keepDoing = true; for (int i = 1; i < worksheet.getLastRowNum() + 1; i++) { HSSFRow row1 = worksheet.getRow(i); HSSFCell cellA1 = row1.getCell((short) 0); String a1Val = cellA1.getNumericCellValue() + ""; HSSFCell cellB1 = row1.getCell((short) 1); String b1Val = cellB1.getStringCellValue(); HSSFCell cellC1 = row1.getCell((short) 2); String c1Val = cellC1.getStringCellValue(); String d1Val = ""; HSSFCell cellD1 = row1.getCell((short) 3); if (cellD1 != null) { d1Val = cellD1.getStringCellValue(); } HSSFCell cellE1 = row1.getCell((short) 4); double e1Val = cellE1.getNumericCellValue(); if (a1Val == null || a1Val.length() == 0 || a1Val.equals("0")) { keepDoing = false; } Teacher t = new Teacher(); t.setFullName(b1Val); t.setMaxCourses((int) e1Val); String[] preferedCourses = c1Val.split(","); ArrayList<LevelCourse> preferedCoursed = new ArrayList<LevelCourse>(); for (String preferedCoursed1 : preferedCourses) { LevelCourse lc = new LevelCourse(); lc.setLevelName(preferedCoursed1); preferedCoursed.add(lc); } String[] preferedTimes = d1Val.split(","); ArrayList<String> preferedTime = new ArrayList<>(); for (String pf : preferedTimes) { preferedTime.add(pf); } t.setListPreferedCourses(preferedCoursed); System.out.println(t); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:edu.ku.brc.specify.utilapps.BuildSampleDatabase.java
License:Open Source License
/** * @param treeDef/*from ww w . j a v a 2 s. c o m*/ * @return */ public Geography convertGeographyFromXLS(final GeographyTreeDef treeDef) { frame.setDesc("Building Geography Tree..."); Hashtable<String, Geography> geoHash = new Hashtable<String, Geography>(); geoHash.clear(); String fileName = "Geography.xls"; File file = XMLHelper.getConfigDir("../demo_files/" + fileName); if (!file.exists()) { log.error("Couldn't file[" + file.getAbsolutePath() + "] checking the config dir"); file = XMLHelper.getConfigDir(fileName); if (!file.exists()) { file = new File("Specify/demo_files/" + fileName); } } if (file == null || !file.exists()) { log.error("Couldn't file[" + file.getAbsolutePath() + "]"); return null; } // setup the root Geography record (planet Earth) Geography earth = new Geography(); earth.initialize(); earth.setName(getResourceString("Earth")); earth.setFullName(earth.getName()); earth.setNodeNumber(1); earth.setHighestChildNodeNumber(1); earth.setRankId(0); earth.setDefinition(treeDef); GeographyTreeDefItem defItem = treeDef.getDefItemByRank(0); earth.setDefinitionItem(defItem); int counter = 0; try { startTx(); persist(earth); String[] cells = new String[4]; InputStream input = new FileInputStream(file); POIFSFileSystem fs = new POIFSFileSystem(input); HSSFWorkbook workBook = new HSSFWorkbook(fs); HSSFSheet sheet = workBook.getSheetAt(0); Iterator<?> rows = sheet.rowIterator(); int lastRowNum = sheet.getLastRowNum(); if (frame != null) { final int mx = lastRowNum; SwingUtilities.invokeLater(new Runnable() { public void run() { frame.setProcess(0, mx); } }); } while (rows.hasNext()) { if (counter == 0) { counter = 1; rows.next(); continue; } if (counter % 100 == 0) { if (frame != null) frame.setProcess(counter); log.info("Converted " + counter + " Geography records"); } HSSFRow row = (HSSFRow) rows.next(); Iterator<?> cellsIter = row.cellIterator(); int i = 0; while (cellsIter.hasNext() && i < 4) { HSSFCell cell = (HSSFCell) cellsIter.next(); if (cell != null) { cells[i] = StringUtils.trim(cell.getRichStringCellValue().getString()); i++; } } // Sets nulls to unused cells for (int j = i; j < 4; j++) { cells[j] = null; } //System.out.println(); @SuppressWarnings("unused") Geography newGeo = convertGeographyRecord(cells[0], cells[1], cells[2], cells[3], earth); counter++; } } catch (Exception ex) { ex.printStackTrace(); } if (frame != null) frame.setProcess(counter); log.info("Converted " + counter + " Geography records"); frame.setDesc("Saving Geography Tree..."); frame.getProcessProgress().setIndeterminate(true); TreeHelper.fixFullnameForNodeAndDescendants(earth); earth.setNodeNumber(1); fixNodeNumbersFromRoot(earth); commitTx(); /*startTx(); TreeHelper.fixFullnameForNodeAndDescendants(earth); earth.setNodeNumber(1); fixNodeNumbersFromRoot(earth); printTree(earth, 0); saveTree(earth); commitTx();*/ log.info("Converted " + counter + " Stratigraphy records"); // set up Geography foreign key mapping for locality geoHash.clear(); return earth; }
From source file:edu.ku.brc.specify.utilapps.BuildSampleDatabase.java
License:Open Source License
/** * @param treeDef//from w w w. jav a 2 s . c om * @param fileName * @param doUserProvidedFile * @return */ public Taxon convertTaxonFromXLS(final TaxonTreeDef treeDef, final String fileName, final boolean doUserProvidedFile) { Hashtable<String, Taxon> taxonHash = new Hashtable<String, Taxon>(); taxonHash.clear(); File file = TaxonLoadSetupPanel.getFileForTaxon(fileName, doUserProvidedFile); if (file == null) { return null; } Vector<TaxonTreeDefItem> rankedItems = new Vector<TaxonTreeDefItem>(); Hashtable<String, Boolean> colNames = new Hashtable<String, Boolean>(); for (TaxonTreeDefItem item : treeDef.getTreeDefItems()) { colNames.put(item.getName().toLowerCase(), true); rankedItems.add(item); } Collections.sort(rankedItems, new Comparator<TaxonTreeDefItem>() { @Override public int compare(TaxonTreeDefItem o1, TaxonTreeDefItem o2) { return o1.getRankId().compareTo(o2.getRankId()); } }); Connection conn = null; Statement stmt = null; TaxonTreeDefItem rootTreeDefItem = rankedItems.get(0); Set<Taxon> rootKids = rootTreeDefItem.getTreeEntries(); Taxon root = rootKids.iterator().next(); Vector<Pair<String, Integer>> nodeList = new Vector<Pair<String, Integer>>(); Pair<String, Integer> rootNode = new Pair<String, Integer>(root.getName(), root.getId()); nodeList.add(rootNode); int counter = 0; int numDataCols = 0; try { startTx(); for (TaxonTreeDefItem item : treeDef.getTreeDefItems()) { persist(item); } persist(root); commitTx(); String[] cells = new String[35]; String[] header = new String[35]; InputStream input = new FileInputStream(file); POIFSFileSystem fs = new POIFSFileSystem(input); HSSFWorkbook workBook = new HSSFWorkbook(fs); HSSFSheet sheet = workBook.getSheetAt(0); Iterator<?> rows = sheet.rowIterator(); int lastRowNum = sheet.getLastRowNum(); if (frame != null) { final int mx = lastRowNum; SwingUtilities.invokeLater(new Runnable() { public void run() { frame.setProcess(0, mx); } }); } conn = DBConnection.getInstance().createConnection(); //conn.setAutoCommit(false); stmt = conn.createStatement(); rows = sheet.rowIterator(); while (rows.hasNext()) { for (int i = 0; i < cells.length; i++) { cells[i] = null; } if (counter == 0) { HSSFRow row = (HSSFRow) rows.next(); Iterator<?> cellsIter = row.cellIterator(); int i = 0; while (cellsIter.hasNext()) { HSSFCell cell = (HSSFCell) cellsIter.next(); if (cell != null) { cells[i] = getXLSCellValueAsStr(cell); header[i] = cells[i]; i++; } } for (i = 0; i < cells.length; i++) { if (cells[i] == null) break; if (colNames.get(cells[i].toLowerCase()) != null) { numDataCols = i + 1; } else { for (String key : colNames.keySet()) { System.err.println("key[" + key + "]"); } System.err.println("Not Found: [" + cells[i].toLowerCase() + "]"); break; } } loadIndexes(cells); counter = 1; for (String hdr : header) { if (hdr == null) break; int inx = 0; for (TaxonTreeDefItem item : rankedItems) { if (hdr.equalsIgnoreCase(item.getName())) { log.debug("Header: " + hdr + " -> " + inx); taxonIndexes.put(hdr, inx); item.setIsInFullName(item.getRankId() >= TaxonTreeDef.GENUS); } else { log.debug("Header: " + hdr + " -> skipped."); } inx++; } } continue; } if (counter % 100 == 0) { if (frame != null) frame.setProcess(counter); //log.info("Converted " + counter + " of "+lastRowNum+" Taxon records"); } HSSFRow row = (HSSFRow) rows.next(); Iterator<?> cellsIter = row.cellIterator(); int i = 0; while (cellsIter.hasNext() && i < cells.length) { HSSFCell cell = (HSSFCell) cellsIter.next(); if (cell != null) { cells[i] = getXLSCellValueAsStr(cell); i++; } } convertTaxonNodes(conn, stmt, header, cells, numDataCols, rootNode, nodeList, rankedItems, root.getDefinition().getId()); counter++; } stmt.executeUpdate( "UPDATE taxon SET IsAccepted = true WHERE IsAccepted IS NULL and AcceptedID IS NULL AND TaxonTReeDefID = " + treeDef.getId()); // Clear all GUIDs in Taxon. stmt.executeUpdate("UPDATE taxon SET GUID = NULL WHERE TaxonTreeDefID = " + treeDef.getId()); conn.close(); input.close(); if (frame != null) frame.setProcess(lastRowNum); root = (Taxon) session.createQuery("FROM Taxon WHERE id = " + root.getId()).list().get(0); } catch (Exception ex) { ex.printStackTrace(); edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(BackupServiceFactory.class, ex); } finally { try { if (stmt != null) { stmt.close(); } if (conn != null) { conn.close(); } } catch (Exception ex) { ex.printStackTrace(); } } if (frame != null) { frame.setDesc("Saving Taxon Tree..."); frame.getProcessProgress().setIndeterminate(true); } NodeNumberer<Taxon, TaxonTreeDef, TaxonTreeDefItem> nodeNumberer = new NodeNumberer<Taxon, TaxonTreeDef, TaxonTreeDefItem>( root.getDefinition()); nodeNumberer.doInBackground(); //startTx(); //TreeHelper.fixFullnameForNodeAndDescendants(root); //root.setNodeNumber(1); //fixNodeNumbersFromRoot(root); //commitTx(); log.info("Converted " + counter + " Taxon records"); // set up Taxon foreign key mapping for locality taxonHash.clear(); return root; }
From source file:edu.ku.brc.specify.utilapps.BuildSampleDatabase.java
License:Open Source License
/** * @param treeDef/*from w w w . ja v a 2 s.co m*/ * @return */ public GeologicTimePeriod convertChronoStratFromXLS(final GeologicTimePeriodTreeDef treeDef, final Agent userAgent) { startTx(); GeologicTimePeriodTreeDefItem root = createGeologicTimePeriodTreeDefItem(null, treeDef, "Root", 0); GeologicTimePeriodTreeDefItem era = createGeologicTimePeriodTreeDefItem(root, treeDef, "Erathem/Era", 100); GeologicTimePeriodTreeDefItem period = createGeologicTimePeriodTreeDefItem(era, treeDef, "System/Period", 200); GeologicTimePeriodTreeDefItem series = createGeologicTimePeriodTreeDefItem(period, treeDef, "Series/Epoch", 300); @SuppressWarnings("unused") GeologicTimePeriodTreeDefItem member = createGeologicTimePeriodTreeDefItem(series, treeDef, "Stage/Age", 400); persist(root); commitTx(); series.setIsInFullName(true); frame.setDesc("Building ChronoStratigraphy Tree..."); Hashtable<String, GeologicTimePeriod> chronoHash = new Hashtable<String, GeologicTimePeriod>(); chronoHash.clear(); String fileName = "chronostrat_tree.xls"; File file = XMLHelper.getConfigDir("../demo_files/" + fileName); if (!file.exists()) { log.error("Couldn't file[" + file.getAbsolutePath() + "] checking the config dir"); file = XMLHelper.getConfigDir(fileName); if (!file.exists()) { file = new File("Specify/demo_files/" + fileName); } } if (file == null || !file.exists()) { log.error("Couldn't file[" + file.getAbsolutePath() + "]"); return null; } // setup the root ChronoStrat record (planet Earth) GeologicTimePeriod rootNode = new GeologicTimePeriod(); rootNode.initialize(); rootNode.setName(getResourceString("Root")); rootNode.setFullName(rootNode.getName()); rootNode.setRankId(0); rootNode.setDefinition(treeDef); rootNode.setDefinitionItem(root); rootNode.setCreatedByAgent(userAgent); int counter = 0; try { startTx(); persist(rootNode); String[] cells = new String[4]; InputStream input = new FileInputStream(file); POIFSFileSystem fs = new POIFSFileSystem(input); HSSFWorkbook workBook = new HSSFWorkbook(fs); HSSFSheet sheet = workBook.getSheetAt(0); Iterator<?> rows = sheet.rowIterator(); int lastRowNum = sheet.getLastRowNum(); if (frame != null) { final int mx = lastRowNum; SwingUtilities.invokeLater(new Runnable() { public void run() { frame.setProcess(0, mx); } }); } while (rows.hasNext()) { if (counter == 0) { counter = 1; continue; } if (counter % 100 == 0) { if (frame != null) frame.setProcess(counter); log.info("Converted " + counter + " ChronoStrat records"); } HSSFRow row = (HSSFRow) rows.next(); Iterator<?> cellsIter = row.cellIterator(); int i = 0; while (cellsIter.hasNext() && i < 4) { HSSFCell cell = (HSSFCell) cellsIter.next(); if (cell != null) { cells[i] = StringUtils.trim(cell.getRichStringCellValue().getString()); i++; } } for (int j = i; j < 4; j++) { cells[j] = null; } //System.out.println(); @SuppressWarnings("unused") GeologicTimePeriod newGeo = convertChronoStratRecord(cells[0], cells[1], cells[2], cells[3], rootNode, userAgent); counter++; } input.close(); } catch (Exception ex) { ex.printStackTrace(); } if (frame != null) frame.setProcess(counter); log.info("Converted " + counter + " ChronoStrat records"); TreeHelper.fixFullnameForNodeAndDescendants(rootNode); rootNode.setNodeNumber(1); fixNodeNumbersFromRoot(rootNode); commitTx(); log.info("Converted " + counter + " Stratigraphy records"); // set up ChronoStrat foreign key mapping for locality chronoHash.clear(); return rootNode; }
From source file:edu.tum.cs.conqat.quamoco.ManualFindingsReader.java
License:Apache License
/** {@inheritDoc} */ @Override/* w ww. ja v a 2s .c o m*/ public MetricCollection process() throws ConQATException { MetricCollection result = new MetricCollection(); HSSFSheet sheet = ExcelUtils.readFirstSheet(file); ExcelUtils.checkName(sheet, 0, "Measure"); ExcelUtils.checkName(sheet, 1, "Location"); ExcelUtils.checkName(sheet, 2, "Message"); FindingGroup group = new FindingReport().getOrCreateCategory(findingCategory) .getOrCreateFindingGroup(findingGroup); for (int i = 1; i < sheet.getLastRowNum() + 1; i++) { HSSFRow row = sheet.getRow(i); String measureName = ExcelUtils.getCellText(row, 0); String location = ExcelUtils.getCellText(row, 1); String message = ExcelUtils.getCellText(row, 2); QualifiedNameLocation qnl = new QualifiedNameLocation(location, location, location); String findingname = getClass().getSimpleName(); // not used anymore after restrusturing to new findings framwork of 21.12.2012 Finding finding = group.createFinding(qnl); finding.setValue(EFindingKeys.MESSAGE.toString(), message); add(measureName, result, finding); } return result; }
From source file:edu.tum.cs.conqat.quamoco.quickeval.MeasureReader.java
License:Apache License
/** {@inheritDoc} */ @Override//from ww w . ja va 2s .c om public MetricCollection process() throws ConQATException { if (!lenient && this.models == null) { throw new ConQATException( "This processor is not in lenient mode. Thus it has to be provided with a quality model"); } assertCollectionInitialized(); File excel = new File(excelFile); // if there is no file, issue a warning and return an empty collection if (!excel.exists()) { getLogger().warn("Excel-file '" + excelFile + "' not found. Returning empty metric collection."); return metricCollection; } getLogger().info("Reading Excel file from " + excelFile); HSSFSheet sheet = ExcelUtils.readFirstSheet(excel); assertFormat(sheet); for (int rowNum = 1; rowNum <= sheet.getLastRowNum(); rowNum++) { processRow(sheet, rowNum); } return metricCollection; }