Java Code Examples for org.apache.commons.vfs2.FileObject#getName()
The following examples show how to use
org.apache.commons.vfs2.FileObject#getName() .
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: ParseResultProcessor.java From spoofax with Apache License 2.0 | 6 votes |
private BehaviorSubject<ParseChange<P>> getUpdates(I unit) { final FileObject resource = unit.source(); final FileName name = resource.getName(); // THREADING: it is possible that two different threads asking for a subject may do the parsing twice here, as // this is not an atomic operation. However, the chance is very low and it does not break anything (only // duplicates some work), so it is acceptable. BehaviorSubject<ParseChange<P>> updates = updatesPerResource.get(name); if(updates == null) { updates = BehaviorSubject.create(); updatesPerResource.put(name, updates); try { logger.trace("Parsing for {}", resource); final P result = syntaxService.parse(unit); updates.onNext(ParseChange.update(result)); } catch(ParseException e) { final String message = String.format("Parsing for %s failed", name); logger.error(message, e); updates.onNext(ParseChange.<P>error(e)); } } return updates; }
Example 2
Source File: Workflow.java From hop with Apache License 2.0 | 6 votes |
/** * Sets the internal hop variables. * * @param space the space in which we want to set the internal variables * @param filename the filename if there is any * @param name the name of the workflow */ public static final void setInternalHopVariables( IVariables space, String filename, String name ) { boolean hasFilename = !Utils.isEmpty( filename ); if ( hasFilename ) { // we have a filename that's defined. try { FileObject fileObject = HopVfs.getFileObject( filename ); FileName fileName = fileObject.getName(); // The filename of the pipeline space.setVariable( Const.INTERNAL_VARIABLE_WORKFLOW_FILENAME_NAME, fileName.getBaseName() ); // The directory of the pipeline FileName fileDir = fileName.getParent(); space.setVariable( Const.INTERNAL_VARIABLE_WORKFLOW_FILENAME_DIRECTORY, fileDir.getURI() ); } catch ( Exception e ) { space.setVariable( Const.INTERNAL_VARIABLE_WORKFLOW_FILENAME_DIRECTORY, "" ); space.setVariable( Const.INTERNAL_VARIABLE_WORKFLOW_FILENAME_NAME, "" ); } } else { space.setVariable( Const.INTERNAL_VARIABLE_WORKFLOW_FILENAME_DIRECTORY, "" ); space.setVariable( Const.INTERNAL_VARIABLE_WORKFLOW_FILENAME_NAME, "" ); } // The name of the workflow space.setVariable( Const.INTERNAL_VARIABLE_WORKFLOW_NAME, Const.NVL( name, "" ) ); }
Example 3
Source File: HopGuiWorkflowGraph.java From hop with Apache License 2.0 | 6 votes |
public String buildTabName() throws HopException { String tabName = null; String realFilename = workflowMeta.environmentSubstitute( workflowMeta.getFilename() ); if ( StringUtils.isEmpty( realFilename ) ) { tabName = workflowMeta.getName(); } else { try { FileObject fileObject = HopVfs.getFileObject( workflowMeta.getFilename() ); FileName fileName = fileObject.getName(); tabName = fileName.getBaseName(); } catch ( Exception e ) { throw new HopException( "Unable to get information from file name '" + workflowMeta.getFilename() + "'", e ); } } return tabName; }
Example 4
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 5
Source File: NullFilesCacheTests.java From commons-vfs with Apache License 2.0 | 6 votes |
@Override public void testBasicCacheOps() throws Exception { final DefaultFileSystemManager manager = getManager(); Assert.assertNotNull("This test should not have a null DefaultFileSystemManager", manager); // the basic test looks different for a null cache: final FilesCache cache = manager.getFilesCache(); final FileObject fo = getWriteFolder().resolveFile("dir1"); final FileName fn = fo.getName(); final FileSystem fs = fo.getFileSystem(); cache.clear(fs); assertNull(cache.getFile(fs, fn)); cache.putFile(fo); assertNull(null, cache.getFile(fs, fn)); assertFalse(cache.putFileIfAbsent(fo)); // hmmm? assertNull(null, cache.getFile(fs, fn)); cache.removeFile(fs, fn); assertNull(cache.getFile(fs, fn)); }
Example 6
Source File: AdvanceOpenPanel.java From otroslogviewer with Apache License 2.0 | 6 votes |
@Override protected Void doInBackground() { try { for (FileObject f : selectedFiles) { if (f.getType() == FileType.FOLDER) { continue; } final FileObjectToImport fileObjectToImport = new FileObjectToImport( f, f.getName(), new FileSize(f.getContent().getSize()), Level.FINEST, OpenMode.FROM_START, CanParse.NOT_TESTED, new PossibleLogImporters()); publish(fileObjectToImport); } return null; } catch (Exception e) { return null; } }
Example 7
Source File: SoftRefFilesCache.java From commons-vfs with Apache License 2.0 | 6 votes |
@Override public boolean putFileIfAbsent(final FileObject fileObject) { if (log.isDebugEnabled()) { log.debug("putFile: " + this.getSafeName(fileObject)); } final Map<FileName, Reference<FileObject>> files = getOrCreateFilesystemCache(fileObject.getFileSystem()); final Reference<FileObject> ref = createReference(fileObject, refQueue); final FileSystemAndNameKey key = new FileSystemAndNameKey(fileObject.getFileSystem(), fileObject.getName()); lock.lock(); try { if (files.containsKey(fileObject.getName()) && files.get(fileObject.getName()).get() != null) { return false; } final Reference<FileObject> old = files.put(fileObject.getName(), ref); if (old != null) { refReverseMap.remove(old); } refReverseMap.put(ref, key); return true; } finally { lock.unlock(); } }
Example 8
Source File: AbstractLayeredFileProvider.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * Creates a layered file system. * * @param scheme The protocol to use. * @param file a FileObject. * @param fileSystemOptions Options to access the FileSystem. * @return A FileObject associated with the new FileSystem. * @throws FileSystemException if an error occurs. */ @Override public synchronized FileObject createFileSystem(final String scheme, final FileObject file, final FileSystemOptions fileSystemOptions) throws FileSystemException { // Check if cached final FileName rootName = file.getName(); FileSystem fs = findFileSystem(rootName, fileSystemOptions); if (fs == null) { // Create the file system fs = doCreateFileSystem(scheme, file, fileSystemOptions); addFileSystem(rootName, fs); } return fs.getRoot(); }
Example 9
Source File: CurrentDirectoryResolver.java From hop with Apache License 2.0 | 5 votes |
/** * The logic of this method: * <p> * We return the child var space with directory extracted from filename * if we do not have a filename we will return the child var space without updates * * @param parentVariables - parent variable space which can be inherited * @param filename - is file which we use at this moment * @return new var space if inherit was set false or child var space with updated system variables */ public IVariables resolveCurrentDirectory( IVariables parentVariables, String filename ) { Variables tmpSpace = new Variables(); tmpSpace.setParentVariableSpace( parentVariables ); tmpSpace.initializeVariablesFrom( parentVariables ); if ( filename != null ) { try { FileObject fileObject = HopVfs.getFileObject( filename ); if ( !fileObject.exists() ) { // don't set variables if the file doesn't exist return tmpSpace; } FileName fileName = fileObject.getName(); // The filename of the pipeline tmpSpace.setVariable( Const.INTERNAL_VARIABLE_WORKFLOW_FILENAME_NAME, fileName.getBaseName() ); // The directory of the pipeline FileName fileDir = fileName.getParent(); tmpSpace.setVariable( Const.INTERNAL_VARIABLE_PIPELINE_FILENAME_DIRECTORY, fileDir.getURI() ); tmpSpace.setVariable( Const.INTERNAL_VARIABLE_WORKFLOW_FILENAME_DIRECTORY, fileDir.getURI() ); tmpSpace.setVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY, fileDir.getURI() ); } catch ( Exception e ) { throw new RuntimeException( "Unable to figure out the current directory", e ); } } return tmpSpace; }
Example 10
Source File: AbstractFileSystem.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * Creates a temporary local copy of a file and its descendants. * * @param file The FileObject to replicate. * @param selector The FileSelector. * @return The replicated File. * @throws FileSystemException if an error occurs. */ @Override public File replicateFile(final FileObject file, final FileSelector selector) throws FileSystemException { if (!FileObjectUtils.exists(file)) { throw new FileSystemException("vfs.provider/replicate-missing-file.error", file.getName()); } try { return doReplicateFile(file, selector); } catch (final Exception e) { throw new FileSystemException("vfs.provider/replicate-file.error", file.getName(), e); } }
Example 11
Source File: TarFileProvider.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * Creates a layered file system. This method is called if the file system is not cached. * * @param scheme The URI scheme. * @param file The file to create the file system on top of. * @return The file system. */ @Override protected FileSystem doCreateFileSystem(final String scheme, final FileObject file, final FileSystemOptions fileSystemOptions) throws FileSystemException { final AbstractFileName rootName = new LayeredFileName(scheme, file.getName(), FileName.ROOT_PATH, FileType.FOLDER); return new TarFileSystem(rootName, file, fileSystemOptions); }
Example 12
Source File: Pipeline.java From hop with Apache License 2.0 | 5 votes |
/** * Sets the internal Hop variables. * * @param var the new internal hop variables */ public void setInternalHopVariables( IVariables var ) { boolean hasFilename = pipelineMeta != null && !Utils.isEmpty( pipelineMeta.getFilename() ); if ( hasFilename ) { // we have a filename that's defined. try { FileObject fileObject = HopVfs.getFileObject( pipelineMeta.getFilename() ); FileName fileName = fileObject.getName(); // The filename of the pipeline variables.setVariable( Const.INTERNAL_VARIABLE_PIPELINE_FILENAME_NAME, fileName.getBaseName() ); // The directory of the pipeline FileName fileDir = fileName.getParent(); variables.setVariable( Const.INTERNAL_VARIABLE_PIPELINE_FILENAME_DIRECTORY, fileDir.getURI() ); } catch ( HopFileException e ) { variables.setVariable( Const.INTERNAL_VARIABLE_PIPELINE_FILENAME_DIRECTORY, "" ); variables.setVariable( Const.INTERNAL_VARIABLE_PIPELINE_FILENAME_NAME, "" ); } } else { variables.setVariable( Const.INTERNAL_VARIABLE_PIPELINE_FILENAME_DIRECTORY, "" ); variables.setVariable( Const.INTERNAL_VARIABLE_PIPELINE_FILENAME_NAME, "" ); } // The name of the pipeline variables.setVariable( Const.INTERNAL_VARIABLE_PIPELINE_NAME, Const.NVL( pipelineMeta.getName(), "" ) ); // Here we don't clear the definition of the workflow specific parameters, as they may come in handy. // A pipeline can be called from a workflow and may inherit the workflow internal variables // but the other around is not possible. setInternalEntryCurrentDirectory( hasFilename ); }
Example 13
Source File: LanguageBuildState.java From spoofax with Apache License 2.0 | 5 votes |
public long add(FileObject resource) { final FileName name = resource.getName(); files.add(name); long newModification; try { newModification = resource.getContent().getLastModifiedTime(); modification.put(name, newModification); } catch(FileSystemException e) { newModification = Long.MAX_VALUE; modification.put(name, Long.MIN_VALUE); } return newModification; }
Example 14
Source File: WeakRefFileListener.java From commons-vfs with Apache License 2.0 | 4 votes |
protected WeakRefFileListener(final FileObject file, final FileListener listener) { this.fs = file.getFileSystem(); this.name = file.getName(); this.listener = new WeakReference<>(listener); }
Example 15
Source File: Trans.java From pentaho-kettle with Apache License 2.0 | 4 votes |
/** * Sets the internal kettle variables. * * @param var the new internal kettle variables */ public void setInternalKettleVariables( VariableSpace var ) { boolean hasFilename = transMeta != null && !Utils.isEmpty( transMeta.getFilename() ); if ( hasFilename ) { // we have a finename that's defined. try { FileObject fileObject = KettleVFS.getFileObject( transMeta.getFilename(), var ); FileName fileName = fileObject.getName(); // The filename of the transformation variables.setVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_NAME, fileName.getBaseName() ); // The directory of the transformation FileName fileDir = fileName.getParent(); variables.setVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_DIRECTORY, fileDir.getURI() ); } catch ( KettleFileException e ) { variables.setVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_DIRECTORY, "" ); variables.setVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_NAME, "" ); } } else { variables.setVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_DIRECTORY, "" ); variables.setVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_NAME, "" ); } boolean hasRepoDir = transMeta.getRepositoryDirectory() != null && transMeta.getRepository() != null; // The name of the transformation variables.setVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_NAME, Const.NVL( transMeta.getName(), "" ) ); // setup fallbacks if ( hasRepoDir ) { variables.setVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_DIRECTORY, variables.getVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_REPOSITORY_DIRECTORY ) ); } else { variables.setVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_REPOSITORY_DIRECTORY, variables.getVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_DIRECTORY ) ); } // TODO PUT THIS INSIDE OF THE "IF" // The name of the directory in the repository variables.setVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_REPOSITORY_DIRECTORY, transMeta .getRepositoryDirectory() != null ? transMeta.getRepositoryDirectory().getPath() : "" ); // Here we don't clear the definition of the job specific parameters, as they may come in handy. // A transformation can be called from a job and may inherit the job internal variables // but the other around is not possible. if ( hasRepoDir ) { variables.setVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY, variables.getVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_REPOSITORY_DIRECTORY ) ); if ( "/".equals( variables.getVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY ) ) ) { variables.setVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY, "" ); } } setInternalEntryCurrentDirectory( hasFilename, hasRepoDir ); }
Example 16
Source File: AbstractFileObject.java From commons-vfs with Apache License 2.0 | 4 votes |
/** * Moves (rename) the file to another one. * * @param destFile The target FileObject. * @throws FileSystemException if an error occurs. */ @Override public void moveTo(final FileObject destFile) throws FileSystemException { if (canRenameTo(destFile)) { if (!getParent().isWriteable()) { throw new FileSystemException("vfs.provider/rename-parent-read-only.error", getName(), getParent().getName()); } } else { if (!isWriteable()) { throw new FileSystemException("vfs.provider/rename-read-only.error", getName()); } } if (destFile.exists() && !isSameFile(destFile)) { destFile.deleteAll(); // throw new FileSystemException("vfs.provider/rename-dest-exists.error", destFile.getName()); } if (canRenameTo(destFile)) { // issue rename on same filesystem try { attach(); // remember type to avoid attach final FileType srcType = getType(); doRename(destFile); FileObjectUtils.getAbstractFileObject(destFile).handleCreate(srcType); destFile.close(); // now the destFile is no longer imaginary. force reattach. handleDelete(); // fire delete-events. This file-object (src) is like deleted. } catch (final RuntimeException re) { throw re; } catch (final Exception exc) { throw new FileSystemException("vfs.provider/rename.error", exc, getName(), destFile.getName()); } } else { // different fs - do the copy/delete stuff destFile.copyFrom(this, Selectors.SELECT_SELF); if ((destFile.getType().hasContent() && destFile.getFileSystem().hasCapability(Capability.SET_LAST_MODIFIED_FILE) || destFile.getType().hasChildren() && destFile.getFileSystem().hasCapability(Capability.SET_LAST_MODIFIED_FOLDER)) && fileSystem.hasCapability(Capability.GET_LAST_MODIFIED)) { destFile.getContent().setLastModifiedTime(this.getContent().getLastModifiedTime()); } deleteSelf(); } }
Example 17
Source File: SpoofaxIgnoresSelector.java From spoofax with Apache License 2.0 | 4 votes |
@Override public boolean traverseDescendents(FileSelectInfo fileInfo) throws Exception { final int depth = fileInfo.getDepth(); final FileObject resource = fileInfo.getFile(); final FileName name = resource.getName(); final String base = name.getBaseName(); switch(depth) { case 1: switch(base) { case "include": // Spoofax/Stratego case ".cache": // Spoofax/Stratego case "bin": // Eclipse case ".settings": // Eclipse case "target": // Maven case ".mvn": // Maven case "build": // Gradle case ".gradle": // Gradle case "out": // IntelliJ case ".idea": // IntelliJ case ".git": // Git return false; } break; case 3: switch(base) { // Ignore editor/java/trans and src-gen/stratego-java/trans. case "trans": { final FileObject parent1 = resource.getParent(); if(parent1 != null) { final String parent1base = parent1.getName().getBaseName(); if(parent1base.equals("java") || parent1base.equals("stratego-java")) { final FileObject parent2 = parent1.getParent(); if(parent2 != null) { final String parent2base = parent2.getName().getBaseName(); return !(parent2base.equals("editor") || parent2base.equals("src-gen")); } } } break; } } break; } return true; }
Example 18
Source File: FileNamePerformance.java From commons-vfs with Apache License 2.0 | 3 votes |
public static void main(final String[] args) throws FileSystemException { final FileSystemManager mgr = VFS.getManager(); final FileObject root = mgr.resolveFile("smb://HOME\\vfsusr:vfs%2f%25\\te:[email protected]/vfsusr"); final FileName rootName = root.getName(); testNames(mgr, rootName); testChildren(root); testFiles(mgr); }
Example 19
Source File: JarFileProvider.java From commons-vfs with Apache License 2.0 | 3 votes |
/** * Creates a layered file system. This method is called if the file system is not cached. * * @param scheme The URI scheme. * @param file The file to create the file system on top of. * @return The file system. */ @Override protected FileSystem doCreateFileSystem(final String scheme, final FileObject file, final FileSystemOptions fileSystemOptions) throws FileSystemException { final AbstractFileName name = new LayeredFileName(scheme, file.getName(), FileName.ROOT_PATH, FileType.FOLDER); return new JarFileSystem(name, file, fileSystemOptions); }
Example 20
Source File: CompressedFileFileProvider.java From commons-vfs with Apache License 2.0 | 3 votes |
/** * Creates a layered file system. This method is called if the file system is not cached. * * @param scheme The URI scheme. * @param file The file to create the file system on top of. * @return The file system. */ @Override protected FileSystem doCreateFileSystem(final String scheme, final FileObject file, final FileSystemOptions fileSystemOptions) throws FileSystemException { final FileName name = new LayeredFileName(scheme, file.getName(), FileName.ROOT_PATH, FileType.FOLDER); return createFileSystem(name, file, fileSystemOptions); }