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

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

Introduction

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

Prototype

FileObject[] getChildren() throws FileSystemException;

Source Link

Document

Lists the children of this file.

Usage

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

public WGADesign getDesign(final String name) throws WGADesignRetrievalException {
    try {/* w w  w.  j  a  va 2 s  .c om*/

        // Design archive (obsolete)
        if (name.startsWith(DESIGNNAMEPREFIX_ARCHIVE)) {
            String designName = name.substring(DESIGNNAMEPREFIX_ARCHIVE.length());
            FileObject designFile = _dir.resolveFile(designName + ARCHIVED_DESIGN_EXTENSION);
            if (!designFile.exists()) {
                return null;
            }

            WGADesign design = new WGADesign();
            design.setSource(this);
            design.setName(name);
            design.setTitle(designFile.getName().getBaseName());
            design.setDescription("Design at location " + designFile.getURL().toString());
            return design;
        }

        // Additional directory
        else if (name.startsWith(DESIGNNAMEPREFIX_ADDITIONALDIR)) {
            String designName = name.substring(DESIGNNAMEPREFIX_ADDITIONALDIR.length());
            String dirPath = _additionalDirs.get(designName);
            if (dirPath == null) {
                return null;
            }

            FileObject dir = VFS.getManager().resolveFile((String) dirPath);
            if (!dir.exists() || !dir.getType().equals(FileType.FOLDER)) {
                return null;
            }

            FileObject syncInfo = DesignDirectory.getDesignDefinitionFile(dir);

            // Non-empty directories without syncinfo may not be used as design directories
            if (syncInfo == null && dir.getChildren().length != 0) {
                return null;
            }

            WGADesign design = new WGADesign();
            design.setSource(this);
            design.setName(DESIGNNAMEPREFIX_ADDITIONALDIR + name);
            design.setTitle(dir.getName().getBaseName());
            design.setDescription("Design at location " + dir.getURL().toString());
            design.setConfig(loadConfig(syncInfo));
            design.setOverlayData(loadOverlayData(syncInfo));

            return design;

        }

        // Regular design in configured directory
        else {
            _dir.refresh();
            FileObject child = _dir.resolveFile(name);
            if (!child.exists()) {
                return null;
            }

            FileObject resolvedChild = WGUtils.resolveDirLink(child);
            if (!resolvedChild.getType().equals(FileType.FOLDER)) {
                return null;
            }

            FileObject syncInfo = DesignDirectory.getDesignDefinitionFile(resolvedChild);

            // Non-empty directories without syncinfo may not be used as design directories
            if (syncInfo == null && child.getChildren().length != 0) {
                return null;
            }

            WGADesign design = new WGADesign();
            design.setSource(this);
            design.setName(child.getName().getBaseName());
            design.setTitle(child.getName().getBaseName());
            design.setDescription("Design at location " + child.getURL().toString());
            design.setConfig(loadConfig(syncInfo));
            design.setOverlayData(loadOverlayData(syncInfo));
            return design;
        }
    } catch (FileSystemException e) {
        throw new WGADesignRetrievalException("Exception retrieving file system designs", e);
    }
}

From source file:de.innovationgate.wgpublisher.design.sync.FileContainerDeployment.java

