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

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

Introduction

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

Prototype

FileContent getContent() throws FileSystemException;

Source Link

Document

Returns this file's content.

Usage

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

public void processDownloadFiles(HttpServletRequest request, HttpServletResponse response) {

    try {//  w  ww . java 2 s .c  o m
        StringArray fileIds = ServletUtils.getObjectParameter(request, "fileIds", StringArray.class, true);

        if (fileIds.size() > 1)
            throw new WTException("Unable to download multiple files for now");
        String fileId = fileIds.get(0);
        //TODO: Implementare download file multipli

        StoreNodeId nodeId = (StoreNodeId) new StoreNodeId().parse(fileId);
        int storeId = Integer.valueOf(nodeId.getStoreId());

        FileObject fo = null;
        try {
            fo = manager.getStoreFile(storeId, nodeId.getPath());

            if (!fo.isFile()) {
                logger.warn("Cannot download a non-file [{}, {}]", storeId, nodeId.getPath());
                throw new WTException("Requested file is not a real file");
            }

            String filename = fo.getName().getBaseName();
            String mediaType = ServletHelper.guessMediaType(filename, true);
            IOUtils.copy(fo.getContent().getInputStream(), response.getOutputStream());
            ServletUtils.setFileStreamHeaders(response, mediaType, DispositionType.ATTACHMENT, filename);
            ServletUtils.setContentLengthHeader(response, fo.getContent().getSize());
        } finally {
            IOUtils.closeQuietly(fo);
        }

    } catch (Exception ex) {
        logger.error("Error in action DownloadFiles", ex);
        ServletUtils.writeErrorHandlingJs(response, ex.getMessage());
    }
}

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

protected FileObject initialDeployFileContainer(WGFileContainer con) throws IOException, InstantiationException,
        IllegalAccessException, WGAPIException, WGDesignSyncException {

    // Create container folder
    FileObject containerFolder = getFilesFolder().resolveFile(con.getName());
    _log.info("Creating file container folder " + getRelativePath(containerFolder));
    try {/*from  w  ww.  j  a v a2s  .  co m*/
        containerFolder.createFolder();
    } catch (FileSystemException e) {
        throw new WGInitialDeployException(
                "Could not create file container folder '" + containerFolder.getName().getPathDecoded() + "'",
                e);
    }

    // Create metadata file
    FCMetadata metaData = new FCMetadata(con);
    FileObject metadataFile = containerFolder
            .resolveFile(AbstractDesignFile.FILECONTAINER_METADATA_FILENAME + DesignDirectory.SUFFIX_METADATA);
    _log.info("Creating file container metadata file " + getRelativePath(metadataFile));
    Writer writer = createWriter(metadataFile);
    writer.write(_xstream.toXML(metaData.getInfo()));
    writer.close();

    // Create contained files
    Iterator fileNames = con.getFileNames().iterator();
    String fileName;
    FileObject file;
    while (fileNames.hasNext()) {
        fileName = (String) fileNames.next();
        InputStream in = con.getFileData(fileName);
        file = containerFolder.resolveFile(fileName);
        _log.info("Creating file container file " + getRelativePath(file));
        try {
            file.createFile();
        } catch (FileSystemException e) {
            throw new WGInitialDeployException(
                    "Could not create container file '" + getRelativePath(file) + "'", e);
        }
        OutputStream out = file.getContent().getOutputStream();
        WGUtils.inToOut(in, out, 2048);
        in.close();
        out.close();
    }

    return containerFolder;

}

From source file:fr.cls.atoll.motu.processor.iso19139.ServiceMetadata.java

/**
 * Marshall iso19139.//  ww  w .j  av  a2 s.  c o  m
 * 
 * @param element the element
 * @param fileObject the file object
 * 
 * @throws MotuMarshallException the motu marshall exception
 * @throws FileSystemException the file system exception
 */
