Example usage for java.net URI isOpaque

List of usage examples for java.net URI isOpaque

Introduction

In this page you can find the example usage for java.net URI isOpaque.

Prototype

public boolean isOpaque() 

Source Link

Document

Tells whether or not this URI is opaque.

Usage

From source file:com.microsoft.tfs.core.util.URIUtils.java

/**
 * <p>/*from w  w w  .  java  2s. c om*/
 * Ensures that the specified {@link URI}'s path component ends with a slash
 * character (<code>/</code>).
 * </p>
 *
 * <p>
 * {@link URI}s that will be resolved against should always have a trailing
 * slash in their path component. For more information, see Sun Java bug
 * 4666701 (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4666701).
 * </p>
 *
 * <p>
 * If the specified {@link URI} is opaque, it is returned. If the specified
 * {@link URI} is hierarchical and its path component already ends in a
 * slash, it is returned. Otherwise, a new {@link URI} is returned that is
 * identical to the specified {@link URI} except in its path component,
 * which will have a slash appended on.
 * </p>
 *
 * @param uri
 *        a {@link URI} to check (must not be <code>null</code>)
 * @return a {@link URI} as described above (never <code>null</code>)
 */
public static URI ensurePathHasTrailingSlash(final URI uri) {
    Check.notNull(uri, "uri"); //$NON-NLS-1$

    if (uri.isOpaque()) {
        return uri;
    }

    String path = uri.getPath();
    if (path != null && path.endsWith("/")) //$NON-NLS-1$
    {
        return uri;
    }

    if (path == null) {
        path = "/"; //$NON-NLS-1$
    } else {
        path = path + "/"; //$NON-NLS-1$
    }

    return newURI(uri.getScheme(), uri.getAuthority(), path, uri.getQuery(), uri.getFragment());
}

From source file:com.microsoft.tfs.core.util.URIUtils.java

/**
 * Ensures that the specified {@link URI} has any trailing slashes REMOVED.
 * VisualStudio uses server URIs that lack trailing slashes, this is for
 * compatibility. However, a path of only / will be maintained.
 *
 * @param uri//from  w  w w .  j  ava2 s  .  c  o m
 *        a {@link URI} to check (must not be <code>null</code>)
 * @return a {@link URI} as described above (never <code>null</code>)
 */
public static URI removeTrailingSlash(final URI uri) {
    Check.notNull(uri, "uri"); //$NON-NLS-1$

    if (uri.isOpaque()) {
        return uri;
    }

    String path = uri.getPath();

    if (path == null) {
        path = "/"; //$NON-NLS-1$
    } else if (!path.equals("/")) //$NON-NLS-1$
    {
        while (path.endsWith("/")) //$NON-NLS-1$
        {
            path = path.substring(0, path.length() - 1);
        }
    }

    return newURI(uri.getScheme(), uri.getAuthority(), path, uri.getQuery(), uri.getFragment());
}

From source file:com.microsoft.tfs.core.util.URIUtils.java

