Search in sources :

Example 1 with PropertyRDFReporter

use of ambit2.rest.property.PropertyRDFReporter 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);
    }
}
Also used : PropertyJSONReporter(ambit2.rest.property.PropertyJSONReporter) Form(org.restlet.data.Form) OutputWriterConvertor(net.idea.restnet.db.convertors.OutputWriterConvertor) StringConvertor(net.idea.restnet.c.StringConvertor) ImageReporter(ambit2.db.reporters.ImageReporter) Dimension(java.awt.Dimension) IQueryRetrieval(net.idea.modbcum.i.IQueryRetrieval) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException) ImageConvertor(ambit2.rest.ImageConvertor) PropertyRDFReporter(ambit2.rest.property.PropertyRDFReporter) ChemicalMediaType(net.idea.restnet.c.ChemicalMediaType) MediaType(org.restlet.data.MediaType) RDFJenaConvertor(ambit2.rest.RDFJenaConvertor) QueryURIReporter(net.idea.restnet.db.QueryURIReporter) Property(ambit2.base.data.Property)

Aggregations

Property (ambit2.base.data.Property)1 ImageReporter (ambit2.db.reporters.ImageReporter)1 ImageConvertor (ambit2.rest.ImageConvertor)1 RDFJenaConvertor (ambit2.rest.RDFJenaConvertor)1 PropertyJSONReporter (ambit2.rest.property.PropertyJSONReporter)1 PropertyRDFReporter (ambit2.rest.property.PropertyRDFReporter)1 Dimension (java.awt.Dimension)1 IQueryRetrieval (net.idea.modbcum.i.IQueryRetrieval)1 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)1 ChemicalMediaType (net.idea.restnet.c.ChemicalMediaType)1 StringConvertor (net.idea.restnet.c.StringConvertor)1 QueryURIReporter (net.idea.restnet.db.QueryURIReporter)1 OutputWriterConvertor (net.idea.restnet.db.convertors.OutputWriterConvertor)1 Form (org.restlet.data.Form)1 MediaType (org.restlet.data.MediaType)1 ResourceException (org.restlet.resource.ResourceException)1