[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Tue Jun 9 18:54:26 UTC 2009


gordonp
Tue Jun  9 14:54:26 EDT 2009
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/extended
In directory dev.open-bio.org:/tmp/cvs-serv19382/src/main/org/biomoby/shared/extended

Modified Files:
	NamespaceParser.java 
Log Message:
Added ability to provide input as a stream instead of as a URL
moby-live/Java/src/main/org/biomoby/shared/extended NamespaceParser.java,1.12,1.13
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/extended/NamespaceParser.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/extended/NamespaceParser.java	2008/07/22 15:49:41	1.12
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/extended/NamespaceParser.java	2009/06/09 18:54:26	1.13
@@ -1,5 +1,6 @@
 package org.biomoby.shared.extended;
 
+import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
@@ -35,6 +36,7 @@
 public class NamespaceParser {
 
 	private URL url = null;
+        private InputStream ins = null;
 
 	/**
 	 * Default constructor - need to set the URL for the RDF document that
@@ -130,6 +132,17 @@
 		return url;
 	}
 
+        /**
+	 * If not null, overrides the URL when reading the definitions (e.g. if you have the RDF as a String, not a URL use this).
+         */
+        public void setInputStream(InputStream is){
+	    ins = is;
+	}
+
+        public InputStream getInputStream(){
+	    return ins;
+        }
+
 	/**
 	 * 
 	 * @return an array of MobyNamespace objects created by parsing the RDF
@@ -139,18 +152,27 @@
 	 *             Namsepace ontology is invalid
 	 */
 	public MobyNamespace[] getMobyNamespacesFromRDF() throws MobyException {
-		// if url is invalid let client know
-		if (this.url == null)
-			throw new MobyException(
-					"Invalid url specified for the location of the RDF document that describes the Namespace ontology: "
-							+ this.url);
+	        InputStream is = null;
+	        if(ins != null){
+		    is = ins;
+	        }
+	        // if url is invalid let client know
+	        else{
+		    if (this.url == null){
+		        throw new MobyException(
+		  			        "Invalid url specified for the location of the "
+						+ "RDF document that describes the Namespace ontology: "
+					        + this.url);
+		    }
+		    is = Utils.getInputStream(getUrl());
+	        }
 
 		// lets start parsing
 		ArrayList<MobyNamespace> list = new ArrayList<MobyNamespace>();
 		// create the model
 		Model model = ModelFactory.createDefaultModel();
 		RDFReader reader = model.getReader();
-		reader.read(model, Utils.getInputStream(getUrl()), null);
+		reader.read(model, is, null);
 		// get all subjects in the document
 		ResIterator iterator = model.listSubjects();
 		while (iterator.hasNext()) {




More information about the MOBY-guts mailing list