// We check the tree to see if the nr of nodes isn't bigger than the allowed nr.
boolean allowDump = true;
int allowedLevel = 0;
final boolean tidy = isTidy(req);
final boolean harray = hasSelector(req, HARRAY);
ResourceTraversor traversor = null;
try {
traversor = new ResourceTraversor(maxRecursionLevels, maximumResults, r, tidy);
allowedLevel = traversor.collectResources();
if ( allowedLevel != -1 ) {
allowDump = false;
}
} catch (final JSONException e) {
reportException(e);
}
try {
// Dump the resource if we can
if (allowDump) {
if (tidy || harray) {
final JSONRenderer.Options opt = renderer.options()
.withIndent(tidy ? INDENT_SPACES : 0)
.withArraysForChildren(harray);
resp.getWriter().write(renderer.prettyPrint(traversor.getJSONObject(), opt));
} else {
// If no rendering options, use the plain toString() method, for
// backwards compatibility. Output might be slightly different
// with prettyPrint and no options
resp.getWriter().write(traversor.getJSONObject().toString());
}
} else {
// We are not allowed to do the dump.
// Send a 300