private void addField(ArrayList<String> record, StringBuilder fieldValue)
      throws CSVParseException {
    record.add(fieldValue == null ? null : fieldValue.toString());

    if (record.size() > maxColumnsPerRow) {
      throw new CSVParseException(
          "Exceeded max number of columns per record : " + maxColumnsPerRow, parser.lineno());
    }
  }
  private void checkRecordExceptions(List<String> line) throws IOException {
    int rowSizeInCharacters = 0;
    if (line != null) {
      for (String value : line) {
        if (value != null) {
          rowSizeInCharacters += value.length();
        }
      }

      if (rowSizeInCharacters > maxRowSizeInCharacters) {
        throw new CSVParseException(
            "Exceeded max length for one record: "
                + rowSizeInCharacters
                + ". Max length for one record should be less than or equal to "
                + maxRowSizeInCharacters,
            parser.lineno());
      }

      fileSizeInCharacters += rowSizeInCharacters;

      if (fileSizeInCharacters > maxFileSizeInCharacters) {
        throw new CSVParseException(
            "Exceeded max file size: "
                + fileSizeInCharacters
                + ". Max file size in characters should be less than or equal to "
                + maxFileSizeInCharacters,
            parser.lineno());
      }

      rowsInFile++;

      if (rowsInFile > maxRowsInFile) {
        throw new CSVParseException(
            "Exceeded number of records : "
                + rowsInFile
                + ". Number of records should be less than or equal to "
                + maxRowsInFile,
            parser.lineno());
      }
    }
  }
  private StringBuilder appendFieldValue(StringBuilder fieldValue, String token)
      throws CSVParseException {
    if (fieldValue == null) {
      fieldValue = new StringBuilder();
    }

    fieldValue.append(token);

    if (token.length() > maxSizeOfIndividualCell) {
      throw new CSVParseException("Exceeded max field size: " + token.length(), parser.lineno());
    }

    return fieldValue;
  }
  private ArrayList<String> nextRecordLocal() throws IOException {
    if (atEOF) {
      return null;
    }

    ArrayList<String> record = new ArrayList<String>(maxFieldCount);

    StringBuilder fieldValue = null;

    while (true) {
      int token = parser.nextToken();

      if (token == StreamTokenizer.TT_EOF) {
        addField(record, fieldValue);
        atEOF = true;
        break;
      }

      if (token == StreamTokenizer.TT_EOL) {
        addField(record, fieldValue);
        break;
      }

      if (token == separator) {
        addField(record, fieldValue);
        fieldValue = null;
        continue;
      }

      if (token == StreamTokenizer.TT_WORD) {
        if (fieldValue != null) {
          throw new CSVParseException("Unknown error", parser.lineno());
        }

        fieldValue = new StringBuilder(parser.sval);
        continue;
      }

      if (token == '"') {
        if (fieldValue != null) {
          throw new CSVParseException(
              "Found unescaped quote. A value with quote should be within a quote",
              parser.lineno());
        }

        while (true) {
          token = parser.nextToken();

          if (token == StreamTokenizer.TT_EOF) {
            atEOF = true;
            throw new CSVParseException(
                "EOF reached before closing an opened quote", parser.lineno());
          }

          if (token == separator) {
            fieldValue = appendFieldValue(fieldValue, token);
            continue;
          }

          if (token == StreamTokenizer.TT_EOL) {
            fieldValue = appendFieldValue(fieldValue, "\n");
            continue;
          }

          if (token == StreamTokenizer.TT_WORD) {
            fieldValue = appendFieldValue(fieldValue, parser.sval);
            continue;
          }

          if (token == '"') {
            int nextToken = parser.nextToken();

            if (nextToken == '"') {
              // escaped quote
              fieldValue = appendFieldValue(fieldValue, nextToken);
              continue;
            }

            if (nextToken == StreamTokenizer.TT_WORD) {
              throw new CSVParseException(
                  "Not expecting more text after end quote at line " + parser.lineno(),
                  parser.lineno());
            } else {
              parser.pushBack();
              break;
            }
          }
        }
      }
    }

    if (record.size() > maxFieldCount) {
      maxFieldCount = record.size();
    }

    return record;
  }
