Exemplo n.º 1
0
  /**
   * Creates a new FTPFile instance by converting the given file: URI into an abstract pathname.
   *
   * <p>FTP URI protocol:<br>
   * ftp:// [ userName [ : password ] @ ] host [ : port ][ / path ]
   *
   * <p>example:<br>
   * ftp://[email protected]:21/pub/testfile.txt
   *
   * @param uri An absolute, hierarchical URI using a supported scheme.
   * @throws NullPointerException if <code>uri</code> is <code>null</code>.
   * @throws IllegalArgumentException If the preconditions on the parameter do not hold.
   */
  public FTPFile(URI uri) throws IOException, URISyntaxException {
    super(uri);

    if (uri.getScheme().equals("ftp")) {
      String userinfo = uri.getUserInfo();
      if (userinfo != null) {
        int index = userinfo.indexOf(":");
        if (index >= 0) {
          setFileSystem(
              new FTPFileSystem(
                  new FTPAccount(
                      uri.getHost(),
                      uri.getPort(),
                      userinfo.substring(0, index - 1),
                      userinfo.substring(index + 1),
                      uri.getPath())));
        } else {
          setFileSystem(
              new FTPFileSystem(
                  new FTPAccount(uri.getHost(), uri.getPort(), userinfo, "", uri.getPath())));
        }
      } else {
        fileSystem =
            new FTPFileSystem(
                new FTPAccount(uri.getHost(), uri.getPort(), null, "", uri.getPath()));
      }

      setFileName(uri.getPath());
      ftpClient = ((FTPFileSystem) fileSystem).getFTPClient();
    } else {
      throw new URISyntaxException(uri.toString(), "Wrong URI scheme");
    }
  }
Exemplo n.º 2
0
  @Override
  public void chatLinkClicked(URI url) {
    String action = url.getPath();
    if (action.equals("/SHOWPREVIEW")) {
      enableReplacement.setSelected(cfg.getBoolean(ReplacementProperty.REPLACEMENT_ENABLE, true));
      enableReplacementProposal.setSelected(
          cfg.getBoolean(ReplacementProperty.REPLACEMENT_PROPOSAL, true));

      currentMessageID = url.getQuery();
      currentLinkPosition = url.getFragment();

      this.setVisible(true);
      this.setLocationRelativeTo(chatPanel);
    }
  }
Exemplo n.º 3
0
 private void setResponseLocationHeader(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException {
   URI requestURI = ServletResourceHandler.getURI(req);
   String responsePath =
       "/"
           + new Path(requestURI.getPath()).segment(0)
           + "/import/"
           + id; //$NON-NLS-1$ //$NON-NLS-2$
   URI responseURI;
   try {
     responseURI =
         new URI(requestURI.getScheme(), requestURI.getAuthority(), responsePath, null, null);
   } catch (URISyntaxException e) {
     // should not be possible
     throw new ServletException(e);
   }
   resp.setHeader(ProtocolConstants.HEADER_LOCATION, responseURI.toString());
 }
Exemplo n.º 4
0
 private boolean identifyNewCommitResource(
     HttpServletRequest request, HttpServletResponse response, Repository db, String newCommit)
     throws ServletException {
   try {
     URI u = getURI(request);
     IPath p = new Path(u.getPath());
     IPath np = new Path("/"); // $NON-NLS-1$
     for (int i = 0; i < p.segmentCount(); i++) {
       String s = p.segment(i);
       if (i == 2) {
         s += ".." + newCommit; // $NON-NLS-1$
       }
       np = np.append(s);
     }
     if (p.hasTrailingSeparator()) np = np.addTrailingSeparator();
     URI nu =
         new URI(
             u.getScheme(),
             u.getUserInfo(),
             u.getHost(),
             u.getPort(),
             np.toString(),
             u.getQuery(),
             u.getFragment());
     JSONObject result = new JSONObject();
     result.put(ProtocolConstants.KEY_LOCATION, nu);
     OrionServlet.writeJSONResponse(
         request, response, result, JsonURIUnqualificationStrategy.ALL_NO_GIT);
     response.setHeader(
         ProtocolConstants.HEADER_LOCATION, resovleOrionURI(request, nu).toString());
     return true;
   } catch (Exception e) {
     return statusHandler.handleRequest(
         request,
         response,
         new ServerStatus(
             IStatus.ERROR,
             HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
             "An error occured when identifying a new Commit resource.",
             e));
   }
 }
Exemplo n.º 5
0
 public static String convertUrlToBaseStringURI(URL url) {
   URI uri = null;
   try {
     uri = url.toURI();
   } catch (URISyntaxException e1) {
     e1.printStackTrace();
   }
   String scheme = uri.getScheme().toLowerCase();
   String host = uri.getHost().toLowerCase();
   int port = uri.getPort();
   if ((scheme.equals(HTTP_PROTOCOL) && port == HTTP_DEFAULT_PORT)
       || (scheme.equals(HTTPS_PROTOCOL) && port == HTTPS_DEFAULT_PORT)) {
     port = -1;
   }
   URI baseUri = null;
   try {
     baseUri = new URI(scheme, null, host, port, uri.getPath(), null, null);
   } catch (URISyntaxException e) {
     e.printStackTrace();
   }
   return baseUri.toString();
 }
Exemplo n.º 6
0
 FileContent(URI uri) {
   fn = new File(ROOT, uri.getPath().replace('/', File.separatorChar));
 }