public void marshallIso19139(JAXBElement<?> element, FileObject fileObject)
        throws MotuMarshallException, FileSystemException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("marshallIso19139(JAXBElement<?>, FileObject) - entering");
    }

    marshallIso19139(element, fileObject.getContent().getOutputStream());
    fileObject.close();

    if (LOG.isDebugEnabled()) {
        LOG.debug("marshallIso19139(JAXBElement<?>, FileObject) - exiting");
    }
}

From source file:de.innovationgate.wgpublisher.services.WGACoreServicesImpl.java

private List<FSDesignResourceState> createStates(FileObject base, FileObject file)
        throws NoSuchAlgorithmException, IOException {
    List<FSDesignResourceState> states = new ArrayList<FSDesignResourceState>();
    FSDesignResourceState state = new FSDesignResourceState();
    String path = computeRelativePath(base, file);
    state.setPath(path);/*from   w w w.  j a v  a  2s  . co  m*/
    states.add(state);
    if (file.getType() == FileType.FOLDER) {
        state.setType(FSDesignResourceState.TYPE_FOLDER);
        long lastModified = 0;
        for (FileObject child : file.getChildren()) {
            List<FSDesignResourceState> childStates = createStates(base, child);
            for (FSDesignResourceState childState : childStates) {
                states.add(childState);
                lastModified = Math.max(lastModified, childState.getLastmodified());
            }
        }
        state.setLastmodified(lastModified);
    } else {
        state.setType(FSDesignResourceState.TYPE_FILE);
        state.setLastmodified(file.getContent().getLastModifiedTime());
        state.setMd5sum(WGUtils.createMD5HEX(file.getContent().getInputStream()));
    }
    return states;
}

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

private static void determineChangedResources(int resourceType, FileObject categoryFolder, FileObject source,
        FileObject target, FileObject baseFolder, String sourceEncoding, String targetEncoding,
        OverlayStatus status, Logger log, DesignFileValidator validator)
        throws WGDesignSyncException, NoSuchAlgorithmException, IOException {

    for (FileObject sourceFile : source.getChildren()) {
        if (!isValidDesignFile(sourceFile, validator)) {
            continue;
        }//  www .ja va 2s.c  o m

        FileObject targetFile = target.resolveFile(sourceFile.getName().getBaseName());
        String resourcePath = baseFolder.getName().getRelativeName(targetFile.getName());

        if (sourceFile.getType().equals(FileType.FOLDER)) {
            if (!targetFile.exists()) {
                status.getNewFolders().add(targetFile.getName().getPath());
            } else if (targetFile.getType().equals(FileType.FILE)) {
                throw new WGDesignSyncException("Unable to apply overlay. Folder '"
                        + baseFolder.getName().getRelativeName(targetFile.getName())
                        + " already exists as file. Delete it to enable overlay management again");
            }
            determineChangedResources(resourceType, categoryFolder, sourceFile, targetFile, baseFolder,
                    sourceEncoding, targetEncoding, status, log, validator);
        } else if (sourceFile.getType().equals(FileType.FILE)) {

            // File does not exist.
            if (!targetFile.exists()) {

                // Was it once deployed?
                ResourceData originalHash = status.getOverlayData().getOverlayResources().get(resourcePath);
                if (originalHash == null) { // No, so it must be new in base
                    status.addChangedResource(resourceType, sourceFile, targetFile, categoryFolder,
                            OverlayStatus.ChangeType.NEW, resourcePath, null);
                } else { // Yes, Check if the base file changed since deployment
                    String newHash = MD5HashingInputStream
                            .getStreamHash(sourceFile.getContent().getInputStream());
                    if (newHash.equals(originalHash.getMd5Hash())) { // Nope. So this is no change. The overlay just chose not to use the file
                        continue;
                    } else { // Yes, so it is indeed a conflict
                        status.addChangedResource(resourceType, sourceFile, targetFile, categoryFolder,
                                OverlayStatus.ChangeType.CONFLICT, resourcePath, null);
                    }
                }

            }

            // File does exist: Determine if is updated in base since the overlay file was deployed
            else {

                ResourceData originalHash = status.getOverlayData().getOverlayResources().get(resourcePath);
                if (originalHash == null) {
                    if (!status.isUpdatedBaseDesign()) {
                        log.info("There is no information about the original deployment state of  resource "
                                + resourcePath
                                + ". Setting original deployment state now to the current base version.");
                        OverlayData.ResourceData resource = new OverlayData.ResourceData();
                        resource.setMd5Hash(
                                MD5HashingInputStream.getStreamHash(sourceFile.getContent().getInputStream()));
                        status.getOverlayData().setOverlayResource(resourcePath, resource);
                    } else {
                        log.info("Cannot update overlay resource " + resourcePath
                                + " as there is no information of its original deployment state.");
                    }
                    continue;
                }

                // First determine if the resource really changed from what was distributed
                String newHash = MD5HashingInputStream.getStreamHash(sourceFile.getContent().getInputStream());
                if (newHash.equals(originalHash.getMd5Hash())) {
                    continue;
                }

                // Determine if the target file is the same as was distributed. If not then it was user modified, so it is a conflict
                String currentHash = MD5HashingInputStream
                        .getStreamHash(targetFile.getContent().getInputStream());
                if (!currentHash.equals(originalHash.getMd5Hash())) {
                    status.addChangedResource(resourceType, sourceFile, targetFile, categoryFolder,
                            OverlayStatus.ChangeType.CONFLICT, resourcePath, null);
                }

                // It is a normal change
                else {
                    status.addChangedResource(resourceType, sourceFile, targetFile, categoryFolder,
                            OverlayStatus.ChangeType.CHANGED, resourcePath, null);
                }
            }
        }
    }

}

