/** * A very simple example that shows how to create a Dublin Core * description of papers with authors (creators). */ //Import every class and interface by name. import java.io.PrintWriter; import java.io.OutputStream; import java.io.FileOutputStream; //The Dublin Core import com.hp.hpl.mesa.rdf.jena.vocabulary.DC; //Use the memory model implementation import com.hp.hpl.mesa.rdf.jena.mem.ModelMem; //Model package imports import com.hp.hpl.mesa.rdf.jena.model.Model; import com.hp.hpl.mesa.rdf.jena.model.Resource; import com.hp.hpl.mesa.rdf.jena.model.Property; import com.hp.hpl.mesa.rdf.jena.model.Statement; import com.hp.hpl.mesa.rdf.jena.model.StmtIterator; import com.hp.hpl.mesa.rdf.jena.model.RDFNode; import com.hp.hpl.mesa.rdf.jena.model.RDFException; public class DublinCoreEx6{ String subjectUri="http://.../CMCS/Entries/X"; String space=" "; Model model=null; Resource publication=null; public DublinCoreEx6() throws RDFException { //Create a new model model=new ModelMem(); publication=model.createResource(subjectUri); } public void addCreator(String creatorUri) throws RDFException{ publication.addProperty(DC.creator,creatorUri); } public void addTitle(String title) throws RDFException{ publication.addProperty(DC.title,title); } /** * Prints the model out as RDF XML */ public void printRDFXML(OutputStream out) throws RDFException { model.write(new PrintWriter(out),"RDF/XML-ABBREV"); } /** * Prints the model as a set of triples */ public void printTriples() throws RDFException{ StmtIterator iter=model.listStatements(); while (iter.hasNext()){ Statement stmt=iter.next(); Resource subject=stmt.getSubject(); Property predicate=stmt.getPredicate(); RDFNode obj=stmt.getObject(); String thing=subject.toString()+space+predicate+space; if(obj instanceof Resource) { thing+=obj.toString(); } else { thing+=obj.toString(); } System.out.println(thing); } } public static void main(String[] args) throws Exception{ String creatorUri1="http://cgl.indiana.edu/people/GCF"; String creatorUri2="http://cgl.indiana.edu/people/MEP"; DublinCoreEx6 dc=new DublinCoreEx6(); dc.addCreator(creatorUri2); dc.addTitle("H2O"); dc.printRDFXML(new FileOutputStream("junk.out")); } }