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

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

Introduction

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

Prototype

URL getURL() throws FileSystemException;

Source Link

Document

Returns a URL representing this file.

Usage

From source file:org.apache.commons.vfs2.example.ShowProperties.java

public static void main(final String[] args) {
    if (args.length == 0) {
        System.err.println("Please pass the name of a file as parameter.");
        System.err.println("e.g. java org.apache.commons.vfs2.example.ShowProperties LICENSE.txt");
        return;/*from www  . j av  a  2s.  c o m*/
    }
    for (final String arg : args) {
        try {
            final FileSystemManager mgr = VFS.getManager();
            System.out.println();
            System.out.println("Parsing: " + arg);
            final FileObject file = mgr.resolveFile(arg);
            System.out.println("URL: " + file.getURL());
            System.out.println("getName(): " + file.getName());
            System.out.println("BaseName: " + file.getName().getBaseName());
            System.out.println("Extension: " + file.getName().getExtension());
            System.out.println("Path: " + file.getName().getPath());
            System.out.println("Scheme: " + file.getName().getScheme());
            System.out.println("URI: " + file.getName().getURI());
            System.out.println("Root URI: " + file.getName().getRootURI());
            System.out.println("Parent: " + file.getName().getParent());
            System.out.println("Type: " + file.getType());
            System.out.println("Exists: " + file.exists());
            System.out.println("Readable: " + file.isReadable());
            System.out.println("Writeable: " + file.isWriteable());
            System.out.println("Root path: " + file.getFileSystem().getRoot().getName().getPath());
            if (file.exists()) {
                if (file.getType().equals(FileType.FILE)) {
                    System.out.println("Size: " + file.getContent().getSize() + " bytes");
                } else if (file.getType().equals(FileType.FOLDER) && file.isReadable()) {
                    final FileObject[] children = file.getChildren();
                    System.out.println("Directory with " + children.length + " files");
                    for (int iterChildren = 0; iterChildren < children.length; iterChildren++) {
                        System.out.println("#" + iterChildren + ": " + children[iterChildren].getName());
                        if (iterChildren > SHOW_MAX) {
                            break;
                        }
                    }
                }
                System.out.println("Last modified: "
                        + DateFormat.getInstance().format(new Date(file.getContent().getLastModifiedTime())));
            } else {
                System.out.println("The file does not exist");
            }
            file.close();
        } catch (final FileSystemException ex) {
            ex.printStackTrace();
        }
    }
}

From source file:org.apache.hadoop.gateway.topology.file.FileTopologyProvider.java

private static Topology loadTopology(FileObject file) throws IOException, SAXException, URISyntaxException {
    log.loadingTopologyFile(file.getName().getFriendlyURI());
    Digester digester = digesterLoader.newDigester();
    FileContent content = file.getContent();
    TopologyBuilder topologyBuilder = digester.parse(content.getInputStream());
    Topology topology = topologyBuilder.build();
    topology.setUri(file.getURL().toURI());
    topology.setName(FilenameUtils.removeExtension(file.getName().getBaseName()));
    topology.setTimestamp(content.getLastModifiedTime());
    return topology;
}

From source file:org.apache.metron.common.dsl.functions.resolver.ClasspathFunctionResolver.java

