String repositoryId = null;
if (pathFragments.length > 0) {
repositoryId = pathFragments[0];
}
CallContextImpl context = new CallContextImpl(binding, repositoryId,
CallContext.BINDING_ATOMPUB.equals(binding));
// call call context handler
if (callContextHandler != null) {
Map<String, String> callContextMap = callContextHandler.getCallContextMap(request);
if (callContextMap != null) {
for (Map.Entry<String, String> e : callContextMap.entrySet()) {
context.put(e.getKey(), e.getValue());
}
}
}
// servlet context and HTTP servlet request and response
context.put(CallContext.SERVLET_CONTEXT, servletContext);
context.put(CallContext.HTTP_SERVLET_REQUEST, request);
context.put(CallContext.HTTP_SERVLET_RESPONSE, response);
// CMIS version
context.put(CallContext.CMIS_VERSION, cmisVersion);
// content
context.put(CallContext.TEMP_DIR, tempDir);
context.put(CallContext.MEMORY_THRESHOLD, memoryThreshold);
context.put(CallContext.MAX_CONTENT_SIZE, maxContentSize);
context.put(CallContext.ENCRYPT_TEMP_FILE, encrypt);
// decode range
String rangeHeader = request.getHeader("Range");
if (rangeHeader != null) {
rangeHeader = rangeHeader.trim().toLowerCase(Locale.ENGLISH);
if (rangeHeader.length() > 6 && rangeHeader.startsWith("bytes=") && rangeHeader.indexOf(',') == -1
&& rangeHeader.charAt(6) != '-') {
BigInteger offset = null;
BigInteger length = null;
int ds = rangeHeader.indexOf('-');
if (ds > 6) {
try {
String firstBytePosStr = rangeHeader.substring(6, ds);
if (firstBytePosStr.length() > 0) {
offset = new BigInteger(firstBytePosStr);
}
if (!rangeHeader.endsWith("-")) {
String lastBytePosStr = rangeHeader.substring(ds + 1);
if (offset == null) {
length = (new BigInteger(lastBytePosStr)).add(BigInteger.ONE);
} else {
length = (new BigInteger(lastBytePosStr)).subtract(offset).add(BigInteger.ONE);
}
}
if (offset != null) {
context.put(CallContext.OFFSET, offset);
}
if (length != null) {
context.put(CallContext.LENGTH, length);
}
} catch (NumberFormatException e) {
// invalid Range header must be ignored
}
}
}
}
// get locale
String acceptLanguage = request.getHeader("Accept-Language");
if (acceptLanguage != null) {
String[] locale = acceptLanguage.split("-");
context.put(CallContext.LOCALE_ISO639_LANGUAGE, locale[0].trim());
if (locale.length > 1) {
int x = locale[1].indexOf(',');
if (x == -1) {
context.put(CallContext.LOCALE_ISO3166_COUNTRY, locale[1].trim());
} else {
context.put(CallContext.LOCALE_ISO3166_COUNTRY, locale[1].substring(0, x).trim());
}
}
}
return context;