public List findFileAttachments()

in src/main/java/com/atlassian/uwc/converters/pmwiki/PmWikiPrepareAttachmentFilesConverter.java [108:190]


    public List findFileAttachments(List<String> attachmentFileTargetTexts, Page page) {
        boolean fileFound = false;
        List filesFound = new ArrayList();
        for (String fileNameText : attachmentFileTargetTexts) {
            fileNameText = fileNameText.trim();
            // chop off non-alpha char
            char lastChar = fileNameText.charAt(fileNameText.length() - 1);
            while (isCharNonAlpha(lastChar) && fileNameText.length() > 0) {
                // chop off non-alpha char
                fileNameText = fileNameText.substring(0, fileNameText.length() - 1);
                lastChar = fileNameText.charAt(fileNameText.length() - 1);
            }
            if (fileNameText.contains("Design/AustinSiteMap.pdf")){
                log.debug("breakpoint");
            }

            File file;
            String attachmentDir = this.getAttachmentDirectory();
            File attdir = new File(attachmentDir);
            if (attachmentDir == null || 
            		!new File(attachmentDir).exists() || 
            		!new File(attachmentDir).isDirectory()) {
            	String note = "Attachment Directory does not exist or is not a directory: '" +
            		attachmentDir + "'";
            	log.error(note);
            	addError(Feedback.BAD_SETTING, note, true);
            	return null;
            }

            // look in group
            String groupDir = page.getFile().getParentFile().getName();
            String fileLocToTry = attachmentDir + File.separator + groupDir + File.separator + fileNameText;
            file = new File(fileLocToTry);
            if (file.exists()) {
                filesFound.add(file);
                continue;
            }
            // look in path if it exists
            String tryFileNametext = fileNameText.replace("/", File.separator);
            fileLocToTry = attachmentDir + File.separator + fileNameText;
            file = new File(fileLocToTry);
            if (file.exists()) {
                filesFound.add(file);
                continue;
            }

            // feel around the rest of the path
            String pathParts[] = fileNameText.split("/");
            fileLocToTry = attachmentDir + File.separator + "Main" + File.separator + pathParts[pathParts.length-1];
            file = new File(fileLocToTry);
            if (file.exists()) {
                filesFound.add(file);
                continue;
            }
            fileLocToTry = attachmentDir + File.separator + pathParts[0] + File.separator + pathParts[pathParts.length-1];
            file = new File(fileLocToTry);
            if (file.exists()) {
                filesFound.add(file);
                continue;
            }
            if (pathParts.length==3) {
                fileLocToTry = attachmentDir + File.separator + pathParts[1] + File.separator + pathParts[pathParts.length-1];
            }
            file = new File(fileLocToTry);
            if (file.exists()) {
                filesFound.add(file);
                continue;
            }


            // look in Main
            fileLocToTry = attachmentDir + File.separator + "Main" + File.separator + fileNameText;
            file = new File(fileLocToTry);
            if (file.exists()) {
                filesFound.add(file);
                continue;
            }

            // the file was not found
            allFilesNotFound.add(fileNameText);
        }
        return filesFound;  // @author brendan.patterson
    }