コード例 #1
0
ファイル: RadarServer.java プロジェクト: feihugis/NetCDF
  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;
  }
コード例 #2
0
ファイル: DatasetEditor.java プロジェクト: qlongyinqw/thredds
  public boolean setDataset(InvDatasetImpl ds) {
    if (!accept()) return false;

    this.dataset = ds;
    this.leafDataset = null;
    exampleButton.setText("Example Dataset");

    //////////
    PersistentBean persBean = new PersistentBean(ds);

    setEditValue(NAME, persBean, 0);
    setEditValue(ID, persBean, 0);

    setEditValueWithInheritence(AUTHORITY, persBean);
    setEditValueWithInheritence(SERVICE_NAME, persBean);

    setEditValueWithInheritence(FORMAT_TYPE, persBean);
    setEditValueWithInheritence(DATA_TYPE, persBean);

    setEditValue(COLLECTION_TYPE, persBean, 0);
    setEditValue(HARVEST, persBean, 0);

    // gotta find which GeospatialCoverage to use.
    int mode = 0;
    ThreddsMetadata.GeospatialCoverage gc = ds.getLocalMetadata().getGeospatialCoverage();
    if ((gc == null) || gc.isEmpty()) {
      gc = ds.getLocalMetadataInheritable().getGeospatialCoverage();
      mode = 1;
    }
    if ((gc == null) || gc.isEmpty()) {
      gc = ds.getGeospatialCoverage();
      mode = 2; // inherited
    }
    metadataPP.setFieldValue(GC_TYPE, inherit_types.get(mode));
    setGC(gc, mode);

    // gotta find which TimeCoverage to use.
    mode = 0;
    CalendarDateRange tc = ds.getLocalMetadata().getCalendarDateCoverage();
    if (tc == null) {
      tc = ds.getLocalMetadataInheritable().getCalendarDateCoverage();
      mode = 1;
    }
    if (tc == null) {
      tc = ds.getCalendarDateCoverage();
      mode = 2; // inherited
    }
    metadataPP.setFieldValue(TC_TYPE, inherit_types.get(mode));
    if (tc != null) dateRangeSelector.setDateRange(tc.toDateRange());
    setTCmode(mode);

    setEditValueWithInheritence(SUMMARY, persBean);
    setEditValueWithInheritence(RIGHTS, persBean);
    setEditValueWithInheritence(HISTORY, persBean);
    setEditValueWithInheritence(PROCESSING, persBean);

    setVariables(variablesFld);
    setBeanList(creatorsFld, CREATORS, persBean);
    setBeanList(publishersFld, PUBLISHERS, persBean);
    setBeanList(projectsFld, PROJECTS, persBean);
    setBeanList(keywordsFld, KEYWORDS, persBean);
    setBeanList(datesFld, DATES, persBean);
    setBeanList(contributorsFld, CONTRIBUTORS, persBean);
    setBeanList(docsFld, DOCUMENTATION, persBean);

    if (ds instanceof InvDatasetScan) {
      dscanPP.setEnabled(true);
      setEditValue(dscanPP, DSCAN_PATH, persBean, 0);
      setEditValue(dscanPP, DSCAN_DIR, persBean, 0);
      // setEditValue( dscanPP, DSCAN_FILTER, persBean, 0);
      setEditValue(dscanPP, DSCAN_ADDSIZE, persBean, 0);
      // setEditValue( dscanPP, DSCAN_ADDLATEST, persBean, 0);
      // setEditValue( dscanPP, DSCAN_TC_MATCH, persBean, 0);
      // setEditValue( dscanPP, DSCAN_TC_SUBS, persBean, 0);
      // setEditValue( dscanPP, DSCAN_TC_DURATOPN, persBean, 0);
    } else dscanPP.setEnabled(false);

    return true;
  }
コード例 #3
0
ファイル: RadarServer.java プロジェクト: feihugis/NetCDF
  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;
  }