示例#1
0
    public WhatsNewItem(Element root, WhatsNewComponentProvider prov, AbstractProjectViewer pv)
        throws Exception {

      this.id = JDOMUtils.getAttributeValue(root, XMLConstants.id, false);

      if ((!this.id.equals("")) && (prov != null)) {

        this.component = prov.getComponent(pv, this.id);

      } else {

        this.id = null;
      }

      this.onlyIfCurrentVersion =
          JDOMUtils.getAttributeValueAsBoolean(root, XMLConstants.onlyIfCurrentVersion, false);
      this.title = JDOMUtils.getChildElementContent(root, XMLConstants.title);
      this.description = JDOMUtils.getChildElementContent(root, XMLConstants.description, false);

      if (this.description.equals("")) {

        this.description = null;
      }
    }
示例#2
0
  public NetcdfFile getNetcdfFile(HttpServletRequest req, HttpServletResponse res)
      throws IOException {
    StringBuffer jnl =
        new StringBuffer("DEFINE ALIAS letdeq1 let/d=1\nDEFINE ALIAS ATTRCMD SET ATT/LIKE=\n");

    StringBuffer urlbuf = req.getRequestURL();
    String url = URLDecoder.decode(urlbuf.toString(), "UTF-8");
    if (url.length() == urlbuf.length()) {
      // Length unchanged, decoding was unnecessary.
      url = urlbuf.toString();
    }

    log.debug("building netcdf file from " + url);

    String base = getBaseURL(url);
    ArrayList<String> expressions = getExpressions(url);

    FerretIOServiceProvider fiosp = new FerretIOServiceProvider();

    String data_path = fiosp.getDataDir();

    if (expressions.size() == 2) {
      if (!expressions.get(0).trim().equals("")) {
        List<String> expression_one = new ArrayList<String>();
        String od = URLDecoder.decode(expressions.get(0), "UTF-8");
        String[] urls = od.split(",");
        for (int i = 0; i < urls.length; i++) {
          String[] cmds;
          if (urls[i].contains("_cr_")) {
            cmds = urls[i].split("_cr_");
            for (int j = 0; j < cmds.length; j++) {
              expression_one.add(cmds[j]);
            }
          } else if (urls[i].contains(";")) {
            cmds = urls[i].split(";");
            for (int j = 0; j < cmds.length; j++) {
              expression_one.add(cmds[j]);
            }
          } else {
            expression_one.add(urls[i]);
          }
        }
        for (int i = 0; i < expression_one.size(); i++) {
          String dataURL = URLDecoder.decode(expression_one.get(i), "UTF-8");
          if (FerretCommands.containsCommand(dataURL)) {
            // This is actually a command, not a data URL.  Treat it as such...
            if (!FerretCommands.containsForbiddenCommand(dataURL)) {
              jnl.append(dataURL + "\n");
            }
          } else {
            if (!FerretCommands.containsForbiddenCommand(dataURL)) {
              int ds = i + 2;
              jnl.append("use \"" + dataURL + "\"\n");
            }
          }
        }
      }
      // Everything in the first bracket goes before the dataset.
      jnl.append("use \"" + base + "\"\n");

      if (!expressions.get(1).trim().equals("")) {

        // Decode the expression because it might contain an encode URL.
        String expr_two = URLDecoder.decode(expressions.get(1), "UTF-8");
        String[] cmds;
        if (expr_two.contains("_cr_")) {
          cmds = expr_two.split("_cr_");
        } else {
          cmds = expr_two.split(";");
        }
        for (int i = 0; i < cmds.length; i++) {
          cmds[i] = cmds[i].replaceAll("_q-t_", "\"");
          if (!FerretCommands.containsForbiddenCommand(cmds[i])) {
            jnl.append(cmds[i].replace("_qt_", "\"") + "\n");
          }
        }
      }
    } else if (expressions.size() == 1) {
      if (!expressions.get(0).trim().equals("")) {
        String od = URLDecoder.decode(expressions.get(0), "UTF-8");
        String[] urls = od.split(",");
        for (int i = 0; i < urls.length; i++) {
          String dataURL = URLDecoder.decode(urls[i], "UTF-8");
          if (FerretCommands.containsCommand(dataURL)) {
            // This is actually a command, not a data URL.  Treat it as such...
            if (!FerretCommands.containsForbiddenCommand(dataURL)) {
              jnl.append(dataURL + "\n");
            }
          } else {
            if (!FerretCommands.containsForbiddenCommand(dataURL)) {
              int ds = i + 2;
              jnl.append("use \"" + dataURL.replace("_qt_", "\"") + "\"\n");
            }
          }
        }
      }
    } else if (expressions.size() == 0) {
      throw new IOException(
          "Expression parsing failed for this URL. "
              + url
              + " Now expressions found inside the curly brackets.");
    } else if (expressions.size() > 2) {
      throw new IOException(
          "Expression parsing failed for this URL. " + url + " Too many expressions found.");
    }

    String key = JDOMUtils.MD5Encode(jnl.toString());

    String script = data_path + File.separator + "data_expr_" + key + ".jnl";

    log.debug("using " + script + " for temporary script file.");
    if (script.contains("../") || script.contains("/..")) {
      throw new IOException("Illegal script file name.");
    }
    File script_file = new File(script);
    if (!script_file.exists()) {
      PrintWriter data_script = new PrintWriter(new FileOutputStream(script_file));
      data_script.println(jnl);
      data_script.close();
    }

    RandomAccessFile raf = new RandomAccessFile(script, "r");
    return new FerretNetcdfFile(raf, req.getRequestURI());
  }