@Override
public void initialize(Context context) {
    super.initialize(context);
    if (context != null) {

        Optional<Object> optional = context.getCapability(STELLAR_CONFIG, false);
        if (optional.isPresent()) {
            Map<String, Object> stellarConfig = (Map<String, Object>) optional.get();
            if (LOG.isDebugEnabled()) {
                LOG.debug("Setting up classloader using the following config: " + stellarConfig);
            }// w  w w. j  a va 2  s . c o  m

            include(STELLAR_SEARCH_INCLUDES_KEY.get(stellarConfig, String.class).split(STELLAR_SEARCH_DELIMS));
            exclude(STELLAR_SEARCH_EXCLUDES_KEY.get(stellarConfig, String.class).split(STELLAR_SEARCH_DELIMS));
            Optional<ClassLoader> vfsLoader = null;
            try {
                vfsLoader = VFSClassloaderUtil
                        .configureClassloader(STELLAR_VFS_PATHS.get(stellarConfig, String.class));
                if (vfsLoader.isPresent()) {
                    LOG.debug("CLASSLOADER LOADED WITH: " + STELLAR_VFS_PATHS.get(stellarConfig, String.class));
                    if (LOG.isDebugEnabled()) {
                        for (FileObject fo : ((VFSClassLoader) vfsLoader.get()).getFileObjects()) {
                            LOG.error(fo.getURL() + " - " + fo.exists());
                        }
                    }
                    classLoaders(vfsLoader.get());
                }
            } catch (FileSystemException e) {
                LOG.error("Unable to process filesystem: " + e.getMessage(), e);
            }
        } else {
            LOG.info("No stellar config set; I'm reverting to the context classpath with no restrictions.");
            if (LOG.isDebugEnabled()) {
                try {
                    throw new IllegalStateException("No config set, stacktrace follows.");
                } catch (IllegalStateException ise) {
                    LOG.error(ise.getMessage(), ise);
                }
            }
        }
    } else {
        throw new IllegalStateException("CONTEXT IS NULL!");
    }
}

From source file:org.apache.metron.stellar.dsl.functions.resolver.ClasspathFunctionResolver.java

@Override
public void initialize(Context context) {
    super.initialize(context);
    if (context != null) {

        Optional<Object> optional = context.getCapability(STELLAR_CONFIG, false);
        if (optional.isPresent()) {
            Map<String, Object> stellarConfig = (Map<String, Object>) optional.get();
            if (LOG.isDebugEnabled()) {
                LOG.debug("Setting up classloader using the following config: {}", stellarConfig);
            }//  w w  w.  j  a v  a2 s  .  c  o  m

            include(STELLAR_SEARCH_INCLUDES_KEY.get(stellarConfig, String.class).split(STELLAR_SEARCH_DELIMS));
            exclude(STELLAR_SEARCH_EXCLUDES_KEY.get(stellarConfig, String.class).split(STELLAR_SEARCH_DELIMS));
            Optional<ClassLoader> vfsLoader = Optional.empty();
            try {
                vfsLoader = VFSClassloaderUtil
                        .configureClassloader(STELLAR_VFS_PATHS.get(stellarConfig, String.class));
                if (vfsLoader.isPresent()) {
                    LOG.debug("CLASSLOADER LOADED WITH: {}",
                            STELLAR_VFS_PATHS.get(stellarConfig, String.class));
                    if (LOG.isDebugEnabled()) {
                        for (FileObject fo : ((VFSClassLoader) vfsLoader.get()).getFileObjects()) {
                            LOG.error("{} - {}", fo.getURL(), fo.exists());
                        }
                    }
                    classLoaders(vfsLoader.get());
                }
            } catch (FileSystemException e) {
                LOG.error("Unable to process filesystem: {}", e.getMessage(), e);
            }
        } else {
            LOG.info("No stellar config set; I'm reverting to the context classpath with no restrictions.");
            if (LOG.isDebugEnabled()) {
                try {
                    throw new IllegalStateException("No config set, stacktrace follows.");
                } catch (IllegalStateException ise) {
                    LOG.error(ise.getMessage(), ise);
                }
            }
        }
    } else {
        throw new IllegalStateException("CONTEXT IS NULL!");
    }
}

From source file:org.apache.olingo.fit.utils.FSManager.java

private FSManager() throws IOException {
    fsManager = VFS.getManager();//from   w  ww.  j av a2 s . co m

    final FileObject basePath = fsManager
            .resolveFile(RES_PREFIX + File.separatorChar + ODataServiceVersion.V40.name());
    final String absoluteBaseFolder = basePath.getURL().getPath();

    for (FileObject fo : find(basePath, null)) {
        if (fo.getType() == FileType.FILE && !fo.getName().getBaseName().contains("Metadata")
                && !fo.getName().getBaseName().contains("metadata")) {
            final String path = fo.getURL().getPath().replace(absoluteBaseFolder,
                    "//" + ODataServiceVersion.V40.name());
            putInMemory(fo.getContent().getInputStream(), path);
        }
    }
}