/**
 * <p>/* w  w w. j a  va 2 s  .  c o  m*/
 * Resolves the specified child {@link URI} against the specified
 * {@link URI}, returning a {@link URI} as the result.
 * </p>
 *
 * <p>
 * This method behaves differently than calling {@link URI#resolve(URI)}.
 * This method first uses the {@link #ensurePathHasTrailingSlash(URI)}
 * method to ensure that the specified parent {@link URI}'s path has a
 * trailing slash. See the documentation of
 * {@link #ensurePathHasTrailingSlash(URI)} method for a reason why this is
 * necessary.
 * </p>
 *
 * @param parent
 *        a base {@link URI} to resolve against (must not be
 *        <code>null</code>)
 * @param child
 *        a relative path to resolve (must not be <code>null</code>)
 * @return a new {@link URI} as described above (never <code>null</code>)
 */
public static URI resolve(URI parent, final URI child) {
    Check.notNull(parent, "parent"); //$NON-NLS-1$
    Check.notNull(child, "child"); //$NON-NLS-1$

    if (!child.isAbsolute() && !parent.isOpaque()) {
        parent = ensurePathHasTrailingSlash(parent);
    }

    return parent.resolve(child);
}

From source file:com.google.caja.plugin.DataUriFetcher.java

private boolean isDataUri(URI uri) {
    if (null != uri && "data".equals(uri.getScheme()) && uri.isOpaque()) {
        return true;
    }//from   w w  w  .j  a  v  a  2 s  .c  o m
    return false;
}

From source file:de.openknowledge.cdi.common.property.source.FilePropertySourceLoader.java

public Properties load(URI resource) {
    Properties properties = new Properties();

    try {//ww  w  . jav a 2s. com
        File file;
        if (resource.isOpaque()) {
            file = new File(resource.getSchemeSpecificPart());
        } else {
            file = new File(resource);
        }
        if (file.exists() && file.canRead()) {
            LOG.debug("Loading properties from file " + file);
            loadFromStream(properties, new FileInputStream(file));
        } else {
            LOG.debug("Unable to load properties from file " + file
                    + ". File does not exist or is not readable.");
        }
    } catch (IOException e) {
        LOG.warn("Error loading properties from file resource " + resource + ": " + e.getMessage());
    }

    return properties;
}

From source file:com.legstar.codegen.tasks.SourceToXsdCobolTask.java

/**
 * Checks that common properties set are valid.
 * /*from  w  ww .  j  a v  a2s.c  om*/
 * @param xsdFileNameMandatory where an xsd file name is mandatory
 * @param namespaceMandatory where a target namespace is mandatory
 */
public void checkInput(final boolean xsdFileNameMandatory, final boolean namespaceMandatory) {

    if (_log.isDebugEnabled()) {
        _log.debug("checkInput started");
        _log.debug("   Target namespace name    = " + getNamespace());
        _log.debug("   Target directory         = " + getTargetDir());
        _log.debug("   Target Xsd file name     = " + getTargetXsdFileName());
    }

    if (getModel() == null) {
        throw (new BuildException("You must specify a model"));
    }

    /* Check that we have a valid target directory. */
    if (getTargetDir() == null) {
        throw (new BuildException("You must provide a target directory"));
    }
    if (!getTargetDir().exists()) {
        throw (new BuildException("Directory " + getTargetDir() + " does not exist"));
    }
    if (!getTargetDir().isDirectory() || !getTargetDir().canWrite()) {
        throw (new BuildException(getTargetDir() + " is not a directory or is not writable"));
    }

    /* Set a valid target annotated XSD file name */
    if (xsdFileNameMandatory) {
        if (getTargetXsdFileName() == null || getTargetXsdFileName().length() == 0) {
            throw (new BuildException("You must provide a target xsd file name"));
        }
        if (getTargetXsdFileName().contains(File.separator) || getTargetXsdFileName().contains("/")) {
            throw (new BuildException("Xsd file name should not specify a path (use targetDir for path)"));
        }
    }

    if (namespaceMandatory) {
        if (getNamespace() == null || getNamespace().length() == 0) {
            throw (new BuildException("You must specify an output XML schema namespace"));
        }
    }

    /*
     * If we have a namespace check it.
     */
    if (getNamespace() != null && getNamespace().length() > 0) {
        try {
            URI nURI = new URI(getNamespace());
            if (nURI.isOpaque()) {
                throw (new BuildException("Namespace " + getNamespace() + " is not a hierarchical URI"));
            }
        } catch (URISyntaxException e) {
            throw new BuildException(e);
        }
    }

}

From source file:ie.deri.unlp.javaservices.topicextraction.topicextractor.gate.TopicExtractorGate.java

public void initGate() throws GateException {
    if (!gateInitialised) {
        logger.info("Initializing GATE");
        try {//from  ww  w  .j a v a  2  s  . c  o  m
            URI url = getClass().getResource("/gate").toURI();
            logger.info("URL to GATE resources: " + url);

            File gateHome;
            if (url.isOpaque()) {
                /*
                 * GATE only has an interface for File objects, which means the files have to be on the filesystem.
                 * If we're running from a JAR we first have to extract the gate/ folder from the JAR. 
                 */

                logger.info("Unpacking GATE resources from JAR");
                String tempDirectoryPath = FileUtils.getTempDirectoryPath();
                //Delete any existing directory
                String gateResource = "gate";
                FileUtils.deleteDirectory(new File(FilenameUtils.concat(tempDirectoryPath, gateResource)));
                String gateHomePath = extractDirectoryFromClasspathJAR(getClass(), gateResource,
                        tempDirectoryPath);
                gateHome = new File(gateHomePath);

            } else {
                gateHome = new File(url);
            }

            Gate.setGateHome(gateHome);
            Gate.setSiteConfigFile(new File(gateHome, "gate-site.xml"));
            Gate.setUserConfigFile(new File(gateHome, "gate-user.xml"));
            // Gate.setUserSessionFile(new File(gateHome, GATE_SESSION));

            Gate.setPluginsHome(new File(gateHome, "plugins/"));

            Gate.init();

            Iterator<URL> pluginItr = Gate.getKnownPlugins().iterator();
            while (pluginItr.hasNext()) {
                URL pluginURL = pluginItr.next();
                Gate.getCreoleRegister().registerDirectories(pluginURL);
            }

            logger.log(Level.INFO, "configuring GATE processor pool..");

            gateProcessorPool = GateProcessorPool.getInstance();

            gateInitialised = true;

        } catch (IOException | URISyntaxException | GateException exn) {
            throw new GateException("Exception while initializing GATE resources", exn);
        }
        logger.info("GATE Initialized");
    }
}

From source file:com.ebay.cloud.cms.metadata.dataloader.MetadataDataLoader.java

private void loadMetaClassesFromPath(String pathName) {
    try {//from ww  w. java 2 s .c o  m

        URL url = MetadataDataLoader.class.getResource(pathName);
        URI uri = url.toURI();
        BasicDBList metas = new BasicDBList();

        if (uri.isOpaque()) {
            JarURLConnection connection = (JarURLConnection) url.openConnection();
            JarFile jar = connection.getJarFile();
            Enumeration<JarEntry> entries = jar.entries();

            while (entries.hasMoreElements()) {
                JarEntry entry = entries.nextElement();
                if (entry.getName().startsWith(pathName.substring(1)) && entry.getName().endsWith(".json")) {
                    InputStream is = jar.getInputStream(entry);
                    readMetaClass(is, metas);
                }
            }

        } else {
            File dir = new File(url.toURI());
            Collection<File> files = FileUtils.listFiles(dir, new String[] { "json" }, true);
            for (File f : files) {
                InputStream is = new FileInputStream(f);
                readMetaClass(is, metas);
            }
        }

        loadMetaClasses(metas);

    } catch (Exception e) {
        logger.error("error in loading metadata: ", e);
    }
}

From source file:net.oneandone.sushi.fs.webdav.WebdavFilesystem.java

@Override
public WebdavNode node(URI uri, Object extra) throws NodeInstantiationException {
    if (extra != null) {
        throw new NodeInstantiationException(uri, "unexpected extra argument: " + extra);
    }//  w w  w . j  a  v a  2 s . c o  m
    if (uri.getFragment() != null) {
        throw new NodeInstantiationException(uri, "unexpected path fragment");
    }
    if (uri.isOpaque()) {
        throw new NodeInstantiationException(uri, "uri is not hierarchical");
    }
    return root(uri).node(getCheckedPath(uri), uri.getRawQuery());
}

From source file:ru.histone.HistoneBuilder.java

/**
 * Builds new Histone engine using current HistoneBuilder settings/resources loaders/etc<br/>
 * This method creates new Histone template engine
 *
 * @return Histone engine instance//from   w w w .  ja  va 2s  . co m
 * @throws HistoneException if error during histone initialization occurs
 */
public Histone build() throws HistoneException {
    log.debug("Building new Histone template engine");

    TokenizerFactory tokenizerFactory = new TokenizerFactory(HistoneTokensHolder.getTokens());
    OldParser parser = new OldParser(tokenizerFactory, nodeFactory);

    EvaluatorBootstrap evaluatorBootstrap = new EvaluatorBootstrap();
    evaluatorBootstrap.setNodeFactory(nodeFactory);
    evaluatorBootstrap.setParser(parser);
    URI baseURI = extractBaseURI(globalProperties);
    if (baseURI != null) {
        if (!baseURI.isAbsolute()) {
            throw new HistoneException(
                    String.format("baseURI = '%s' and it's not absolute URI!", baseURI.toString()));
        }
        if (baseURI.isOpaque()) {
            throw new HistoneException(
                    String.format("baseURI = '%s' and it's opaque URI!", baseURI.toString()));
        }
    }
    GlobalFunctionsManager globalFunctionsManager = new GlobalFunctionsManager(globalFunctions);
    NodeFunctionsManager nodeFunctionsManager = new NodeFunctionsManager(nodeFunctions);

    if (resourceLoader instanceof DefaultResourceLoader) {
        ((DefaultResourceLoader) resourceLoader).setHttpClientConnectionManager(httpClientConnectionManager);
    }
    evaluatorBootstrap.setResourceLoader(resourceLoader);
    evaluatorBootstrap.setGlobalFunctionsManager(globalFunctionsManager);
    evaluatorBootstrap.setNodeFunctionsManager(nodeFunctionsManager);

    GlobalObjectNode global = new GlobalObjectNode(nodeFactory);
    for (Map.Entry<GlobalProperty, Node> entry : globalProperties.entrySet()) {
        global.add(entry.getKey().getName(), entry.getValue());
    }
    evaluatorBootstrap.setGlobal(global);

    Evaluator evaluator = new Evaluator(evaluatorBootstrap);

    AstImportResolver astImportResolver = new AstImportResolver(parser, resourceLoader, nodeFactory);

    HistoneBootstrap histoneBootstrap = new HistoneBootstrap();
    histoneBootstrap.setNodeFactory(nodeFactory);
    histoneBootstrap.setParser(parser);
    histoneBootstrap.setEvaluator(evaluator);
    histoneBootstrap.setResourceLoader(new DefaultResourceLoader());

    return new Histone(histoneBootstrap);
}