From source file:com.seer.datacruncher.spring.ConnectionsFileDownloadController.java

private String getFileContent(long connId, ConnectionsEntity connectionEntity) {
    String content = "";
    DefaultFileSystemManager fsManager = null;
    FileObject fileObject = null;
    try {/*  w w  w.j  av  a 2  s.c  om*/

        fsManager = (DefaultFileSystemManager) VFS.getManager();
        int serviceId = connectionEntity.getService();

        String hostName = connectionEntity.getHost();
        String port = connectionEntity.getPort();
        String userName = connectionEntity.getUserName();
        String password = connectionEntity.getPassword();
        String inputDirectory = connectionEntity.getDirectory();
        String fileName = connectionEntity.getFileName();

        log.info("Trying to Server polling at server [" + hostName + ":" + port + "] with user[" + userName
                + "].");

        String url = "";
        if (serviceId == Servers.SAMBA.getDbCode()) {
            if (!fsManager.hasProvider("smb")) {
                fsManager.addProvider("smb", new SmbFileProvider());
            }
            url = "smb://" + userName + ":" + password + "@" + hostName + ":" + port + "/" + inputDirectory
                    + "/" + fileName;
        } else if (serviceId == Servers.HTTP.getDbCode()) {
            if (!fsManager.hasProvider("http")) {
                fsManager.addProvider("http", new HttpFileProvider());
            }
            url = "http://" + hostName + ":" + port + "/" + inputDirectory + "/" + fileName;
        } else if (serviceId == Servers.FTP.getDbCode()) {
            if (!fsManager.hasProvider("ftp")) {
                fsManager.addProvider("ftp", new SmbFileProvider());
            }
            url = "ftp://" + userName + ":" + password + "@" + hostName + ":" + port + "/" + inputDirectory
                    + "/" + fileName;
        }

        fileObject = fsManager.resolveFile(url);

        if (fileObject == null || !fileObject.exists() || fileObject.getType().equals(FileType.IMAGINARY)) {
            return null;
        }

        BufferedReader fileReader = new BufferedReader(
                new InputStreamReader(fileObject.getContent().getInputStream()));
        StringBuilder sb = new StringBuilder();

        String line;
        while ((line = fileReader.readLine()) != null) {
            sb.append(line);
        }

        content = sb.toString();

    } catch (Exception ex) {

    } finally {
        try {
            if (fileObject != null) {
                fileObject.close();
            }
            if (fsManager != null) {
                fsManager.freeUnusedResources();
                fsManager.close();
                fsManager = null;
            }
        } catch (Exception ex) {

        } finally {
            fileObject = null;
            fsManager = null;
        }
    }
    return content;

}

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

