Java Code Examples for org.apache.commons.vfs2.FileName#getRootURI()
The following examples show how to use
org.apache.commons.vfs2.FileName#getRootURI() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HopVfs.java From hop with Apache License 2.0 | 6 votes |
public static String getFilename( FileObject fileObject ) { FileName fileName = fileObject.getName(); String root = fileName.getRootURI(); if ( !root.startsWith( "file:" ) ) { return fileName.getURI(); // nothing we can do about non-normal files. } if ( root.startsWith( "file:////" ) ) { return fileName.getURI(); // we'll see 4 forward slashes for a windows/smb network share } if ( root.endsWith( ":/" ) ) { // Windows root = root.substring( 8, 10 ); } else { // *nix & OSX root = ""; } String fileString = root + fileName.getPath(); if ( !"/".equals( Const.FILE_SEPARATOR ) ) { fileString = Const.replace( fileString, "/", Const.FILE_SEPARATOR ); } return fileString; }
Example 2
Source File: KettleVFS.java From pentaho-kettle with Apache License 2.0 | 6 votes |
public static String getFilename( FileObject fileObject ) { FileName fileName = fileObject.getName(); String root = fileName.getRootURI(); if ( !root.startsWith( "file:" ) ) { return fileName.getURI(); // nothing we can do about non-normal files. } if ( root.startsWith( "file:////" ) ) { return fileName.getURI(); // we'll see 4 forward slashes for a windows/smb network share } if ( root.endsWith( ":/" ) ) { // Windows root = root.substring( 8, 10 ); } else { // *nix & OSX root = ""; } String fileString = root + fileName.getPath(); if ( !"/".equals( Const.FILE_SEPARATOR ) ) { fileString = Const.replace( fileString, "/", Const.FILE_SEPARATOR ); } return fileString; }
Example 3
Source File: AccessInputMeta.java From pentaho-kettle with Apache License 2.0 | 6 votes |
public static String getFilename( FileObject fileObject ) { FileName fileName = fileObject.getName(); String root = fileName.getRootURI(); if ( !root.startsWith( "file:" ) ) { return fileName.getURI(); } if ( root.endsWith( ":/" ) ) { root = root.substring( 8, 10 ); } else { root = root.substring( 7, root.length() - 1 ); } String fileString = root + fileName.getPath(); if ( !"/".equals( Const.FILE_SEPARATOR ) ) { fileString = Const.replace( fileString, "/", Const.FILE_SEPARATOR ); } return fileString; }
Example 4
Source File: GoogleDriveFileSystem.java From hop with Apache License 2.0 | 5 votes |
private synchronized FileObject processFile( FileName name, boolean useCache ) throws FileSystemException { if ( !super.getRootName().getRootURI().equals( name.getRootURI() ) ) { throw new FileSystemException( "vfs.provider/mismatched-fs-for-name.error", new Object[] { name, super.getRootName(), name.getRootURI() } ); } else { FileObject file; if ( useCache ) { file = super.getFileFromCache( name ); } else { file = null; } if ( file == null ) { try { file = this.createFile( (AbstractFileName) name ); } catch ( Exception e ) { throw new FileSystemException( "Unable to get Google Drive file object for '"+name+"'", e ); } file = super.decorateFileObject( file ); if ( useCache ) { super.putFileToCache( file ); } } if ( super.getFileSystemManager().getCacheStrategy().equals( CacheStrategy.ON_RESOLVE ) ) { file.refresh(); } return file; } }
Example 5
Source File: ActionCopyFiles.java From hop with Apache License 2.0 | 5 votes |
public String getUrlPath( String incomingURL ) { String path = null; try { String noVariablesURL = incomingURL.replaceAll( "[${}]", "/" ); FileName fileName = HopVfs.getFileSystemManager().resolveURI( noVariablesURL ); String root = fileName.getRootURI(); path = incomingURL.substring( root.length() - 1 ); } catch ( FileSystemException e ) { path = null; } return path; }
Example 6
Source File: AbstractFileSystem.java From commons-vfs with Apache License 2.0 | 5 votes |
private synchronized FileObject resolveFile(final FileName name, final boolean useCache) throws FileSystemException { if (!rootName.getRootURI().equals(name.getRootURI())) { throw new FileSystemException("vfs.provider/mismatched-fs-for-name.error", name, rootName, name.getRootURI()); } // [email protected] ==> use getFileFromCache FileObject file; if (useCache) { file = getFileFromCache(name); } else { file = null; } if (file == null) { try { file = createFile((AbstractFileName) name); } catch (final Exception e) { throw new FileSystemException("vfs.provider/resolve-file.error", name, e); } file = decorateFileObject(file); // [email protected] ==> use putFileToCache if (useCache) { putFileToCache(file); } } /** * resync the file information if requested */ if (getFileSystemManager().getCacheStrategy().equals(CacheStrategy.ON_RESOLVE)) { file.refresh(); } return file; }
Example 7
Source File: JobEntryCopyFiles.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public String getUrlPath( String incomingURL ) { String path = null; try { String noVariablesURL = incomingURL.replaceAll( "[${}]", "/" ); FileName fileName = KettleVFS.getInstance().getFileSystemManager().resolveURI( noVariablesURL ); String root = fileName.getRootURI(); path = incomingURL.substring( root.length() - 1 ); } catch ( FileSystemException e ) { path = null; } return path; }
Example 8
Source File: GoogleDriveFileSystem.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private synchronized FileObject processFile( FileName name, boolean useCache ) throws FileSystemException { if ( !super.getRootName().getRootURI().equals( name.getRootURI() ) ) { throw new FileSystemException( "vfs.provider/mismatched-fs-for-name.error", new Object[] { name, super.getRootName(), name.getRootURI() } ); } else { FileObject file; if ( useCache ) { file = super.getFileFromCache( name ); } else { file = null; } if ( file == null ) { try { file = this.createFile( (AbstractFileName) name ); } catch ( Exception var5 ) { return null; } file = super.decorateFileObject( file ); if ( useCache ) { super.putFileToCache( file ); } } if ( super.getFileSystemManager().getCacheStrategy().equals( CacheStrategy.ON_RESOLVE ) ) { file.refresh(); } return file; } }
Example 9
Source File: DefaultFileSystemManager.java From commons-vfs with Apache License 2.0 | 4 votes |
/** * Resolves a name, relative to the root. * * @param base the base file name * @param name the name * @param scope the {@link NameScope} * @return The FileName of the file. * @throws FileSystemException if an error occurs. */ @Override public FileName resolveName(final FileName base, final String name, final NameScope scope) throws FileSystemException { FileSystemException.requireNonNull(base, "Invalid base FileName."); FileSystemException.requireNonNull(name, "Invalid name FileName."); final FileName realBase; if (VFS.isUriStyle() && base.isFile()) { realBase = base.getParent(); } else { realBase = base; } final StringBuilder buffer = new StringBuilder(name); // Adjust separators UriParser.fixSeparators(buffer); String scheme = UriParser.extractScheme(getSchemes(), buffer.toString()); // Determine whether to prepend the base path if (name.length() == 0 || (scheme == null && buffer.charAt(0) != FileName.SEPARATOR_CHAR)) { // Supplied path is not absolute if (!VFS.isUriStyle()) { // when using URIs the parent already do have the trailing "/" buffer.insert(0, FileName.SEPARATOR_CHAR); } buffer.insert(0, realBase.getPath()); } // Normalise the path final FileType fileType = UriParser.normalisePath(buffer); // Check the name is ok final String resolvedPath = buffer.toString(); if (!AbstractFileName.checkName(realBase.getPath(), resolvedPath, scope)) { throw new FileSystemException("vfs.provider/invalid-descendent-name.error", name); } String fullPath; if (scheme != null) { fullPath = resolvedPath; } else { scheme = realBase.getScheme(); fullPath = realBase.getRootURI() + resolvedPath; } final FileProvider provider = providers.get(scheme); if (provider != null) { // TODO: extend the file name parser to be able to parse // only a pathname and take the missing informations from // the base. Then we can get rid of the string operation. // // String fullPath = base.getRootURI() + // resolvedPath.substring(1); return provider.parseUri(realBase, fullPath); } // An unknown scheme - hand it to the default provider - if possible if (scheme != null && defaultProvider != null) { return defaultProvider.parseUri(realBase, fullPath); } // TODO: avoid fallback to this point // this happens if we have a virtual filesystem (no provider for scheme) return ((AbstractFileName) realBase).createName(resolvedPath, fileType); }