String oaipmhurl = post.get("urlstartone");
if (oaipmhurl.indexOf('?',0) < 0) oaipmhurl = oaipmhurl + "?verb=ListRecords&metadataPrefix=oai_dc";
DigestURI url = null;
try {
url = new DigestURI(oaipmhurl);
final OAIPMHLoader r = new OAIPMHLoader(sb.loader, url, sb.surrogatesInPath, "oaipmh-one");
final ResumptionToken rt = r.getResumptionToken();
prop.put("import-one", 1);
prop.put("import-one_count", (rt == null) ? "not available" : Integer.toString(rt.getRecordCounter()));
prop.put("import-one_source", r.source());
prop.put("import-one_rt", r.getResumptionToken().toString());
// set next default url
try {
final DigestURI nexturl = (rt == null) ? null : rt.resumptionURL();
if (rt != null) prop.put("defaulturl", (nexturl == null) ? "" : nexturl.toNormalform(true, false));
} catch (final MalformedURLException e) {
prop.put("defaulturl", e.getMessage());
} catch (final IOException e) {
// reached end of resumption
prop.put("defaulturl", e.getMessage());
}
} catch (final MalformedURLException e) {
Log.logException(e);
prop.put("import-one", 2);
prop.put("import-one_error", e.getMessage());
} catch (final IOException e) {
Log.logException(e);
prop.put("import-one", 2);
prop.put("import-one_error", e.getMessage());
}
}
if (post.get("urlstart", "").length() > 0) {
final String oaipmhurl = post.get("urlstart", "");
sb.tables.recordAPICall(post, "IndexImportOAIPMH_p.html", WorkTables.TABLE_API_TYPE_CRAWLER, "OAI-PMH import for " + oaipmhurl);
DigestURI url = null;
try {
url = new DigestURI(oaipmhurl);
final OAIPMHImporter job = new OAIPMHImporter(sb.loader, url);
job.start();
prop.put("status", 1);
prop.put("optiongetlist", 1);
prop.put("iframetype", 1);
} catch (final MalformedURLException e) {
Log.logException(e);
prop.put("status", 2);
prop.put("status_message", e.getMessage());
}
}
if (post.get("loadrows", "").length() > 0) {
// create a time-ordered list of events to execute
final Set<String> sources = new TreeSet<String>();
for (final Map.Entry<String, String> entry: post.entrySet()) {
if (entry.getValue().startsWith("mark_")) {
sources.add(entry.getValue().substring(5));
}
}
prop.put("status", 1);
prop.put("optiongetlist", 1);
prop.put("iframetype", 1);
// prepare the set for random read from it (to protect the servers at the beginning of the list)
final List<String> sourceList = new ArrayList<String>(sources.size());
for (final String oaipmhurl: sources) sourceList.add(oaipmhurl);
final Random r = new Random(System.currentTimeMillis());
// start jobs for the sources
DigestURI url = null;
while (sourceList.size() > 0) {
final String oaipmhurl = sourceList.remove(r.nextInt(sourceList.size()));
try {
url = new DigestURI(oaipmhurl);
final OAIPMHImporter job = new OAIPMHImporter(sb.loader, url);
job.start();
} catch (final MalformedURLException e) {