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:hadoopInstaller.installation.UploadConfiguration.java

private void uploadConfiguration(FileObject remoteDirectory, Host host) throws InstallationError {
    try {//w ww.ja  va 2  s  .c  o  m
        FileObject configurationDirectory = remoteDirectory.resolveFile("hadoop/etc/hadoop/"); //$NON-NLS-1$
        if (deleteOldFiles) {
            configurationDirectory.delete(new AllFileSelector());
            log.debug("HostInstallation.Upload.DeletingOldFiles", //$NON-NLS-1$
                    host.getHostname());
        } else if (!configurationDirectory.exists()) {
            throw new InstallationError("HostInstallation.Upload.NotDeployed"); //$NON-NLS-1$
        }
        configurationDirectory.copyFrom(filesToUpload, new AllFileSelector());
        modifyEnvShFile(host, configurationDirectory, InstallerConstants.ENV_FILE_HADOOP);
        modifyEnvShFile(host, configurationDirectory, InstallerConstants.ENV_FILE_YARN);
        try {
            configurationDirectory.close();
        } catch (FileSystemException ex) {
            log.warn("HostInstallation.CouldNotClose", //$NON-NLS-1$
                    configurationDirectory.getName().getURI());
        }
    } catch (FileSystemException e) {
        throw new InstallationError(e, "HostInstallation.Upload.Error", //$NON-NLS-1$
                remoteDirectory.getName().getURI());
    }
}

From source file:com.stratuscom.harvester.deployer.StarterServiceDeployer.java

public Properties readStartProperties(FileObject serviceRoot)
        throws FileSystemException, LocalizedRuntimeException, IOException {
    /*/*from w  ww. j  av a2s. co m*/
     Read the start.properties file.
     */
    FileObject startProperties = serviceRoot.resolveFile(Strings.START_PROPERTIES);
    if (startProperties == null || !startProperties.getType().equals(FileType.FILE)
            || !startProperties.isReadable()) {
        throw new LocalizedRuntimeException(MessageNames.BUNDLE_NAME, MessageNames.CANT_READ_START_PROPERTIES,
                new Object[] { Strings.START_PROPERTIES, serviceRoot.getName().getBaseName() });
    }
    Properties startProps = propertiesFileReader.getProperties(startProperties);
    return startProps;
}

From source file:com.sludev.commons.vfs.simpleshell.SimpleShell.java

/**
 * Does a 'cp' command.//w ww .j ava  2 s. c o  m
 * 
 * @param cmd
 * @throws SimpleShellException
 */
public void cp(String[] cmd) throws SimpleShellException {
    if (cmd.length < 3) {
        throw new SimpleShellException("USAGE: cp <src> <dest>");
    }

    FileObject src = null;
    try {
        src = mgr.resolveFile(cwd, cmd[1]);
    } catch (FileSystemException ex) {
        String errMsg = String.format("Error resolving source file '%s'", cmd[1]);
        //log.error( errMsg, ex);
        throw new SimpleShellException(errMsg, ex);
    }

    FileObject dest = null;
    try {
        dest = mgr.resolveFile(cwd, cmd[2]);
    } catch (FileSystemException ex) {
        String errMsg = String.format("Error resolving destination file '%s'", cmd[2]);
        //log.error( errMsg, ex);
        throw new SimpleShellException(errMsg, ex);
    }

    try {
        if (dest.exists() && dest.getType() == FileType.FOLDER) {
            dest = dest.resolveFile(src.getName().getBaseName());
        }
    } catch (FileSystemException ex) {
        String errMsg = String.format("Error resolving folder '%s'", cmd[2]);
        //log.error( errMsg, ex);
        throw new SimpleShellException(errMsg, ex);
    }

    try {
        dest.copyFrom(src, Selectors.SELECT_ALL);
    } catch (FileSystemException ex) {
        String errMsg = String.format("Error copyFrom() file '%s' to '%s'", cmd[1], cmd[2]);
        //log.error( errMsg, ex);
        throw new SimpleShellException(errMsg, ex);
    }
}

