Search in sources :

Example 1 with OntologyPrettyPrintResource

use of org.apache.stanbol.ontologymanager.web.util.OntologyPrettyPrintResource in project stanbol by apache.

the class ScopeResource method managedOntologyShow.

@GET
@Path("/{ontologyId:.+}")
@Produces(TEXT_HTML)
public Response managedOntologyShow(@PathParam("scopeid") String scopeid, @PathParam("ontologyId") String ontologyId, @Context HttpHeaders headers) {
    ResponseBuilder rb;
    scope = onm.getScope(scopeid);
    if (scope == null)
        rb = Response.status(NOT_FOUND);
    else if (ontologyId == null || ontologyId.isEmpty())
        rb = Response.status(BAD_REQUEST);
    else if (!ontologyProvider.hasOntology(OntologyUtils.decode(ontologyId)))
        rb = Response.status(NOT_FOUND);
    else {
        IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/ontology/");
        OWLOntology o = scope.getCustomSpace().getOntology(OntologyUtils.decode(ontologyId), OWLOntology.class, false, prefix);
        if (o == null)
            o = scope.getCoreSpace().getOntology(OntologyUtils.decode(ontologyId), OWLOntology.class, false, prefix);
        if (o == null)
            rb = Response.status(NOT_FOUND);
        else
            try {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                o.getOWLOntologyManager().saveOntology(o, new ManchesterOWLSyntaxOntologyFormat(), out);
                rb = Response.ok(new Viewable("ontology", new OntologyPrettyPrintResource(uriInfo, out, scope)));
            } catch (OWLOntologyStorageException e) {
                throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
            }
    }
    rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
    // addCORSOrigin(servletContext, rb, headers);
    return rb.build();
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) ManchesterOWLSyntaxOntologyFormat(org.coode.owlapi.manchesterowlsyntax.ManchesterOWLSyntaxOntologyFormat) WebApplicationException(javax.ws.rs.WebApplicationException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) Viewable(org.apache.stanbol.commons.web.viewable.Viewable) OntologyPrettyPrintResource(org.apache.stanbol.ontologymanager.web.util.OntologyPrettyPrintResource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) OWLOntologyStorageException(org.semanticweb.owlapi.model.OWLOntologyStorageException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with OntologyPrettyPrintResource

use of org.apache.stanbol.ontologymanager.web.util.OntologyPrettyPrintResource in project stanbol by apache.

the class SessionResource method managedOntologyShow.

@GET
@Path("/{ontologyId:.+}")
@Produces(TEXT_HTML)
public Response managedOntologyShow(@PathParam("ontologyId") String ontologyId, @Context HttpHeaders headers) {
    ResponseBuilder rb;
    if (session == null)
        rb = Response.status(NOT_FOUND);
    else if (ontologyId == null || ontologyId.isEmpty())
        rb = Response.status(BAD_REQUEST);
    else if (!ontologyProvider.hasOntology(OntologyUtils.decode(ontologyId)))
        rb = Response.status(NOT_FOUND);
    else {
        IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/session/");
        OWLOntology o = session.getOntology(OntologyUtils.decode(ontologyId), OWLOntology.class, false, prefix);
        if (o == null)
            rb = Response.status(NOT_FOUND);
        else
            try {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                o.getOWLOntologyManager().saveOntology(o, new ManchesterOWLSyntaxOntologyFormat(), out);
                rb = Response.ok(new Viewable("ontology", new OntologyPrettyPrintResource(uriInfo, out, session)));
            } catch (OWLOntologyStorageException e) {
                throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
            }
    }
    rb.header(HttpHeaders.CONTENT_TYPE, TEXT_HTML + "; charset=utf-8");
    //        addCORSOrigin(servletContext, rb, headers);
    return rb.build();
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) ManchesterOWLSyntaxOntologyFormat(org.coode.owlapi.manchesterowlsyntax.ManchesterOWLSyntaxOntologyFormat) WebApplicationException(javax.ws.rs.WebApplicationException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) Viewable(org.apache.stanbol.commons.web.viewable.Viewable) OntologyPrettyPrintResource(org.apache.stanbol.ontologymanager.web.util.OntologyPrettyPrintResource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) OWLOntologyStorageException(org.semanticweb.owlapi.model.OWLOntologyStorageException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)2 Viewable (org.apache.stanbol.commons.web.viewable.Viewable)2 OntologyPrettyPrintResource (org.apache.stanbol.ontologymanager.web.util.OntologyPrettyPrintResource)2 ManchesterOWLSyntaxOntologyFormat (org.coode.owlapi.manchesterowlsyntax.ManchesterOWLSyntaxOntologyFormat)2 IRI (org.semanticweb.owlapi.model.IRI)2 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)2 OWLOntologyStorageException (org.semanticweb.owlapi.model.OWLOntologyStorageException)2