public InputStream addOrReplaceEntity(final String key, final String entitySetName, final InputStream is)
        throws Exception {

    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    IOUtils.copy(is, bos);//  ww  w  .  j a  v  a 2  s .com
    is.close();

    // -----------------------------------------
    // 0. Retrieve navigation links to be mantained
    // -----------------------------------------
    Set<String> linksToBeMantained;
    try {
        linksToBeMantained = Commons.linkInfo.get(version).getNavigationLinkNames(entitySetName);
    } catch (Exception e) {
        linksToBeMantained = Collections.<String>emptySet();
    }

    for (String availableLink : new HashSet<String>(linksToBeMantained)) {
        try {
            fsManager.resolve(
                    Commons.getLinksPath(version, entitySetName, key, availableLink, Accept.JSON_FULLMETA));
        } catch (Exception e) {
            linksToBeMantained.remove(availableLink);
        }
    }

    for (String linkName : retrieveAllLinkNames(new ByteArrayInputStream(bos.toByteArray()))) {
        linksToBeMantained.remove(linkName);
    }
    // -----------------------------------------

    // -----------------------------------------
    // 1. Get default entry key and path (N.B. operation will consume/close the stream; use a copy instead)
    // -----------------------------------------
    final String entityKey = key == null
            ? getDefaultEntryKey(entitySetName, new ByteArrayInputStream(bos.toByteArray()), getDefaultFormat())
            : key;

    final String path = entitySetName + File.separatorChar + Commons.getEntityKey(entityKey)
            + File.separatorChar;
    // -----------------------------------------

    // -----------------------------------------
    // 2. Retrieve navigation info
    // -----------------------------------------
    final NavigationLinks links = retrieveNavigationInfo(entitySetName,
            new ByteArrayInputStream(bos.toByteArray()));
    // -----------------------------------------

    // -----------------------------------------
    // 3. Normalize navigation info; add edit link; ... and save entity ....
    // -----------------------------------------
    final InputStream createdEntity = saveSingleEntity(entityKey, entitySetName,
            new ByteArrayInputStream(bos.toByteArray()), links);
    // -----------------------------------------

    bos.reset();
    IOUtils.copy(createdEntity, bos);

    // -----------------------------------------
    // 4. Add navigation links to be mantained
    // -----------------------------------------
    final InputStream normalizedEntity = addLinks(entitySetName, entityKey,
            new ByteArrayInputStream(bos.toByteArray()), linksToBeMantained);
    // -----------------------------------------

    IOUtils.closeQuietly(bos);

    // -----------------------------------------
    // 5. save the entity
    // -----------------------------------------
    final FileObject fo = fsManager.putInMemory(normalizedEntity,
            fsManager.getAbsolutePath(path + ENTITY, getDefaultFormat()));
    // -----------------------------------------

    // -----------------------------------------
    // 4. Create links file and provided inlines
    // -----------------------------------------
    for (Map.Entry<String, List<String>> link : links.getLinks()) {
        putLinksInMemory(path, entitySetName, entityKey, link.getKey(), link.getValue());
    }

    for (Map.Entry<String, List<InputStream>> inlineEntry : links.getInlines()) {
        final String inlineEntitySetName = Commons.linkInfo.get(version).getTargetName(entitySetName,
                inlineEntry.getKey());

        final List<String> hrefs = new ArrayList<String>();

        for (InputStream stream : inlineEntry.getValue()) {
            final ByteArrayOutputStream inlineBos = new ByteArrayOutputStream();
            IOUtils.copy(stream, inlineBos);
            IOUtils.closeQuietly(stream);

            final String inlineEntryKey = getDefaultEntryKey(inlineEntitySetName,
                    new ByteArrayInputStream(inlineBos.toByteArray()), getDefaultFormat());

            addOrReplaceEntity(inlineEntryKey, inlineEntitySetName,
                    new ByteArrayInputStream(inlineBos.toByteArray()));

            hrefs.add(inlineEntitySetName + "(" + inlineEntryKey + ")");
        }

        putLinksInMemory(path, entitySetName, entityKey, inlineEntry.getKey(), hrefs);
    }
    // -----------------------------------------

    return fo.getContent().getInputStream();
}

