{
renderer = _htmlRenderer;
}
else if (formatList.size() > 1)
{
throw new RoutingException(
String.format("\"format\" query parameter must be unique, where multiple are specified: %s",
Arrays.toString(formatList.toArray())),
HttpStatus.S_400_BAD_REQUEST.getCode());
}
else
{
renderer = (formatList.contains(DOC_JSON_FORMAT) ? _jsonRenderer : _htmlRenderer);
}
if (renderer == _htmlRenderer)
{
_htmlRenderer.setJsonFormatUri(UriBuilder.fromUri(request.getURI())
.queryParam("format", DOC_JSON_FORMAT)
.build());
}
try
{
if (typeSegment == null || typeSegment.isEmpty())
{
renderer.renderHome(out);
}
else
{
if (DOC_RESOURCE_TYPE.equals(typeSegment))
{
if (objectSegment == null || objectSegment.isEmpty())
{
renderer.renderResourceHome(out);
}
else
{
renderer.renderResource(objectSegment, out);
}
}
else if (DOC_DATA_TYPE.equals(typeSegment))
{
if (objectSegment == null || objectSegment.isEmpty())
{
renderer.renderDataModelHome(out);
}
else
{
renderer.renderDataModel(objectSegment, out);
}
}
else
{
throw createRoutingError(path);
}
}
}
catch (RuntimeException e)
{
if (!renderer.handleException(e, out))
{
throw e;
}
}
}
else
{
throw new RoutingException(HttpStatus.S_405_METHOD_NOT_ALLOWED.getCode());
}
return new RestResponseBuilder().
setStatus(HttpStatus.S_200_OK.getCode()).
setHeader(RestConstants.HEADER_CONTENT_TYPE, renderer.getMIMEType()).