Example usage for java.io File isAbsolute

List of usage examples for java.io File isAbsolute

Introduction

In this page you can find the example usage for java.io File isAbsolute.

Prototype

public boolean isAbsolute() 

Source Link

Document

Tests whether this abstract pathname is absolute.

Usage

From source file:hd3gtv.mydmam.auth.AuthenticationBackend.java

public static void refreshConfiguration() throws Exception {
    if (Configuration.global.isElementExists("auth") == false) {
        throw new NullPointerException("Can't found \"auth\" element in configuration");
    }/*from   w  w w  .  j  a va2 s  .c  om*/
    if (Configuration.global.isElementKeyExists("auth", "backend") == false) {
        throw new NullPointerException("Can't found \"auth/backend\" element in configuration");
    }

    List<LinkedHashMap<String, ?>> elements = Configuration.global.getListMapValues("auth", "backend");

    if (elements == null) {
        throw new NullPointerException("No items for \"auth/backend\" element in configuration");
    }

    force_select_domain = Configuration.global.getValueBoolean("auth", "force_select_domain");

    authenticators = new ArrayList<Authenticator>(elements.size());
    authenticators_domains = new ArrayList<String>(elements.size());

    LinkedHashMap<String, ?> configuration_element;
    File auth_file;
    for (int pos = 0; pos < elements.size(); pos++) {
        configuration_element = elements.get(pos);
        String element_source = (String) configuration_element.get("source");
        if (element_source.equals("local")) {
            String path = (String) configuration_element.get("path");

            auth_file = new File(path);
            if (auth_file.exists() == false) {
                if (auth_file.isAbsolute() == false) {
                    if (auth_file.getParentFile().getName().equals("conf") & Configuration
                            .getGlobalConfigurationDirectory().getParentFile().getName().equals("conf")) {
                        /**
                         * SQLite file is located in Play conf directory, and Play /app.d/ is also located in conf directory.
                         * We consider that conf directory is the same.
                         */
                        auth_file = new File(Configuration.getGlobalConfigurationDirectory().getParent()
                                + File.separator + auth_file.getName());
                    }
                }
            }
            if (auth_file.exists() == false) {
                throw new FileNotFoundException(path);
            }

            String masterkey = (String) configuration_element.get("masterkey");
            authenticators.add(new AuthenticatorLocalsqlite(auth_file, masterkey));

            String label = (String) configuration_element.get("label");
            authenticators_domains.add(label);
        } else if (element_source.equals("ad")) {
            String domain = (String) configuration_element.get("domain");
            String server = (String) configuration_element.get("server");
            int port = (Integer) configuration_element.get("port");
            authenticators.add(new AuthenticatorActivedirectory(domain, server, port));

            authenticators_domains.add(domain);
        } else {
            Log2.log.error("Can't import \"auth/backend\" " + (pos + 1) + " configuration item", null,
                    new Log2Dump("item", configuration_element.toString()));
        }
    }

    if (authenticators.isEmpty()) {
        throw new NullPointerException("No authentication backend is correctly set");
    }
}

From source file:nl.b3p.catalog.xml.mdeXml2Html.java

/**
 * The following transformers should be present in de configuration under
 * mdeConfig:/*from  w w  w  . jav  a  2  s.  c  o  m*/
 * <li> mdemain
 * <li> mdeXmlPreprocessor
 * <li> ISO19115toDC
 * <li> DCtoISO19115
 * The next transformers may be present:
 * <li> extrapreprocessor1
 * <li> extrapreprocessor2
 * <li> extrasync1
 * <li> extrasync2
 * <li> extrapostprocessor1
 * 
 * @param xslName
 * @return inputstream to transformer
 * @throws TransformerConfigurationException
 * @throws FileNotFoundException 
 */
private static InputStream getXslStream(String xslName)
        throws TransformerConfigurationException, FileNotFoundException {
    CatalogAppConfig cfg = CatalogAppConfig.getConfig();
    Map<String, String> params = cfg.getMdeConfig();
    if (params == null) {
        throw new TransformerConfigurationException("Transformers are missing from configuration!");
    }
    String xslPath = params.get(xslName);
    if (xslPath == null) {
        return null;
    }
    File f = new File(xslPath);
    if (!f.isAbsolute()) {
        f = new File(cfg.getConfigFilePath(), xslPath);
    }

    return new FileInputStream(f);
}

From source file:com.nary.io.FileUtils.java

public static File getFile(cfSession _Session, String _path, boolean _bURI) {
    File file = new File(getCleanFilePath(_Session, _path, _bURI));
    if (!file.isAbsolute()) {
        file = new File(cfEngine.thisPlatform.getFileIO().getTempDirectory(), file.getPath());
    }/*  www . j  a v a  2s .c  om*/
    return file;
}

From source file:hudson.ClassicPluginStrategy.java

private static File resolve(File base, String relative) {
    File rel = new File(relative);
    if (rel.isAbsolute())
        return rel;
    else//ww w.j  ava  2s .  com
        return new File(base.getParentFile(), relative);
}

From source file:com.buaa.cfs.utils.Shell.java

/** Centralized logic to discover and validate the sanity of the Hadoop 
 *  home directory. Returns either NULL or a directory that exists and 
 *  was specified via either -Dhadoop.home.dir or the HADOOP_HOME ENV 
 *  variable.  This does a lot of work so it should only be called 
 *  privately for initialization once per process.
 **//*from   w  w w .  ja  v a  2s . co  m*/
