[MOBY-guts] biomoby commit
Paul Gordon
gordonp at dev.open-bio.org
Thu Dec 6 17:24:14 UTC 2007
gordonp
Thu Dec 6 12:24:13 EST 2007
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui
In directory dev.open-bio.org:/tmp/cvs-serv25509/src/main/ca/ucalgary/seahawk/gui
Modified Files:
MobyContentPane.java
Log Message:
Added typechecking for maps
moby-live/Java/src/main/ca/ucalgary/seahawk/gui MobyContentPane.java,1.13,1.14
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentPane.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentPane.java 2007/07/28 03:40:18 1.13
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/gui/MobyContentPane.java 2007/12/06 17:24:13 1.14
@@ -56,8 +56,8 @@
protected PrintableJEditorPane editorPane; // does the HTML display
protected MobyServicesGUI servicesGUI;
protected MobyContentGUI contentGUI;
- private Vector history;
- private HashMap historyTabLabels;
+ private Vector<URL> history;
+ private HashMap<URL,String> historyTabLabels;
private int historyIndex = -1;
private int lastClickX = 1;
private int lastClickY = 1;
@@ -95,8 +95,8 @@
scrollPane = new JScrollPane(editorPane);
add(scrollPane);
- history = new Vector();
- historyTabLabels = new HashMap();
+ history = new Vector<URL>();
+ historyTabLabels = new HashMap<URL,String>();
ClassLoader cl = getClass().getClassLoader();
if(cl == null){
@@ -173,24 +173,7 @@
if(!hasXMLSource()){
return null;
}
- return getInputStreamContents(((URL) history.elementAt(historyIndex)).openStream());
- }
-
- /**
- * Convenience method to grab all data from a input stream into a String.
- */
- protected String getInputStreamContents(InputStream resourceStream) throws IOException{
- StringBuffer xml = new StringBuffer();
-
- // Copy data verbatim 1 k at a time
- byte[] dataBuffer = new byte[1024];
- for(int numBytesRead = resourceStream.read(dataBuffer);
- numBytesRead != -1;
- numBytesRead = resourceStream.read(dataBuffer)){
- xml.append(new String(dataBuffer, 0, numBytesRead));
- }
-
- return xml.toString();
+ return HTMLUtils.getURLContents(history.elementAt(historyIndex));
}
public String getHTMLSource(){
@@ -265,10 +248,16 @@
else if((protocol.equals("file") || protocol.equals("jar")) &&
(urlString.lastIndexOf(".xhtml") == urlString.length()-6 ||
urlString.lastIndexOf(".html") == urlString.length()-5 ||
- urlString.lastIndexOf(".htm") == urlString.length()-4)){
+ urlString.lastIndexOf(".htm") == urlString.length()-4) ||
+ urlString.lastIndexOf(".tex") == urlString.length()-4){
editorPane.setContentType("text/html");
isContentsXML = false;
- resultBuffer.append(getInputStreamContents(urlCon.getInputStream()));
+ if(urlString.lastIndexOf(".tex") == urlString.length()-4){
+ resultBuffer.append(TEX2HTML.convert(HTMLUtils.getInputStreamContents(urlCon.getInputStream())));
+ }
+ else{
+ resultBuffer.append(HTMLUtils.getInputStreamContents(urlCon.getInputStream()));
+ }
}
// Maybe RTF?
else if(protocol.equals("file") &&
@@ -278,23 +267,26 @@
// Put the results in the RTF viewer
isContentsXML = false;
editorPane.setContentType("text/rtf");
- resultBuffer.append(getInputStreamContents(urlCon.getInputStream()));
+ resultBuffer.append(HTMLUtils.getInputStreamContents(urlCon.getInputStream()));
}
// If we got here, we are either a file not ending in an XML, HTML, or RTF suffix,
// Or we are a non text/xml content-type Web URL.
// Assume it's plain text, or whatever the JEditorPane can glean from the content-type
// such as a remote HTML or RTF doc, because result buffer will be empty in condition below
else{
+ if(MobySaveDialog.isConvertible(urlCon)){
+ urlCon = MobySaveDialog.convertToDisplayable(urlCon);
+ url = urlCon.getURL();
+ }
//editorPane.setContentType("text/plain");
isContentsXML = false;
//editorPane.setFont(java.awt.Font.getFont("Monospaced"));
editorPane.setContentType("text/html");
- String body = getInputStreamContents(url.openStream());
+ String body = HTMLUtils.getURLContents(url);
if(body.toLowerCase().indexOf("<html") != -1){
resultBuffer = null;
}
else{
- unformatted = true;
resultBuffer = new StringBuffer("<html><body><pre>"+
body.replaceAll("&", "&").replaceAll("<","<")+
"</pre></body></html>");
@@ -341,9 +333,9 @@
// By default the pane will annoyingly scroll to the bottom when new data is loaded.
editorPane.scrollToReference("start");
}
- catch (java.io.IOException ioe) {
- status.setText("Warning: Could not read transformed (HTML) response from MOBY: " + ioe);
- ioe.printStackTrace();
+ catch (Exception e) {
+ status.setText("Warning: Could not read transformed (HTML) response from MOBY, or given panel contents: " + e);
+ e.printStackTrace();
}
if(addToHistory){
@@ -359,7 +351,7 @@
// 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());
+ tabbedPane.setTitleAt(tabbedPane.indexOfComponent(this), historyTabLabels.get(url));
}
}
@@ -375,7 +367,7 @@
if(historyIndex < 0 || historyIndex > history.size()-1){
return null;
}
- return (URL) history.elementAt(historyIndex);
+ return history.elementAt(historyIndex);
}
public boolean canGoBack(){
@@ -388,13 +380,13 @@
public void goForward(){
if(canGoForward()){
- gotoURL((URL) history.elementAt(++historyIndex), false);
+ gotoURL(history.elementAt(++historyIndex), false);
}
}
public void goBackward(){
if(canGoBack()){
- gotoURL((URL) history.elementAt(--historyIndex), false);
+ gotoURL(history.elementAt(--historyIndex), false);
}
}
@@ -709,10 +701,13 @@
// Build a MOBY object using the URL info
// Links have the form moby_xml_url#child_xpath refering to complex objects
// or http://moby/namespace?id=moby_id&string=cdata_value for simple objects and strings
- String docFragID = targetURL.getRef(); // We store the xpath in the anchor part of the URL
+ String docFragID = targetURL
+.getRef(); // We store the xpath in the anchor part of the URL
MobyDataInstance mobyData = null;
// Complex case, load the doc fragment from the MOBY XML source file
+
+
if(docFragID != null && docFragID.length() > 0 && contentGUI.getDocumentBuilder() != null){
mobyData = loadMobyDataFromXPointer(targetURL);
}
More information about the MOBY-guts
mailing list