From source file:org.apache.river.container.classloading.VirtualFileSystemClassLoader.java

@Override
public Enumeration<URL> findResources(final String name) throws IOException {

    Enumeration result = (Enumeration) Security.doPrivileged(new PrivilegedAction<Enumeration>() {

        public Enumeration run() {
            List<URL> urlList = new ArrayList<URL>();
            try {

                List<FileObject> foList = findResourceFileObjects(name);
                for (FileObject fo : foList) {
                    urlList.add(fo.getURL());
                }/*from  www . jav  a2s  .  co  m*/
            } catch (FileSystemException ex) {
                Logger.getLogger(VirtualFileSystemClassLoader.class.getName()).log(Level.SEVERE, null, ex);
            }
            return Collections.enumeration(urlList);
        }
    });
    return result;
}

From source file:org.apache.synapse.transport.vfs.VFSTransportListener.java

/**
 * Search for files that match the given regex pattern and create a list
 * Then process each of these files and update the status of the scan on
 * the poll table/*from   w w w  . ja  v  a2s. co m*/
 * @param entry the poll table entry for the scan
 * @param fileURI the file or directory to be scanned
 */
private void scanFileOrDirectory(final PollTableEntry entry, String fileURI) {
    FileSystemOptions fso = null;
    setFileSystemClosed(false);
    try {
        fso = VFSUtils.attachFileSystemOptions(entry.getVfsSchemeProperties(), fsManager);
    } catch (Exception e) {
        log.error("Error while attaching VFS file system properties. " + e.getMessage());
    }

    FileObject fileObject = null;

    //TODO : Trying to make the correct URL out of the malformed one.
    if (fileURI.contains("vfs:")) {
        fileURI = fileURI.substring(fileURI.indexOf("vfs:") + 4);
    }

    if (log.isDebugEnabled()) {
        log.debug("Scanning directory or file : " + VFSUtils.maskURLPassword(fileURI));
    }

    boolean wasError = true;
    int retryCount = 0;
    int maxRetryCount = entry.getMaxRetryCount();
    long reconnectionTimeout = entry.getReconnectTimeout();

    while (wasError) {
        try {
            retryCount++;
            fileObject = fsManager.resolveFile(fileURI, fso);

            if (fileObject == null) {
                log.error("fileObject is null");
                throw new FileSystemException("fileObject is null");
            }

            wasError = false;

        } catch (FileSystemException e) {
            if (retryCount >= maxRetryCount) {
                processFailure(
                        "Repeatedly failed to resolve the file URI: " + VFSUtils.maskURLPassword(fileURI), e,
                        entry);
                closeFileSystem(fileObject);
                return;
            } else {
                log.warn("Failed to resolve the file URI: " + VFSUtils.maskURLPassword(fileURI)
                        + ", in attempt " + retryCount + ", " + e.getMessage() + " Retrying in "
                        + reconnectionTimeout + " milliseconds.");
            }
        }

        if (wasError) {
            try {
                Thread.sleep(reconnectionTimeout);
            } catch (InterruptedException e2) {
                log.error("Thread was interrupted while waiting to reconnect.", e2);
            }
        }
    }

    try {
        if (fileObject.exists() && fileObject.isReadable()) {

            entry.setLastPollState(PollTableEntry.NONE);
            FileObject[] children = null;
            try {
                children = fileObject.getChildren();
            } catch (FileNotFolderException ignored) {
            } catch (FileSystemException ex) {
                log.error(ex.getMessage(), ex);
            }

            // if this is a file that would translate to a single message
            if (children == null || children.length == 0) {
                boolean isFailedRecord = false;
                if (entry.getMoveAfterMoveFailure() != null) {
                    isFailedRecord = isFailedRecord(fileObject, entry);
                }

                if (fileObject.getType() == FileType.FILE && !isFailedRecord) {
                    boolean runPostProcess = true;
                    if (!entry.isFileLockingEnabled() || (entry.isFileLockingEnabled()
                            && acquireLock(fsManager, fileObject, entry, fso))) {
                        try {
                            if (fileObject.getType() == FileType.FILE) {
                                processFile(entry, fileObject);
                                entry.setLastPollState(PollTableEntry.SUCCSESSFUL);
                                metrics.incrementMessagesReceived();
                            } else {
                                runPostProcess = false;
                            }

                        } catch (AxisFault e) {
                            if (e.getCause() instanceof FileNotFoundException) {
                                log.warn("Error processing File URI : "
                                        + VFSUtils.maskURLPassword(fileObject.getName().toString())
                                        + ". This can be due to file moved from another process.");
                                runPostProcess = false;
                            } else {
                                logException("Error processing File URI : "
                                        + VFSUtils.maskURLPassword(fileObject.getName().getURI()), e);
                                entry.setLastPollState(PollTableEntry.FAILED);
                                metrics.incrementFaultsReceiving();
                            }
                        }
                        if (runPostProcess) {
                            try {
                                moveOrDeleteAfterProcessing(entry, fileObject, fso);
                            } catch (AxisFault axisFault) {
                                logException("File object '"
                                        + VFSUtils.maskURLPassword(fileObject.getURL().toString()) + "' "
                                        + "cloud not be moved", axisFault);
                                entry.setLastPollState(PollTableEntry.FAILED);
                                String timeStamp = VFSUtils
                                        .getSystemTime(entry.getFailedRecordTimestampFormat());
                                addFailedRecord(entry, fileObject, timeStamp);
                            }
                        }
                        if (entry.isFileLockingEnabled()) {
                            VFSUtils.releaseLock(fsManager, fileObject, fso);
                            if (log.isDebugEnabled()) {
                                log.debug("Removed the lock file '"
                                        + VFSUtils.maskURLPassword(fileObject.toString())
                                        + ".lock' of the file '"
                                        + VFSUtils.maskURLPassword(fileObject.toString()));
                            }
                        }
                    } else if (log.isDebugEnabled()) {
                        log.debug("Couldn't get the lock for processing the file : "
                                + VFSUtils.maskURLPassword(fileObject.getName().getURI()));
                    } else if (isFailedRecord) {
                        if (entry.isFileLockingEnabled()) {
                            VFSUtils.releaseLock(fsManager, fileObject, fso);
                        }
                        // schedule a cleanup task if the file is there
                        if (fsManager.resolveFile(fileObject.getURL().toString(), fso) != null
                                && removeTaskState == STATE_STOPPED
                                && entry.getMoveAfterMoveFailure() != null) {
                            workerPool.execute(new FileRemoveTask(entry, fileObject, fso));
                        }
                        if (log.isDebugEnabled()) {
                            log.debug("File '" + VFSUtils.maskURLPassword(fileObject.getURL().toString())
                                    + "' has been marked as a failed" + " record, it will not process");
                        }
                    }
                }

            } else {
                int failCount = 0;
                int successCount = 0;
                int processCount = 0;
                Integer iFileProcessingInterval = entry.getFileProcessingInterval();
                Integer iFileProcessingCount = entry.getFileProcessingCount();

                if (log.isDebugEnabled()) {
                    log.debug("File name pattern : " + entry.getFileNamePattern());
                }
                // Sort the files
                String strSortParam = entry.getFileSortParam();
                if (strSortParam != null) {
                    log.debug("Start Sorting the files.");
                    boolean bSortOrderAsscending = entry.isFileSortAscending();
                    if (log.isDebugEnabled()) {
                        log.debug(
                                "Sorting the files by : " + strSortParam + ". (" + bSortOrderAsscending + ")");
                    }
                    if (strSortParam.equals(VFSConstants.FILE_SORT_VALUE_NAME) && bSortOrderAsscending) {
                        Arrays.sort(children, new FileNameAscComparator());
                    } else if (strSortParam.equals(VFSConstants.FILE_SORT_VALUE_NAME)
                            && !bSortOrderAsscending) {
                        Arrays.sort(children, new FileNameDesComparator());
                    } else if (strSortParam.equals(VFSConstants.FILE_SORT_VALUE_SIZE) && bSortOrderAsscending) {
                        Arrays.sort(children, new FileSizeAscComparator());
                    } else if (strSortParam.equals(VFSConstants.FILE_SORT_VALUE_SIZE)
                            && !bSortOrderAsscending) {
                        Arrays.sort(children, new FileSizeDesComparator());
                    } else if (strSortParam.equals(VFSConstants.FILE_SORT_VALUE_LASTMODIFIEDTIMESTAMP)
                            && bSortOrderAsscending) {
                        Arrays.sort(children, new FileLastmodifiedtimestampAscComparator());
                    } else if (strSortParam.equals(VFSConstants.FILE_SORT_VALUE_LASTMODIFIEDTIMESTAMP)
                            && !bSortOrderAsscending) {
                        Arrays.sort(children, new FileLastmodifiedtimestampDesComparator());
                    }
                    log.debug("End Sorting the files.");
                }
                for (FileObject child : children) {
                    //skipping *.lock file
                    if (child.getName().getBaseName().endsWith(".lock")) {
                        continue;
                    }
                    boolean isFailedRecord = false;
                    if (entry.getMoveAfterMoveFailure() != null) {
                        isFailedRecord = isFailedRecord(child, entry);
                    }

                    if (entry.getFileNamePattern() != null
                            && child.getName().getBaseName().matches(entry.getFileNamePattern())) {
                        //child's file name matches the file name pattern
                        //now we try to get the lock and process
                        if (log.isDebugEnabled()) {
                            log.debug("Matching file : " + child.getName().getBaseName());
                        }
                        boolean runPostProcess = true;
                        if ((!entry.isFileLockingEnabled() || (entry.isFileLockingEnabled()
                                && VFSUtils.acquireLock(fsManager, child, fso))) && !isFailedRecord) {
                            //process the file
                            try {
                                if (log.isDebugEnabled()) {
                                    log.debug("Processing file :" + VFSUtils.maskURLPassword(child.toString()));
                                }
                                processCount++;

                                if (child.getType() == FileType.FILE) {
                                    processFile(entry, child);
                                    successCount++;
                                    // tell moveOrDeleteAfterProcessing() file was success
                                    entry.setLastPollState(PollTableEntry.SUCCSESSFUL);
                                    metrics.incrementMessagesReceived();
                                } else {
                                    runPostProcess = false;
                                }
                            } catch (Exception e) {
                                if (e.getCause() instanceof FileNotFoundException) {
                                    log.warn("Error processing File URI : "
                                            + VFSUtils.maskURLPassword(child.getName().toString())
                                            + ". This can be due to file moved from another process.");
                                    runPostProcess = false;
                                } else {
                                    logException("Error processing File URI : "
                                            + VFSUtils.maskURLPassword(child.getName().getURI()), e);
                                    failCount++;
                                    // tell moveOrDeleteAfterProcessing() file failed
                                    entry.setLastPollState(PollTableEntry.FAILED);
                                    metrics.incrementFaultsReceiving();
                                }
                            }
                            //skipping un-locking file if failed to do delete/move after process
                            boolean skipUnlock = false;
                            if (runPostProcess) {
                                try {
                                    moveOrDeleteAfterProcessing(entry, child, fso);
                                } catch (AxisFault axisFault) {
                                    logException(
                                            "File object '"
                                                    + VFSUtils.maskURLPassword(child.getURL().toString())
                                                    + "'cloud not be moved, will remain in \"locked\" state",
                                            axisFault);
                                    skipUnlock = true;
                                    failCount++;
                                    entry.setLastPollState(PollTableEntry.FAILED);
                                    String timeStamp = VFSUtils
                                            .getSystemTime(entry.getFailedRecordTimestampFormat());
                                    addFailedRecord(entry, child, timeStamp);
                                }
                            }
                            // if there is a failure or not we'll try to release the lock
                            if (entry.isFileLockingEnabled() && !skipUnlock) {
                                VFSUtils.releaseLock(fsManager, child, fso);
                            }
                        }
                    } else if (entry.getFileNamePattern() != null
                            && !child.getName().getBaseName().matches(entry.getFileNamePattern())) {
                        //child's file name does not match the file name pattern
                        if (log.isDebugEnabled()) {
                            log.debug("Non-Matching file : " + child.getName().getBaseName());
                        }
                    } else if (isFailedRecord) {
                        //it is a failed record
                        if (entry.isFileLockingEnabled()) {
                            VFSUtils.releaseLock(fsManager, child, fso);
                            VFSUtils.releaseLock(fsManager, fileObject, fso);
                        }
                        if (fsManager.resolveFile(child.getURL().toString()) != null
                                && removeTaskState == STATE_STOPPED
                                && entry.getMoveAfterMoveFailure() != null) {
                            workerPool.execute(new FileRemoveTask(entry, child, fso));
                        }
                        if (log.isDebugEnabled()) {
                            log.debug("File '" + VFSUtils.maskURLPassword(fileObject.getURL().toString())
                                    + "' has been marked as a failed record, it will not " + "process");
                        }
                    }

                    if (iFileProcessingInterval != null && iFileProcessingInterval > 0) {
                        try {
                            if (log.isDebugEnabled()) {
                                log.debug("Put the VFS processor to sleep for : " + iFileProcessingInterval);
                            }
                            Thread.sleep(iFileProcessingInterval);
                        } catch (InterruptedException ie) {
                            log.error("Unable to set the interval between file processors." + ie);
                        }
                    } else if (iFileProcessingCount != null && iFileProcessingCount <= processCount) {
                        break;
                    }
                }

                if (failCount == 0 && successCount > 0) {
                    entry.setLastPollState(PollTableEntry.SUCCSESSFUL);
                } else if (successCount == 0 && failCount > 0) {
                    entry.setLastPollState(PollTableEntry.FAILED);
                } else {
                    entry.setLastPollState(PollTableEntry.WITH_ERRORS);
                }
            }

            // processing of this poll table entry is complete
            long now = System.currentTimeMillis();
            entry.setLastPollTime(now);
            entry.setNextPollTime(now + entry.getPollInterval());

        } else if (log.isDebugEnabled()) {
            log.debug("Unable to access or read file or directory : " + VFSUtils.maskURLPassword(fileURI) + "."
                    + " Reason: "
                    + (fileObject.exists()
                            ? (fileObject.isReadable() ? "Unknown reason" : "The file can not be read!")
                            : "The file does not exists!"));
        }
        onPollCompletion(entry);
    } catch (FileSystemException e) {
        processFailure("Error checking for existence and readability : " + VFSUtils.maskURLPassword(fileURI), e,
                entry);
    } catch (Exception ex) {
        processFailure("Un-handled exception thrown when processing the file : ", ex, entry);
    } finally {
        closeFileSystem(fileObject);
    }
}

