Package com.Ostermiller.util

Examples of com.Ostermiller.util.CSVPrint


   *
   * @param  selectedFields  Description of the Parameter
   */
  private void DoExport(boolean[] selectedFields) {
    //setup the csv printer
    CSVPrint printer;
    OutputStream out;
    //create the export
    String sSelectString = getSelectString(selectedFields, fromDate, toDate);
    WorkingDialog workDialog = new WorkingDialog(null);
    workDialog.setVisible(true);
    workDialog.SetProgress(0);
    try {
      out = new FileOutputStream(outputFile);
      if (isExcel) {
        printer = new ExcelCSVPrinter(out);
      } else {
        printer = new CSVPrinter(out);
      }
      printer.changeDelimiter(delimiter);
      DataConnection dc = DataConnection.getInstance(view);
      if (dc == null || !dc.bIsConnectionMade) {
        return;
      }
      Statement st = dc.con.createStatement();
      ResultSet rs = st.executeQuery(dc.filterSQL(sSelectString));
      ResultSetMetaData rsmd = rs.getMetaData();
      if (rsmd == null) {
        return;
      }
      int iNumColumns = rsmd.getColumnCount();
      String[] outputStrings = new String[iNumColumns];

      //count how many rows
      int numRows = 0;
      if (rs.next()) {
        rs.last();
        numRows = rs.getRow();
      }
      rs.beforeFirst();
      //print out the rows
      int rowCountShowProgress = 0;
      int rowNum = 0;
      while (rs.next()) {
        rowNum++;
        rowCountShowProgress++;
        if (rowCountShowProgress >= 10) {
          workDialog.SetProgress(rowNum * 100 / numRows);
          rowCountShowProgress = 0;
        }
        for (int i = 1; i <= iNumColumns; i++) {
          switch (rsmd.getColumnType(i)) {
            case Types.VARCHAR:
              outputStrings[i - 1] = rs.getString(i);
              if (outputStrings[i - 1] == null) {
                outputStrings[i - 1] = "";
              }
              if (rsmd.getColumnName(i).equals("TypeName")) {
                //it needs to be translated...
                outputStrings[i - 1] = Translator.getTranslation(outputStrings[i - 1]);
              }
              break;
            case Types.INTEGER:
              outputStrings[i - 1] = formatNumPane.numPanels[formatNumPane.SHOW_INTEGER].format(new Integer(rs.getInt(i)));
              break;
            case Types.NUMERIC:
            case Types.REAL:
            case Types.FLOAT:
            case Types.DECIMAL:
            case Types.DOUBLE:
              outputStrings[i - 1] = formatNumPane.numPanels[formatNumPane.SHOW_WHOLE_NUMBER].format(new Double(rs.getDouble(i)));
              break;
            case Types.DATE:
              outputStrings[i - 1] = formatNumPane.numPanels[formatNumPane.SHOW_DATE].format(rs.getDate(i));
              break;
            default:
              outputStrings[i - 1] = StringBinaryConverter.BinaryToString(
                  rs.getBytes(i));
              break;
          }
          Log.log(Log.DEBUG, this, "outputStrings[i-1]=" + outputStrings[i - 1]);
        }
        //send to the output
        printer.println(outputStrings);
      }
      out.close();
    } catch (Exception e) {
      Log.log(Log.ERROR, this, "Error printing CSV file=" + e);
    }
View Full Code Here


        // Create the new cvs file
        csvFile.createNewFile();

        // Create the printer
        CSVPrint csvPrint = null;
        if("UNIX".equals(style)) {
          csvPrint = new CSVPrinter(new OutputStreamWriter(new FileOutputStream(csvFile), "UTF-8"), '#', quoteCharacter, seperator, false, true);
        } else if("EXCEL".equals(style)) {
          csvPrint = new ExcelCSVPrinter(new OutputStreamWriter(new FileOutputStream(csvFile), "UTF-8"), quoteCharacter, seperator, false, true);
        }
        nameCsvPrintMap.put(entry.getParameterMap().get(NAME), csvPrint);

        // If this flag is set add the first
        if (Boolean.valueOf(FilterUtils.getNullSafe(entry.getParameterMap().get(ADD_FIELD_NAMES_TO_FIRST_LINE), "false"))) {

          String[] fieldNames = new String[entry.getFieldList().size()];
          List<Field> fieldList = entry.getFieldList();
          for (int i = 0; i < fieldList.size(); i++) {
            if(fieldList.get(i).getAlias() != null) {
              fieldNames[i] = fieldList.get(i).getAlias();
            } else {
              fieldNames[i] = fieldList.get(i).getName();
            }
           
          }

          // Write field names to CSV file
          csvPrint.println(fieldNames);
        }

      }

      // Set the flag to initialized
View Full Code Here

  @Override
  public void destroy() {
    for (String name : nameCsvPrintMap.keySet()) {
      try {
       
        CSVPrint csvPrint = nameCsvPrintMap.get(name);
        csvPrint.close();
      } catch (IOException e) {
        // DOESN'T MATTER IF IT THROWS AN EXCEPTION
      }
    }
  }
View Full Code Here

      // Only on the first execution
      initWriters();
     
      for(Entry entry : entryList) {
       
        CSVPrint csvPrint = nameCsvPrintMap.get(entry.getParameterMap().get(NAME));
       
        String[] fieldValues = new String[entry.getFieldList().size()];
        List<Field> fieldList = entry.getFieldList();
        for (int i = 0; i < fieldList.size(); i++) {
          fieldValues[i] = FilterUtils.getNullSafe(metadata.get(fieldList.get(i).getName()), "");
        }
       
        // Write field values to CSV file
        csvPrint.println(fieldValues);
      }
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
View Full Code Here

TOP

Related Classes of com.Ostermiller.util.CSVPrint

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.