Beispiel #5
0
 private void parse() throws IOException {
   while (true) {
     int token = nextToken();
     if (token == TT_EOF) {
       break;
     }
     if (token == TT_EOL) {
       continue;
     }
     if (token != TT_WORD) {
       throw excToken("Unexpected token:");
     }
     String word = st.sval;
     if (word.equals("name")) {
       name = parseStringEntry(word);
     } else if (word.equals("library")) {
       library = parseLibrary(word);
     } else if (word.equals("description")) {
       parseDescription(word);
     } else if (word.equals("slot")) {
       parseSlotID(word);
     } else if (word.equals("slotListIndex")) {
       parseSlotListIndex(word);
     } else if (word.equals("enabledMechanisms")) {
       parseEnabledMechanisms(word);
     } else if (word.equals("disabledMechanisms")) {
       parseDisabledMechanisms(word);
     } else if (word.equals("attributes")) {
       parseAttributes(word);
     } else if (word.equals("handleStartupErrors")) {
       parseHandleStartupErrors(word);
     } else if (word.endsWith("insertionCheckInterval")) {
       insertionCheckInterval = parseIntegerEntry(word);
       if (insertionCheckInterval < 100) {
         throw excLine(word + " must be at least 100 ms");
       }
     } else if (word.equals("showInfo")) {
       showInfo = parseBooleanEntry(word);
     } else if (word.equals("keyStoreCompatibilityMode")) {
       keyStoreCompatibilityMode = parseBooleanEntry(word);
     } else if (word.equals("explicitCancel")) {
       explicitCancel = parseBooleanEntry(word);
     } else if (word.equals("omitInitialize")) {
       omitInitialize = parseBooleanEntry(word);
     } else if (word.equals("allowSingleThreadedModules")) {
       allowSingleThreadedModules = parseBooleanEntry(word);
     } else if (word.equals("functionList")) {
       functionList = parseStringEntry(word);
     } else if (word.equals("nssUseSecmod")) {
       nssUseSecmod = parseBooleanEntry(word);
     } else if (word.equals("nssLibraryDirectory")) {
       nssLibraryDirectory = parseLibrary(word);
       nssUseSecmod = true;
     } else if (word.equals("nssSecmodDirectory")) {
       nssSecmodDirectory = expand(parseStringEntry(word));
       nssUseSecmod = true;
     } else if (word.equals("nssModule")) {
       nssModule = parseStringEntry(word);
       nssUseSecmod = true;
     } else if (word.equals("nssDbMode")) {
       String mode = parseStringEntry(word);
       if (mode.equals("readWrite")) {
         nssDbMode = Secmod.DbMode.READ_WRITE;
       } else if (mode.equals("readOnly")) {
         nssDbMode = Secmod.DbMode.READ_ONLY;
       } else if (mode.equals("noDb")) {
         nssDbMode = Secmod.DbMode.NO_DB;
       } else {
         throw excToken("nssDbMode must be one of readWrite, readOnly, and noDb:");
       }
       nssUseSecmod = true;
     } else if (word.equals("nssNetscapeDbWorkaround")) {
       nssNetscapeDbWorkaround = parseBooleanEntry(word);
       nssUseSecmod = true;
     } else if (word.equals("nssArgs")) {
       parseNSSArgs(word);
     } else if (word.equals("nssUseSecmodTrust")) {
       nssUseSecmodTrust = parseBooleanEntry(word);
     } else if (word.equals("useEcX963Encoding")) {
       useEcX963Encoding = parseBooleanEntry(word);
     } else if (word.equals("nssOptimizeSpace")) {
       nssOptimizeSpace = parseBooleanEntry(word);
     } else {
       throw new ConfigurationException("Unknown keyword '" + word + "', line " + st.lineno());
     }
     parsedKeywords.add(word);
   }
   reader.close();
   reader = null;
   st = null;
   parsedKeywords = null;
   if (name == null) {
     throw new ConfigurationException("name must be specified");
   }
   if (nssUseSecmod == false) {
     if (library == null) {
       throw new ConfigurationException("library must be specified");
     }
   } else {
     if (library != null) {
       throw new ConfigurationException("library must not be specified in NSS mode");
     }
     if ((slotID != -1) || (slotListIndex != -1)) {
       throw new ConfigurationException(
           "slot and slotListIndex must not be specified in NSS mode");
     }
     if (nssArgs != null) {
       throw new ConfigurationException("nssArgs must not be specified in NSS mode");
     }
     if (nssUseSecmodTrust != false) {
       throw new ConfigurationException(
           "nssUseSecmodTrust is an " + "internal option and must not be specified in NSS mode");
     }
   }
 }
Beispiel #6
0
 private ConfigurationException excLine(String msg) {
   return new ConfigurationException(msg + ", line " + st.lineno());
 }