use of ambit2.rest.property.PropertyJSONReporter in project ambit-mirror by ideaconsult.
the class BundlePropertyResource method createConvertor.
@Override
public IProcessor<Q, Representation> createConvertor(Variant variant) throws AmbitException, ResourceException {
/* workaround for clients not being able to set accept headers */
Form acceptform = getResourceRef(getRequest()).getQueryAsForm();
Dimension d = new Dimension(250, 250);
try {
d.width = Integer.parseInt(acceptform.getFirstValue("w").toString());
} catch (Exception x) {
}
try {
d.height = Integer.parseInt(acceptform.getFirstValue("h").toString());
} catch (Exception x) {
}
String media = acceptform.getFirstValue("accept-header");
if (media != null)
variant.setMediaType(new MediaType(media));
String filenamePrefix = getRequest().getResourceRef().getPath();
if (variant.getMediaType().equals(MediaType.TEXT_URI_LIST)) {
QueryURIReporter r = (QueryURIReporter) getURIReporter(getRequest());
return new StringConvertor(r, MediaType.TEXT_URI_LIST, filenamePrefix);
} else if (variant.getMediaType().equals(MediaType.IMAGE_PNG)) {
return new ImageConvertor(new ImageReporter(variant.getMediaType().getMainType(), variant.getMediaType().getSubType(), d), variant.getMediaType());
} else if (variant.getMediaType().equals(MediaType.APPLICATION_JAVASCRIPT)) {
String jsonpcallback = getParams().getFirstValue("jsonp");
if (jsonpcallback == null)
jsonpcallback = getParams().getFirstValue("callback");
return new OutputWriterConvertor(new PropertyJSONReporter(getRequest(), jsonpcallback), MediaType.APPLICATION_JAVASCRIPT);
} else if (variant.getMediaType().equals(MediaType.APPLICATION_RDF_XML) || variant.getMediaType().equals(MediaType.APPLICATION_RDF_TURTLE) || variant.getMediaType().equals(MediaType.TEXT_RDF_N3) || variant.getMediaType().equals(MediaType.TEXT_RDF_NTRIPLES) || variant.getMediaType().equals(ChemicalMediaType.APPLICATION_JSONLD)) {
RDFJenaConvertor convertor = new RDFJenaConvertor<Property, IQueryRetrieval<Property>>(new PropertyRDFReporter<IQueryRetrieval<Property>>(getRequest(), variant.getMediaType()), variant.getMediaType(), filenamePrefix);
return convertor;
} else {
// (variant.getMediaType().equals(MediaType.APPLICATION_JSON)) {
return new OutputWriterConvertor(new PropertyJSONReporter(getRequest()), MediaType.APPLICATION_JSON);
}
}
use of ambit2.rest.property.PropertyJSONReporter in project ambit-mirror by ideaconsult.
the class FilteredIterator method toJSON.
public static String toJSON(Object[][] algorithms) {
StringBuilder b = new StringBuilder();
String[] headers = _headers.split("\t");
b.append("[");
String s1 = "";
for (Object[] oo : algorithms) {
int cols = 0;
b.append(s1);
b.append("{");
s1 = ",";
String s2 = "";
for (int c = 0; c < oo.length; c++) {
Object col = oo[c];
cols++;
b.append(s2);
s2 = ",";
b.append(JSONUtils.jsonQuote(headers[c]));
b.append(":");
if (col == null) {
b.append("null");
} else if ("inputparam".equals(headers[c])) {
Object[] a = (Object[]) col;
b.append("{");
PropertyJSONReporter pr = new PropertyJSONReporter(null);
StringWriter w = new StringWriter();
try {
pr.setOutput(w);
for (Object subitem : a) if (subitem instanceof Property)
pr.processItem((Property) subitem);
b.append(w);
} catch (Exception x) {
Logger.getGlobal().log(Level.SEVERE, x.getMessage(), x);
}
b.append("}");
} else if (col.getClass().isArray()) {
Object[] a = (Object[]) col;
String d = "[";
for (Object subitem : a) {
b.append(d);
b.append(JSONUtils.jsonQuote(subitem.toString()));
d = ",";
}
b.append("]");
} else
b.append(JSONUtils.jsonQuote(col.toString()));
}
b.append("}\n");
}
b.append("]");
return b.toString();
}
Aggregations