String format = parameters.getProperty("format");
// If a format is specified, it might still be wrong, so we need
// to check if we have a parser for it. If not, null it out.
if (format != null && !format.isEmpty()) {
Format formatRecord = ImportingManager.formatToRecord.get(format);
if (formatRecord == null || formatRecord.parser == null) {
format = null;
}
}
// If we don't have a format specified, try to guess it.
if (format == null || format.isEmpty()) {
// Use legacy parameters to guess the format.
if ("false".equals(parameters.getProperty("split-into-columns"))) {
format = "text/line-based";
} else if (",".equals(parameters.getProperty("separator")) ||
"\\t".equals(parameters.getProperty("separator"))) {
format = "text/line-based/*sv";
} else {
JSONArray rankedFormats = JSONUtilities.getArray(config, "rankedFormats");
if (rankedFormats != null && rankedFormats.length() > 0) {
format = rankedFormats.getString(0);
}
}
if (format == null || format.isEmpty()) {
// If we have failed in guessing, default to something simple.
format = "text/line-based";
}
}
JSONObject optionObj = null;
String optionsString = request.getParameter("options");
if (optionsString != null && !optionsString.isEmpty()) {
optionObj = ParsingUtilities.evaluateJsonStringToObject(optionsString);
} else {
Format formatRecord = ImportingManager.formatToRecord.get(format);
optionObj = formatRecord.parser.createParserUIInitializationData(
job, ImportingUtilities.getSelectedFileRecords(job), format);
}
adjustLegacyOptions(format, parameters, optionObj);