public DefaultAttributeTableReader(
      final URL source, AttributeMappingParameters mapping, InputStream is) {
    this.source = source;
    this.mapping = mapping;
    this.startLineNumber = mapping.getStartLineNumber();
    this.parser = new AttributeLineParser(mapping);
    this.commentChar = mapping.getCommentChar();

    this.is = is;
  }
  /**
   * DOCUMENT ME!
   *
   * @return DOCUMENT ME!
   */
  public List getColumnNames() {
    List<String> colNamesList = new ArrayList<String>();

    for (String name : mapping.getAttributeNames()) {
      colNamesList.add(name);
    }

    return colNamesList;
  }
  /** For a given Excel row, convert the cells into String. */
  private String[] createElementStringArray(Row row) {
    String[] cells = new String[mapping.getColumnCount()];
    Cell cell = null;

    for (short i = 0; i < mapping.getColumnCount(); i++) {
      cell = row.getCell(i);

      if (cell == null
          || cell.getCellType() == Cell.CELL_TYPE_ERROR
          || (cell.getCellType() == Cell.CELL_TYPE_FORMULA
              && cell.getCachedFormulaResultType() == Cell.CELL_TYPE_ERROR)) {
        cells[i] = null;
      } else {
        cells[i] = formatter.formatCellValue(cell, evaluator);
      }
    }

    return cells;
  }
 public ExcelAttributeSheetReader(
     final Sheet sheet,
     final AttributeMappingParameters mapping,
     final CyServiceRegistrar serviceRegistrar) {
   this.sheet = sheet;
   this.mapping = mapping;
   this.startLineNumber = mapping.getStartLineNumber();
   this.parser = new AttributeLineParser(mapping, serviceRegistrar);
   this.evaluator = sheet.getWorkbook().getCreationHelper().createFormulaEvaluator();
   this.formatter = new DataFormatter();
 }
  /** Read table from the data source. */
  public void readTable(CyTable table) throws IOException {
    // InputStream is = null;

    try {
      BufferedReader bufRd = null;

      if (is == null) {
        is = URLUtil.getInputStream(source);
      }
      try {

        // This data is shared by both the OpenCSV and the old method of reading files.
        int lineCount = 0;
        bufRd =
            new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8").newDecoder()));
        /*
         * Read & extract one line at a time. The line can be Tab delimited,
         */
        final String delimiter = mapping.getDelimiterRegEx();

        // If the delimiter contains a comma, treat the file as a CSV file.
        if (delimiter.contains(TextFileDelimiters.COMMA.toString())
            && mapping.getDelimiters().size() == 1) {
          // Use OpenCSV.. New method...
          CSVReader reader = new CSVReader(bufRd);
          String[] rowData; // Note that rowData is roughly equivalent to "parts" in the old code.
          while ((rowData = reader.readNext()) != null) {
            // If key dos not exists, ignore the line.
            if (lineCount >= startLineNumber && rowData.length >= mapping.getKeyIndex() + 1) {
              try {
                // if(importAll) {
                parser.parseAll(table, rowData);
                // } else
                //	parser.parseEntry(table, parts);
              } catch (Exception ex) {
                logger.warn("Couldn't parse row from OpenCSV: " + lineCount);
              }
              globalCounter++;
            }
            lineCount++;
          }

        } else // Use the "old" method for splitting the lines.
        {
          String line;
          String[] parts = null;
          while ((line = bufRd.readLine()) != null) {
            /*
             * Ignore Empty & Commnet lines.
             */
            if ((commentChar != null) && line.startsWith(commentChar)) {
              // Do nothing
            } else if ((lineCount >= startLineNumber) && (line.trim().length() > 0)) {
              parts = line.split(delimiter);
              // If key dos not exists, ignore the line.
              if (parts.length >= mapping.getKeyIndex() + 1) {
                try {
                  // if(importAll) {
                  parser.parseAll(table, parts);
                  // } else
                  //	parser.parseEntry(table, parts);
                } catch (Exception ex) {
                  logger.warn("Couldn't parse row: " + lineCount);
                }
                globalCounter++;
              }
            }

            lineCount++;
          }
        }
      } finally {
        if (bufRd != null) {
          bufRd.close();
        }
      }
    } finally {
      if (is != null) {
        is.close();
      }
    }
  }
 @Override
 public List<String> getColumnNames() {
   return Arrays.asList(mapping.getAttributeNames());
 }