/** * Test utility to determine whether the given list of directories contains a directory of given * path. */ private boolean containsPath(Collection<MediaFileDirectory> directories, String path) { for (MediaFileDirectory directory : directories) { if (path.equals(directory.getPath())) { return true; } } return false; }
/** * Fetches and displays list of media file for the given directory. The directory could be chosen * by ID or path. * * @return String The result of the action. */ @SkipValidation public String execute() { MediaFileManager manager = WebloggerFactory.getWeblogger().getMediaFileManager(); try { MediaFileDirectory directory; if (StringUtils.isNotEmpty(this.directoryId)) { directory = manager.getMediaFileDirectory(this.directoryId); } else if (StringUtils.isNotEmpty(this.directoryPath)) { directory = manager.getMediaFileDirectoryByPath(getActionWeblog(), this.directoryPath); } else { directory = manager.getMediaFileRootDirectory(getActionWeblog()); } this.directoryId = directory.getId(); this.directoryPath = directory.getPath(); this.childDirectories = new ArrayList<MediaFileDirectory>(); this.childDirectories.addAll(directory.getChildDirectories()); this.childFiles = new ArrayList<MediaFile>(); this.childFiles.addAll(directory.getMediaFiles()); if ("type".equals(sortBy)) { Collections.sort(this.childFiles, new MediaFileComparator(MediaFileComparatorType.TYPE)); } else if ("date_uploaded".equals(sortBy)) { Collections.sort( this.childFiles, new MediaFileComparator(MediaFileComparatorType.DATE_UPLOADED)); } else { // default to sort by name sortBy = "name"; Collections.sort( this.childDirectories, new MediaFileDirectoryComparator(DirectoryComparatorType.NAME)); Collections.sort(this.childFiles, new MediaFileComparator(MediaFileComparatorType.NAME)); } this.currentDirectory = directory; return SUCCESS; } catch (FileIOException ex) { log.error("Error viewing media file directory ", ex); addError("MediaFile.error.view"); } catch (Exception e) { log.error("Error viewing media file directory ", e); addError("MediaFile.error.view"); } return SUCCESS; }