Author: noelr
Date: 2009-08-12 10:18:03 -0700 (Wed, 12 Aug 2009)
New Revision: 17792
Modified:
cytoscape/trunk/src/cytoscape/util/BioDataServerUtil.java
cytoscape/trunk/src/cytoscape/visual/CalculatorCatalogFactory.java
cytoscape/trunk/tests/cytoscape/data/ontology/readers/DBCrossReferenceReaderTest.java
Log:
Second batch of fixes for Bug 1988
These are the files that required non-trivial alteration
Also fixed some unsafe string comparisons using == instead of equals()
Modified: cytoscape/trunk/src/cytoscape/util/BioDataServerUtil.java
===================================================================
--- cytoscape/trunk/src/cytoscape/util/BioDataServerUtil.java 2009-08-12
16:52:17 UTC (rev 17791)
+++ cytoscape/trunk/src/cytoscape/util/BioDataServerUtil.java 2009-08-12
17:18:03 UTC (rev 17792)
@@ -83,40 +83,39 @@
String sp = null;
String curLine = null;
- while (null != (curLine = gaRd.readLine())) {
- curLine.trim();
+ try {
+ while ((sp == null) && (null != (curLine = gaRd.readLine()))) {
+ curLine.trim();
- // Skip comment
- if (curLine.startsWith("!")) {
- // do nothing
- // logger.info("Comment: " + curLine);
- } else {
- StringTokenizer st = new
StringTokenizer(curLine, "\t");
+ // Skip comment
+ if (curLine.startsWith("!")) {
+ // do nothing
+ // logger.info("Comment: " + curLine);
+ } else {
+ StringTokenizer st = new StringTokenizer(curLine, "\t");
- while (st.hasMoreTokens()) {
- String curToken = st.nextToken();
+ while ((sp == null) && (st.hasMoreTokens())) {
+ String curToken = st.nextToken();
- if (curToken.startsWith("taxon") ||
curToken.startsWith("Taxon")) {
- st = new
StringTokenizer(curToken, ":");
- st.nextToken();
- curToken = st.nextToken();
- st = new
StringTokenizer(curToken, "|");
- curToken = st.nextToken();
- // logger.info("Taxon ID found:
" + curToken);
- sp = curToken;
- sp = taxIdToName(sp, taxRd);
- taxRd.close();
- gaRd.close();
+ if (curToken.startsWith("taxon") ||
curToken.startsWith("Taxon")) {
+ st = new StringTokenizer(curToken, ":");
+ st.nextToken();
+ curToken = st.nextToken();
+ st = new StringTokenizer(curToken, "|");
+ curToken = st.nextToken();
+ // logger.info("Taxon ID found: " + curToken);
+ sp = curToken;
+ sp = taxIdToName(sp, taxRd);
+ }
+ }
+ }
+ }
+ }
+ finally {
+ taxRd.close();
+ gaRd.close();
+ }
- return sp;
- }
- }
- }
- }
-
- taxRd.close();
- gaRd.close();
-
return sp;
}
@@ -278,25 +277,26 @@
// and because pages may be cached:
htmlPageReader = new BufferedReader(new
InputStreamReader(URLUtil.getBasicInputStream(taxonURL)));
- while ((curLine = htmlPageReader.readLine()) != null) {
- curLine.trim();
+ try {
+ while ((txName == null) && ((curLine =
htmlPageReader.readLine()) != null)) {
+ curLine.trim();
- // logger.info("HTML:" + curLine);
- if (curLine.startsWith("<title>Taxonomy")) {
- logger.info("HTML:" + curLine);
+ // logger.info("HTML:" + curLine);
+ if (curLine.startsWith("<title>Taxonomy")) {
+ logger.info("HTML:" + curLine);
- StringTokenizer st = new
StringTokenizer(curLine, "(");
- st.nextToken();
- curLine = st.nextToken();
- st = new StringTokenizer(curLine, ")");
- txName = st.nextToken().trim();
- logger.info("Fetch result: NCBI code "
+ id + " is " + txName);
-
- return txName;
- }
- }
-
- htmlPageReader.close();
+ StringTokenizer st = new StringTokenizer(curLine, "(");
+ st.nextToken();
+ curLine = st.nextToken();
+ st = new StringTokenizer(curLine, ")");
+ txName = st.nextToken().trim();
+ logger.info("Fetch result: NCBI code " + id + " is " +
txName);
+ }
+ }
+ }
+ finally {
+ htmlPageReader.close();
+ }
} catch (IOException e) {
logger.error("Unable to get taxonomy "+id+" from NCBI:
"+e.getMessage());
}
Modified: cytoscape/trunk/src/cytoscape/visual/CalculatorCatalogFactory.java
===================================================================
--- cytoscape/trunk/src/cytoscape/visual/CalculatorCatalogFactory.java
2009-08-12 16:52:17 UTC (rev 17791)
+++ cytoscape/trunk/src/cytoscape/visual/CalculatorCatalogFactory.java
2009-08-12 17:18:03 UTC (rev 17792)
@@ -67,6 +67,7 @@
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;
+import java.util.zip.ZipFile;
/**
@@ -147,7 +148,13 @@
private static class VizMapListener
implements PropertyChangeListener {
public void propertyChange(PropertyChangeEvent e) {
- if (e.getPropertyName() == Cytoscape.SAVE_VIZMAP_PROPS) {
+ String pn = null;
+
+ if (e != null) {
+ pn = e.getPropertyName();
+ }
+
+ if (Cytoscape.SAVE_VIZMAP_PROPS.equals(pn)) {
/*
* This section is for saving VS in a vizmap.props file.
*
@@ -177,15 +184,15 @@
logger.error("Unable to save vizmap to: " +
propertiesFile, e1);
}
}
- } else if ((e.getPropertyName() == Cytoscape.VIZMAP_RESTORED) ||
- (e.getPropertyName() == Cytoscape.VIZMAP_LOADED)) {
+ } else if ((Cytoscape.VIZMAP_RESTORED.equals(pn)) ||
+ (Cytoscape.VIZMAP_LOADED.equals(pn))) {
/*
* This section is for restoring VS from a file.
*/
// only clear the existing vizmap.props if we're restoring
// from a session file
- if (e.getPropertyName() == Cytoscape.VIZMAP_RESTORED)
+ if (Cytoscape.VIZMAP_RESTORED.equals(pn))
vizmapProps.clear();
// get the new vizmap.props and apply it the existing
properties
@@ -195,6 +202,7 @@
try {
InputStream is = null;
+ ZipFile zf = null;
if (vizmapSource.getClass() == URL.class)
// is = ((URL) vizmapSource).openStream();
@@ -204,8 +212,9 @@
else if (vizmapSource.getClass() == String.class) {
// if its a RESTORED event the vizmap
// file will be in a zip file.
- if (e.getPropertyName() == Cytoscape.VIZMAP_RESTORED) {
- is = ZipUtil.readFile((String) vizmapSource,
+ if (Cytoscape.VIZMAP_RESTORED.equals(pn)) {
+ zf = new ZipFile((String) vizmapSource);
+ is = ZipUtil.readFile(zf,
".*vizmap.props");
// if its a LOADED event the vizmap file
@@ -215,8 +224,19 @@
}
if (is != null) {
- vizmapProps.load(is);
- is.close();
+ try {
+ vizmapProps.load(is);
+ }
+ finally {
+ try {
+ if (zf != null) {
+ zf.close();
+ }
+ }
+ finally {
+ is.close();
+ }
+ }
}
} catch (FileNotFoundException e1) {
logger.error("Unable to open visual mapper file: "+e1.getMessage());
Modified:
cytoscape/trunk/tests/cytoscape/data/ontology/readers/DBCrossReferenceReaderTest.java
===================================================================
---
cytoscape/trunk/tests/cytoscape/data/ontology/readers/DBCrossReferenceReaderTest.java
2009-08-12 16:52:17 UTC (rev 17791)
+++
cytoscape/trunk/tests/cytoscape/data/ontology/readers/DBCrossReferenceReaderTest.java
2009-08-12 17:18:03 UTC (rev 17792)
@@ -146,15 +146,20 @@
InputStream is = uc.getInputStream();
BufferedReader reader = new BufferedReader(new
InputStreamReader(is));
- String s;
- StringBuffer sb = new StringBuffer();
- while ((s = reader.readLine()) != null) {
- sb.append(s);
- }
+ StringBuffer sb = new StringBuffer();
- reader.close();
+ try {
+ String s;
+ while ((s = reader.readLine()) != null) {
+ sb.append(s);
+ }
+ }
+ finally {
+ reader.close();
+ }
+
return sb.toString();
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en
-~----------~----~----~----~------~----~------~--~---