public InputStream locate()

in src/java/org/apache/fulcrum/yaafi/framework/util/InputStreamLocator.java [79:143]


	public InputStream locate(String location) throws IOException {
		if (location == null || location.length() == 0) {
			return null;
		}

		String baseName = null;
		File file = null;
		InputStream is = null;

		// try to load a relative location with the given root dir
		// e.g. "componentRoles.xml" located in the current working directory
		if (is == null) {
			file = new File(this.rootDir, location);

			this.logger.debug("Looking for " + location + " in the root directory");

			if (file.exists()) {
				is = new FileInputStream(file);
				this.logger.debug("Found " + location + " as " + file.getAbsolutePath());
			}
		}

		// try to load an absolute location as file
		// e.g. "/foo/componentRoles.xml" from the root of the file system
		if (is == null) {
			file = new File(location);

			this.logger.debug("Looking for " + location + " as absolute file location");

			if (file.isAbsolute() && file.exists()) {
				is = new FileInputStream(file);
				this.logger.debug("Found " + location + " as " + file.getAbsolutePath());
			}
		}

		// try to load an absolute location through the classpath
		// e.g. "/componentRoles.xml" located in the classpath
		if (is == null && location.startsWith("/") == true) {
			this.logger.debug("Looking for " + location + " using the class loader");
			is = getClass().getResourceAsStream(location);

			if (is != null) {
				this.logger.debug("Successfully located " + location);
			}
		}

		// try to load the last part of the file name using the classloader
		// e.g. "conf/componentRoles.xml" as "/componentRoles.xml" located in
		// the classpath.

		if (is == null && location.startsWith("/") == false) {
			baseName = '/' + new File(location).getName();
			this.logger.debug("Looking for " + baseName + " using the class loader");
			is = getClass().getResourceAsStream(baseName);
			if (is != null) {
				this.logger.debug("Successfully located " + baseName);
			}
		}

		if (is == null) {
			this.logger.debug("Unable to find any resource with the name '" + location + "'");
		}

		return is;
	}