From source file:hadoopInstaller.installation.UploadConfiguration.java

private void modifyEnvShFile(Host host, FileObject configurationDirectory, String fileName)
        throws InstallationError {
    log.debug("HostInstallation.Upload.File.Start", //$NON-NLS-1$
            fileName, host.getHostname());
    FileObject configurationFile;
    try {/*from w  ww  . j a v  a  2 s .co m*/
        configurationFile = configurationDirectory.resolveFile(fileName);
    } catch (FileSystemException e) {
        throw new InstallationError(e, "HostInstallation.CouldNotOpen", //$NON-NLS-1$
                fileName);
    }
    EnvShBuilder builder = new EnvShBuilder(configurationFile);
    String path = host.getInstallationDirectory();
    URI hadoop = URI.create(MessageFormat.format("file://{0}/{1}/", //$NON-NLS-1$
            path, InstallerConstants.HADOOP_DIRECTORY));
    URI java = URI.create(MessageFormat.format("file://{0}/{1}/", //$NON-NLS-1$
            path, InstallerConstants.JAVA_DIRECTORY));
    builder.setCustomConfig(getLocalFileContents(fileName));
    builder.setHadoopPrefix(hadoop.getPath());
    builder.setJavaHome(java.getPath());
    try {
        builder.build();
    } catch (IOException e) {
        throw new InstallationError(e, "HostInstallation.CouldNotWrite", //$NON-NLS-1$
                configurationFile.getName().getURI());
    }
    try {
        configurationFile.close();
    } catch (FileSystemException e) {
        log.warn("HostInstallation.CouldNotClose", //$NON-NLS-1$
                configurationFile.getName().getURI());
    }
    log.debug("HostInstallation.Upload.File.Success", //$NON-NLS-1$
            fileName, host.getHostname());
}

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

private void populateResponseFile(FileObject responseFile, MessageContext msgContext, boolean append,
        boolean lockingEnabled) throws AxisFault {

    MessageFormatter messageFormatter = getMessageFormatter(msgContext);
    OMOutputFormat format = BaseUtils.getOMOutputFormat(msgContext);

    try {/*  ww w  . j a  va  2  s  .co m*/
        CountingOutputStream os = new CountingOutputStream(responseFile.getContent().getOutputStream(append));
        try {
            messageFormatter.writeTo(msgContext, format, os, true);
        } finally {
            os.close();
        }

        // update metrics
        metrics.incrementMessagesSent(msgContext);
        metrics.incrementBytesSent(msgContext, os.getByteCount());

    } catch (FileSystemException e) {
        if (lockingEnabled) {
            VFSUtils.releaseLock(fsManager, responseFile);
        }
        metrics.incrementFaultsSending();
        handleException("IO Error while creating response file : " + responseFile.getName(), e);
    } catch (IOException e) {
        if (lockingEnabled) {
            VFSUtils.releaseLock(fsManager, responseFile);
        }
        metrics.incrementFaultsSending();
        handleException("IO Error while creating response file : " + responseFile.getName(), e);
    }
}

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

