Skip to content

Commit 57f3d4a

Browse files
committed
Investigator force graph node legends now only sites appearing in the graph. This is supported by additions to GraphTagLib.
1 parent bdec9a0 commit 57f3d4a

5 files changed

Lines changed: 181 additions & 1 deletion

File tree

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ src/main/java/edu/uiowa/slis/graphtaglib/NodeIterator.java -text
3838
src/main/java/edu/uiowa/slis/graphtaglib/NodeLabel.java -text
3939
src/main/java/edu/uiowa/slis/graphtaglib/NodeScore.java -text
4040
src/main/java/edu/uiowa/slis/graphtaglib/NodeUri.java -text
41+
src/main/java/edu/uiowa/slis/graphtaglib/SiteID.java -text
42+
src/main/java/edu/uiowa/slis/graphtaglib/SiteIDIterator.java -text
43+
src/main/java/edu/uiowa/slis/graphtaglib/SiteName.java -text
4144
src/main/java/edu/uiowa/slis/graphtaglib/filters/EdgeLookup.java -text
4245
src/main/java/edu/uiowa/slis/graphtaglib/filters/EdgePopulator.java -text
4346
src/main/java/edu/uiowa/slis/graphtaglib/filters/ImplicitEdgeLookup.java -text
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package edu.uiowa.slis.graphtaglib;
2+
3+
import java.io.IOException;
4+
5+
import javax.servlet.jsp.JspException;
6+
import javax.servlet.jsp.JspTagException;
7+
import javax.servlet.jsp.tagext.TagSupport;
8+
9+
public class SiteID extends TagSupport {
10+
private static final long serialVersionUID = 1L;
11+
12+
public int doStartTag() throws JspException {
13+
SiteIDIterator theIterator = (SiteIDIterator) findAncestorWithClass(this, SiteIDIterator.class);
14+
try {
15+
pageContext.getOut().print(theIterator.currentID);
16+
} catch (IOException e) {
17+
e.printStackTrace();
18+
}
19+
return SKIP_BODY;
20+
}
21+
22+
public int doEndTag() throws JspTagException, JspException {
23+
clearServiceState();
24+
return super.doEndTag();
25+
}
26+
27+
private void clearServiceState() {
28+
}
29+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package edu.uiowa.slis.graphtaglib;
2+
3+
import java.sql.Connection;
4+
import java.sql.PreparedStatement;
5+
import java.sql.ResultSet;
6+
import java.sql.SQLException;
7+
import java.util.Hashtable;
8+
import java.util.Iterator;
9+
import java.util.SortedSet;
10+
import java.util.TreeSet;
11+
12+
import org.apache.commons.logging.Log;
13+
import org.apache.commons.logging.LogFactory;
14+
15+
import javax.naming.InitialContext;
16+
import javax.naming.NamingException;
17+
import javax.servlet.jsp.JspException;
18+
import javax.servlet.jsp.JspTagException;
19+
import javax.servlet.jsp.tagext.BodyTagSupport;
20+
import javax.sql.DataSource;
21+
22+
public class SiteIDIterator extends BodyTagSupport {
23+
private static final long serialVersionUID = 1L;
24+
25+
private static final Log logger = LogFactory.getLog(SiteIDIterator.class);
26+
static Hashtable<Integer, String> siteHash = null;
27+
28+
SortedSet<Integer> idSet = null;
29+
Iterator<Integer> idIterator = null;
30+
int currentID = 0;
31+
String currentSite = null;
32+
33+
boolean pruneOrphans = false;
34+
35+
synchronized void init() throws NamingException, SQLException {
36+
if (siteHash != null)
37+
return;
38+
siteHash = new Hashtable<Integer, String>();
39+
DataSource theDataSource = (DataSource) new InitialContext().lookup("java:/comp/env/jdbc/VIVOTagLib");
40+
Connection conn = theDataSource.getConnection();
41+
PreparedStatement stmt = conn.prepareStatement("select id,site from vivo_aggregated.site order by id");
42+
ResultSet rs = stmt.executeQuery();
43+
while (rs.next()) {
44+
siteHash.put(rs.getInt(1), rs.getString(2));
45+
}
46+
stmt.close();
47+
conn.close();
48+
}
49+
50+
public int doStartTag() throws JspException {
51+
logger.debug("doStartTag");
52+
try {
53+
init();
54+
} catch (Exception e) {
55+
logger.error("error initializing SiteIDIterator:", e);
56+
}
57+
idSet = new TreeSet<Integer>();
58+
Graph theGraph = (Graph) findAncestorWithClass(this, Graph.class);
59+
for (GraphNode node: theGraph.nodes) {
60+
idSet.add(node.getGroup("site"));
61+
}
62+
63+
idIterator = idSet.iterator();
64+
65+
if (idIterator.hasNext()) {
66+
currentID = idIterator.next();
67+
currentSite = siteHash.get(currentID);
68+
pageContext.setAttribute("isLastID", !idIterator.hasNext());
69+
return EVAL_BODY_INCLUDE;
70+
}
71+
72+
return SKIP_BODY;
73+
}
74+
75+
public int doAfterBody() throws JspTagException {
76+
if (idIterator.hasNext()) {
77+
currentID = idIterator.next();
78+
currentSite = siteHash.get(currentID);
79+
pageContext.setAttribute("isLastID", !idIterator.hasNext());
80+
return EVAL_BODY_AGAIN;
81+
}
82+
83+
return SKIP_BODY;
84+
}
85+
86+
public int doEndTag() throws JspTagException, JspException {
87+
logger.debug("doEndTag");
88+
clearServiceState();
89+
return super.doEndTag();
90+
}
91+
92+
private void clearServiceState() {
93+
idSet = null;
94+
idIterator = null;
95+
currentID = 0;
96+
currentSite = null;
97+
98+
pageContext.removeAttribute("isLastNode");
99+
}
100+
101+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package edu.uiowa.slis.graphtaglib;
2+
3+
import java.io.IOException;
4+
5+
import javax.servlet.jsp.JspException;
6+
import javax.servlet.jsp.JspTagException;
7+
import javax.servlet.jsp.tagext.TagSupport;
8+
9+
public class SiteName extends TagSupport {
10+
private static final long serialVersionUID = 1L;
11+
12+
public int doStartTag() throws JspException {
13+
SiteIDIterator theIterator = (SiteIDIterator) findAncestorWithClass(this, SiteIDIterator.class);
14+
try {
15+
pageContext.getOut().print(theIterator.currentSite);
16+
} catch (IOException e) {
17+
e.printStackTrace();
18+
}
19+
return SKIP_BODY;
20+
}
21+
22+
public int doEndTag() throws JspTagException, JspException {
23+
clearServiceState();
24+
return super.doEndTag();
25+
}
26+
27+
private void clearServiceState() {
28+
}
29+
}

src/main/resources/META-INF/taglib.tld

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,4 +228,22 @@
228228
<rtexprvalue>true</rtexprvalue>
229229
</attribute>
230230
</tag>
231-
</taglib>
231+
232+
<tag>
233+
<name>foreachSiteID</name>
234+
<tag-class>edu.uiowa.slis.graphtaglib.SiteIDIterator</tag-class>
235+
<body-content>JSP</body-content>
236+
</tag>
237+
238+
<tag>
239+
<name>SiteID</name>
240+
<tag-class>edu.uiowa.slis.graphtaglib.SiteID</tag-class>
241+
<body-content>JSP</body-content>
242+
</tag>
243+
244+
<tag>
245+
<name>SiteName</name>
246+
<tag-class>edu.uiowa.slis.graphtaglib.SiteName</tag-class>
247+
<body-content>JSP</body-content>
248+
</tag>
249+
</taglib>

0 commit comments

Comments
 (0)