From source file:org.eobjects.datacleaner.Main.java

/**
 * Initializes logging, specifically by looking for log4j.xml or
 * log4j.properties file in DataCleaner's home directory.
 * //w w  w.  jav  a2  s.  c om
 * @return true if a logging configuration file was found, or false
 *         otherwise
 */
protected static boolean initializeLogging() {
    try {

        // initial logging config, used before anything else
        {
            final URL url = Main.class.getResource("log4j-initial.xml");
            assert url != null;
            DOMConfigurator.configure(url);
        }

        if (ClassLoaderUtils.IS_WEB_START) {
            final URL url = Main.class.getResource("log4j-jnlp.xml");
            assert url != null;
            println("Using JNLP log configuration: " + url);
            DOMConfigurator.configure(url);
            return true;
        }

        final FileObject dataCleanerHome = DataCleanerHome.get();

        try {
            final FileObject xmlConfigurationFile = dataCleanerHome.resolveFile("log4j.xml");
            if (xmlConfigurationFile.exists() && xmlConfigurationFile.getType() == FileType.FILE) {
                println("Using custom log configuration: " + xmlConfigurationFile);
                DOMConfigurator.configure(xmlConfigurationFile.getURL());
                return true;
            }
        } catch (FileSystemException e) {
            // no xml logging found, ignore
        }

        try {
            final FileObject propertiesConfigurationFile = dataCleanerHome.resolveFile("log4j.properties");
            if (propertiesConfigurationFile.exists()
                    && propertiesConfigurationFile.getType() == FileType.FILE) {
                println("Using custom log configuration: " + propertiesConfigurationFile);
                PropertyConfigurator.configure(propertiesConfigurationFile.getURL());
                return true;
            }
        } catch (FileSystemException e) {
            // no xml logging found, ignore
        }

        // fall back to default log4j.xml file in classpath
        final URL url = Main.class.getResource("log4j-default.xml");
        assert url != null;
        println("Using default log configuration: " + url);
        DOMConfigurator.configure(url);
        return false;

    } catch (NoClassDefFoundError e) {
        // can happen if log4j is not on the classpath
        println("Failed to initialize logging, class not found: " + e.getMessage());
        return false;
    }
}

