use of org.apache.stanbol.commons.web.viewable.Viewable in project stanbol by apache.
the class ReferencedSiteRootResource method getHtmlInfo.
@GET
@Produces(value = MediaType.TEXT_HTML)
public Response getHtmlInfo(@PathParam(value = "site") String siteId, @Context HttpHeaders headers) {
ResponseBuilder rb = Response.ok(new Viewable("index", new SiteResultData(getSite(siteId))));
rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
//addCORSOrigin(servletContext, rb, headers);
return rb.build();
}
use of org.apache.stanbol.commons.web.viewable.Viewable in project stanbol by apache.
the class EntityhubRootResource method getSymbol.
@GET
@Path("entity")
@Produces({ APPLICATION_JSON, RDF_XML, N3, TURTLE, X_TURTLE, RDF_JSON, N_TRIPLE, TEXT_HTML })
public Response getSymbol(@QueryParam("id") String symbolId, @Context HttpHeaders headers) throws WebApplicationException {
log.info("GET /entity Request");
log.info(" > id: " + symbolId);
log.info(" > accept: " + headers.getAcceptableMediaTypes());
MediaType acceptedMediaType = getAcceptableMediaType(headers, ENTITY_SUPPORTED_MEDIA_TYPE_INCL_HTML, APPLICATION_JSON_TYPE);
if (acceptedMediaType.isCompatible(TEXT_HTML_TYPE) && symbolId == null) {
//return HTML docu
ResponseBuilder rb = Response.ok(new Viewable("entity", this));
rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
//addCORSOrigin(servletContext, rb, headers);
return rb.build();
}
if (symbolId == null || symbolId.isEmpty()) {
// TODO: how to parse an error message
throw new WebApplicationException(BAD_REQUEST);
}
//Entityhub entityhub = ContextHelper.getServiceFromContext(Entityhub.class, servletContext);
Entity entity;
try {
entity = entityhub.getEntity(symbolId);
} catch (EntityhubException e) {
throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
}
if (entity == null) {
throw new WebApplicationException(NOT_FOUND);
} else {
ResponseBuilder rb = Response.ok(entity);
rb.header(HttpHeaders.CONTENT_TYPE, acceptedMediaType + "; charset=utf-8");
//addCORSOrigin(servletContext, rb, headers);
return rb.build();
}
}
use of org.apache.stanbol.commons.web.viewable.Viewable in project stanbol by apache.
the class EntityhubRootResource method lookupSymbol.
@GET
@Path("lookup")
@Produces({ APPLICATION_JSON, RDF_XML, N3, TURTLE, X_TURTLE, RDF_JSON, N_TRIPLE, TEXT_HTML })
public Response lookupSymbol(@QueryParam("id") String reference, @QueryParam("create") boolean create, @Context HttpHeaders headers) throws WebApplicationException {
log.info("GET /lookup Request");
log.info(" > id: " + reference);
log.info(" > create : " + create);
log.info(" > accept: " + headers.getAcceptableMediaTypes());
MediaType acceptedMediaType = getAcceptableMediaType(headers, ENTITY_SUPPORTED_MEDIA_TYPE_INCL_HTML, APPLICATION_JSON_TYPE);
if (acceptedMediaType.isCompatible(TEXT_HTML_TYPE) && reference == null) {
//return docu
ResponseBuilder rb = Response.ok(new Viewable("lookup", this));
rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
//addCORSOrigin(servletContext, rb, headers);
return rb.build();
} else {
if (reference == null || reference.isEmpty()) {
// TODO: how to parse an error message
throw new WebApplicationException(BAD_REQUEST);
}
Entity entity;
try {
entity = entityhub.lookupLocalEntity(reference, create);
} catch (EntityhubException e) {
throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
}
if (entity == null) {
return Response.status(Status.NOT_FOUND).entity("No symbol found for '" + reference + "'.").header(HttpHeaders.ACCEPT, acceptedMediaType).build();
} else {
ResponseBuilder rb = Response.ok(entity);
rb.header(HttpHeaders.CONTENT_TYPE, acceptedMediaType + "; charset=utf-8");
//addCORSOrigin(servletContext, rb, headers);
return rb.build();
}
}
}
Aggregations