Example usage for java.net URI isAbsolute

List of usage examples for java.net URI isAbsolute

Introduction

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

Prototype

public boolean isAbsolute() 

Source Link

Document

Tells whether or not this URI is absolute.

Usage

From source file:pl.touk.ode.validator.XQueryAnalyzer.java

public void init(CompilerContext compilerContext) throws Exception {
    processor = new Processor(true);
    Configuration config2 = processor.getUnderlyingConfiguration();
    config2.displayLicenseMessage();/*from ww  w .ja  v a2 s .  c om*/
    config2.setValidationWarnings(true);

    config2.setErrorListener(new ErrorListener() {
        public void error(TransformerException arg0) throws TransformerException {
            __log.error(arg0);
        }

        public void fatalError(TransformerException arg0) throws TransformerException {
            if (!arg0.getMessage().contains("Duplicate")) {
                __log.fatal(arg0);
            }
        }

        public void warning(TransformerException arg0) throws TransformerException {
            __log.warn(arg0);
        }
    });

    __log.debug("schemaSourcesURIs " + compilerContext.getSchemaSources().keySet());
    schemaNamespaces = new HashMap<String, List<URI>>();

    URI baseURI = compilerContext.getBaseResourceURI();
    Map<URI, Source> odeSchemaSources = compilerContext.getSchemaSources();
    final Map<URI, XdmNode> schemaSources = new HashMap<URI, XdmNode>();
    for (URI u : odeSchemaSources.keySet()) {
        schemaSources.put(u, buildXdmNode(odeSchemaSources.get(u), u.isAbsolute() ? u : baseURI));
    }
    schemaSources.put(URI.create("ode-validator.xsd"), buildXdmNode(
            new javax.xml.transform.stream.StreamSource(getClass().getResourceAsStream("/ode-validator.xsd")),
            baseURI));

    //        config2.setSchemaURIResolver(new SchemaURIResolver() {
    //         public Source[] resolve(String targetNamespace, String baseURI, String[] locations)
    //               throws XPathException {
    //            if (__log.isDebugEnabled()) {
    //               List<String> l = new ArrayList<String>();
    //               Collections.addAll(l, locations);
    //               __log.debug("resolve schema tns: " + targetNamespace + " baseURI: " + baseURI + " locations: " + l);
    //            }
    //            Source[] result = new Source[locations.length];
    //            for (int i = 0; i < locations.length; i++) {
    //               String location = locations[i];
    //               XdmNode n = schemaSources.get(URI.create(location));
    //               if (__log.isDebugEnabled()) {
    //                  __log.debug("schema: " + n);
    //               }
    //               result[i] = n == null ? null : n.asSource();
    //            }
    //            return result;
    //         }
    //
    //         public void setConfiguration(Configuration arg0) {
    //         }
    //        });

    for (URI u : schemaSources.keySet()) {
        XdmNode schema = schemaSources.get(u);
        String tns = getSchemaTNS(schema);
        __log.debug("Schema URI: " + u + " tns: " + tns);
        try {
            //              if (new File(u.toASCIIString()).exists()) {
            //                 config2.loadSchema(u.toASCIIString());
            //              } else {
            config2.addSchemaSource(schema.asSource());
            __log.debug("schema contents: " + schema);
            //              }

            if (tns != null) {
                List<URI> l = schemaNamespaces.get(tns);
                if (l == null) {
                    l = new ArrayList<URI>();
                    schemaNamespaces.put(tns, l);
                }
                l.add(u);
            }
        } catch (Exception e) {
            __log.warn("Can't load schema " + u + " due to " + e);
        }
    }

    //      config2.loadSchema("file:/home/joker/dev/mnp/manager/trunk/process-mnpm-portOut/ode-su/target/classes/CaseProcess.wsdl");

    //      __log.debug("loaded target namespace " + ((SchemaAwareConfiguration) config2).getSuperSchema().getTargetNamespaces());
}

From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceImpl.java

private boolean isResolvedToRootURI(URI path) {
    URI userRoot = getUserRoot();
    if (path.isAbsolute()) {
        return userRoot.equals(path);
    }/*from w  w  w. j  a  v a2 s . c o  m*/
    return userRoot.equals(resolveAsDirectoryURI(path));
}

From source file:com.unboundid.scim2.client.ScimService.java

/**
 * Resolve a URL (relative or absolute) to a web target.
 *
 * @param url The URL to resolve.//from ww  w.  j  a  v a  2 s  .  c o m
 * @return The WebTarget.
 */
private WebTarget resolveWebTarget(final URI url) {
    URI relativePath;
    if (url.isAbsolute()) {
        relativePath = baseTarget.getUri().relativize(url);
        if (relativePath.equals(url)) {
            // The given resource's location is from another service provider
            throw new IllegalArgumentException("Given resource's location " + url
                    + " is not under this service's " + "base path " + baseTarget.getUri());
        }
    } else {
        relativePath = url;
    }

    return baseTarget.path(relativePath.getRawPath());
}