public void performUpdate(WGDatabase db)
        throws IOException, WGException, InstantiationException, IllegalAccessException, WGDesignSyncException {

    FileObject codeFile = getCodeFile();
    // Check if file has been deleted in the meantime
    if (!codeFile.exists()) {
        return;/*from   ww w  . ja v a  2 s .c o  m*/
    }

    WGFileContainer con = (WGFileContainer) db.getDocumentByDocumentKey(getDocumentKey());
    if (con == null) {
        WGDocumentKey docKey = new WGDocumentKey(getDocumentKey());
        con = db.createFileContainer(docKey.getName());
        con.save();
    }

    // Find new and updated files
    FileObject[] filesArray = codeFile.getChildren();
    if (filesArray == null) {
        throw new WGDesignSyncException("Cannot collect files from directory '"
                + codeFile.getName().getPathDecoded() + "'. Please verify directory existence.");
    }

    List<FileObject> files = new ArrayList<FileObject>(Arrays.asList(filesArray));
    Collections.sort(files, new FileNameComparator());

    FileObject file;
    Map existingFiles = new HashMap();
    for (int i = 0; i < files.size(); i++) {
        file = (FileObject) files.get(i);
        if (isExcludedFileContainerFile(file)) {
            continue;
        }

        ContainerFile containerFile = getContainerFile(file);
        if (containerFile != null) {
            if (existingFiles.containsKey(containerFile.getName())) {
                // Possible in case-sensitive file systems. Another file of the same name with another case is in the dir.
                continue;
            }

            if (file.getContent().getLastModifiedTime() != containerFile.getTimestamp()) {
                doRemoveFile(con, file.getName().getBaseName());
                doSaveDocument(con);
                doAttachFile(con, file);
                doSaveDocument(con);
                containerFile.setTimestamp(file.getContent().getLastModifiedTime());
            }
        } else {
            containerFile = new ContainerFile(file);
            if (con.hasFile(file.getName().getBaseName())) {
                doRemoveFile(con, file.getName().getBaseName());
                doSaveDocument(con);
            }
            doAttachFile(con, file);
            doSaveDocument(con);
        }
        existingFiles.put(containerFile.getName(), containerFile);
    }

    // Remove deleted files from container
    _files = existingFiles;
    List fileNamesInContainer = WGUtils.toLowerCase(con.getFileNames());
    fileNamesInContainer.removeAll(existingFiles.keySet());
    Iterator deletedFiles = fileNamesInContainer.iterator();
    while (deletedFiles.hasNext()) {
        con.removeFile((String) deletedFiles.next());
        con.save();
    }

    // Update metadata and save
    FCMetadata metaData = (FCMetadata) readMetaData();
    metaData.writeToDocument(con);
    con.save();
    FileObject metadataFile = getMetadataFile();
    if (metadataFile.exists()) {
        _timestampOfMetadataFile = metadataFile.getContent().getLastModifiedTime();
    }

    // We wont do this here, since this would rebuild all ContainerFiles, which is not neccessary
    // Instead we have updated just the metadata file timestamp
    // resetUpdateInformation();
}

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

public void obtainUrls(FileObject rootEar, FileObject ear, CopyOnWriteArrayList<URL> fileObjects,
        CopyOnWriteArrayList<FileObject> warObjects, CopyOnWriteArrayList<FileObject> jarObjects,
        CopyOnWriteArrayList<FileObject> sarObjects, CopyOnWriteArrayList<FileObject> rarObjects,
        CopyOnWriteArrayList<FileObject> ezbObjects, StandardFileSystemManager fsManager) throws IOException {
    FileObject[] childrenJars = ear.getChildren();
    for (int childcount = 0; childcount < childrenJars.length; childcount++) {
        if (childrenJars[childcount].getType() == FileType.FOLDER) {
            obtainUrls(rootEar, childrenJars[childcount], fileObjects, warObjects, jarObjects, sarObjects,
                    rarObjects, ezbObjects, fsManager);
        }//from w w w.  jav  a2 s  .co m
        // log.info(childrenJars[childcount]);
        // log.info(childrenJars[childcount].getName().getBaseName());
        // log.info(ear.getURL());
        if (childrenJars[childcount].getType() == FileType.FILE
                && (childrenJars[childcount].getName().getBaseName().endsWith(".jar")
                        || childrenJars[childcount].getName().getBaseName().endsWith(".war")
                        || childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".rar")
                        || childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".sar"))) {
            // log.info(childrenJars[childcount].getURL());
            if ((childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".war")
                    || childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".jar")
                    || childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".rar")
                    || childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".sar")
                    || childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".ezb"))
                    && !childrenJars[childcount].getURL().toString().trim()
                            .startsWith(rootEar.getURL().toString() + "lib/")) {
                //File file=new File(serverConfig.getDeploydirectory()+"/"+childrenJars[childcount].getName().getBaseName());
                /*if(!file.exists()||(file.exists()&&file.lastModified()!=childrenJars[childcount].getContent().getLastModifiedTime())){
                   //InputStream fistr=childrenJars[childcount].getContent().getInputStream();
                   byte[] filyByt=new byte[4096];
                   FileOutputStream warFile=new FileOutputStream(serverConfig.getDeploydirectory()+"/"+childrenJars[childcount].getName().getBaseName()+".part");
                   int len=0;
                   while((len=fistr.read(filyByt))!=-1){
                      warFile.write(filyByt,0,len);
                   }
                   warFile.close();
                   fistr.close();
                   new File(serverConfig.getDeploydirectory()+"/"+childrenJars[childcount].getName().getBaseName()+".part").renameTo(file);
                   warObjects.add(childrenJars[childcount]);
                }*/
                if (childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".war")) {
                    warObjects.add(childrenJars[childcount]);
                } else if (childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".jar")) {
                    jarObjects.add(childrenJars[childcount]);
                } else if (childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".sar")) {
                    sarObjects.add(childrenJars[childcount]);
                } else if (childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".rar")) {
                    rarObjects.add(childrenJars[childcount]);
                } else if (childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".ezb")) {
                    ezbObjects.add(childrenJars[childcount]);
                }
            } else {
                log.info("ear libs/" + childrenJars[childcount]);
                fileObjects.add(new URL(childrenJars[childcount].getURL().toString()
                        .replace(rootEar.getURL().toString(), "rsrc:")));
            }
            // log.info(childrenJars[childcount].getURL().toString()+" "+rootEar.getURL());

        } else {
            childrenJars[childcount].close();
        }
    }
}

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

