Package com.adito.vfs.utils

Examples of com.adito.vfs.utils.URI


    public URI getRootVFSURI(String charset) throws MalformedURIException {
      File baseDir = new File(siteDir, "icons");
      if(!baseDir.exists()) {
        baseDir.mkdirs();
      }
      return new URI(baseDir.toURI().toString());
    }
View Full Code Here


      }
      return new URI(baseDir.toURI().toString());
    }

    protected FileObject createVFSFileObject(String path, PasswordCredentials credentials) throws IOException {
      URI uri = getRootVFSURI();
      uri.setPath(DAVUtilities.concatenatePaths(uri.getPath(), path));
      FileObject root = getStore().getRepository().getFileSystemManager().resolveFile(uri.toString());
      return root;
    }
View Full Code Here

     */
    public FileObject createVFSFileObject(String path, PasswordCredentials credentials/*, DAVTransaction transaction*/) throws IOException, DAVAuthenticationRequiredException {

        super.getStore().getName();
       
        URI uri = getRootVFSURI(SystemProperties.get("jcifs.encoding", "cp860"));

        try {
            uri.setScheme("smb");
            if (credentials != null) {
                uri.setUserinfo(DAVUtilities.encodeURIUserInfo(credentials.getUsername() + (credentials.getPassword() != null ? ":" + new String(credentials.getPassword()) : "")));
            }
            uri.setPath(uri.getPath() + (uri.getPath().endsWith("/") ? "" : "/") + DAVUtilities.encodePath(path, SystemProperties.get("jcifs.encoding", "cp860")));
            FileObject root = getStore().getRepository().getFileSystemManager().resolveFile(uri.toString());
            if (root.getType().equals(FileType.FOLDER)) {
                // Extra check so that the correct exception is thrown.
                root.getChildren();
            }
            return root;
        } catch (FileSystemException fse) {
            if (fse.getCause().getClass().getName().equals("jcifs.smb.SmbAuthException")) {
                throw new DAVAuthenticationRequiredException(getMountString());
            }
            if (fse.getCause() != null && fse.getCause() instanceof SmbException && ((SmbException) fse.getCause()).getRootCause() != null
                            && "Connection timeout".equals(((SmbException) fse.getCause()).getRootCause().getMessage())) {
                throw new UnknownHostException(uri.getHost());
            }
            if(log.isDebugEnabled())
                log.debug("File system exception! ", fse);
            throw fse;
        }
View Full Code Here

    /* (non-Javadoc)
     * @see com.adito.networkplaces.AbstractNetworkPlaceMount#createVFSFileObject(java.lang.String, com.adito.security.PasswordCredentials)
     */
    public FileObject createVFSFileObject(String path, PasswordCredentials credentials) throws IOException {
        URI uri = getRootVFSURI();
        String uriPath = uri.getPath();
        if(!uriPath.contains("!")) {
          uriPath = DAVUtilities.stripTrailingSlash(uriPath) + "!/./";
        }
        uriPath = uriPath.replace('\\', '/');
        if(uriPath.matches("^[a-zA-Z]?\\:/")) {
           
        }       
        String newPath = DAVUtilities.concatenatePaths(uriPath, path);
        uri.setPath(newPath);
        FileObject root = getStore().getRepository().getFileSystemManager().resolveFile(uri.toString());
        return root;
    }
View Full Code Here

        }
      }

      // User info from URI
      if (type == 1) {
        URI uri = getRootVFSURI(store.getEncoding());
        String userInfo = uri.getUserinfo();
        if (userInfo == null || userInfo.equals("")) {
          type++;
        } else {
          String username = null;
          char[] pw = null;
View Full Code Here

   
    // Fragment. TODO we need to support
    String fragment = null;

    // Create the URI
    URI uri = new URI(getNetworkPlace().getScheme(), userinfo, host, port, path, queryString, fragment);
    if(log.isDebugEnabled())
      log.debug("Creating URI " + VfsUtils.maskSensitiveArguments(uri.toString()));
    return uri;
  }
View Full Code Here

        }
      }

      // User info from URI
      if (type == 1) {
        URI uri = getRootVFSURI(store.getEncoding());
        String userInfo = uri.getUserinfo();
        if (userInfo == null || userInfo.equals("")) {
          type++;
        } else {
          String username = null;
          char[] pw = null;
View Full Code Here

    try {
      String userInfo = URLUTF8Encoder.encode(np.getUsername(), false);
      if(!Util.isNullOrTrimmedBlank(np.getPassword())) {
        userInfo = URLUTF8Encoder.encode(np.getUsername(), false);
      }
        URI uri = new URI(np.getScheme(), userInfo, np.getHost(), np.getPort(), np.getPath(), null, null);
        return uri;
    }
    catch(Exception e) {
      throw new IllegalArgumentException("Could not create URI.");
    }
View Full Code Here

            NetworkPlace np = (NetworkPlace) i.next();
            try {
                VFSProvider provider = VFSProviderManager.getInstance().getProvider(np.getScheme());
                if (provider == null) {
                  if(np.getScheme().equals("")) {
                  URI uri = createURIForPath(np.getPath());
                  provider = VFSProviderManager.getInstance().getProvider(uri.getScheme());
                  }
                  if(provider == null)
                    throw new Exception("No provider for network place URI " + np.getPath());
                }
                if (np.getType() != NetworkPlace.TYPE_HIDDEN) {
View Full Code Here

          ReplacementEngine engine = new ReplacementEngine();
          engine.addPattern(NetworkPlaceInstall.VARIABLE_PATTERN, r, null);
          path = engine.replace(path);
         
          //
          URI newUri = null;
     
      // Is it a UNC path
      if(path.startsWith("\\\\")) {
        try {
          newUri = new URI("smb:" + path.replace('\\', '/'));
        }
        catch(MalformedURIException murie) {
          murie.printStackTrace();
        }
      }
     
      // Is this a supported RI?
      if(newUri == null) {
        int idx = path.indexOf(':');
        if(idx > 1) { // index of 1 would mean a windows absolute path           
          // Is it an non windows absolute file URI?
          String rpath = path.substring(idx + 1);
          String scheme = path.substring(0, idx);
          if(scheme.equals("file")) {
            if(rpath.startsWith("//") && !rpath.startsWith("///") &&
                    ( rpath.length() < 4 || rpath.charAt(3) != ':' ) ) {
              path = scheme + ":/" + rpath;
            }
          }
         
          newUri = new URI(path);         
        }
      }
     
      // Is it a local file? (wont work for replacements)
      boolean switchSlash = false;
      if(newUri == null) {   
          if(path.contains("\\")) {
            switchSlash = true;
          }
          try {
                    String scheme;
                    if(path.toLowerCase().endsWith(".jar")) {
                        scheme = "jar";
                    } else if(path.toLowerCase().endsWith(".zip")) {
                        scheme = "zip";
                    } else {
                        scheme = "file";
                    }
          newUri = new URI(scheme + ":///" + DAVUtilities.stripLeadingSlash(path.replace('\\', '/')));
        } catch (MalformedURIException e) {
          e.printStackTrace();
        }
      }
     
      // Convert the network place if required
      if(newUri != null) {
            engine = new ReplacementEngine();
 
       
        r = new Replacer() {
          public String getReplacement(Pattern pattern, Matcher matcher, String replacementPattern) {
                String match = matcher.group();
                String key = match.substring(11, match.length() - 1);
                try {
                    int idx = key.indexOf("_");
                    if (idx == -1) {
                        throw new Exception("String replacement pattern is in incorrect format for " + key
                            + ". Must be <TYPE>:<key>");
                    }
                    String type = key.substring(0, idx);
                    key = key.substring(idx + 1);
                    return "${" + type + ":" + key + "}";
                }
                catch(Exception e) {
                  NetworkPlaceInstall.log.error("Failed to replace.", e);
                }
                return "prototype";
          }
         
        };
            engine.addPattern(NetworkPlaceInstall.PROTOTYPE_PATTERN, r, null);
            String newScheme = newUri.getScheme();
            String newHost = newUri.getHost();
            if(!Util.isNullOrTrimmedBlank(newHost)) {
              newHost = engine.replace(newHost);
            }
            int newPort = Math.max(newUri.getPort(), 0);
            String newPath = newUri.getPath();
            if(!Util.isNullOrTrimmedBlank(newPath)) {
              newPath = Util.urlDecode(engine.replace(newPath));
            }
            if(newPath.startsWith("/") && newPath.length() > 2 && newPath.charAt(2) == ':') {
              newPath = newPath.substring(1);
            }
            if(switchSlash) {
              newPath = newPath.replace('/', '\\');
            }
            String newFragment = newUri.getFragment();
            if(!Util.isNullOrTrimmedBlank(newFragment)) {
              newFragment = engine.replace(newFragment);
            }
            String newUserinfo = newUri.getUserinfo();
        int idx = newUserinfo == null ? -1 : newUserinfo.indexOf(':');
        String newUsername = newUserinfo;
        String newPassword = "";
        if(idx != -1) {
          newPassword = newUsername.substring(idx + 1);
View Full Code Here

TOP

Related Classes of com.adito.vfs.utils.URI

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.