Example usage for org.apache.commons.vfs2 FileObject getName

List of usage examples for org.apache.commons.vfs2 FileObject getName

Introduction

In this page you can find the example usage for org.apache.commons.vfs2 FileObject getName.

Prototype

FileName getName();

Source Link

Document

Returns the name of this file.

Usage

From source file:com.streamsets.pipeline.stage.origin.remote.RemoteDownloadSource.java

private void queueFiles(FileObject remoteDir) throws FileSystemException {
    remoteDir.refresh();//from  ww  w .  ja v  a  2  s .  c  o  m
    for (FileObject remoteFile : remoteDir.getChildren()) {
        if (remoteFile.getType().toString().equals("folder")) {
            queueFiles(remoteFile);
            continue;
        }
        long lastModified = remoteFile.getContent().getLastModifiedTime();
        RemoteFile tempFile = new RemoteFile(remoteFile.getName().getBaseName(), lastModified, remoteFile);

        if (shouldQueue(tempFile)) {
            // If we are done with all files, the files with the final mtime might get re-ingested over and over.
            // So if it is the one of those, don't pull it in.
            fileQueue.add(tempFile);
        }
    }
}

From source file:de.innovationgate.wgpublisher.design.fs.DesignFileDocument.java

public List getFileNames() throws WGBackendException {
    try {/*from w w w  . j a  v a  2 s.  co  m*/
        if (getType() != WGDocument.TYPE_FILECONTAINER) {
            return null;
        }
        getCodeFile().refresh();

        Iterator<FileObject> files = getFileContainerFiles().iterator();
        List<String> fileNames = new ArrayList<String>();
        while (files.hasNext()) {
            FileObject file = files.next();
            fileNames.add(file.getName().getBaseName().toLowerCase());
        }
        return fileNames;

    } catch (Exception e) {
        throw new WGBackendException("Exception reading container file data", e);
    }
}

From source file:com.app.server.EARDeployer.java

/**
 * This method configures the executor services from the jar file.
 * /*from  w ww .  j  a  v  a2s.  com*/
 * @param jarFile
 * @param classList
 * @throws FileSystemException
 */