public void obtainUrls(FileObject rootEar, FileObject ear, CopyOnWriteArrayList<FileObject> fileObjects,
        ConcurrentHashMap jarclassListMap, CopyOnWriteArrayList<FileObject> warObjects,
        StandardFileSystemManager fsManager) throws IOException {
    FileObject[] childrenJars = ear.getChildren();
    for (int childcount = 0; childcount < childrenJars.length; childcount++) {
        if (childrenJars[childcount].getType() == FileType.FOLDER) {
            obtainUrls(rootEar, childrenJars[childcount], fileObjects, jarclassListMap, warObjects, fsManager);
        }//from   w  w  w  .  ja  v  a 2 s.  c o  m
        // System.out.println(childrenJars[childcount]);
        // System.out.println(childrenJars[childcount].getName().getBaseName());
        // System.out.println(ear.getURL());
        if (childrenJars[childcount].getType() == FileType.FILE
                && (childrenJars[childcount].getName().getBaseName().endsWith(".jar")
                        || childrenJars[childcount].getName().getBaseName().endsWith(".war"))) {
            // System.out.println(childrenJars[childcount].getURL());
            if (childrenJars[childcount].getName().getBaseName().endsWith(".war")) {
                File file = new File(scanDirectory + "/" + childrenJars[childcount].getName().getBaseName());
                if (!file.exists() || (file.exists() && file.lastModified() != childrenJars[childcount]
                        .getContent().getLastModifiedTime())) {
                    InputStream fistr = childrenJars[childcount].getContent().getInputStream();
                    byte[] filyByt = new byte[4096];
                    FileOutputStream warFile = new FileOutputStream(
                            scanDirectory + "/" + childrenJars[childcount].getName().getBaseName());
                    int len = 0;
                    while ((len = fistr.read(filyByt)) != -1) {
                        warFile.write(filyByt, 0, len);
                    }
                    warFile.close();
                    fistr.close();
                    warObjects.add(childrenJars[childcount]);
                }
            }
            // System.out.println(childrenJars[childcount].getURL().toString()+" "+rootEar.getURL());
            else if (!childrenJars[childcount].getURL().toString().trim()
                    .startsWith(rootEar.getURL().toString() + "lib/")) {
                CopyOnWriteArrayList<String> classList = new CopyOnWriteArrayList<String>();
                getClassList(childrenJars[childcount], classList, fsManager);
                jarclassListMap.put(childrenJars[childcount], classList);
            } else {
                System.out.println("ear libs/" + childrenJars[childcount]);
                fileObjects.add(childrenJars[childcount]);
            }
        } else {
            childrenJars[childcount].close();
        }
    }
}

From source file:fi.mystes.synapse.mediator.vfs.VfsFileTransferUtility.java