public Vector<URL> unpack(final FileObject unpackFileObject, final File outputDir,
        StandardFileSystemManager fileSystemManager, ConcurrentHashMap<String, String> jsps)
        throws IOException {
    outputDir.mkdirs();/*from  w  w w  .j a v  a2s.c  o  m*/
    URLClassLoader webClassLoader;
    Vector<URL> libraries = new Vector<URL>();
    final FileObject packFileObject = fileSystemManager.resolveFile(unpackFileObject.toString());
    try {
        FileObject outputDirFileObject = fileSystemManager.toFileObject(outputDir);
        outputDirFileObject.copyFrom(packFileObject, new AllFileSelector());
        FileObject[] jspFiles = outputDirFileObject.findFiles(new FileSelector() {

            public boolean includeFile(FileSelectInfo arg0) throws Exception {
                return arg0.getFile().getName().getBaseName().toLowerCase().endsWith(".jsp")
                        || 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 jsplibs : jspFiles) {
            // System.out.println(outputDir.getAbsolutePath());
            // System.out.println(jsp.getName().getFriendlyURI());
            if (jsplibs.getName().getBaseName().endsWith(".jar")) {
                libraries.add(new URL(jsplibs.getName().getFriendlyURI()));
            } else {
                String relJspName = jsplibs.getName().getFriendlyURI().replace(replaceString, "");
                jsps.put(relJspName, relJspName);
            }
            // System.out.println(relJspName);
        }
    } finally {
        packFileObject.close();
    }
    return libraries;
}

From source file:com.msopentech.odatajclient.testservice.utils.XMLUtilities.java

public int countAllElements(final String entitySetName) throws Exception {
    final String basePath = entitySetName + File.separatorChar;
    int count = countFeedElements(fsManager.readFile(basePath + FEED, Accept.XML), "entry");

    final String skipTokenDirPath = fsManager.getAbsolutePath(basePath + SKIP_TOKEN, null);

    try {/*ww w  . j  a v a2s.co m*/
        final FileObject skipToken = fsManager.resolve(skipTokenDirPath);
        final FileObject[] files = fsManager.findByExtension(skipToken, Accept.XML.getExtension().substring(1));

        for (FileObject file : files) {
            count += countFeedElements(
                    fsManager.readFile(
                            basePath + SKIP_TOKEN + File.separatorChar + file.getName().getBaseName(), null),
                    "entry");
        }
    } catch (FileSystemException fse) {
        LOG.debug("Resource path '{}' not found", skipTokenDirPath);
    }

    return count;
}

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

private boolean isFailedRecord(FileObject fileObject, PollTableEntry entry) {
    String failedFile = entry.getFailedRecordFileDestination() + entry.getFailedRecordFileName();
    File file = new File(failedFile);
    if (file.exists()) {
        try {//from ww  w.  ja  v  a 2s.c  o  m
            List list = FileUtils.readLines(file);
            for (Object aList : list) {
                String str = (String) aList;
                StringTokenizer st = new StringTokenizer(str, VFSConstants.FAILED_RECORD_DELIMITER);
                String fileName = st.nextToken();
                if (fileName != null && fileName.equals(fileObject.getName().getBaseName())) {
                    return true;
                }
            }
        } catch (IOException e) {
            log.fatal("Error while reading the file '" + failedFile + "'", e);
        }
    }
    return false;
}

From source file:com.sonicle.webtop.vfs.Service.java

private ExtTreeNode createFileNode(StoreShareFolder folder, String filePath, String dlLink, String ulLink,
        FileObject fo) {
    StoreNodeId nodeId = new StoreNodeId();
    nodeId.setShareId(folder.getShareId());
    nodeId.setStoreId(String.valueOf(folder.getStore().getStoreId()));
    nodeId.setPath(filePath);/*w w  w . j a  v  a  2s  . c  o m*/

    ExtTreeNode node = new ExtTreeNode(nodeId.toString(true), fo.getName().getBaseName(), false);
    node.put("_type", "file");//JsFolderNode.TYPE_FOLDER);
    //node.put("_pid", store.getProfileId().toString());
    node.put("_storeId", folder.getStore().getStoreId());
    node.put("_eperms", folder.getElementsPerms().toString());
    node.put("_dlLink", dlLink);
    node.put("_ulLink", ulLink);

    return node;
}

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

public static boolean upgradeOverlay(FileSystemDesignProvider originalDesignProvider, PluginID baseId,
        OverlayStatus status, FileObject targetFolder, String targetEncoding, Logger log,
        DesignFileValidator validator) throws Exception {

    if (!status.isUpdatedBaseDesign() && !status.isNewOverlay()) {
        throw new WGDesignSyncException(
                "Used base plugin is no higher version than overlay compliance version. Cannot perform upgrade");
    }/*  w  w w .  j ava  2s.com*/

    if (status.isNewOverlay()) {
        log.info("Initializing empty overlay");
    } else {
        log.info("Upgrading overlay from base design version " + status.getCompliantBaseVersion() + " to "
                + status.getCurrentBaseVersion());
    }

    // Creating new folders (Done separately because there may be empty folders in the overlay which would not be created via resource changes)
    for (String folder : status.getNewFolders()) {
        FileObject targetFile = targetFolder.resolveFile(folder);
        if (!targetFile.exists()) {
            log.info("Adding new overlay folder "
                    + targetFolder.getName().getRelativeName(targetFile.getName()));
            targetFile.createFolder();
        }
    }

    // Perform resource changes
    boolean conflictFileCreated = false;
    for (ChangedDocument resource : status.getChangedDocuments().values()) {
        if (performChange(resource, originalDesignProvider, status, targetEncoding, targetFolder, log,
                validator)) {
            conflictFileCreated = true;
        }
    }

    // Overwrite plugin version
    status.getOverlayData().setBasepluginVersion(baseId.getVersion().toString());

    // Write new overlay data file
    FileObject targetFCFolder = targetFolder.resolveFile(DesignDirectory.FOLDERNAME_FILES);
    FileObject systemFC = targetFCFolder.resolveFile("system");
    FileObject overlayDataFile = systemFC.resolveFile(OverlayDesignProvider.OVERLAY_DATA_FILE);
    OutputStream out = new BufferedOutputStream(overlayDataFile.getContent().getOutputStream(false));
    status.getOverlayData().write(out);
    out.flush();
    out.close();

    // Eventually update base-csconfig.xml
    FileObject baseCsConfigFile = originalDesignProvider.getFilesFolder().resolveFile("system/csconfig.xml");
    if (baseCsConfigFile.exists()) {
        String sourceHash = MD5HashingInputStream.getStreamHash(baseCsConfigFile.getContent().getInputStream());
        String targetHash = "";
        FileObject baseCsConfigFileOnOverlay = systemFC.resolveFile("base-csconfig.xml");
        if (baseCsConfigFileOnOverlay.exists()) {
            targetHash = MD5HashingInputStream
                    .getStreamHash(baseCsConfigFileOnOverlay.getContent().getInputStream());
        }
        if (!sourceHash.equals(targetHash)) {
            baseCsConfigFileOnOverlay.delete();
            FileUtil.copyContent(baseCsConfigFile, baseCsConfigFileOnOverlay);
        }
    }

    // Eventually update the dependency to the base plugin on csconfig.xml's plugin config
    FileObject overlayCsConfigFile = systemFC.resolveFile("csconfig.xml");
    if (overlayCsConfigFile.exists()) {
        CSConfig overlayCsConfig = CSConfig.load(overlayCsConfigFile);
        if (overlayCsConfig.getPluginConfig() != null) {
            boolean dependencyUpdated = false;
            for (PluginID id : overlayCsConfig.getPluginConfig().getDependencies()) {
                if (id.getUniqueName().equals(baseId.getUniqueName())
                        && !id.getVersion().equals(baseId.getVersion())) {
                    Version dependencyVersion = new Version(baseId.getVersion().getMajorVersion(),
                            baseId.getVersion().getMinorVersion(), baseId.getVersion().getMaintenanceVersion(),
                            baseId.getVersion().getPatchVersion(), 0);
                    id.setVersion(dependencyVersion);
                    dependencyUpdated = true;
                }
            }

            if (dependencyUpdated) {
                log.info("Updating dependency to base plugin in overlay plugin to new version "
                        + baseId.getVersion());
                overlayCsConfig.write(overlayCsConfigFile);
            }
        }
    }

    // Read/Write design configuration model to ensure correct storage versions of csconfig.xml (#00003634)
    FileObject designDefinitionFile = DesignDirectory.getDesignDefinitionFile(targetFolder);
    WGADesignConfigurationModel model = new WGADesignConfigurationModel(
            new File(designDefinitionFile.getName().getPath()));
    model.saveChanges();

    // Clear the overlay status
    status.overlayWasUpgraded();

    return conflictFileCreated;

}