public void deployExecutorServicesEar(String earFileName, FileObject earFile) throws FileSystemException {
    try {
        log.info("EARFILE NAMEs=" + earFileName);
        CopyOnWriteArrayList<URL> libs = new CopyOnWriteArrayList<URL>();
        CopyOnWriteArrayList<FileObject> warObjects = new CopyOnWriteArrayList<FileObject>();
        CopyOnWriteArrayList<FileObject> jarObjects = new CopyOnWriteArrayList<FileObject>();
        CopyOnWriteArrayList<FileObject> sarObjects = new CopyOnWriteArrayList<FileObject>();
        CopyOnWriteArrayList<FileObject> rarObjects = new CopyOnWriteArrayList<FileObject>();
        CopyOnWriteArrayList<FileObject> ezbObjects = new CopyOnWriteArrayList<FileObject>();
        WebClassLoader customClassLoaderBaseLib = new WebClassLoader(new URL[] { earFile.getURL() },
                Thread.currentThread().getContextClassLoader());
        final Field factoryField = URL.class.getDeclaredField("factory");
        factoryField.setAccessible(true);
        factoryField.set(null, new RsrcURLStreamHandlerFactory(customClassLoaderBaseLib));
        //URL.setURLStreamHandlerFactory(new RsrcURLStreamHandlerFactory(customClassLoaderBaseLib));
        obtainUrls(earFile, earFile, libs, warObjects, jarObjects, sarObjects, rarObjects, ezbObjects,
                fsManager);
        VFSClassLoader customClassLoader = null;
        for (URL earLib : libs) {
            customClassLoaderBaseLib.addURL(earLib);
        }
        FileObject jarFileObject;
        ConcurrentHashMap classLoaderPath = new ConcurrentHashMap();
        filesMap.put(earFileName, classLoaderPath);
        for (FileObject rarFileObj : rarObjects) {

            //log.info(classLoader);
            //warDeployer.deleteDir(new File(serverConfig.getDeploydirectory()+"/"+fileName.substring(0,fileName.lastIndexOf(".war"))));
            mbeanServer.invoke(rarObjectName, "deploy", new Object[] { rarFileObj },
                    new String[] { FileObject.class.getName() });
            //}
        }
        for (FileObject sarFileObj : sarObjects) {

            //log.info(classLoader);
            //warDeployer.deleteDir(new File(serverConfig.getDeploydirectory()+"/"+fileName.substring(0,fileName.lastIndexOf(".war"))));
            mbeanServer.invoke(sarObjectName, "deploy",
                    new Object[] { sarFileObj, fsManager, customClassLoaderBaseLib },
                    new String[] { FileObject.class.getName(), StandardFileSystemManager.class.getName(),
                            ClassLoader.class.getName() });
            //}
        }

        for (FileObject ezbFileObj : ezbObjects) {

            //log.info(classLoader);
            //warDeployer.deleteDir(new File(serverConfig.getDeploydirectory()+"/"+fileName.substring(0,fileName.lastIndexOf(".war"))));
            mbeanServer.invoke(ezbObjectName, "deploy", new Object[] { ezbFileObj, customClassLoaderBaseLib },
                    new String[] { FileObject.class.getName(), VFSClassLoader.class.getName() });
            //}
        }

        for (FileObject warFileObj : warObjects) {
            //if(warFileObj.getName().getBaseName().endsWith(".war")){
            //logger.info("filePath"+filePath);
            String filePath = serverConfig.getDeploydirectory() + "/" + warFileObj.getName().getBaseName();
            log.info(filePath);
            String fileName = warFileObj.getName().getBaseName();
            String directoryName = fileName.substring(0, fileName.indexOf('.'));

            log.info(customClassLoaderBaseLib);
            //warDeployer.deleteDir(new File(serverConfig.getDeploydirectory()+"/"+fileName.substring(0,fileName.lastIndexOf(".war"))));
            new File(serverConfig.getDeploydirectory() + "/"
                    + fileName.substring(0, fileName.lastIndexOf(".war"))).mkdirs();
            log.info(serverConfig.getDeploydirectory() + "/"
                    + fileName.substring(0, fileName.lastIndexOf(".war")));
            classLoaderPath.put(warFileObj.getName().getBaseName(), serverConfig.getDeploydirectory() + "/"
                    + fileName.substring(0, fileName.lastIndexOf(".war")));
            mbeanServer.invoke(warObjectName, "extractWar",
                    new Object[] { warFileObj, customClassLoaderBaseLib, fsManager },
                    new String[] { FileObject.class.getName(), WebClassLoader.class.getName(),
                            StandardFileSystemManager.class.getName() });
            //}
        }
        //URL.setURLStreamHandlerFactory(new RsrcURLStreamHandlerFactory(null));
        for (FileObject jarFileObj : jarObjects) {

            //log.info(classLoader);
            //warDeployer.deleteDir(new File(serverConfig.getDeploydirectory()+"/"+fileName.substring(0,fileName.lastIndexOf(".war"))));
            mbeanServer.invoke(ejbObjectName, "deploy",
                    new Object[] { new URL(jarFileObj.getURL().toURI().toString()), fsManager,
                            customClassLoaderBaseLib },
                    new String[] { URL.class.getName(), StandardFileSystemManager.class.getName(),
                            ClassLoader.class.getName() });
            //}
        }
        //for (int keyCount = 0; keyCount < keys.size(); keyCount++) {}
        /*for (FileObject fobject : fileObjects) {
           fobject.close();
        }*/
        //log.info("Channel unlocked");
        earsDeployed.add(earFile.getName().getURI());
        earFile.close();
        fsManager.closeFileSystem(earFile.getFileSystem());
        // ClassLoaderUtil.closeClassLoader(customClassLoader);
    } catch (Exception ex) {
        log.error("Error in deploying the ear ", ex);
        //ex.printStackTrace();
    }
}

From source file:com.yenlo.synapse.transport.vfs.VFSTransportListener.java

private synchronized void addFailedRecord(PollTableEntry pollTableEntry, FileObject failedObject,
        String timeString) {/* w  w  w.  ja  v a 2  s.c  om*/
    try {
        String record = failedObject.getName().getBaseName() + VFSConstants.FAILED_RECORD_DELIMITER
                + timeString;
        String recordFile = pollTableEntry.getFailedRecordFileDestination()
                + pollTableEntry.getFailedRecordFileName();
        File failedRecordFile = new File(recordFile);
        if (!failedRecordFile.exists()) {
            FileUtils.writeStringToFile(failedRecordFile, record);
            if (log.isDebugEnabled()) {
                log.debug("Added fail record '" + record + "' into the record file '" + recordFile + "'");
            }
        } else {
            List<String> content = FileUtils.readLines(failedRecordFile);
            if (!content.contains(record)) {
                content.add(record);
            }
            FileUtils.writeLines(failedRecordFile, content);
        }
    } catch (IOException e) {
        log.fatal("Failure while writing the failed records!", e);
    }
}

From source file:de.unioninvestment.portal.explorer.view.vfs.TableView.java

