package com.galactichorse;

import com.hp.hpl.jena.rdf.model.*;
import org.apache.jena.riot.Lang;

import javax.servlet.http.*;
import java.io.*;

public class Ontology extends HttpServlet {
    private static final String ONTOLOGY_PATH = "WEB-INF/accessibility-ontology.ttl";
    private static final Lang ONTOLOGY_INPUT_LANGUAGE = Lang.TURTLE;
    private static final Lang ONTOLOGY_OUTPUT_LANGUAGE = Lang.JSONLD;

    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
            resp.setContentType(ONTOLOGY_OUTPUT_LANGUAGE.getHeaderString());
            getOntologyModel().write(resp.getOutputStream(), ONTOLOGY_OUTPUT_LANGUAGE.getLabel());
    }

    public static Model getOntologyModel() throws FileNotFoundException {
        File file = new File(ONTOLOGY_PATH);
        InputStream inputStream = new FileInputStream(file);
        Model model = ModelFactory.createOntologyModel();
        model.read(inputStream, null, ONTOLOGY_INPUT_LANGUAGE.getLabel());
        return model;
    }
}

@@ -21,16 +21,59 @@
 horse;%0A%0A
+import com.google.api.server.spi.config.*;%0A
 import c
@@ -150,44 +150,90 @@
 java
-x.servlet.http.*;%0Aimport java.io.*;%0A
+.io.*;%0Aimport java.util.Collection;%0Aimport java.util.Map;%0A%0A@Api(name = %22ontology%22)
 %0Apub
@@ -255,28 +255,8 @@
 ogy 
-extends HttpServlet 
 %7B%0A  
@@ -488,191 +488,248 @@
    @
-Override%0A    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException %7B%0A            resp.setContentType(ONTOLOGY_OUTPUT_LANGUAGE.getHeaderString());%0A    
+ApiMethod(name = %22get%22, httpMethod = ApiMethod.HttpMethod.GET)%0A    public OntologyBean getOntologyJsonld() throws IOException %7B%0A        OntologyBean ob = new OntologyBean();%0A        ByteArrayOutputStream baos = new ByteArrayOutputStream();%0A
     
@@ -761,30 +761,12 @@
 ite(
-resp.getOutputStream()
+baos
 , ON
@@ -797,24 +797,82 @@
 etLabel());%0A
+        ob.setJsonld(baos.toString());%0A        return ob;%0A
     %7D%0A%0A    p
@@ -1209,8 +1209,495 @@
     %7D%0A%7D%0A
+%0Aclass OntologyBean %7B%0A    private String jsonld;%0A    private Map%3CString,Collection%3CLinkBean%3E%3E _links;%0A%0A    public String getJsonld() %7B%0A        return jsonld;%0A    %7D%0A%0A    public void setJsonld(String jsonld) %7B%0A        this.jsonld = jsonld;%0A    %7D%0A%7D%0A%0Aclass LinkBean %7B%0A    private String href;%0A    private Boolean templated;%0A    private String type;%0A    private String deprecation;%0A    private String name;%0A    private String profile;%0A    private String title;%0A    private String hreflang;%0A%7D%0A

prepare link relation