Ejemplo n.º 1
0
  public void openLink(String link) {
    if (WWUtil.isEmpty(link)) return;

    try {
      try {
        // See if the link is a URL, and invoke the browser if it is
        URL url = new URL(link.replace(" ", "%20"));
        Desktop.getDesktop().browse(url.toURI());
        return;
      } catch (MalformedURLException ignored) { // just means that the link is not a URL
      }

      // It's not a URL, so see if it's a file and invoke the desktop to open it if it is.
      File file = new File(link);
      if (file.exists()) {
        Desktop.getDesktop().open(new File(link));
        return;
      }

      String message = "Cannot open resource. It's not a valid file or URL.";
      Util.getLogger().log(Level.SEVERE, message);
      this.showErrorDialog(null, "No Reconocido V\u00ednculo", message);
    } catch (UnsupportedOperationException e) {
      String message =
          "Unable to open resource.\n"
              + link
              + (e.getMessage() != null ? "\n" + e.getMessage() : "");
      Util.getLogger().log(Level.SEVERE, message, e);
      this.showErrorDialog(e, "Error Opening Resource", message);
    } catch (IOException e) {
      String message =
          "I/O error while opening resource.\n"
              + link
              + (e.getMessage() != null ? ".\n" + e.getMessage() : "");
      Util.getLogger().log(Level.SEVERE, message, e);
      this.showErrorDialog(e, "I/O Error", message);
    } catch (Exception e) {
      String message =
          "Error attempting to open resource.\n"
              + link
              + (e.getMessage() != null ? "\n" + e.getMessage() : "");
      Util.getLogger().log(Level.SEVERE, message);
      this.showMessageDialog(message, "Error Opening Resource", JOptionPane.ERROR_MESSAGE);
    }
  }
Ejemplo n.º 2
0
  /** Run the tool */
  public static void main(String args[]) throws Throwable {
    String inEncoding = args[0];
    String inFile = args[1];
    String outEncoding = args[2];
    String outFile = args[3];
    String outClass = args[4];

    FileInputStream fin = new FileInputStream(inFile);
    InputStreamReader r = new InputStreamReader(fin, inEncoding);
    reader = new BufferedReader(r);

    FileOutputStream fout = new FileOutputStream(outFile);
    OutputStreamWriter w = new OutputStreamWriter(fout, outEncoding);
    writer = new PrintWriter(w);

    // Write the XML file prolog.
    pl("<?xml version=\"1.0\" encoding=\"" + outEncoding + "\"?>");
    pl("<!DOCTYPE configuration SYSTEM \"../configuration.dtd\">");
    pl("<!--");
    pl("         ");
    pl("");
    pl("  Copyright  1990-2009 Sun Microsystems, Inc. All Rights Reserved.");
    pl("  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER");
    pl("  ");
    pl("  This program is free software; you can redistribute it and/or");
    pl("  modify it under the terms of the GNU General Public License version");
    pl("  2 only, as published by the Free Software Foundation.");
    pl("  ");
    pl("  This program is distributed in the hope that it will be useful, but");
    pl("  WITHOUT ANY WARRANTY; without even the implied warranty of");
    pl("  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU");
    pl("  General Public License version 2 for more details (a copy is");
    pl("  included at /legal/license.txt).");
    pl("  ");
    pl("  You should have received a copy of the GNU General Public License");
    pl("  version 2 along with this work; if not, write to the Free Software");
    pl("  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA");
    pl("  02110-1301 USA");
    pl("  ");
    pl("  Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa");
    pl("  Clara, CA 95054 or visit www.sun.com if you need additional");
    pl("  information or have any questions.");
    pl("-->");
    pl("<configuration>");
    pl("<localized_strings Package=\"com.sun.midp.l10n\" Name=\"" + outClass + "\">");

    StringBuffer sbuf = new StringBuffer();
    String line;
    while ((line = reader.readLine()) != null) {
      sbuf.append(line);
      sbuf.append("\n");
    }

    // Find all occurrences of
    // new Integer(ResourceConstants.DONE), "\u5B8C\u6210"
    //                               ^^^^    ^^^^^^^^^^^^
    //                               key     value
    Parser p = new Parser(sbuf.toString());
    while (p.advance("Integer")) {
      p.mark();
      try {
        p.skipSpaces();
        p.skip('(');
        p.skipSpaces();
        p.skip("ResourceConstants");
        p.skipSpaces();
        p.skip(".");
        p.skipSpaces();

        String key = p.readSymbol();

        p.skipSpaces();
        p.skip(')');
        p.skipSpaces();
        p.skip(',');
        p.skipSpaces();

        String value = p.readStringLiteral();

        while (true) {
          p.mark();

          try {
            // Handle any "xxx" + "yyy" cases
            p.skipSpaces();
            p.skip('+');
            p.skipSpaces();
            String more = p.readStringLiteral();
            value += more;
            p.pop();
          } catch (Error t) {
            p.reset();
            break;
          }
        }
        pl("<localized_string Key=\"" + key + "\"");
        pl("                Value=\"" + quote(value) + "\"/>");
      } catch (UnsupportedOperationException t) {
        System.out.println("Error: " + t.getMessage());
        System.out.println("at line " + p.countLine());
        System.out.println("at character " + p.countPos());
        System.exit(1);
      } catch (Error t) {
        // This loop will eventually terminate, since we at least
        // consume ".*Integer" from each iteration.
        p.reset();
      }
    }
    pl("</localized_strings>");
    pl("</configuration>");
    writer.close();
  }
