package com.galactichorse;

import com.google.api.server.spi.config.Api;
import com.google.api.server.spi.config.ApiMethod;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;

@Api(name = "ontology")
public class Ontology {
    @ApiMethod(name = "get", httpMethod = ApiMethod.HttpMethod.GET)
    public Collection<String> get() throws Exception {
        File f = new File("WEB-INF/accessibility-ontology.ttl");
        InputStream is = new FileInputStream(f);
        Model model = ModelFactory.createDefaultModel();
        Collection<String> c = new ArrayList<String>();
        model.read(is, null, "TURTLE");
        c.add(model.toString());
        return c;
    }
}

@@ -154,60 +154,9 @@
 del.
-Model;%0Aimport com.hp.hpl.jena.rdf.model.ModelFactory
+*
 ;%0A%0Ai
@@ -291,16 +291,38 @@
 lection;
+%0Aimport java.util.Map;
 %0A%0A@Api(n
@@ -645,15 +645,16 @@
 eate
-Default
+Ontology
 Mode
@@ -754,24 +754,25 @@
 RTLE%22);%0A
+%0A
         
 c.add(mo
@@ -767,49 +767,1350 @@
     
-c.add(model.toString());%0A        return c
+// list the statements in the Model%0A        StmtIterator iter = model.listStatements();%0A%0A        // print out the predicate, subject and object of each statement%0A        while (iter.hasNext()) %7B%0A            Statement stmt = iter.nextStatement();  // get next statement%0A            Resource subject = stmt.getSubject();     // get the subject%0A            Property predicate = stmt.getPredicate();   // get the predicate%0A            RDFNode object = stmt.getObject();      // get the object%0A%0A            c.add(subject.toString());%0A            c.add(%22 %22 + predicate.toString() + %22 %22);%0A            if (object instanceof Resource) %7B%0A                c.add(object.toString());%0A            %7D else %7B%0A                // object is a literal%0A                c.add(%22 %5C%22%22 + object.toString() + %22%5C%22%22);%0A            %7D%0A        %7D%0A%0A        return c;%0A    %7D%0A%7D%0A%0Aclass ElementBean %7B%0A    private Collection%3CElementBean%3E elements;%0A    private Map%3CString, Object%3E subCategories;%0A%0A    public Collection%3CElementBean%3E getElements() %7B%0A        return elements;%0A    %7D%0A%0A    public void setElements(Collection%3CElementBean%3E elements) %7B%0A        this.elements = elements;%0A    %7D%0A%0A    public Map%3CString, Object%3E getSubCategories() %7B%0A        return subCategories;%0A    %7D%0A%0A    public void setSubCategories(Map%3CString, Object%3E subCategories) %7B%0A        this.subCategories = subCategories
 ;%0A  

test model iterator