public String getFreemindBaseDir() {
        if (baseDir == null) {
            try {
                File file;
                String dir = System.getProperty("freemind.base.dir");
                if (dir == null) {
                    // Property isn't set, we try to find the
                    // base directory ourselves.
                    // System.err.println("property not set");
                    // We locate first the current class.
                    String classname = this.getClass().getName();
                    URL url = this.getClass().getResource(
                            classname.replaceFirst("^"
                                    + this.getClass().getPackage().getName()
                                    + ".", "")
                                    + ".class");
                    // then we create a file out of it, after
                    // removing file: and jar:, removing everything
                    // after !, as well as the class name part.
                    // Finally we decode everything (e.g. %20)
                    // TODO: is UTF-8 always the right value?
                    file = new File(URLDecoder.decode(
                            url.getPath()
                                    .replaceFirst("^(file:|jar:)+", "")
                                    .replaceFirst("!.*$", "")
                                    .replaceFirst(
                                            classname.replace('.', '/')
                                                    + ".class$", ""), "UTF-8"));
                    // if it's a file, we take its parent, a dir
                    if (file.isFile())
                        file = file.getParentFile();
					/*
					 * Now, we remove the lib directory: Example:
					 * /home/foltin/freemindapp/lib/freemind.jar gives
					 * /home/foltin/freemindapp
					 */
                    if (file.getName().equals("lib"))
                        file = file.getParentFile();
                } else {
                    file = new File(dir);
                }
                // then we check if the directory exists and is really
                // a directory.
                if (!file.exists()) {
                    throw new IllegalArgumentException("FreeMind base dir '"
                            + file + "' does not exist.");
                }
                if (!file.isDirectory()) {
                    throw new IllegalArgumentException(
                            "FreeMind base dir (!) '" + file
                                    + "' is not a directory.");
                }
                // set the member variable
                baseDir = file.getCanonicalPath();
                logger.info("Basedir is: " + baseDir);
            } catch (Exception e) {
                Resources.getInstance().logException(e);
                throw new IllegalArgumentException(
                        "FreeMind base dir can't be determined.");
            }
        }
        // return the value of the cache variable
        return baseDir;
    }