} else if (BrowserBindingUtils.ROOT_PATH_FRAGMENT.equals(pathFragments[1])) {
callUrl = CallUrl.ROOT;
}
if (callUrl == null) {
throw new CmisNotSupportedException("Unknown operation");
}
String method = request.getMethod();
String repositoryId = pathFragments[0];
boolean methodFound = false;
if (METHOD_GET.equals(method)) {
String selector = getStringParameter(request, PARAM_SELECTOR);
String objectId = getStringParameter(request, PARAM_OBJECT_ID);
// add object id and object base type id to context
prepareContext(context, callUrl, service, repositoryId, objectId, null, request);
// dispatch
if (callUrl == CallUrl.REPOSITORY) {
if (selector == null) {
selector = "";
}
methodFound = repositoryDispatcher.dispatch(selector, method, context, service, repositoryId,
request, response);
} else if (callUrl == CallUrl.ROOT) {
// set default method if necessary
if (selector == null) {
try {
BaseTypeId basetype = BaseTypeId.fromValue((String) context.get(CONTEXT_BASETYPE_ID));
switch (basetype) {
case CMIS_DOCUMENT:
selector = SELECTOR_CONTENT;
break;
case CMIS_FOLDER:
selector = SELECTOR_CHILDREN;
break;
default:
selector = SELECTOR_OBJECT;
break;
}
} catch (Exception e) {
selector = SELECTOR_OBJECT;
}
}
methodFound = rootDispatcher.dispatch(selector, method, context, service, repositoryId, request,
response);
}
} else if (METHOD_POST.equals(method)) {
POSTHttpServletRequestWrapper postRequest = new POSTHttpServletRequestWrapper(request);
String cmisaction = getStringParameter(postRequest, CONTROL_CMISACTION);
String objectId = getStringParameter(postRequest, CONTROL_OBJECT_ID);
String transaction = getStringParameter(postRequest, CONTROL_TRANSACTION);
if (cmisaction == null || cmisaction.length() == 0) {
throw new CmisNotSupportedException("Unknown action");
}
// add object id and object base type id to context
prepareContext(context, callUrl, service, repositoryId, objectId, transaction,
postRequest);
// dispatch
if (callUrl == CallUrl.REPOSITORY) {
methodFound = repositoryDispatcher.dispatch(cmisaction, method, context, service, repositoryId,
postRequest, response);
} else if (callUrl == CallUrl.ROOT) {
methodFound = rootDispatcher.dispatch(cmisaction, method, context, service, repositoryId,
postRequest, response);
}
}
// if the dispatcher couldn't find a matching method, return an
// error message
if (!methodFound) {
throw new CmisNotSupportedException("Unknown operation");
}
} finally {
if (service != null) {
service.close();
}