From source file:org.jahia.modules.external.modules.ModulesDataSource.java

/**
 * Get the local NodeTypeRegistry for one specific file. Contains system definitions, dependencies and
 * definitions from the current file./*from  www. jav a2s  .  c  o m*/
 *
 * @param path
 * @return
 * @throws RepositoryException
 */
private synchronized NodeTypeRegistry loadRegistry(String path) throws RepositoryException {
    NodeTypeRegistry ntr = nodeTypeRegistryMap.get(path);
    if (ntr != null) {
        return ntr;
    } else {
        try {
            ntr = createBaseRegistry();
            FileObject file = getFile(path);
            if (file.exists()) {
                nodeTypeRegistryMap.put(path, ntr);
                namespaceDefinitions.put(ntr, new HashMap<String, String>());
                ntr.addDefinitionsFile(new UrlResource(file.getURL()), module.getId());
            }
        } catch (ParseException | IOException e) {
            throw new RepositoryException("Failed to load node type registry", e);
        }
        return ntr;
    }
}

From source file:org.kalypso.commons.io.VFSUtilities.java

/**
 * This function will copy one directory to another one. If the destination base directory does not exist, it will be
 * created.//  w w  w .j a  va  2s  .  c o  m
 *
 * @param source
 *          The source directory.
 * @param destination
 *          The destination directory.
 * @param overwrite
 *          If set, always overwrite existing and newer files
 */