Ejemplo n.º 3
0
  public void doGet(HttpServletRequest request, HttpServletResponse response) {
    log.info("doGet(): " + UsageLog.setupRequestContext(request));
    // System.out.printf("opendap doGet: req=%s%n%s%n", ServletUtil.getRequest(request),
    // ServletUtil.showRequestDetail(this, request));

    String path = null;

    ReqState rs = getRequestState(request, response);

    try {
      path = request.getPathInfo();
      log.debug("doGet path={}", path);

      if (thredds.servlet.Debug.isSet("showRequestDetail"))
        log.debug(ServletUtil.showRequestDetail(this, request));

      if (path == null) {
        log.info(
            "doGet(): "
                + UsageLog.closingMessageForRequestContext(HttpServletResponse.SC_NOT_FOUND, -1));
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
      }

      if (baseURI == null) { // first time, set baseURI
        URI reqURI = ServletUtil.getRequestURI(request);
        // Build base URI from request (rather than hard-coding "/thredds/dodsC/").
        String baseUriString = request.getContextPath() + request.getServletPath() + "/";
        baseURI = reqURI.resolve(baseUriString);
        log.debug("doGet(): baseURI was set = {}", baseURI);
      }

      if (path.endsWith("latest.xml")) {
        DataRootHandler.getInstance().processReqForLatestDataset(this, request, response);
        return;
      }

      // Redirect all catalog requests at the root level.
      if (path.equals("/") || path.equals("/catalog.html") || path.equals("/catalog.xml")) {
        ServletUtil.sendPermanentRedirect(ServletUtil.getContextPath() + path, request, response);
        return;
      }

      // Make sure catalog requests match a dataRoot before trying to handle.
      if (path.endsWith("/") || path.endsWith("/catalog.html") || path.endsWith("/catalog.xml")) {
        if (!DataRootHandler.getInstance().hasDataRootMatch(path)) {
          log.info(
              "doGet(): "
                  + UsageLog.closingMessageForRequestContext(HttpServletResponse.SC_NOT_FOUND, -1));
          response.sendError(HttpServletResponse.SC_NOT_FOUND);
          return;
        }

        if (!DataRootHandler.getInstance().processReqForCatalog(request, response))
          log.error(
              "doGet(): "
                  + UsageLog.closingMessageForRequestContext(
                      ServletUtil.STATUS_FORWARD_FAILURE, -1));

        return;
      }

      if (rs != null) {
        String dataSet = rs.getDataSet();
        String requestSuffix = rs.getRequestSuffix();

        if ((dataSet == null) || dataSet.equals("/") || dataSet.equals("")) {
          doGetDIR(rs);
        } else if (requestSuffix.equalsIgnoreCase("blob")) {
          doGetBLOB(rs);
        } else if (requestSuffix.equalsIgnoreCase("close")) {
          doClose(rs);
        } else if (requestSuffix.equalsIgnoreCase("dds")) {
          doGetDDS(rs);
        } else if (requestSuffix.equalsIgnoreCase("das")) {
          doGetDAS(rs);
        } else if (requestSuffix.equalsIgnoreCase("ddx")) {
          doGetDDX(rs);
        } else if (requestSuffix.equalsIgnoreCase("dods")) {
          doGetDAP2Data(rs);
        } else if (requestSuffix.equalsIgnoreCase("asc")
            || requestSuffix.equalsIgnoreCase("ascii")) {
          doGetASC(rs);
        } else if (requestSuffix.equalsIgnoreCase("info")) {
          doGetINFO(rs);
        } else if (requestSuffix.equalsIgnoreCase("html")
            || requestSuffix.equalsIgnoreCase("htm")) {
          doGetHTML(rs);
        } else if (requestSuffix.equalsIgnoreCase("ver")
            || requestSuffix.equalsIgnoreCase("version")
            || dataSet.equalsIgnoreCase("/version")
            || dataSet.equalsIgnoreCase("/version/")) {
          doGetVER(rs);
        } else if (dataSet.equalsIgnoreCase("/help")
            || dataSet.equalsIgnoreCase("/help/")
            || dataSet.equalsIgnoreCase("/" + requestSuffix)
            || requestSuffix.equalsIgnoreCase("help")) {
          doGetHELP(rs);
        } else {
          sendErrorResponse(response, HttpServletResponse.SC_BAD_REQUEST, "Unrecognized request");
          return;
        }

      } else {
        sendErrorResponse(response, HttpServletResponse.SC_BAD_REQUEST, "Unrecognized request");
        return;
      }

      log.info(UsageLog.closingMessageForRequestContext(HttpServletResponse.SC_OK, -1));

      // plain ol' 404
    } catch (FileNotFoundException e) {
      sendErrorResponse(response, HttpServletResponse.SC_NOT_FOUND, e.getMessage());

      // DAP2Exception bad url
    } catch (BadURLException e) {
      log.info(UsageLog.closingMessageForRequestContext(HttpServletResponse.SC_BAD_REQUEST, -1));
      response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
      dap2ExceptionHandler(e, rs);

      // all other DAP2Exception
    } catch (DAP2Exception de) {
      int status =
          (de.getErrorCode() == DAP2Exception.NO_SUCH_FILE)
              ? HttpServletResponse.SC_NOT_FOUND
              : HttpServletResponse.SC_BAD_REQUEST;
      if ((de.getErrorCode() != DAP2Exception.NO_SUCH_FILE) && (de.getErrorMessage() != null))
        log.debug(de.getErrorMessage());
      log.info(UsageLog.closingMessageForRequestContext(status, -1));
      response.setStatus(status);
      dap2ExceptionHandler(de, rs);

      // parsing, usually the CE
    } catch (ParseException pe) {
      log.info(UsageLog.closingMessageForRequestContext(HttpServletResponse.SC_BAD_REQUEST, -1));
      response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
      parseExceptionHandler(pe, response);

      // 403 - request too big
    } catch (UnsupportedOperationException e) {
      sendErrorResponse(response, HttpServletResponse.SC_FORBIDDEN, e.getMessage());

    } catch (java.net.SocketException e) {
      log.info("SocketException: " + e.getMessage(), e);
      log.info(UsageLog.closingMessageForRequestContext(ServletUtil.STATUS_CLIENT_ABORT, -1));

    } catch (IOException e) {
      String eName =
          e.getClass().getName(); // dont want compile time dependency on ClientAbortException
      if (eName.equals("org.apache.catalina.connector.ClientAbortException")) {
        log.debug("ClientAbortException: " + e.getMessage());
        log.info(UsageLog.closingMessageForRequestContext(ServletUtil.STATUS_CLIENT_ABORT, -1));
        return;
      }

      log.error("path= " + path, e);
      sendErrorResponse(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());

      // everything else
    } catch (Throwable t) {
      log.error("path= " + path, t);
      t.printStackTrace();
      sendErrorResponse(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, t.getMessage());
    }
  }