}
private void renderResult(final PrintWriter pw, final Component component)
throws IOException
{
final JSONWriter jw = new JSONWriter(pw);
try
{
jw.object();
final ScrService scrService = getScrService();
if (scrService == null)
{
jw.key("status"); //$NON-NLS-1$
jw.value(-1);
}
else
{
final Component[] components = scrService.getComponents();
if (components == null || components.length == 0)
{
jw.key("status"); //$NON-NLS-1$
jw.value(0);
}
else
{
// order components by name
sortComponents(components);
final StringBuffer buffer = new StringBuffer();
buffer.append(components.length);
buffer.append(" component"); //$NON-NLS-1$
if (components.length != 1)
{
buffer.append('s');
}
buffer.append(" installed."); //$NON-NLS-1$
jw.key("status"); //$NON-NLS-1$
jw.value(components.length);
// render components
jw.key("data"); //$NON-NLS-1$
jw.array();
if (component != null)
{
component(jw, component, true);
}
else
{
for (int i = 0; i < components.length; i++)
{
component(jw, components[i], false);
}
}
jw.endArray();
}
}
jw.endObject();
}
catch (JSONException je)
{
throw new IOException(je.toString());
}