public static void copyDirectoryToDirectory(final FileObject source, final FileObject destination,
        final boolean overwrite) throws IOException {
    if (!FileType.FOLDER.equals(source.getType()))
        throw new IllegalArgumentException(
                Messages.getString("org.kalypso.commons.io.VFSUtilities.3") + source.getURL()); //$NON-NLS-1$

    if (destination.exists()) {
        if (!FileType.FOLDER.equals(destination.getType()))
            throw new IllegalArgumentException(
                    Messages.getString("org.kalypso.commons.io.VFSUtilities.4") + destination.getURL()); //$NON-NLS-1$
    } else {
        KalypsoCommonsDebug.DEBUG.printf("Creating directory '%s'...%", destination.getName()); //$NON-NLS-1$
        destination.createFolder();
    }

    final FileObject[] children = source.getChildren();
    for (final FileObject child : children) {
        if (FileType.FILE.equals(child.getType())) {
            /* Need a destination file with the same name as the source file. */
            final FileObject destinationFile = destination.resolveFile(child.getName().getBaseName());

            /* Copy ... */
            copyFileTo(child, destinationFile, overwrite);
        } else if (FileType.FOLDER.equals(child.getType())) {
            /* Need the same name for destination directory, as the source directory has. */
            final FileObject destinationDir = destination.resolveFile(child.getName().getBaseName());

            /* Copy ... */
            KalypsoCommonsDebug.DEBUG.printf("Copy directory %s to %s ...", child.getName(), //$NON-NLS-1$
                    destinationDir.getName());
            copyDirectoryToDirectory(child, destinationDir, overwrite);
        } else {
            KalypsoCommonsDebug.DEBUG.printf("Could not determine the file type ...%n"); //$NON-NLS-1$
        }
    }
}