From source file:info.magnolia.ui.admincentral.shellapp.favorites.FavoritesPresenter.java

String getCompleteURIFromFragment(final String fragment) {
    URI uri = null;
    try {//from  w  w  w .jav  a 2s  .  com
        uri = new URI(fragment);
    } catch (URISyntaxException e) {
        log.warn("Could not create URI from fragment {}. Exception: {}", fragment, e.toString());
    }
    if (uri == null || uri.isAbsolute()) {
        return fragment;
    }
    return getWebAppRootURI() + fragment;
}

From source file:org.cloudfoundry.maven.AbstractCloudFoundryMojo.java

/**
 * If the target property was provided via the command line, use that property.
 * Otherwise use the property that was injected via Maven. If that is Null
 * as well, Null is returned./*from   w  w  w  .  jav a 2  s  .co m*/
 *
 * @return Returns the Cloud Foundry Target Url - Can return Null.
 *
 */
public URI getTarget() {

    final String targetProperty = getCommandlineProperty(SystemProperties.TARGET);

    if (targetProperty != null) {
        try {

            URI uri = new URI(targetProperty);

            if (uri.isAbsolute()) {
                return uri;
            } else {
                throw new URISyntaxException(targetProperty, "URI is not opaque.");
            }

        } catch (URISyntaxException e) {
            throw new IllegalStateException(String.format(
                    "The Url parameter '%s' " + "which was passed in as system property is not valid.",
                    targetProperty));
        }
    }

    if (this.target == null) {
        return null;
    }

    try {
        return new URI(this.target);
    } catch (URISyntaxException e) {
        throw new IllegalStateException(String.format(
                "The Url parameter '%s' "
                        + "which was passed in as pom.xml configiuration parameter is not valid.",
                this.target));
    }

}

From source file:eu.esdihumboldt.hale.common.core.io.PathUpdate.java

/**
 * Tries to find an existing readable URI.<br>
 * <ul>//from   ww w.  j ava2s .co  m
 * <li>if the URI isn't absolute:
 * <ul>
 * <li>if a new location is available it is resolved against that</li>
 * <li>if an old location is available it is resolved against that</li>
 * </ul>
 * </li>
 * <li>if the URI is absolute:
 * <ul>
 * <li>if an old and a new location is available it is transformed in the
 * same way</li>
 * <li>the URI is used as is</li>
 * </ul>
 * </li>
 * </ul>
 * If none of the applicable cases results in a valid, existing URI and
 * tryFallback is true {@link #updatePathFallback(URI)} is returned,
 * otherwise <code>null</code> is returned.
 * 
 * @param uri the URI in question
 * @param tryFallback whether to use {@link #updatePathFallback(URI)} in the
 *            end or not
 * @param allowResource whether to allow resolving through {@link Resources}
 * @param keepRelative If the URI is relative to the new location and
 *            keepRelative is set, the URI is returned as is.<br>
 *            Also, if the URI is relative to the old location and it is
 *            possible to construct a relative path to the new location,
 *            that is returned
 * @return a valid, existing URI or <code>null</code>
 */
public URI findLocation(URI uri, boolean tryFallback, boolean allowResource, boolean keepRelative) {
    if ("jdbc".equals(uri.getScheme())) {
        // not possible to update JDBC URLs or test the stream
        return uri;
    }

    if (!uri.isAbsolute()) {
        if (newLocation != null) {
            URI newAbsolute = newLocation.resolve(uri);
            if (HaleIO.testStream(newAbsolute, allowResource)) {
                if (keepRelative) {
                    return uri;
                } else {
                    return newAbsolute;
                }
            } else {
                // Check if the resource file name needs
                // to be URL-encoded first (for project archives
                // that were created w/ hale studio 3.2.0 and before)
                String resourcePath = FilenameUtils.getPath(uri.toString());
                String resourceFileName = FilenameUtils.getName(uri.toString());
                try {
                    String encodedPath = resourcePath + URLEncoder.encode(resourceFileName, "UTF-8");
                    URI encodedUri = URI.create(encodedPath);
                    newAbsolute = newLocation.resolve(encodedUri);
                    if (HaleIO.testStream(newAbsolute, allowResource)) {
                        if (keepRelative) {
                            return encodedUri;
                        } else {
                            return newAbsolute;
                        }
                    }
                } catch (UnsupportedEncodingException e) {
                    log.debug(MessageFormat.format("Could not URL-encode \"{0}\"", resourceFileName), e);
                }
            }
        }
        if (oldLocation != null) {
            URI oldAbsolute = oldLocation.resolve(uri);
            if (HaleIO.testStream(oldAbsolute, allowResource)) {
                if (keepRelative)
                    return IOUtils.getRelativePath(oldAbsolute, newLocation);
                else
                    return oldAbsolute;
            }
        }
    } else {
        if (oldLocation != null && newLocation != null) {
            URI changed = changePath(uri);
            if (HaleIO.testStream(changed, allowResource))
                return changed;
        }
        if (HaleIO.testStream(uri, allowResource))
            return uri;
    }
    if (tryFallback)
        return updatePathFallback(uri);
    else
        return null;
}

