Transformer serverTransformer)
throws OAIInternalServerError, TransformerException {
if (debug) System.out.println("ListRecords.construct: entered");
Properties properties = (Properties)context.get("OAIHandler.properties");
AbstractCatalog abstractCatalog = (AbstractCatalog)context.get("OAIHandler.catalog");
boolean xmlEncodeSetSpec = "true".equalsIgnoreCase((String)properties.getProperty("OAIHandler.xmlEncodeSetSpec"));
boolean urlEncodeSetSpec = !"false".equalsIgnoreCase((String)properties.getProperty("OAIHandler.urlEncodeSetSpec"));
String baseURL = (String)properties.getProperty("OAIHandler.baseURL");
if (baseURL == null) {
try {
baseURL = request.getRequestURL().toString();
} catch (java.lang.NoSuchMethodError f) {
baseURL = HttpUtils.getRequestURL(request).toString();
}
}
StringBuffer sb = new StringBuffer();
String oldResumptionToken = request.getParameter("resumptionToken");
String metadataPrefix = request.getParameter("metadataPrefix");
if (metadataPrefix != null && metadataPrefix.length() == 0)
metadataPrefix = null;
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
String styleSheet = properties.getProperty("OAIHandler.styleSheet");
if (styleSheet != null) {
sb.append("<?xml-stylesheet type=\"text/xsl\" href=\"");
sb.append(styleSheet);
sb.append("\"?>");
}
sb.append("<OAI-PMH xmlns=\"http://www.openarchives.org/OAI/2.0/\"");
sb.append(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
String extraXmlns = properties.getProperty("OAIHandler.extraXmlns");
if (extraXmlns != null)
sb.append(" ").append(extraXmlns);
sb.append(" xsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/");
sb.append(" http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd\">");
sb.append("<responseDate>");
sb.append(createResponseDate(new Date()));
sb.append("</responseDate>");
// sb.append("<requestURL>");
// sb.append(getRequestURL(request));
// sb.append("</requestURL>");
if (!abstractCatalog.isHarvestable()) {
sb.append("<request verb=\"ListRecords\">");
sb.append(baseURL);
sb.append("</request>");
sb.append("<error code=\"badArgument\">Database is unavailable for harvesting</error>");
} else {
// if (debug) {
// System.gc();
// System.gc();
// Runtime rt = Runtime.getRuntime();
// long freeMemoryK = rt.freeMemory() / 1024;
// long totalMemoryK = rt.totalMemory() / 1024;
// System.out.print("ListRecords.construct: " + oldResumptionToken);
// System.out.print(" freeMemory=" + freeMemoryK / 1024.0 + "M");
// System.out.print(" of " + totalMemoryK / 1024.0 + "M ");
// System.out.println("(" + (100 * freeMemoryK) / totalMemoryK + "%)");
// }
Map listRecordsMap = null;
ArrayList validParamNames = null;
ArrayList requiredParamNames = null;
if (oldResumptionToken == null) {
validParamNames = validParamNames1;
requiredParamNames = requiredParamNames1;
String from = request.getParameter("from");
String until = request.getParameter("until");
try {
if (from != null && from.length() > 0 && from.length() < 10) {
throw new BadArgumentException();
}
if (until != null && until.length() > 0 && until.length() < 10) {
throw new BadArgumentException();
}
if (from != null && until != null && from.length() != until.length()) {
throw new BadArgumentException();
}
if (from == null || from.length() == 0) {
from = "0001-01-01";
}
if (until == null || until.length() == 0) {
until = "9999-12-31";
}
from = abstractCatalog.toFinestFrom(from);
until = abstractCatalog.toFinestUntil(until);
if (from.compareTo(until) > 0)
throw new BadArgumentException();
String set = request.getParameter("set");
if (set != null) {
if (set.length() == 0) set = null;
else if (urlEncodeSetSpec) set = set.replace(' ', '+');
}
Crosswalks crosswalks = abstractCatalog.getCrosswalks();
if (metadataPrefix == null) {
throw new BadArgumentException();
}
if (!crosswalks.containsValue(metadataPrefix)) {
throw new CannotDisseminateFormatException(metadataPrefix);
} else {
listRecordsMap = abstractCatalog.listRecords(from, until, set,
metadataPrefix);
}
} catch (NoItemsMatchException e) {
sb.append(getRequestElement(request, validParamNames, baseURL, xmlEncodeSetSpec));
sb.append(e.getMessage());
} catch (BadArgumentException e) {
sb.append("<request verb=\"ListRecords\">");
sb.append(baseURL);
sb.append("</request>");
sb.append(e.getMessage());
// } catch (BadGranularityException e) {
// sb.append(getRequestElement(request));
// sb.append(e.getMessage());
} catch (CannotDisseminateFormatException e) {
sb.append(getRequestElement(request, validParamNames, baseURL, xmlEncodeSetSpec));
sb.append(e.getMessage());
} catch (NoSetHierarchyException e) {
sb.append(getRequestElement(request, validParamNames, baseURL, xmlEncodeSetSpec));
sb.append(e.getMessage());
}
} else {
validParamNames = validParamNames2;
requiredParamNames = requiredParamNames2;
if (hasBadArguments(request, requiredParamNames.iterator(), validParamNames)) {
sb.append(getRequestElement(request, validParamNames, baseURL, xmlEncodeSetSpec));
sb.append(new BadArgumentException().getMessage());
} else {
try {
listRecordsMap = abstractCatalog.listRecords(oldResumptionToken);
} catch (BadResumptionTokenException e) {
sb.append(getRequestElement(request, validParamNames, baseURL, xmlEncodeSetSpec));
sb.append(e.getMessage());
}
}