private void fillTableData(String selectedDir, Table table, FileSystemManager fsManager, FileSystemOptions opts,
        String filterVal) throws IOException {
    table.removeAllItems();//www  . j  a  v  a2s  .  c o m

    FileObject fileObject = fsManager.resolveFile(selectedDir, opts);
    FileObject[] files = fileObject.getChildren();
    for (FileObject file : files) {

        if (filterVal == null) {
            addTableItem(table, file);
        } else {
            String regex = filterVal.replace("?", ".?").replace("*", ".*?");
            String name = getDisplayPath(file.getName().toString());
            if (name.matches(regex))
                addTableItem(table, file);
        }

    }
}

From source file:com.app.server.SARDeployer.java

public CopyOnWriteArrayList<String> unpack(final FileObject unpackFileObject, final File outputDir,
        StandardFileSystemManager fileSystemManager) throws IOException {
    outputDir.mkdirs();//from  www .j av  a  2s.c o m
    URLClassLoader webClassLoader;
    CopyOnWriteArrayList<String> classPath = new CopyOnWriteArrayList<String>();
    final FileObject packFileObject = fileSystemManager
            .resolveFile("jar:" + unpackFileObject.toString() + "!/");
    try {
        FileObject outputDirFileObject = fileSystemManager.toFileObject(outputDir);
        outputDirFileObject.copyFrom(packFileObject, new AllFileSelector());
        FileObject[] libs = outputDirFileObject.findFiles(new FileSelector() {

            public boolean includeFile(FileSelectInfo arg0) throws Exception {
                return arg0.getFile().getName().getBaseName().toLowerCase().endsWith(".jar");
            }

            public boolean traverseDescendents(FileSelectInfo arg0) throws Exception {
                // TODO Auto-generated method stub
                return true;
            }

        });
        /*String replaceString="file:///"+outputDir.getAbsolutePath().replace("\\","/");
        replaceString=replaceString.endsWith("/")?replaceString:replaceString+"/";*/
        // System.out.println(replaceString);
        for (FileObject lib : libs) {
            // System.out.println(outputDir.getAbsolutePath());
            // System.out.println(jsp.getName().getFriendlyURI());
            classPath.add(lib.getName().getFriendlyURI());
            // System.out.println(relJspName);
        }
    } finally {
        packFileObject.close();
    }
    return classPath;
}

From source file:com.web.server.EARDeployer.java

/**
 * This method configures the executor services from the jar file.
 * /* w w w  .ja v  a2s.  c om*/
 * @param jarFile
 * @param classList
 * @throws FileSystemException
 */
