ViewersThe TDS lists the set of known viewers for a direct dataset the bottom of its HTML web page. You can get your own viewer listed by creating a Java class that tells the TDS what datasets are viewable, and what HTML fragment to include.
Your class must implement the thredds.servlet.Viewer interface:
public interface Viewer {
1) public boolean isViewable( thredds.catalog.InvDatasetImpl dataset);
2) public String getViewerLinkHtml( InvDatasetImpl ds, HttpServletRequest req);
}
Example:
package my.package;
include thredds.catalog.*;
public class IDV implements Viewer {
public boolean isViewable( InvDatasetImpl ds) {
InvAccess access = ds.getAccess(ServiceType.DODS);
if (access == null) access = ds.getAccess(ServiceType.OPENDAP);
1) if (access == null) return false;
2) return (ds.getDataType() == DataType.GRID);
}
public String getViewerLinkHtml( InvDatasetImpl ds, HttpServletRequest req) {
InvAccess access = ds.getAccess(ServiceType.DODS);
3) if (access == null) access = ds.getAccess(ServiceType.OPENDAP);
4) URI dataURI = access.getStandardUri();
try {
URI base = new URI( req.getRequestURL().toString());
5) dataURI = base.resolve( dataURI);
} catch (URISyntaxException e) {
log.error("Resolve URL with "+req.getRequestURL(),e);
}
6) return "<a href='/thredds/view/idv.jnlp?url="+dataURI.toString()+"'>Integrated Data Viewer (IDV) (webstart)</a>"; }
If the viewer you want to reference is not part of the TDS, just make the href absolute, eg:
<a href='http://my.server/viewer?url=http://motherlode.ucar.edu:8080/thredds/dodsC/model/data.grib2'>My Server</a>
In this example, the server would see the OPeNDAP data access URL and remotely read it.
The IDV example returns a JNLP file, which allows the IDV client program to be automatically started through Java Webstart. If you have a webstart-enabled viewer, you can also get the TDS to return your own JNLP file. To do so:
Example:
This is an approximately what is used in the IDV JNLP file. Note that the {url} string on the boldface line is replaced by the actual data access URL. This will create a command line argument -data type:opendap.grid:http://motherlode.ucar.edu:8080/thredds/dodsC/model/data.grib2 and pass it to the IDV application.
<?xml version="1.0" encoding="utf-8"?>
<!-- JNLP File for Integrated Data Viewer -->
<jnlp spec="1.0+" codebase="http://www.unidata.ucar.edu/software/idv/webstart/">
<information>
<title>Integrated Data Viewer</title>
<vendor>Unidata</vendor>
<homepage href="http://www.unidata.ucar.edu/software/idv/index.html"/>
<description>Integrated Data Viewer(IDV)</description>
<description kind="short">A tool for geoscientific analysis and visualization.
</description>
<icon href="IDV/idv.gif"/>
<offline-allowed/>
</information>
<security> <all-permissions/> </security>
<resources>
<j2se version="1.4+" max-heap-size="512m"/>
<jar href="IDV/idv.jar"/>
<extension name="IDV Base" href="IDV/idvbase.jnlp"/>
</resources>
<application-desc main-class="ucar.unidata.idv.DefaultIdv">
<argument>-data</argument>
<argument>type:opendap.grid:{url}</argument>
</application-desc>
</jnlp>
You must place your Viewer class into the ${tomcat_home}/webapps/thredds/WEB-INF/lib or classes directory. (Previous instructions to place it into the ${tomcat_home}/shared directory doesn't work, because of classloader problems).
Then tell the TDS to load it by adding a line to the ${tomcat_home}/content/thredds/threddsConfig.xml file, for example:
<viewer>my.package.MyViewer</viewer>
This document is maintained by John Caron and was last updated on Jan 31, 2007