[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Fri Dec 15 04:40:36 UTC 2006


gordonp
Thu Dec 14 23:40:36 EST 2006
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui
In directory dev.open-bio.org:/tmp/cvs-serv17144/src/main/ca/ucalgary/seahawk/gui

Modified Files:
	FileAndTextTransferHandler.java 
Log Message:
Added better support for windows URL links
moby-live/Java/src/main/ca/ucalgary/seahawk/gui FileAndTextTransferHandler.java,1.1,1.2
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/FileAndTextTransferHandler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/FileAndTextTransferHandler.java	2006/12/14 22:20:10	1.1
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/FileAndTextTransferHandler.java	2006/12/15 04:40:36	1.2
@@ -46,7 +46,36 @@
             if (hasFileFlavor(t.getTransferDataFlavors())) {
                 // Load any dragged file as a URL
                 for (File file: (java.util.List<File>) t.getTransferData(DataFlavor.javaFileListFlavor)) {
-                    gui.loadPaneFromURL(file.toURI().toURL(), true);
+		    String fileString = file.toURI().toURL().toString().toLowerCase();
+
+		    // Windows Web shortcut?
+		    URL u = null;
+		    if(fileString.lastIndexOf(".url") == fileString.length()-4){
+			LineNumberReader in = new LineNumberReader(
+						new InputStreamReader(file.toURI().toURL().openStream()));
+			for(String line = in.readLine(); line != null; line = in.readLine()){
+			    int urlIndex = line.indexOf("URL=");
+			    if(line.indexOf("URL=") == 0){
+				try{
+				    u = new URL(line.substring(4));
+				} catch(MalformedURLException murle){
+				    System.err.println("Could not format " +line);
+				    murle.printStackTrace();
+				// Not a URL, but really it should have been.
+				// oh well, move on to normal file loading...
+				}
+				break;  // done with this file as a URL, no need to execute other loadPaneFromURL
+			    }
+			}
+		    }
+		    // Was it a shortcut file after all?
+		    if(u != null){
+			gui.loadPaneFromURL(u, true);
+		    }
+		    // Any other type of file is loaded as-is
+		    else{
+			gui.loadPaneFromURL(file.toURI().toURL(), true);
+		    }
                 }
                 return true;
             } else if (hasTextFlavor(t.getTransferDataFlavors())) {
@@ -61,10 +90,24 @@
 		// Some readers put funny nulls before each char (8->16 bit char encoding goof)
 		String text = textBuffer.toString().replaceAll("\00", "");  
 
+		// Is it an address bar icon dragged from firefox?  Strip the surrounding html
+		String linktext = null;
+		if(text.indexOf("<html><a href=\"") == 0 && text.indexOf("</a></html>") == text.length()-11){
+		    linktext = text.substring(15, text.indexOf("\"",15));
+		}
+		else if(text.indexOf("<a href=\"") == 0 && text.indexOf("</a>") == text.length()-4){ //unix
+		    linktext = text.substring(9, text.indexOf("\"",9));
+		}
+		else if(text.indexOf("<!--StartFragment--><a href=\"") != -1 && // windows
+		   text.indexOf("</a><!--EndFragment-->") != -1){
+		    int startHref = text.indexOf("<!--StartFragment--><a href=\"");
+		    linktext = text.substring(startHref+29, text.indexOf("\"",startHref+29));
+		}
+
                 // First see if it's a URL
                 URL u = null;
                 try{
-                   u = new URL(text);
+                   u = new URL(linktext == null ? text : linktext);
                 } catch(MalformedURLException murle){
                    // Not a URL, oh well, move on to string handling...
                 }
@@ -80,8 +123,11 @@
 		   text.indexOf("id=\"") != -1){
 		    String xmltext = text;
 		    // See if the xml needs unescaping (e.g. if preformatted HTML dropped from Firefox or Thunderbird)
-		    if(xmltext.indexOf("<pre") < 2){
-			xmltext = xmltext.replaceFirst("<pre.*?>((?:.*|\n)*)</pre>", "$1");
+		    int preStart = xmltext.indexOf("<pre");
+		    if(preStart == 0 ||  //unix
+		       xmltext.indexOf("--StartFragment--") != -1){ //windows
+			xmltext = xmltext.substring(preStart, xmltext.indexOf("</pre")); 
+			xmltext = xmltext.substring(xmltext.indexOf(">")+1);			
 			xmltext = xmltext.replaceAll("&gt;", ">");
 			xmltext = xmltext.replaceAll("&lt;", "<");
 			xmltext = xmltext.replaceAll("&amp;", "&");
@@ -113,7 +159,6 @@
 			    content.parseDataGroup(data);
 			}
 			else{
-			    System.err.println("Using object creator for "+data.getLocalName());
 			    // Any other data can be processed by the base object class 
 			    content = new MobyContentInstance(MobyDataObject.createInstanceFromDOM(data), "Drag 'n' Drop data");
 			}




More information about the MOBY-guts mailing list