[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Wed Apr 18 16:04:06 UTC 2007


gordonp
Wed Apr 18 12:04:06 EDT 2007
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui
In directory dev.open-bio.org:/tmp/cvs-serv12518/src/main/ca/ucalgary/seahawk/gui

Modified Files:
	MobyContentPane.java 
Log Message:
Added better binary data support, and only add to history if load successful
moby-live/Java/src/main/ca/ucalgary/seahawk/gui MobyContentPane.java,1.6,1.7
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentPane.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentPane.java	2007/04/03 02:34:08	1.6
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentPane.java	2007/04/18 16:04:06	1.7
@@ -209,17 +209,6 @@
 	    return;
 	}
 	
-	if(addToHistory){
-	    // Are we truncating the history? (i.e. loading a new doc in the middle of the history)
-	    if(historyIndex != history.size()-1){
-		history.setSize(historyIndex+1);
-	    }
-	    history.add(url);
-	    
-	    historyIndex = history.size()-1;
-	    contentGUI.updateHistory(this);
-	}
-
 	try {
 	    // 1000 is initial, unimportant guess as to resulting HTML size
 	    StringBuffer resultBuffer = new StringBuffer(1000); 
@@ -238,17 +227,25 @@
 		// Tell the stylesheet the URL of the moby data (it will create xpointers to it)
 		contentGUI.getTransformer().setParameter(XSL_DOC_SOURCE_PARAM, url.toString());
 		// Do the actual transformation
-		StringWriter stringWriter = new StringWriter(1000);
+		String htmlContents = "[Seahawk Internal Error]";
 		try{
+		    StringWriter stringWriter = new StringWriter(1000);
 		    contentGUI.getTransformer().transform(new StreamSource(url.openStream()),
 							  new StreamResult(stringWriter));
+		    htmlContents = stringWriter.toString();
+		    htmlContents = HTMLUtils.encapsulateBinaryData(url, htmlContents);
 		}
 		catch(TransformerException te){
 		    status.setText("Sorry!  Could not transform the MOBY data into presentation form");
 		    logger.error("Sorry!  Could not transform the MOBY data into presentation form: " + te);
 		    return;
 		}
-		String htmlContents = stringWriter.toString();
+		catch(Exception e){
+		    status.setText("Note: There was an error transforming the MOBY data " +
+				   "into presentation form, it may not be displayed correctly");
+		    logger.error("Note: There was an error transforming the MOBY data " +
+				 "into presentation form, it may not be displayed correctly");
+		}
 		// Looks like tab-formatted text (at least 3 tabs)?
 		if(htmlContents.indexOf('\t') != -1){
 		    htmlContents = htmlContents.replaceAll(">(([^<]*\t){3,}[^<]+)", "><pre>$1</pre>");
@@ -295,6 +292,27 @@
 	    }
 
 	    if(resultBuffer.length() == 0){
+		// Attempt to use MobyClient to convert the url's data into a Moby object
+		// (e.g. if the file to load is an image, or a chromatogram) 
+		try{
+		    MobyContentInstance mobyContents = 
+			MobyUtils.convertURLtoMobyBinaryData(servicesGUI.getMobyClient(), url);
+		    if(mobyContents != null){
+			File mobyRepresentation = File.createTempFile("seahawkBase64BinData", ".xml");
+			mobyRepresentation.deleteOnExit();
+			FileWriter fw = new FileWriter(mobyRepresentation);
+			MobyDataUtils.toXMLDocument(fw, mobyContents);
+			fw.close();
+			// Recursive call with new URL, should be displayed using the MOBY XSLT
+			gotoURL(mobyRepresentation.toURI().toURL(), addToHistory);
+			return;
+		    }
+		} catch(Exception e){
+		    e.printStackTrace();
+		    editorPane.setText("Failure in loading MOBYfied binary data:\n" + e);
+		    logger.error("Failure in loading MOBYfied binary data:\n" + e);
+		}
+		// Shouldn't get here unless either not binary, or the binary data load failed
 		editorPane.setPage(url);
 	    }
 	    else{
@@ -311,6 +329,17 @@
 	    ioe.printStackTrace();
 	}
 
+	if(addToHistory){
+	    // Are we truncating the history? (i.e. loading a new doc in the middle of the history)
+	    if(historyIndex != history.size()-1){
+		history.setSize(historyIndex+1);
+	    }
+	    history.add(url);
+	    
+	    historyIndex = history.size()-1;
+	    contentGUI.updateHistory(this);
+	}
+
 	// This page has had a title associated with it before...reuse it!
 	if(historyTabLabels.containsKey(url)){
 	    tabbedPane.setTitleAt(tabbedPane.indexOfComponent(this), historyTabLabels.get(url).toString());




More information about the MOBY-guts mailing list