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 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; }