From source file:com.mongolduu.android.ng.misc.RedirectHandler.java

public URI getLocationURI(final HttpResponse response, final HttpContext context) throws ProtocolException {
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }//from w ww. ja v  a  2  s  .  c o m
    // get the location header to find out where to redirect to
    Header locationHeader = response.getFirstHeader("location");
    if (locationHeader == null) {
        // got a redirect response, but no location header
        throw new ProtocolException(
                "Received redirect response " + response.getStatusLine() + " but no location header");
    }
    // HERE IS THE MODIFIED LINE OF CODE
    String location = locationHeader.getValue().replaceAll(" ", "%20");

    URI uri;
    try {
        uri = new URI(location);
    } catch (URISyntaxException ex) {
        throw new ProtocolException("Invalid redirect URI: " + location, ex);
    }

    HttpParams params = response.getParams();
    // rfc2616 demands the location value be a complete URI
    // Location = "Location" ":" absoluteURI
    if (!uri.isAbsolute()) {
        if (params.isParameterTrue(ClientPNames.REJECT_RELATIVE_REDIRECT)) {
            throw new ProtocolException("Relative redirect location '" + uri + "' not allowed");
        }
        // Adjust location URI
        HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
        if (target == null) {
            throw new IllegalStateException("Target host not available " + "in the HTTP context");
        }

        HttpRequest request = (HttpRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);

        try {
            URI requestURI = new URI(request.getRequestLine().getUri());
            URI absoluteRequestURI = URIUtils.rewriteURI(requestURI, target, true);
            uri = URIUtils.resolve(absoluteRequestURI, uri);
        } catch (URISyntaxException ex) {
            throw new ProtocolException(ex.getMessage(), ex);
        }
    }

    if (params.isParameterFalse(ClientPNames.ALLOW_CIRCULAR_REDIRECTS)) {

        RedirectLocations redirectLocations = (RedirectLocations) context.getAttribute(REDIRECT_LOCATIONS);

        if (redirectLocations == null) {
            redirectLocations = new RedirectLocations();
            context.setAttribute(REDIRECT_LOCATIONS, redirectLocations);
        }

        URI redirectURI;
        if (uri.getFragment() != null) {
            try {
                HttpHost target = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
                redirectURI = URIUtils.rewriteURI(uri, target, true);
            } catch (URISyntaxException ex) {
                throw new ProtocolException(ex.getMessage(), ex);
            }
        } else {
            redirectURI = uri;
        }

        if (redirectLocations.contains(redirectURI)) {
            throw new CircularRedirectException("Circular redirect to '" + redirectURI + "'");
        } else {
            redirectLocations.add(redirectURI);
        }
    }

    return uri;
}

From source file:com.jobaline.uiautomation.framework.selenium.phantomJsThreeHourTimeoutFix.HttpCommandExecutor.java

private URI buildUri(HttpContext context, String location) throws URISyntaxException {
    URI uri;
    uri = new URI(location);
    if (!uri.isAbsolute()) {
        HttpHost host = (HttpHost) context.getAttribute(HTTP_TARGET_HOST);
        uri = new URI(host.toURI() + location);
    }/*  w  w w  .j  ava2  s  .  c  o  m*/
    return uri;
}

From source file:be.solidx.hot.nio.http.SSLContextBuilder.java

private InputStream getInputStream(URI uri) throws IOException {
    InputStream jksFileInputStream;
    if (uri.getScheme() != null && uri.equals("file")) {
        jksFileInputStream = new FileInputStream(new File(uri));
    } else {//w w  w .  j  a v  a  2 s . c  o  m
        if (uri.isAbsolute()) {
            jksFileInputStream = getClass().getResourceAsStream(uri.getPath());
        } else {
            jksFileInputStream = getClass().getClassLoader().getResourceAsStream(uri.getPath());
        }
    }
    return jksFileInputStream;
}

From source file:org.kitodo.filemanagement.FileManagement.java

@Override
public List<URI> getSubUris(FilenameFilter filter, URI uri) {
    if (!uri.isAbsolute()) {
        uri = fileMapper.mapUriToKitodoDataDirectoryUri(uri);
    }//  w ww . j a va  2  s  .  com
    List<URI> resultList = new ArrayList<>();
    File[] files;
    if (filter == null) {
        files = listFiles(new File(uri));
    } else {
        files = listFiles(filter, new File(uri));
    }
    for (File file : files) {
        URI tempURI = Paths.get(file.getPath()).toUri();
        resultList.add(fileMapper.unmapUriFromKitodoDataDirectoryUri(tempURI));
    }
    return resultList;
}