From source file:de.innovationgate.utils.WGUtils.java

/**
 * Resolves an eventually present directory link file (variant with Commons VFS file objects). Use this with folders that either may be used themselves or that contain a directory link pointing to the directory to use.
 * @param file The directory that might contain a directory link file.
 * @return Either the path that an available directory link file points to or the given directory itself again.
 *//*from w  ww  .  j a  v  a 2 s.c om*/
public static FileObject resolveDirLink(FileObject file) throws FileSystemException {

    if (file != null && file.exists()) {
        if (file.getType().equals(FileType.FOLDER)) {
            FileObject link = file.resolveFile(DIRLINK_FILE);
            if (link.exists()) {
                // dir link present resolve

                Document doc;
                try {
                    InputStream fileInputStream = link.getContent().getInputStream();
                    String linkLocation = readDirLinkLocation(fileInputStream);
                    if (linkLocation != null) {
                        if (linkLocation.startsWith("../")) {
                            return file.resolveFile(linkLocation);
                        } else {
                            return file.getFileSystem().resolveFile(linkLocation);
                        }
                    }
                } catch (Exception e) {
                    Logger.getLogger("wga.utils")
                            .error("Unable to resolve dir link. '" + link.getName().getPath() + "'.", e);
                }
            }
        }
    }
    // no dir link or file does not exist - just return
    return file;

}

From source file:com.seer.datacruncher.spring.IsSuccessfulConnectionController.java

private String checkServiceRunning(int service, String connID) {

    String success = "true";
    String url = "";
    ConnectionsEntity conn = connectionsDao.find(Long.parseLong(connID));
    DefaultFileSystemManager fsManager = null;
    FileObject fileObject = null;
    String userName = "";
    String password = "";
    String hostName = "";
    String port = "";
    String inputDirectory = "";
    String fileName = "";
    int connType = 1;

    if (conn != null) {
        userName = conn.getUserName();//w ww .j a v  a  2s  . c om
        password = conn.getPassword();
        hostName = conn.getHost();
        port = conn.getPort();
        inputDirectory = conn.getDirectory();
        fileName = conn.getFileName();
        connType = conn.getIdConnType();

    }

    if (connType == GenericType.DownloadTypeConn) {
        if (fileName == null || fileName.trim().length() == 0) {
            return "false";
        } else {
            fileName = "/" + fileName;
        }
    } else {
        fileName = "";
    }

    try {
        fsManager = (DefaultFileSystemManager) VFS.getManager();
        if (service == Servers.SAMBA.getDbCode()) {
            if (!fsManager.hasProvider("smb")) {
                fsManager.addProvider("smb", new SmbFileProvider());
            }
            url = "smb://" + userName + ":" + password + "@" + hostName + ":" + port + "/" + inputDirectory
                    + fileName;
        } else if (service == Servers.HTTP.getDbCode()) {
            if (!fsManager.hasProvider("http")) {
                fsManager.addProvider("http", new HttpFileProvider());
            }
            url = "http://" + hostName + ":" + port + "/" + inputDirectory + fileName;
        } else if (service == Servers.FTP.getDbCode()) {
            if (!fsManager.hasProvider("ftp")) {
                fsManager.addProvider("ftp", new FtpFileProvider());
            }
            url = "ftp://" + userName + ":" + password + "@" + hostName + ":" + port + "/" + inputDirectory
                    + fileName;
        }

        fileObject = fsManager.resolveFile(url);

        if (fileObject == null || !fileObject.exists()) {
            success = "false";
        }

        if (connType == GenericType.DownloadTypeConn) {
            if (fileObject.getType().equals(FileType.IMAGINARY)) {
                success = "false";
            }
            byte data[] = new byte[(int) fileObject.getContent().getSize()];
            fileObject.getContent().getInputStream().read(data);
        }

    } catch (Exception ex) {
        success = "false";
    } finally {
        try {
            if (fileObject != null) {
                fileObject.close();
            }
            if (fsManager != null) {
                fsManager.freeUnusedResources();
                fsManager.close();
                fsManager = null;
            }
        } catch (Exception ex) {

        } finally {
            fileObject = null;
            fsManager = null;
        }
    }

    return success;
}

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