/**
 * Helper method for file listing.//  w ww . java 2  s .co m
 * 
 * @param sourceDirectoryPath
 *            Source directory path to list files from
 * @param filePatternRegex
 *            File pattern regex for file listing
 * @return Array containing file object listed by given file pattern regex
 * @throws FileSystemException
 *             If file listing fails
 */
private FileObject[] listFiles(String sourceDirectoryPath, String filePatternRegex) throws FileSystemException {
    FileObject fromDirectory = resolveFile(sourceDirectoryPath);
    log.debug("Source directory: " + fileObjectNameForDebug(fromDirectory));
    // check that both of the parameters are folders
    isFolder(fromDirectory);

    FileObject[] fileList;
    // if file pattern exists, get files from folder according to that
    if (filePatternRegex != null) {
        log.debug("Applying file pattern " + filePatternRegex);
        FileFilter ff = initFileFilter(filePatternRegex);
        fileList = fromDirectory.findFiles(new FileFilterSelector(ff));
    } else {
        // List all the files in that directory and copy each
        fileList = fromDirectory.getChildren();
    }

    fromDirectory.close();
    log.debug("Found " + fileList.length + " files in source directory");
    return fileList;
}

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);
            }//from www  .j av a  2  s.co  m
        }
        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);
    }

}

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

private static boolean performChange(ChangedDocument changedDocument,
        FileSystemDesignProvider originalDesignProvider, OverlayStatus status, String targetEncoding,
        FileObject baseFolder, Logger log, DesignFileValidator validator) throws FileSystemException,
        NoSuchAlgorithmException, UnsupportedEncodingException, IOException, WGDesignSyncException {

    boolean conflictFileCreated = false;
    log.info("Updating overlay resource " + changedDocument.getDocumentKey());

    // Find files which represent the document in source and target
    FileObject sourceDocFile = originalDesignProvider.getBaseFolder()
            .resolveFile(changedDocument.getSourceFilePath());
    FileObject targetDocFile = baseFolder.resolveFile(changedDocument.getTargetFilePath());

    // Collect files to copy and delete
    Map<FileObject, FileObject> filesToCopy = new HashMap<FileObject, FileObject>();
    List<FileObject> filesToDelete = new ArrayList<FileObject>();

    // Collect for file containers: Must traverse container content
    if (changedDocument.getDocumentKey().getDocType() == WGDocument.TYPE_FILECONTAINER) {

        if (changedDocument.getChangeType() == ChangeType.NEW) {
            targetDocFile.createFolder();
        }//from www .j  a  v  a 2 s. c o  m

        // Copy all files in container from the source to the target 
        for (FileObject sourceFile : sourceDocFile.getChildren()) {
            if (sourceFile.getType().equals(FileType.FILE)) {
                if (!isValidDesignFile(sourceFile, validator)) {
                    continue;
                }
                filesToCopy.put(sourceFile, targetDocFile.resolveFile(sourceFile.getName().getBaseName()));
            }
        }

        // Delete all files in target that were deployed with previous base version but are deleted in current base version 
        for (FileObject targetFile : targetDocFile.getChildren()) {
            if (targetFile.getType().equals(FileType.FILE)) {
                if (!isValidDesignFile(targetFile, validator)) {
                    continue;
                }

                FileObject sourceFile = sourceDocFile.resolveFile(targetFile.getName().getBaseName());
                if (sourceFile.exists()) {
                    continue;
                }

                // Only delete those that were deployed with previous base version and have unaltered content
                String resourcePath = baseFolder.getName().getRelativeName(targetFile.getName());
                ResourceData resourceData = status.getOverlayData().getOverlayResources().get(resourcePath);
                if (resourceData != null) {
                    String hash = MD5HashingInputStream.getStreamHash(targetFile.getContent().getInputStream());
                    if (resourceData.getMd5Hash().equals(hash)) {
                        filesToDelete.add(targetFile);
                    }
                }
            }
        }

    }

    // Collect for anything else
    else {
        filesToCopy.put(sourceDocFile, targetDocFile);
    }

    // Copy files
    for (Map.Entry<FileObject, FileObject> files : filesToCopy.entrySet()) {

        FileObject sourceFile = files.getKey();
        FileObject targetFile = files.getValue();
        String resourcePath = baseFolder.getName().getRelativeName(targetFile.getName());

        if (changedDocument.getChangeType() == ChangeType.CONFLICT) {
            // Do a test if the current file is conflicting. If so we write to a conflict file instead
            InputStream in = new BufferedInputStream(sourceFile.getContent().getInputStream());
            String currentHash = MD5HashingInputStream.getStreamHash(in);
            ResourceData deployedHash = status.getOverlayData().getOverlayResources().get(resourcePath);
            boolean skipConflict = false;

            // Conflict on file container: A single file might just be missing in the target. We can safely copy that to the target without treating as conflict (#00002440)
            if (deployedHash == null
                    && changedDocument.getDocumentKey().getDocType() == WGDocument.TYPE_FILECONTAINER
                    && !targetFile.exists()) {
                skipConflict = true;
            }

            if (!skipConflict && (deployedHash == null || !deployedHash.getMd5Hash().equals(currentHash))) {
                targetFile = createConflictFile(targetFile);
                conflictFileCreated = true;
                log.warn("Modified overlay resource " + resourcePath
                        + " is updated in base design. We write the updated base version to conflict file for manual resolution: "
                        + baseFolder.getName().getRelativeName(targetFile.getName()));
            }
        }

        // Write file
        InputStream in = new BufferedInputStream(sourceFile.getContent().getInputStream());
        MD5HashingOutputStream out = new MD5HashingOutputStream(
                new BufferedOutputStream(targetFile.getContent().getOutputStream(false)));

        // Update resource data
        resourceInToOut(in, originalDesignProvider.getFileEncoding(), out, targetEncoding);
        OverlayData.ResourceData resourceData = new OverlayData.ResourceData();
        resourceData.setMd5Hash(out.getHash());
        status.getOverlayData().setOverlayResource(resourcePath, resourceData);

    }

    // Delete files
    for (FileObject fileToDelete : filesToDelete) {
        String resourcePath = baseFolder.getName().getRelativeName(fileToDelete.getName());
        fileToDelete.delete();
        status.getOverlayData().removeOverlayResource(resourcePath);
    }

    return conflictFileCreated;

}

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