示例#3
0
  public WhatsNew(AbstractProjectViewer pv, boolean onlyShowCurrentVersion)
      throws GeneralException {

    super(pv);

    String wn = Environment.getProperty(Constants.WHATS_NEW_VERSION_VIEWED_PROPERTY_NAME);

    if (wn == null) {

      wn = "0";
    }

    // Get the current whats new version (i.e. old).
    Version lastWhatsNewVersion = new Version(wn);

    boolean betasAllowed =
        Environment.getUserProperties()
            .getPropertyAsBoolean(Constants.OPTIN_TO_BETA_VERSIONS_PROPERTY_NAME);

    try {

      String whatsNew = Environment.getResourceFileAsString(Constants.WHATS_NEW_FILE);

      // Load up all the whats new for greater versions.
      Element root = JDOMUtils.getStringAsElement(whatsNew);

      java.util.List verEls = JDOMUtils.getChildElements(root, XMLConstants.version, false);

      // Assume they are in the right order
      // TODO: Enforce the order and/or sort.
      for (int i = 0; i < verEls.size(); i++) {

        Element vEl = (Element) verEls.get(i);

        String id = JDOMUtils.getAttributeValue(vEl, XMLConstants.id, true);

        Version v = new Version(id);
        /*
                      if ((v.isBeta ())
                          &&
                          (!betasAllowed)
                         )
                      {

                          // Ignore, the user isn't interested in betas.
                          continue;

                      }
        */
        if ((lastWhatsNewVersion.isNewer(v))
            || ((onlyShowCurrentVersion) && (v.isSame(Environment.getQuollWriterVersion())))) {

          String c = WhatsNewComponentProvider.class.getName();

          int ind = c.lastIndexOf(".");

          if (ind > 0) {

            c = c.substring(0, ind);
          }

          WhatsNewComponentProvider compProv = null;

          String cl = JDOMUtils.getAttributeValue(vEl, XMLConstants.clazz, false);

          if (!cl.equals("")) {

            Class clz = null;

            try {

              clz = Class.forName(cl);

              if (WhatsNewComponentProvider.class.isAssignableFrom(clz)) {

                compProv = (WhatsNewComponentProvider) clz.newInstance();
              }

            } catch (Exception e) {

            }
          }

          // This is a version we are interested in.
          java.util.List itemEls =
              JDOMUtils.getChildElements(vEl, WhatsNewItem.XMLConstants.root, true);

          java.util.List<WhatsNewItem> its = new ArrayList();

          for (int j = 0; j < itemEls.size(); j++) {

            Element itEl = (Element) itemEls.get(j);

            WhatsNewItem it = new WhatsNewItem(itEl, compProv, pv);

            if (it.onlyIfCurrentVersion) {

              if (!Environment.getQuollWriterVersion().isSame(v)) {

                continue;
              }
            }

            if ((it.description == null) && (it.component == null)) {

              Environment.logMessage(
                  "Whats new item has no description or component, referenced by: "
                      + JDOMUtils.getPath(itEl));

              continue;
            }

            its.add(it);
          }

          if (its.size() > 0) {

            this.items.put(v, its);
          }
        }
      }

    } catch (Exception e) {

      throw new GeneralException("Unable to init whats new", e);
    }
  }
