Java Code Examples for org.apache.commons.vfs2.FileName#getParent()
The following examples show how to use
org.apache.commons.vfs2.FileName#getParent() .
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: 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 2
Source File: JCRSolutionFileModel.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
protected String[] computeFileNames( FileName file ) { final FastStack<String> stack = new FastStack<String>(); while ( file != null ) { String name; try { name = URLDecoder.decode( file.getBaseName().trim().replaceAll( "\\+", "%2B" ), "UTF-8" ); } catch ( UnsupportedEncodingException e ) { name = file.getBaseName().trim(); } if ( !"".equals( name ) ) { stack.push( name ); } file = file.getParent(); } final int size = stack.size(); final String[] result = new String[ size ]; for ( int i = 0; i < result.length; i++ ) { result[ i ] = stack.pop(); } return result; }
Example 3
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 4
Source File: PipelineMeta.java From hop with Apache License 2.0 | 5 votes |
/** * Sets the internal filename hop variables. * * @param var the new internal filename hop variables */ @Override protected void setInternalFilenameHopVariables( IVariables var ) { // If we have a filename that's defined, set variables. If not, clear them. // if ( !Utils.isEmpty( filename ) ) { try { FileObject fileObject = HopVfs.getFileObject( filename ); 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 ) { log.logError( "Unexpected error setting internal filename variables!", 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, "" ); } setInternalEntryCurrentDirectory(); }
Example 5
Source File: WorkflowMeta.java From hop with Apache License 2.0 | 5 votes |
/** * Sets the internal filename hop variables. * * @param var the new internal filename hop variables */ @Override protected void setInternalFilenameHopVariables( IVariables var ) { if ( filename != null ) { // we have a filename that's defined. try { FileObject fileObject = HopVfs.getFileObject( filename ); FileName fileName = fileObject.getName(); // The filename of the workflow variables.setVariable( Const.INTERNAL_VARIABLE_WORKFLOW_FILENAME_NAME, fileName.getBaseName() ); // The directory of the workflow FileName fileDir = fileName.getParent(); variables.setVariable( Const.INTERNAL_VARIABLE_WORKFLOW_FILENAME_DIRECTORY, fileDir.getURI() ); } catch ( Exception e ) { variables.setVariable( Const.INTERNAL_VARIABLE_WORKFLOW_FILENAME_DIRECTORY, "" ); variables.setVariable( Const.INTERNAL_VARIABLE_WORKFLOW_FILENAME_NAME, "" ); } } else { variables.setVariable( Const.INTERNAL_VARIABLE_WORKFLOW_FILENAME_DIRECTORY, "" ); variables.setVariable( Const.INTERNAL_VARIABLE_WORKFLOW_FILENAME_NAME, "" ); } setInternalEntryCurrentDirectory(); }
Example 6
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 7
Source File: JCRSolutionDirectFileModel.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
private FastStack<String> stackName( FileName fullName ) { final FastStack<String> stack = new FastStack<String>(); while ( fullName != null ) { final String name = fullName.getBaseName().trim(); if ( !name.equals( "" ) ) { stack.push( name ); } fullName = fullName.getParent(); } return stack; }
Example 8
Source File: XmlSolutionFileModel.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
protected String[] computeFileNames( FileName file ) { final FastStack stack = new FastStack(); while ( file != null ) { final String name = file.getBaseName(); stack.push( name ); file = file.getParent(); } final int size = stack.size(); final String[] result = new String[ size ]; for ( int i = 0; i < result.length; i++ ) { result[ i ] = (String) stack.pop(); } return result; }
Example 9
Source File: AbstractFileName.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * find the root of the file system. * * @return The root FileName. */ @Override public FileName getRoot() { FileName root = this; while (root.getParent() != null) { root = root.getParent(); } return root; }
Example 10
Source File: JobMeta.java From pentaho-kettle with Apache License 2.0 | 5 votes |
/** * Sets the internal filename kettle variables. * * @param var the new internal filename kettle variables */ @Override protected void setInternalFilenameKettleVariables( VariableSpace var ) { if ( filename != null ) { // we have a filename that's defined. try { FileObject fileObject = KettleVFS.getFileObject( filename, var ); FileName fileName = fileObject.getName(); // The filename of the job variables.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_NAME, fileName.getBaseName() ); // The directory of the job FileName fileDir = fileName.getParent(); variables.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, fileDir.getURI() ); } catch ( Exception e ) { variables.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, "" ); variables.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_NAME, "" ); } } else { variables.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, "" ); variables.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_NAME, "" ); } setInternalEntryCurrentDirectory(); }
Example 11
Source File: CurrentDirectoryResolver.java From pentaho-kettle with Apache License 2.0 | 5 votes |
/** * The logic of this method: * * if we have directory we return the child var space with directory used as system property * if we have not directory we return the child var space with directory extracted from filanme * if we don not have directory and filename we will return the child var space without updates * * * @param parentVariables - parent variable space which can be inherited * @param directory - current path which will be used as path for start trans/job * @param filename - is file which we use at this moment * @param inheritParentVar - flag which indicate should we inherit variables from parent var space to child var space * @return new var space if inherit was set false or child var space with updated system variables */ public VariableSpace resolveCurrentDirectory( VariableSpace parentVariables, RepositoryDirectoryInterface directory, String filename ) { Variables tmpSpace = new Variables(); tmpSpace.setParentVariableSpace( parentVariables ); tmpSpace.initializeVariablesFrom( parentVariables ); if ( directory != null ) { tmpSpace.setVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY, directory.toString() ); tmpSpace.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, directory.toString() ); tmpSpace.setVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_DIRECTORY, directory.toString() ); } else if ( filename != null ) { try { FileObject fileObject = KettleVFS.getFileObject( filename, tmpSpace ); if ( !fileObject.exists() ) { // don't set variables if the file doesn't exist return tmpSpace; } FileName fileName = fileObject.getName(); // The filename of the transformation tmpSpace.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_NAME, fileName.getBaseName() ); // The directory of the transformation FileName fileDir = fileName.getParent(); tmpSpace.setVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_DIRECTORY, fileDir.getURI() ); tmpSpace.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, fileDir.getURI() ); tmpSpace.setVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY, fileDir.getURI() ); } catch ( Exception e ) { } } return tmpSpace; }
Example 12
Source File: VirtualFileSystem.java From commons-vfs with Apache License 2.0 | 4 votes |
/** * Adds a junction to this file system. * * @param junctionPoint The location of the junction. * @param targetFile The target file to base the junction on. * @throws FileSystemException if an error occurs. */ @Override public void addJunction(final String junctionPoint, final FileObject targetFile) throws FileSystemException { final FileName junctionName = getFileSystemManager().resolveName(getRootName(), junctionPoint); // Check for nested junction - these are not supported yet if (getJunctionForFile(junctionName) != null) { throw new FileSystemException("vfs.impl/nested-junction.error", junctionName); } try { // Add to junction table junctions.put(junctionName, targetFile); // Attach to file final DelegateFileObject junctionFile = (DelegateFileObject) getFileFromCache(junctionName); if (junctionFile != null) { junctionFile.setFile(targetFile); } // Create ancestors of junction point FileName childName = junctionName; boolean done = false; for (AbstractFileName parentName = (AbstractFileName) childName.getParent(); !done && parentName != null; childName = parentName, parentName = (AbstractFileName) parentName .getParent()) { DelegateFileObject file = (DelegateFileObject) getFileFromCache(parentName); if (file == null) { file = new DelegateFileObject(parentName, this, null); putFileToCache(file); } else { done = file.exists(); } // As this is the parent of our junction it has to be a folder file.attachChild(childName, FileType.FOLDER); } // TODO - attach all cached children of the junction point to their real file } catch (final Exception e) { throw new FileSystemException("vfs.impl/create-junction.error", junctionName, e); } }
Example 13
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); }
Example 14
Source File: Job.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 = jobMeta != null && !Utils.isEmpty( jobMeta.getFilename() ); if ( hasFilename ) { // we have a finename that's defined. try { FileObject fileObject = KettleVFS.getFileObject( jobMeta.getFilename(), this ); FileName fileName = fileObject.getName(); // The filename of the transformation variables.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_NAME, fileName.getBaseName() ); // The directory of the transformation FileName fileDir = fileName.getParent(); variables.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, fileDir.getURI() ); } catch ( Exception e ) { variables.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, "" ); variables.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_NAME, "" ); } } else { variables.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, "" ); variables.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_NAME, "" ); } boolean hasRepoDir = jobMeta.getRepositoryDirectory() != null && jobMeta.getRepository() != null; // The name of the job variables.setVariable( Const.INTERNAL_VARIABLE_JOB_NAME, Const.NVL( jobMeta.getName(), "" ) ); // The name of the directory in the repository variables.setVariable( Const.INTERNAL_VARIABLE_JOB_REPOSITORY_DIRECTORY, hasRepoDir ? jobMeta .getRepositoryDirectory().getPath() : "" ); // setup fallbacks if ( hasRepoDir ) { variables.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, variables.getVariable( Const.INTERNAL_VARIABLE_JOB_REPOSITORY_DIRECTORY ) ); } else { variables.setVariable( Const.INTERNAL_VARIABLE_JOB_REPOSITORY_DIRECTORY, variables.getVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY ) ); } if ( hasRepoDir ) { variables.setVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY, variables.getVariable( Const.INTERNAL_VARIABLE_JOB_REPOSITORY_DIRECTORY ) ); if ( "/".equals( variables.getVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY ) ) ) { variables.setVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY, "" ); } } setInternalEntryCurrentDirectory( hasFilename, hasRepoDir ); }
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 ); }