private List<ModuleFile> getFileContainerFiles(FileObject filesFolder, String prefix)
        throws FileSystemException {
    FileObject[] files = filesFolder.getChildren();
    List<ModuleFile> designFiles = new ArrayList<ModuleFile>();
    for (int i = 0; i < files.length; i++) {
        FileObject file = files[i];
        if (file.getType().equals(FileType.FOLDER) && isValidDesignFile(file)) {
            designFiles.add(new ModuleFile(file, prefix, "", WGDocument.TYPE_FILECONTAINER));
            String newPrefix = (prefix.trim().equals("") ? file.getName().getBaseName().toLowerCase()
                    : prefix + DIRECTORY_DIVIDER + file.getName().getBaseName().toLowerCase());
            designFiles.addAll(getFileContainerFiles(file, newPrefix));
        }//from   w  ww .j  a v a2  s.co m
    }
    return designFiles;
}

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);/*  w w  w  .  j av  a  2s .c o  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.FileSystemDesignManager.java

private FileObject findMatchingChild(FileObject folder, String baseName, Set<String> suffixes,
        boolean exactMatch) throws FileSystemException {
    FileObject matchingChild = null;

    // First try fast straight fetch using lowercase file
    for (String suffix : suffixes) {
        FileObject straightChild = folder.resolveFile(baseName.toLowerCase() + suffix.toLowerCase());
        if (straightChild.exists()) {
            return straightChild;
        }/*  w  w w .  j  ava  2 s  .c  o m*/
    }

    // Secondly we iterate over all children and to a case-insensitive
    // equals
    FileObject[] children = folder.getChildren();

    for (String suffix : suffixes) {
        for (FileObject child : children) {
            if (exactMatch) {
                if (child.getName().getBaseName().equalsIgnoreCase(baseName + suffix)) {
                    matchingChild = child;
                    break;
                }
            } else {
                String fileName = child.getName().getBaseName().toLowerCase();
                String elementName = baseName.toLowerCase() + suffix.toLowerCase();
                if (fileName.startsWith(elementName) && fileName.indexOf(".", elementName.length()) == -1) {
                    matchingChild = child;
                    break;
                }
            }
        }
    }

    return matchingChild;
}