public void deployExecutorServicesEar(String earFileName, FileObject earFile,
        StandardFileSystemManager fsManager) throws FileSystemException {
    try {
        System.out.println("EARFILE NAMEs=" + earFileName);
        CopyOnWriteArrayList<FileObject> fileObjects = new CopyOnWriteArrayList<FileObject>();
        CopyOnWriteArrayList<FileObject> warObjects = new CopyOnWriteArrayList<FileObject>();
        ConcurrentHashMap jarClassListMap = new ConcurrentHashMap();
        CopyOnWriteArrayList<String> classList;
        obtainUrls(earFile, earFile, fileObjects, jarClassListMap, warObjects, fsManager);
        VFSClassLoader customClassLoaderBaseLib = new VFSClassLoader(
                fileObjects.toArray(new FileObject[fileObjects.size()]), fsManager,
                Thread.currentThread().getContextClassLoader());
        VFSClassLoader customClassLoader = null;
        Set keys = jarClassListMap.keySet();
        Iterator key = keys.iterator();
        FileObject jarFileObject;
        ConcurrentHashMap classLoaderPath = new ConcurrentHashMap();
        filesMap.put(earFileName, classLoaderPath);
        for (FileObject warFileObj : warObjects) {
            if (warFileObj.getName().getBaseName().endsWith(".war")) {
                //logger.info("filePath"+filePath);
                String filePath = scanDirectory + "/" + warFileObj.getName().getBaseName();
                log.info(filePath);
                String fileName = warFileObj.getName().getBaseName();
                WebClassLoader classLoader = new WebClassLoader(new URL[] {});
                log.info(classLoader);
                warDeployer.deleteDir(
                        new File(deployDirectory + "/" + fileName.substring(0, fileName.lastIndexOf(".war"))));
                new File(deployDirectory + "/" + fileName.substring(0, fileName.lastIndexOf(".war"))).mkdirs();
                log.info(deployDirectory + "/" + fileName.substring(0, fileName.lastIndexOf(".war")));
                urlClassLoaderMap.put(
                        deployDirectory + "/" + fileName.substring(0, fileName.lastIndexOf(".war")),
                        classLoader);
                classLoaderPath.put(warFileObj.getName().getBaseName(),
                        deployDirectory + "/" + fileName.substring(0, fileName.lastIndexOf(".war")));
                warDeployer.extractWar(new File(filePath), classLoader);

                if (exec != null) {
                    exec.shutdown();
                }
                new File(scanDirectory + "/" + warFileObj.getName().getBaseName()).delete();
                exec = Executors.newSingleThreadScheduledExecutor();
                exec.scheduleAtFixedRate(task, 0, 1000, TimeUnit.MILLISECONDS);
            }
        }
        for (int keyCount = 0; keyCount < keys.size(); keyCount++) {
            jarFileObject = (FileObject) key.next();
            {
                classList = (CopyOnWriteArrayList<String>) jarClassListMap.get(jarFileObject);
                customClassLoader = new VFSClassLoader(jarFileObject, fsManager, customClassLoaderBaseLib);
                this.urlClassLoaderMap.put(
                        scanDirectory + "/" + earFileName + "/" + jarFileObject.getName().getBaseName(),
                        customClassLoader);
                classLoaderPath.put(jarFileObject.getName().getBaseName(),
                        scanDirectory + "/" + earFileName + "/" + jarFileObject.getName().getBaseName());
                for (int classCount = 0; classCount < classList.size(); classCount++) {
                    String classwithpackage = classList.get(classCount).substring(0,
                            classList.get(classCount).indexOf(".class"));
                    classwithpackage = classwithpackage.replace("/", ".");
                    // System.out.println("classList:"+classwithpackage.replace("/","."));
                    try {
                        if (!classwithpackage.contains("$")) {

                            /*System.out.println("EARFILE NAME="+fileName);
                            System.out
                                  .println(scanDirectory
                            + "/"
                            + fileName
                            + "/"
                            + jarFileObject.getName()
                                  .getBaseName());
                                    
                            System.out.println(urlClassLoaderMap);*/
                            Class executorServiceClass = customClassLoader.loadClass(classwithpackage);

                            Annotation[] classServicesAnnot = executorServiceClass.getDeclaredAnnotations();

                            if (classServicesAnnot != null) {
                                for (int annotcount = 0; annotcount < classServicesAnnot.length; annotcount++) {
                                    if (classServicesAnnot[annotcount] instanceof RemoteCall) {
                                        RemoteCall remoteCall = (RemoteCall) classServicesAnnot[annotcount];
                                        //registry.unbind(remoteCall.servicename());
                                        System.out.println(remoteCall.servicename().trim());
                                        try {
                                            for (int count = 0; count < 2; count++) {
                                                RemoteInterface reminterface = (RemoteInterface) UnicastRemoteObject
                                                        .exportObject(
                                                                (Remote) executorServiceClass.newInstance(), 0);
                                                registry.rebind(remoteCall.servicename().trim(), reminterface);
                                            }
                                        } catch (Exception ex) {
                                            ex.printStackTrace();
                                        }
                                    }
                                }
                            }
                            // System.out.println(executorServiceClass.newInstance());
                            // System.out.println("executor class in ExecutorServicesConstruct"+executorServiceClass);
                            // System.out.println();
                            Method[] methods = executorServiceClass.getDeclaredMethods();
                            for (Method method : methods) {
                                Annotation[] annotations = method.getDeclaredAnnotations();
                                for (Annotation annotation : annotations) {
                                    if (annotation instanceof ExecutorServiceAnnot) {
                                        ExecutorServiceAnnot executorServiceAnnot = (ExecutorServiceAnnot) annotation;
                                        ExecutorServiceInfo executorServiceInfo = new ExecutorServiceInfo();
                                        executorServiceInfo.setExecutorServicesClass(executorServiceClass);
                                        executorServiceInfo.setMethod(method);
                                        executorServiceInfo.setMethodParams(method.getParameterTypes());
                                        //                              System.out.println("serice name="
                                        //                                    + executorServiceAnnot
                                        //                                          .servicename());
                                        //                              System.out.println("method info="
                                        //                                    + executorServiceInfo);
                                        //                              System.out.println(method);
                                        // if(servicesMap.get(executorServiceAnnot.servicename())==null)throw
                                        // new Exception();
                                        executorServiceMap.put(executorServiceAnnot.servicename(),
                                                executorServiceInfo);
                                    }
                                }
                            }
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
            jarFileObject.close();
        }
        for (FileObject fobject : fileObjects) {
            fobject.close();
        }
        System.out.println("Channel unlocked");
        earFile.close();
        fsManager.closeFileSystem(earFile.getFileSystem());
        // ClassLoaderUtil.closeClassLoader(customClassLoader);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:de.innovationgate.wgpublisher.design.fs.FileSystemDesignSource.java

public List<String> getDesignNames() throws WGADesignRetrievalException {

    try {/*from  w  w w . j  av  a 2 s  .c o  m*/
        List<String> designs = new ArrayList<String>();

        // Add child design directories - All with a syncinfo/design.xml or those that are completely empty and can be initialized
        _dir.refresh();
        FileObject[] children = _dir.getChildren();
        for (int i = 0; i < children.length; i++) {
            FileObject child = children[i];
            if (child.getType().equals(FileType.FOLDER)) {
                FileObject resolvedChild = WGUtils.resolveDirLink(child);
                if (resolvedChild.getType().equals(FileType.FOLDER)) {
                    FileObject syncInfo = DesignDirectory.getDesignDefinitionFile(resolvedChild);
                    if (syncInfo != null || child.getChildren().length == 0) {
                        designs.add(child.getName().getBaseName());
                    }
                }
            } else if (child.getType().equals(FileType.FILE)
                    && child.getName().getExtension().equalsIgnoreCase(ARCHIVED_DESIGN_EXTENSION)) {
                designs.add(DESIGNNAMEPREFIX_ARCHIVE + child.getName().getBaseName().substring(0,
                        child.getName().getBaseName().lastIndexOf(".")));
            }
        }

        // Add additional directories
        Iterator<Map.Entry<String, String>> dirs = _additionalDirs.entrySet().iterator();
        while (dirs.hasNext()) {
            Map.Entry<String, String> entry = dirs.next();
            FileObject dir = VFS.getManager().resolveFile((String) entry.getValue());
            if (dir.exists() && dir.getType().equals(FileType.FOLDER)) {
                FileObject syncInfo = DesignDirectory.getDesignDefinitionFile(dir);
                if (syncInfo != null || dir.getChildren().length == 0) {
                    designs.add(DESIGNNAMEPREFIX_ADDITIONALDIR + entry.getKey());
                }
            }
        }

        return designs;
    } catch (FileSystemException e) {
        throw new WGADesignRetrievalException("Exception retrieving file system designs", e);
    }

}

From source file:hadoopInstaller.installation.HostInstallation.java

public void run() throws InstallationError {
    log.info("HostInstallation.Started", //$NON-NLS-1$
            host.getHostname());/*from  w ww .ja va 2  s. co  m*/
    Session session = sshConnect();
    // TODO- Detect if the hostname is correctly set in the target host, and
    // promp to fix it. if needed
    FileObject remoteDirectory = sftpConnect();
    try {
        if (installer.doDeploy()) {
            new DeployInstallationFiles(host, session, remoteDirectory, installer).run();
        }
        new UploadConfiguration(installer.getConfigurationFilesToUpload(),
                installer.getConfig().deleteOldConfigurationFiles(), log).run(host, remoteDirectory);
    } finally {
        try {
            remoteDirectory.close();
            log.debug("HostInstallation.SFTP.Disconnect", //$NON-NLS-1$
                    host.getHostname());
        } catch (FileSystemException e) {
            throw new InstallationError(e, "HostInstallation.CouldNotClose", //$NON-NLS-1$
                    remoteDirectory.getName().getURI());
        }
        if (session.isConnected()) {
            session.disconnect();
            log.debug("HostInstallation.SSH.Disconnect", //$NON-NLS-1$
                    host.getHostname());
        }
    }
    log.info("HostInstallation.Ended", //$NON-NLS-1$
            host.getHostname());
}

From source file:fr.cls.atoll.motu.library.misc.vfs.provider.gsiftp.GsiFtpFileObject.java

/**
 * Renames the file./*from   w  ww.  j a v a2 s  .  com*/
 * 
 * @param newfile the newfile
 * 
 * @throws Exception the exception
 */
@Override
protected void doRename(FileObject newfile) throws Exception {
    boolean ok = true;
    final GridFTPClient ftpClient = ftpFs.getClient();
    try {
        String oldName = getName().getPath();
        String newName = newfile.getName().getPath();
        ftpClient.rename(oldName, newName);
    } catch (IOException ioe) {
        ok = false;
    } catch (ServerException e) {
        ok = false;
    } finally {
        ftpFs.putClient(ftpClient);
    }

    if (!ok) {
        throw new FileSystemException("vfs.provider.gsiftp/rename-file.error",
                new Object[] { getName().toString(), newfile });
    }
    this.fileInfo = null;
    children = EMPTY_FTP_FILE_MAP;
}