public synchronized File getAppUserHome()

in taverna-app-configuration-impl/src/main/java/org/apache/taverna/configuration/app/impl/ApplicationUserHome.java [133:189]


	public synchronized File getAppUserHome() {
		if (homeDir != null) {
			return homeDir;
		}
		File appHome;
		String applicationHome = getDefaultApplicationHome();
		if (applicationHome != null) {
			appHome = new File(applicationHome);
		} else {
			if (getApplicationName() == null) {
				logger.warn("Unknown application name");
				return null;
			}
			File home = new File(System.getProperty("user.home"));
			if (!home.isDirectory()) {
				logger.error("User home not a valid directory: " + home);
				return null;
			}
			String os = System.getProperty("os.name");
			// logger.debug("OS is " + os);
			if (os.equals("Mac OS X")) {
				File libDir = new File(home, "Library/Application Support");
				libDir.mkdirs();
				appHome = new File(libDir, getApplicationName());
			} else if (os.startsWith("Windows")) {
				String APPDATA = System.getenv("APPDATA");
				File appData = null;
				if (APPDATA != null) {					
					appData = new File(APPDATA);
				}
				if (appData != null && appData.isDirectory()) {
					appHome = new File(appData, getApplicationName());
				} else {
					logger.warn("Could not find %APPDATA%: " + APPDATA);
					appHome = new File(home, getApplicationName());
				}
			} else {
				// We'll assume UNIX style is OK
				appHome = new File(home, "."
						+ getApplicationName().toLowerCase().replace(' ', '-'));
			}
		}
		if (!appHome.exists()) {
			if (appHome.mkdir()) {
				logger.info("Created " + appHome);
			} else {
				logger.error("Could not create " + appHome);
				return null;
			}
		}
		if (!appHome.isDirectory()) {
			logger.error("User home not a valid directory: " + appHome);
			return null;
		}
		this.homeDir = appHome.getAbsoluteFile();
		return this.homeDir;
	}