[MOBY-guts] biomoby commit
Paul Gordon
gordonp at dev.open-bio.org
Wed Apr 18 15:55:18 UTC 2007
gordonp
Wed Apr 18 11:55:18 EDT 2007
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/util
In directory dev.open-bio.org:/tmp/cvs-serv12197/src/main/ca/ucalgary/seahawk/util
Modified Files:
MobyUtils.java
Log Message:
Added binary data support, and create GlobalKeyword only if data is not also a sequence
moby-live/Java/src/main/ca/ucalgary/seahawk/util MobyUtils.java,1.5,1.6
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/util/MobyUtils.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/util/MobyUtils.java 2007/02/08 16:59:58 1.5
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/util/MobyUtils.java 2007/04/18 15:55:18 1.6
@@ -2,17 +2,21 @@
import ca.ucalgary.seahawk.gui.MobyContentGUI;
import ca.ucalgary.seahawk.gui.MobyServicesGUI;
+import ca.ucalgary.seahawk.services.MobyClient;
import org.biomoby.shared.data.*;
import org.biomoby.shared.MobyDataType;
import org.biomoby.shared.MobyNamespace;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.net.URL;
import java.util.Vector;
import javax.swing.JLabel;
/**
* Contains utility methods for Moby Object creation from unstructured data, and for
- * creating the Seahawk GUI.
+ * creating the Seahawk GUI.
*/
public class MobyUtils{
@@ -21,6 +25,41 @@
private static MobyContentGUI mobyContentGUI = null;
private static MobyServicesGUI mobyServicesGUI = null;
+ /**
+ * The purpose of this method is to create a MOBY document to encapsulate
+ * a binary data object stored at the given URL. If the data does
+ * not represent a single binary MOBY object, the method returns null.
+ * If the provided client or URL is null, null will be returned too.
+ */
+ public static MobyContentInstance convertURLtoMobyBinaryData(MobyClient client, URL url)throws Exception{
+ if(url == null || client == null){
+ return null;
+ }
+
+ ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+ InputStream is = url.openStream();
+
+ // Slurp up the file as bytes
+ byte[] buffer = new byte[4096];
+ for(int bytesRead = is.read(buffer); bytesRead != -1; bytesRead = is.read(buffer)){
+ bytes.write(buffer, 0, bytesRead);
+ }
+
+ // Find MOBY Objects in it
+ MobyDataObject[] foundObjects = client.getMobyObjects(bytes.toByteArray(),
+ MobyDataType.getDataType(MobyDataBytes.BASE64_DATATYPE));
+ // Did we unambiguously find one binary object?
+ if(foundObjects != null && foundObjects.length == 1){
+ MobyContentInstance mci = new MobyContentInstance();
+ String[] dataName = url.getPath().split("/");
+ MobyDataJob job = new MobyDataJob();
+ job.put(dataName[dataName.length-1], foundObjects[0]);
+ mci.put(dataName[dataName.length-1], job); // name the data by the last part of the URL path
+ return mci;
+ }
+ return null;
+ }
+
public static MobyDataInstance[] convertStringToObjects(String data, boolean reverseSelected){
if(data == null){
return new MobyDataInstance[0];
@@ -39,14 +78,6 @@
strObject.setPrimaryNamespace(new MobyNamespace("seahawk"));
objects.add(strObject);
- // If it's a single word, give keyword options
- if(data.trim().matches("^[A-Za-z0-9_-]{3,}$")){
- objects.add(new MobyDataComposite("Global_Keyword",
- "dummy_name",
- "seahawk",
- data.trim()));
- }
-
// See if it's sequence
MobyDataComposite mdc = createMobySequence(data, "user-selection");
if(mdc != null){
@@ -63,6 +94,16 @@
mdc.setName(objectName);
objects.add(mdc);
}
+ // If it's a single word, give keyword options
+ else{
+ if(data.trim().matches("^[A-Za-z0-9_-]{3,35}$")){
+ objects.add(new MobyDataComposite("Global_Keyword",
+ "dummy_name",
+ "seahawk",
+ data.trim()));
+ }
+ }
+
return (MobyDataInstance[]) objects.toArray(new MobyDataInstance[objects.size()]);
}
More information about the MOBY-guts
mailing list