示例#4
0
  public void read(String src) {
    //		addXML ax = new addXML();
    InvCatalogFactory factory = new InvCatalogFactory("default", false);
    InvCatalog catalog = (InvCatalog) factory.readXML(src);
    StringBuilder buff = new StringBuilder();
    int count = catalog.getDatasets().size();
    if (!catalog.check(buff, true)) {
      log.error("Invalid catalog <" + src + ">\n" + buff.toString());
    } else {

      for (int index = 0; index < count; index++) {
        factory = new InvCatalogFactory("default", false);
        catalog = (InvCatalog) factory.readXML(src);
        InvDataset invDataset = catalog.getDatasets().get(index);
        System.out.println(invDataset.getName());
        String file = "/home/rhs/NCAR/las_categories_";
        try {
          file = file + JDOMUtils.MD5Encode(invDataset.getName()) + ".xml";
        } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
        }
        Element las_categories = new Element("las_categories");

        //				CategoryBean cb = new CategoryBean();
        //				cb.setName(invDataset.getName());
        //				cb.setID(invDataset.getID());
        //				// This is the top level...
        //				//cb.setContributors(getContributors(invDataset));
        //				Vector topCats = new Vector();
        for (Iterator topLevelIt = invDataset.getDatasets().iterator(); topLevelIt.hasNext(); ) {
          InvDataset topDS = (InvDataset) topLevelIt.next();
          //					CategoryBean topCB = new CategoryBean();
          //					topCB.setName(topDS.getName());
          String id = topDS.getID();
          if (id == null) {
            try {
              id = "id_" + JDOMUtils.MD5Encode(topDS.getName());
            } catch (UnsupportedEncodingException e) {
              id = "id_" + String.valueOf(Math.random());
            }
          }
          System.out.println("top: " + topDS.getName() + ", " + topDS.getID());
          // topCB.setID(id);

          //					for (Iterator subDatasetsIt = topDS.getDatasets().iterator();
          // subDatasetsIt.hasNext(); ) {
          //						InvDataset subDataset = (InvDataset) subDatasetsIt.next();
          //						topCB.addCatID(subDataset.getID());
          //						// These will be the catalog containers that will contain the aggregations...
          //						for (Iterator grandChildrenIt = subDataset.getDatasets().iterator();
          // grandChildrenIt.hasNext(); ) {
          //							InvDataset grandChild = (InvDataset) grandChildrenIt.next();
          //							if ( grandChild.hasAccess() && grandChild.getName().contains("aggregation")) {
          //								// We are done.
          //								String url = null;
          //								InvAccess access = null;
          //								for (Iterator ait = grandChild.getAccess().iterator(); ait.hasNext(); ) {
          //									access = (InvAccess) ait.next();
          //									if (access.getService().getServiceType() == ServiceType.DODS ||
          //											access.getService().getServiceType() == ServiceType.OPENDAP ||
          //											access.getService().getServiceType() == ServiceType.NETCDF) {
          //										url = access.getStandardUrlName();
          //									}
          //								}
          //								if ( url != null && url.contains("aggregation") ){
          //									FilterBean filter = new FilterBean();
          //									filter.setAction("apply-variable");
          //									String tag = grandChild.getID();
          //									filter.setContainstag(tag);
          //									topCB.addFilter(filter);
          //									topCB.addCatID(grandChild.getID());
          //								}
          //							}
          //						}
          //					}
          //					if ( topCB.getFilters().size() > 0 ) {
          //						topCats.add(topCB);
          //					}
        }
        //				if ( topCats.size() > 0 ) {
        //					cb.setCategories(topCats);
        //				}
        //				las_categories.addContent(cb.toXml());

        //				ax.processESGCategories(invDataset, las_categories);
        //				LASDocument document = new LASDocument();
        //				document.setRootElement(las_categories);
        //				System.out.println("Writing "+file+" for "+invDataset.getName());
        //				document.write(file);
        //				document = null;
      }
    }
  }