private void level2level3catalog( RadarType radarType, String pathInfo, PrintWriter pw, HttpServletRequest req, HttpServletResponse res) throws IOException { try { String type; if (pathInfo.contains("level2")) type = radarType.toString() + "/level2"; else type = radarType.toString() + "/level3"; ByteArrayOutputStream os = new ByteArrayOutputStream(10000); InvCatalogFactory factory = InvCatalogFactory.getDefaultFactory(false); factory.writeXML(cat, os, true); InvCatalogImpl tCat = factory.readXML(new ByteArrayInputStream(os.toByteArray()), catURI); Iterator parents = tCat.getDatasets().iterator(); while (parents.hasNext()) { ArrayList<InvDatasetImpl> delete = new ArrayList<InvDatasetImpl>(); InvDatasetImpl top = (InvDatasetImpl) parents.next(); Iterator tDatasets = top.getDatasets().iterator(); while (tDatasets.hasNext()) { InvDatasetImpl ds = (InvDatasetImpl) tDatasets.next(); if (ds instanceof InvDatasetScan) { InvDatasetScan ids = (InvDatasetScan) ds; if (ids.getPath() == null) continue; if (ids.getPath().contains(type)) { ids.setXlinkHref(ids.getPath() + "/dataset.xml"); } else { delete.add(ds); } } } // remove datasets for (InvDatasetImpl idi : delete) { top.removeDataset(idi); } } if (pathInfo.endsWith("xml")) { String catAsString = factory.writeXML(tCat); pw.println(catAsString); pw.flush(); } else { HtmlWriter.getInstance().writeCatalog(req, res, tCat, true); // show catalog as HTML } } catch (Throwable e) { log.error("RadarServer.level2level3catalog failed", e); if (!res.isCommitted()) res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } return; }
public void init() throws ServletException { super.init(); // allow = ThreddsConfig.getBoolean("NetcdfSubsetService.allow", true); // String radarLevel2Dir = ThreddsConfig.get("NetcdfSubsetService.radarLevel2DataDir", // "/data/ldm/pub/native/radar/level2/"); // if (!allow) return; contentPath = ServletUtil.getContentPath(); rm = new RadarMethods(contentPath, logServerStartup); // read in radarCollections.xml catalog InvCatalogFactory factory = InvCatalogFactory.getDefaultFactory(false); // no validation cat = readCatalog(factory, getPath() + catName, contentPath + getPath() + catName); if (cat == null) { logServerStartup.info("cat initialization failed"); return; } // URI tmpURI = cat.getBaseURI(); cat.setBaseURI(catURI); // get path and location from cat List parents = cat.getDatasets(); for (int i = 0; i < parents.size(); i++) { InvDataset top = (InvDataset) parents.get(i); datasets = top.getDatasets(); // dataset scans for (int j = 0; j < datasets.size(); j++) { InvDatasetScan ds = (InvDatasetScan) datasets.get(j); if (ds.getPath() != null) { dataLocation.put(ds.getPath(), ds.getScanLocation()); logServerStartup.info("path =" + ds.getPath() + " location =" + ds.getScanLocation()); } ds.setXlinkHref(ds.getPath() + "/dataset.xml"); } } logServerStartup.info(getClass().getName() + " initialization complete "); } // end init
private void datasetInfoHtml( RadarType radarType, String pathInfo, PrintWriter pw, HttpServletResponse res) throws IOException { pathInfo = pathInfo.replace("/dataset.html", ""); pathInfo = pathInfo.replace("/catalog.html", ""); Element root = new Element("RadarNexrad"); Document doc = new Document(root); if (pathInfo.startsWith("/")) pathInfo = pathInfo.substring(1); for (int i = 0; i < datasets.size(); i++) { InvDatasetScan ds = (InvDatasetScan) datasets.get(i); if (!(pathInfo.equals(ds.getPath()))) { continue; } // at this point a valid dataset // fix the location root.setAttribute("location", "/thredds/radarServer/" + ds.getPath()); // spatial range ThreddsMetadata.GeospatialCoverage gc = ds.getGeospatialCoverage(); LatLonRect bb = new LatLonRect(); gc.setBoundingBox(bb); String north = Double.toString(gc.getLatNorth()); String south = Double.toString(gc.getLatSouth()); String east = Double.toString(gc.getLonEast()); String west = Double.toString(gc.getLonWest()); Element LatLonBox = new Element("LatLonBox"); LatLonBox.addContent(new Element("north").addContent(north)); LatLonBox.addContent(new Element("south").addContent(south)); LatLonBox.addContent(new Element("east").addContent(east)); LatLonBox.addContent(new Element("west").addContent(west)); root.addContent(LatLonBox); // get the time range Element timeSpan = new Element("TimeSpan"); CalendarDateRange dr = ds.getCalendarDateCoverage(); timeSpan.addContent(new Element("begin").addContent(dr.getStart().toString())); timeSpan.addContent(new Element("end").addContent(dr.getEnd().toString())); root.addContent(timeSpan); ThreddsMetadata.Variables cvs = (ThreddsMetadata.Variables) ds.getVariables().get(0); List vl = cvs.getVariableList(); for (int j = 0; j < vl.size(); j++) { ThreddsMetadata.Variable v = (ThreddsMetadata.Variable) vl.get(j); Element variable = new Element("variable"); variable.setAttribute("name", v.getName()); root.addContent(variable); } // add pointer to the station list XML /* Element stnList = new Element("stationList"); stnList.setAttribute("title", "Available Stations", XMLEntityResolver.xlinkNS); stnList.setAttribute("href", "/thredds/radarServer/"+ pathInfo +"/stations.xml", XMLEntityResolver.xlinkNS); root.addContent(stnList); */ // String[] stations = rns.stationsDS( dataLocation.get( ds.getPath() )); // rns.printStations( stations ); // add accept list Element a = new Element("AcceptList"); a.addContent(new Element("accept").addContent("xml")); a.addContent(new Element("accept").addContent("html")); root.addContent(a); } ServerMethods sm = new ServerMethods(log); InputStream xslt = sm.getInputStream(contentPath + getPath() + "radar.xsl", RadarServer.class); try { // what's wrong here xslt = getXSLT( "radar.xsl" ); XSLTransformer transformer = new XSLTransformer(xslt); Document html = transformer.transform(doc); XMLOutputter fmt = new XMLOutputter(Format.getPrettyFormat()); String infoString = fmt.outputString(html); res.setContentType("text/html; charset=iso-8859-1"); pw = res.getWriter(); pw.println(infoString); pw.flush(); } catch (Exception e) { log.error("radarServer reading " + contentPath + getPath() + "radar.xsl"); log.error("radarServer XSLTransformer problem for web form ", e); } finally { if (xslt != null) { try { xslt.close(); } catch (IOException e) { log.error("radarServer radar.xsl: error closing" + contentPath + getPath() + "radar.xsl"); } } } return; }
private void datasetInfoXml(RadarType radarType, String pathInfo, PrintWriter pw) throws IOException { try { pw.println( "<catalog xmlns=\"http://www.unidata.ucar.edu/namespaces/thredds/InvCatalog/v1.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" name=\"Radar Data\" version=\"1.0.1\">\n"); // add service pw.println( " <service name=\"radarServer\" base=\"/thredds/radarServer/\" serviceType=\"DQC\" />\n"); pathInfo = pathInfo.replace("/dataset.xml", ""); pathInfo = pathInfo.replace("/catalog.xml", ""); if (pathInfo.startsWith("/")) pathInfo = pathInfo.substring(1); for (int i = 0; i < datasets.size(); i++) { InvDatasetScan ds = (InvDatasetScan) datasets.get(i); if (!(pathInfo.equals(ds.getPath()))) { continue; } pw.println(" <dataset ID=\"" + ds.getID() + "\" serviceName=\"radarServer\">"); pw.println(" <urlpath>" + ds.getPath() + "</urlpath>"); pw.println(" <dataType>" + ds.getDataType() + "</dataType>"); pw.println(" <dataFormat>" + ds.getDataFormatType() + "</dataFormat>"); pw.println(" <serviceName>radarServer</serviceName>"); pw.println(" <metadata inherited=\"true\">"); pw.println(" <documentation type=\"summary\">" + ds.getSummary() + "</documentation>"); CalendarDateRange dr = ds.getCalendarDateCoverage(); pw.println(" <TimeSpan>"); pw.print(" <start>"); if (pathInfo.contains("IDD")) { pw.print(rm.getStartDateTime(ds.getPath())); } else { pw.print(dr.getStart().toString()); } pw.println("</start>"); pw.println(" <end>" + dr.getEnd().toString() + "</end>"); pw.println(" </TimeSpan>"); ThreddsMetadata.GeospatialCoverage gc = ds.getGeospatialCoverage(); LatLonRect bb = new LatLonRect(); gc.setBoundingBox(bb); pw.println(" <LatLonBox>"); pw.println(" <north>" + gc.getLatNorth() + "</north>"); pw.println(" <south>" + gc.getLatSouth() + "</south>"); pw.println(" <east>" + gc.getLonEast() + "</east>"); pw.println(" <west>" + gc.getLonWest() + "</west>"); pw.println(" </LatLonBox>"); ThreddsMetadata.Variables cvs = (ThreddsMetadata.Variables) ds.getVariables().get(0); List vl = cvs.getVariableList(); pw.println(" <Variables>"); for (int j = 0; j < vl.size(); j++) { ThreddsMetadata.Variable v = (ThreddsMetadata.Variable) vl.get(j); pw.println( " <variable name=\"" + v.getName() + "\" vocabulary_name=\"" + v.getVocabularyName() + "\" units=\"" + v.getUnits() + "\" />"); } pw.println(" </Variables>"); String[] stations = rm.stationsDS(radarType, dataLocation.get(ds.getPath())); rm.printStations(stations, pw, radarType); pw.println(" </metadata>"); pw.println(" </dataset>"); } pw.println("</catalog>"); pw.flush(); } catch (Throwable e) { log.error("RadarServer.datasetInfoXml", e); } return; }