private static boolean checkRelativePath()

in ti/phase2/jars/core/src/java/org/apache/ti/compiler/internal/grammar/WebappPathType.java [171:233]


    private static boolean checkRelativePath(String filePath, TypeDeclaration outerClass, CompilerUtils.Mutable retFileToCheck,
                                             boolean ignoreDirectories, boolean allowFileInPageFlowSourceDir,
                                             AnnotationProcessorEnvironment env)
            throws FatalCompileTimeException {
        File fileToCheck = null;
        boolean fileExists = true;

        if (filePath.endsWith(JPF_FILE_EXTENSION_DOT)) {
            String className = filePath.substring(0, filePath.length() - JPF_FILE_EXTENSION_DOT.length());
            String pkg = outerClass.getPackage().getQualifiedName();

            while (className.startsWith("../") && (className.length() > 3)) {
                className = className.substring(3);

                int lastDot = pkg.lastIndexOf('.');
                pkg = (lastDot != -1) ? pkg.substring(0, lastDot) : "";
            }

            className = ((pkg.length() > 0) ? (pkg + '.') : "") + className.replace('/', '.');

            TypeDeclaration type = env.getTypeDeclaration(className);
            fileToCheck = (type != null) ? CompilerUtils.getSourceFile(type, false) : null;

            if (fileToCheck == null) {
                fileExists = false;
            }
        }
        // In certain error conditions (jpfFile == null), we can't determine the file.  In this case, just ignore.
        else if (CompilerUtils.getSourceFile(outerClass, false) != null) {
            if (allowFileInPageFlowSourceDir) {
                fileToCheck = CompilerUtils.getFileRelativeToSourceFile(outerClass, filePath, env);
            } else {
                // Use the package name to infer the relative path (from web content root) to the page flow directory.
                String[] webContentRoots = CompilerUtils.getWebContentRoots(env);
                String jpfParentRelativePath = "";
                PackageDeclaration jpfPackage = outerClass.getPackage();

                if (jpfPackage != null) {
                    jpfParentRelativePath = jpfPackage.getQualifiedName().replace('.', '/');
                }

                for (int i = 0; i < webContentRoots.length; i++) {
                    String webContentRoot = webContentRoots[i];
                    File desiredParentDir = new File(webContentRoot, jpfParentRelativePath);
                    fileToCheck = new File(desiredParentDir, filePath);

                    if (fileToCheck.exists()) {
                        break;
                    }
                }
            }

            if ((fileToCheck == null) || !fileToCheck.exists()) {
                fileExists = false;
            }
        }

        if (retFileToCheck != null) {
            retFileToCheck.set(fileToCheck);
        }

        return fileExists;
    }