private static String checkHadoopHome() {

    // first check the Dflag hadoop.home.dir with JVM scope
    String home = System.getProperty("hadoop.home.dir");

    // fall back to the system/user-global env variable
    if (home == null) {
        home = System.getenv("HADOOP_HOME");
    }

    try {
        // couldn't find either setting for hadoop's home directory
        if (home == null) {
            throw new IOException("HADOOP_HOME or hadoop.home.dir are not set.");
        }

        if (home.startsWith("\"") && home.endsWith("\"")) {
            home = home.substring(1, home.length() - 1);
        }

        // check that the home setting is actually a directory that exists
        File homedir = new File(home);
        if (!homedir.isAbsolute() || !homedir.exists() || !homedir.isDirectory()) {
            throw new IOException("Hadoop home directory " + homedir
                    + " does not exist, is not a directory, or is not an absolute path.");
        }

        home = homedir.getCanonicalPath();

    } catch (IOException ioe) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Failed to detect a valid hadoop home directory", ioe);
        }
        home = null;
    }

    return home;
}

From source file:com.cloudera.flume.agent.FlumeNode.java

public static String getWebPath(FlumeConfiguration conf) {
    String webPath = conf.getWebAppsPath();
    File f = new File(webPath);
    // absolute paths win, but if is not absolute, prefix with flume home
    if (!f.isAbsolute()) {
        String basepath = FlumeConfiguration.getFlumeHome();
        if (basepath == null) {
            LOG.warn("FLUME_HOME not set, potential for odd behavior!");
        }//from   w  w  w.j  av  a2 s  . c o  m
        File base = new File(basepath, webPath);
        webPath = base.getAbsolutePath();
    }
    return webPath;
}

From source file:microsoft.exchange.webservices.data.core.ExchangeServiceBase.java

/**
 * @param location file path//from  w  w  w.j  a va  2 s .  c om
 * @return false if location is null,true if this abstract pathname is absolute
 */
public static boolean checkURIPath(String location) {
    if (location == null) {
        return false;
    }
    final File file = new File(location);
    return file.isAbsolute();
}

From source file:com.aurel.track.admin.server.siteConfig.SiteConfigBL.java

public static String createAndCheckDirectory(String directoryName,
        /*List<ControlError> errors, List<String> controlPath,*/ Locale locale) {
    String keyBase = "admin.server.config.err.directory";
    if (directoryName == null || directoryName.trim().length() == 0) {
        /*errors.add(new ControlError(controlPath, getText(keyBase+".DirectoryRequired", locale)));
        return errors;*//*w w  w  .ja va2 s .  c  o m*/
        return getText(keyBase + ".DirIsRequired", locale);
    }

    File f = new File(directoryName);

    if (f.isFile()) {
        /*errors.add(new ControlError(controlPath, getText(keyBase+".DirIsFile", locale)));
        return errors;*/
        return getText(keyBase + ".DirIsFile", locale);
    }

    if (!f.isAbsolute()) {
        /*errors.add(new ControlError(controlPath, getText(keyBase+".DirIsRelative", locale)));
        return errors;*/
        return getText(keyBase + ".DirIsRelative", locale);
    }

    // if the directory does not exist, create it
    if (!f.exists()) {
        LOGGER.info("Creating directory " + directoryName);
        try {
            f.mkdir();
        } catch (Exception e) {
            /*errors.add(new ControlError(controlPath, getText(keyBase+".CantWrite", locale)));
            return errors;*/
            return getText(keyBase + ".CantWrite", locale);
        }
    }

    if (!f.canWrite() || !f.canRead()) {
        /*errors.add(new ControlError(controlPath, getText(keyBase+".CantAccess", locale)));
        return errors;*/
        return getText(keyBase + ".CantAccess", locale);
    }
    //return errors;
    return null;
}

From source file:nl.nn.adapterframework.util.Misc.java

public static String getWebContentDirectory() {
    String path = new File(AppConstants.class.getClassLoader().getResource("").getPath()).getPath();
    String fullPath;//w  ww  . j  a  v a  2  s.  c o m
    try {
        fullPath = URLDecoder.decode(path, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        log.warn("Error decoding path [" + path + "]", e);
        return null;
    }
    if (fullPath.endsWith("classes")) {
        String wcDirectory = null;
        File file = new File(fullPath);
        while (wcDirectory == null) {
            File file2 = new File(file, "WebContent");
            if (file2.exists() && file2.isAbsolute()) {
                wcDirectory = file2.getPath();
            } else {
                file = file.getParentFile();
                if (file == null) {
                    return null;
                }
            }
        }
        return wcDirectory;
    } else {
        return null;
    }
}

From source file:eu.asterics.mw.services.ResourceRegistry.java

/**
 * Resolves the given nonURIConformingFilePath to the given baseURI URI. The string may contain normal file path characters like space and supports \\ and / as seperators if parameter slashify=true 
 * @param baseURIPath/*from   w  ww  .j ava  2  s .c  om*/
 * @param nonURIConformingFilePath
 * @param slashify true: Convert seperators to unix-style /
 * @return
 */
public static File resolveRelativeFilePath(File baseURIPath, String nonURIConformingFilePath,
        boolean slashify) {
    if (slashify) {
        nonURIConformingFilePath = FilenameUtils.separatorsToUnix(nonURIConformingFilePath);
    }

    File absFile = new File(nonURIConformingFilePath);
    if (!absFile.isAbsolute()) {
        absFile = new File(baseURIPath, nonURIConformingFilePath);
    }
    return absFile;
}