private static void determineChangedFileContainerResources(FileObject categoryFolder, FileObject source,
        FileObject target, FileObject baseFolder, String sourceEncoding, String targetEncoding,
        OverlayStatus status, Logger log, DesignFileValidator validator)
        throws WGDesignSyncException, NoSuchAlgorithmException, IOException {

    String targetResourcePath = baseFolder.getName().getRelativeName(target.getName());
    Set<String> involvedFiles = new HashSet<String>();

    // Completely new folder is a new file container
    if (!target.exists()) {

        status.addChangedResource(WGDocument.TYPE_FILECONTAINER, source, target, categoryFolder, ChangeType.NEW,
                targetResourcePath, null);
        // Als add all subfolders
        for (FileObject sourceFile : source.getChildren()) {
            if (sourceFile.getType().equals(FileType.FOLDER)) {
                FileObject targetFile = target.resolveFile(sourceFile.getName().getBaseName());
                determineChangedFileContainerResources(categoryFolder, sourceFile, targetFile, baseFolder,
                        sourceEncoding, targetEncoding, status, log, validator);
            }// w  w w.  j  a va 2s.c om
        }
        return;
    }

    if (target.getType().equals(FileType.FILE)) {
        throw new WGDesignSyncException(
                "Unable to apply overlay. Folder '" + baseFolder.getName().getRelativeName(target.getName())
                        + " already exists as file. Delete it to enable overlay management again");
    }

    // Determine change type by iterating through source child files and compare with target
    boolean overlayChanged = false;
    boolean baseChanged = false;
    boolean directConflict = false;

    for (FileObject sourceFile : source.getChildren()) {
        if (!isValidDesignFile(sourceFile, validator)) {
            continue;
        }

        FileObject targetFile = target.resolveFile(sourceFile.getName().getBaseName());
        String fileResourcePath = baseFolder.getName().getRelativeName(targetFile.getName());

        if (sourceFile.getType().equals(FileType.FOLDER)) {
            // Descend onto subcontainer
            determineChangedFileContainerResources(categoryFolder, sourceFile, targetFile, baseFolder,
                    sourceEncoding, targetEncoding, status, log, validator);
        } else if (sourceFile.getType().equals(FileType.FILE)) {

            // File does not exist. Look if it was once deployed.
            if (!targetFile.exists()) {

                ResourceData resourceData = status.getOverlayData().getOverlayResources().get(fileResourcePath);
                if (resourceData != null) {
                    // Did already exist. But did it have the same content?
                    String newHash = MD5HashingInputStream
                            .getStreamHash(sourceFile.getContent().getInputStream());
                    if (newHash.equals(resourceData.getMd5Hash())) {
                        overlayChanged = true;
                        involvedFiles.add(sourceFile.getName().getBaseName() + " (removed in overlay)");
                    } else {
                        baseChanged = true;
                        overlayChanged = true;
                        directConflict = true;
                        involvedFiles.add(
                                sourceFile.getName().getBaseName() + " (removed in overlay, changed in base)");
                    }

                }

                // Did not yet exist. It is a new file in the base version.
                else {
                    baseChanged = true;
                    involvedFiles.add(sourceFile.getName().getBaseName() + " (new in base)");
                }

            }

            // File does exist: Determine if is updated in base since the overlay file was deployed
            else {

                ResourceData originalHash = status.getOverlayData().getOverlayResources().get(fileResourcePath);
                if (originalHash == null) {
                    log.warn("There is no information about the original deployment state of resource '"
                            + fileResourcePath + "' so its change status cannot be determined.");
                    OverlayData.ResourceData resource = new OverlayData.ResourceData();
                    resource.setMd5Hash(
                            MD5HashingInputStream.getStreamHash(sourceFile.getContent().getInputStream()));
                    status.getOverlayData().setOverlayResource(fileResourcePath, resource);
                    continue;
                }

                // First determine if the resource really changed from what was distributed
                String newHash = MD5HashingInputStream.getStreamHash(sourceFile.getContent().getInputStream());
                if (newHash.equals(originalHash.getMd5Hash())) {
                    continue;
                }

                // Determine if the target file is the same as was distributed. If not then it was user modified, so it is a conflict
                String currentHash = MD5HashingInputStream
                        .getStreamHash(targetFile.getContent().getInputStream());
                if (!currentHash.equals(originalHash.getMd5Hash())) {
                    overlayChanged = true;
                    baseChanged = true;
                    directConflict = true;
                    involvedFiles.add(sourceFile.getName().getBaseName() + " (changed in base and overlay)");
                    break;
                }

                // It is a normal change
                else {
                    baseChanged = true;
                    involvedFiles.add(sourceFile.getName().getBaseName() + " (changed in base)");
                }
            }
        }
    }

    // Test the target files. Files may have been added there, or files from the previous base version may still be present that got deleted in the new base version.
    if (!baseChanged || !overlayChanged) {
        for (FileObject targetFile : target.getChildren()) {
            FileObject sourceFile = source.resolveFile(targetFile.getName().getBaseName());
            if (!sourceFile.exists()) {

                // Look if it was deployed with the previous base version.
                String fileResourcePath = baseFolder.getName().getRelativeName(targetFile.getName());
                ResourceData resourceData = status.getOverlayData().getOverlayResources().get(fileResourcePath);
                if (resourceData != null) {
                    // Was deployed. But with same contents?
                    String targetHash = MD5HashingInputStream
                            .getStreamHash(targetFile.getContent().getInputStream());
                    if (targetHash.equals(resourceData.getMd5Hash())) {
                        // This is a file that was from previous base version and got removed in the new base version.
                        involvedFiles.add(targetFile.getName().getBaseName() + " (removed from base)");
                        baseChanged = true;
                    }

                    // File got removed in new base version, updated in overlay. Conflict.
                    else {
                        baseChanged = true;
                        overlayChanged = true;
                        directConflict = true;
                        involvedFiles.add(targetFile.getName().getBaseName()
                                + " (removed from base, changed in overlay)");
                        break;
                    }
                } else {
                    involvedFiles.add(targetFile.getName().getBaseName() + " (new in overlay)");
                    overlayChanged = true;
                }
            }
        }
    }

    // Determine change type based on the found changes
    ChangeType changeType = null;
    if (baseChanged) {
        if (overlayChanged) {
            changeType = ChangeType.CONFLICT;
        } else {
            changeType = ChangeType.CHANGED;
        }
    }

    if (changeType != null) {
        status.addChangedResource(WGDocument.TYPE_FILECONTAINER, source, target, categoryFolder, changeType,
                targetResourcePath, involvedFiles);
    }

}