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:edu.isi.karma.kr2rml.writer.JSONKR2RMLRDFWriter.java

@Override
public JSONObject getNewObject(String triplesMapId, String subjUri) {
    JSONObject object = new JSONObject();
    subjUri.trim();/*  w ww . ja  va 2s  .c o  m*/
    if (subjUri.startsWith("<") && subjUri.endsWith(">")) {
        subjUri = subjUri.substring(1, subjUri.length() - 1);
        try {
            URI uri = new URI(subjUri);
            if (!uri.isAbsolute())
                subjUri = baseURI + subjUri;
        } catch (Exception e) {

        }
    }
    object.put(atId, subjUri);
    return object;
}

From source file:org.aludratest.service.gui.web.selenium.selenium2.AludraSeleniumHttpCommandExecutor.java

private URI buildUri(HttpContext context, String location) throws URISyntaxException {
    URI uri;
    uri = new URI(location);
    if (!uri.isAbsolute()) {
        HttpHost host = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);
        uri = new URI(host.toURI() + location);
    }/*from   w w  w .j a  va  2  s.  c om*/
    return uri;
}

From source file:net.hillsdon.reviki.wiki.renderer.creole.CreoleLinkContentsSplitter.java

/**
 * Splits links of the form target or text|target where target is
 * //from ww  w.j  av a 2  s . c o  m
 * PageName wiki:PageName PageName#fragment wiki:PageName#fragment
 * A String representing an absolute URI scheme://valid/absolute/uri
 * Any character not in the `unreserved`, `punct`, `escaped`, or `other` categories (RFC 2396),
 * and not equal '/' or '@', is %-encoded. 
 * 
 * @param in The String to split
 * @return The split LinkParts
 */
LinkParts split(final String in) {
    String target = StringUtils.trimToEmpty(StringUtils.substringBefore(in, "|"));
    String text = StringUtils.trimToNull(StringUtils.substringAfter(in, "|"));
    if (target == null) {
        target = "";
    }
    if (text == null) {
        text = target;
    }
    // Link target can be PageName, wiki:PageName or a URL.
    URI uri = null;
    try {
        URL url = new URL(target);

        uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
                url.getQuery(), url.getRef());
        if (uri.getPath() == null || !uri.isAbsolute()) {
            uri = null;
        }
    } catch (URISyntaxException e) {
        // uri remains null
    } catch (MalformedURLException e) {
        // uri remains null
    }

    if (uri != null) {
        return new LinkParts(text, uri);
    } else {
        // Split into wiki:pageName
        String[] parts = target.split(":", 2);
        String wiki = null;
        String pageName = target;
        if (parts.length == 2) {
            wiki = parts[0];
            pageName = parts[1];
        }

        // Split into pageName#fragment
        parts = pageName.split("#", 2);
        String fragment = null;
        if (parts.length == 2) {
            pageName = parts[0];
            fragment = parts[1];
        }

        // Split into pageName/attachment
        parts = pageName.split("/", 2);
        String attachment = null;
        if (parts.length == 2) {
            pageName = parts[0];
            attachment = parts[1];
        }

        return new LinkParts(text, wiki, pageName, fragment, attachment);
    }
}

From source file:pl.psnc.synat.wrdz.zmd.download.DownloadManagerBean.java

@Override
public String downloadFromUri(URI uri, String relativePath) throws DownloadException, IllegalArgumentException {
    if (uri == null) {
        throw new IllegalArgumentException("Cannot download content - given URI is null");
    } else if (!uri.isAbsolute()) {
        throw new IllegalArgumentException("Cannot download content - given URI is not a URL");
    }//from   w  w w .j  a va 2s.co  m
    if (relativePath == null || relativePath.trim().isEmpty()) {
        throw new IllegalArgumentException("Cannot download content - given path is empty or null");
    }
    String cachedResourcePath = null;
    if (isLocallyCached(uri)) {
        return (new File(uri.getSchemeSpecificPart())).getAbsolutePath(); // must be getSchemeSpecificPart() because of mounted network drives 
    } else {
        try {
            ConnectionInformation connectionInfo = connectionHelper.getConnectionInformation(uri);
            DownloadAdapter downloadAdapter = getAdapterForProtocolName(uri.getScheme().toUpperCase(),
                    connectionInfo);
            cachedResourcePath = downloadAdapter.downloadFile(uri, relativePath);
        } catch (AmbiguousResultException e) {
            throw new DownloadException("Could not determine connection information to use", e);
        } catch (OperationNotSupportedException e) {
            throw new DownloadException("Cannot download using specified protocol " + uri.getScheme()
                    + ", no compatible adapters present in the system", e);
        } catch (DownloadAdapterException e) {
            throw new DownloadException("An error occured while creating the download adapter", e);
        }
    }
    return cachedResourcePath;
}

From source file:org.wso2.bps.samples.migration.deployment.ArchiveBasedHumanTaskDeploymentUnitBuilder.java

@Override
public void buildWSDLs() throws HumanTaskDeploymentException {
    URI baseUri = humantaskDir.toURI();
    for (File file : FileUtils.directoryEntriesInPath(humantaskDir, wsdlFilter)) {

        try {//from ww  w  . j  a  v  a 2  s  . c  om
            URI uri = baseUri.relativize(file.toURI());
            if (!uri.isAbsolute()) {
                File f = new File(baseUri.getPath() + File.separator + uri.getPath());
                URI abUri = f.toURI();
                if (abUri.isAbsolute()) {
                    uri = abUri;
                }
            }

            WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
            reader.setFeature(HumanTaskConstants.JAVAX_WSDL_VERBOSE_MODE_KEY, false);
            reader.setFeature("javax.wsdl.importDocuments", true);
            Definition definition = reader.readWSDL(new HumanTaskWSDLLocator(uri));
            wsdlDefinitions.add(definition);

        } catch (WSDLException e) {
            System.out.println("Error processing wsdl " + file.getName());
            throw new HumanTaskDeploymentException(" Error processing wsdl ", e);
        } catch (URISyntaxException e) {
            System.out.println("Invalid uri in reading wsdl ");
            throw new HumanTaskDeploymentException(" Invalid uri in reading wsdl ", e);
        }
        //            wsdlsMap.put(file.getName(), is);
    }
}

From source file:org.geoserver.wms.web.data.ExternalGraphicPanel.java

/**
 * Validates the external graphic and returns a connection to the graphic.
 * If validation fails, error messages will be added to the passed form
 * //ww w .j a  v  a 2s .  c  om
 * @param target
 * @param form
 * @return URLConnection to the External Graphic file
 */
protected URLConnection getExternalGraphic(AjaxRequestTarget target, Form<?> form) {
    onlineResource.processInput();
    if (onlineResource.getModelObject() != null) {
        URL url = null;
        try {
            String baseUrl = baseURL(form);
            String external = onlineResource.getModelObject().toString();

            URI uri = new URI(external);
            if (uri.isAbsolute()) {
                url = uri.toURL();
                if (!external.startsWith(baseUrl)) {
                    form.warn("Recommend use of styles directory at " + baseUrl);
                }
            } else {
                WorkspaceInfo wsInfo = ((StyleInfo) getDefaultModelObject()).getWorkspace();
                if (wsInfo != null) {
                    url = new URL(ResponseUtils.appendPath(baseUrl, "styles", wsInfo.getName(), external));
                } else {
                    url = new URL(ResponseUtils.appendPath(baseUrl, "styles", external));
                }
            }

            URLConnection conn = url.openConnection();
            if ("text/html".equals(conn.getContentType())) {
                form.error("Unable to access url");
                return null; // error message back!
            }
            return conn;

        } catch (FileNotFoundException notFound) {
            form.error("Unable to access " + url);
        } catch (Exception e) {
            e.printStackTrace();
            form.error("Recommend use of styles directory at " + e);
        }
    }
    return null;
}

From source file:com.epam.reportportal.apache.http.impl.execchain.ProtocolExec.java

void rewriteRequestURI(final HttpRequestWrapper request, final HttpRoute route) throws ProtocolException {
    try {//from   w  w  w .jav a2s  .  com
        URI uri = request.getURI();
        if (uri != null) {
            if (route.getProxyHost() != null && !route.isTunnelled()) {
                // Make sure the request URI is absolute
                if (!uri.isAbsolute()) {
                    final HttpHost target = route.getTargetHost();
                    uri = URIUtils.rewriteURI(uri, target, true);
                } else {
                    uri = URIUtils.rewriteURI(uri);
                }
            } else {
                // Make sure the request URI is relative
                if (uri.isAbsolute()) {
                    uri = URIUtils.rewriteURI(uri, null, true);
                } else {
                    uri = URIUtils.rewriteURI(uri);
                }
            }
            request.setURI(uri);
        }
    } catch (final URISyntaxException ex) {
        throw new ProtocolException("Invalid URI: " + request.getRequestLine().getUri(), ex);
    }
}

From source file:com.microsoft.tfs.client.common.credentials.internal.EclipseCredentialsManager.java

private String getNodePath(final URI serverURI) {
    Check.notNull(serverURI, "serverURI"); //$NON-NLS-1$
    Check.isTrue(serverURI.isAbsolute(), "URI has to be absolute"); //$NON-NLS-1$
    Check.notNull(serverURI.getHost(), "serverURI.getHost()"); //$NON-NLS-1$

    final StringBuffer sb = new StringBuffer(rootPathPrefix);

    final String scheme = serverURI.getScheme();
    sb.append(scheme.toLowerCase());/*from   w  w w  .  j  a  v a  2  s .  com*/
    sb.append(':');

    sb.append(ENCODED_SLASH);
    sb.append(ENCODED_SLASH);

    final String host = serverURI.getHost().toLowerCase();
    sb.append(host);

    sb.append(':');
    if (serverURI.getPort() < 0) {
        if (scheme.equalsIgnoreCase(HTTP_SCHEME)) {
            sb.append("80"); //$NON-NLS-1$
        } else if (scheme.equalsIgnoreCase(HTTPS_SCHEME)) {
            sb.append("443"); //$NON-NLS-1$
        }
    } else {
        sb.append(serverURI.getPort());
    }

    return sb.toString();
}

From source file:org.gbif.api.model.registry.Contact.java

/**
 * Adds a new user id that is assembled from a directory name and a local id within it.
 * Format used by EML.//  w ww. j av a2 s .com
 * The directory should be a valid URI, if it's not, it will be ignored by this method.
 *
 * @param directory identifier for the directory, preferably a URL domain like http://orcid.org
 * @param id the identifier in that directory
 */
public void addUserId(String directory, String id) {
    if (!Strings.isNullOrEmpty(id)) {
        if (Strings.isNullOrEmpty(directory)) {
            userId.add(id);
        } else {
            try {
                URI dir = URI.create(directory);
                if (dir.isAbsolute()) {
                    String dir2 = dir.toString();
                    if (!dir2.endsWith("/") && !dir2.endsWith("=")) {
                        dir2 = dir2 + "/";
                    }
                    userId.add(dir2 + id);
                } else {
                    userId.add(dir + ":" + id);
                }
            } catch (IllegalArgumentException iaEx) {
                //in case the directory is not a valid url keep only the user id
                userId.add(id);
            }
        }
    }
}

From source file:org.apache.cxf.fediz.service.idp.STSAuthenticationProvider.java

protected List<Claim> parseClaimsInAssertion(org.opensaml.saml2.core.Assertion assertion) {
    List<org.opensaml.saml2.core.AttributeStatement> attributeStatements = assertion.getAttributeStatements();
    if (attributeStatements == null || attributeStatements.isEmpty()) {
        LOG.debug("No attribute statements found");
        return Collections.emptyList();
    }/*from  w ww  . jav  a2  s  .  co m*/

    List<Claim> collection = new ArrayList<Claim>();
    Map<String, Claim> claimsMap = new HashMap<String, Claim>();

    for (org.opensaml.saml2.core.AttributeStatement statement : attributeStatements) {
        LOG.debug("parsing statement: {}", statement.getElementQName());
        List<org.opensaml.saml2.core.Attribute> attributes = statement.getAttributes();
        for (org.opensaml.saml2.core.Attribute attribute : attributes) {
            LOG.debug("parsing attribute: {}", attribute.getName());
            Claim c = new Claim();
            // Workaround for CXF-4484 
            // Value of Attribute Name not fully qualified
            // if NameFormat is http://schemas.xmlsoap.org/ws/2005/05/identity/claims
            // but ClaimType value must be fully qualified as Namespace attribute goes away
            URI attrName = URI.create(attribute.getName());
            if (ClaimTypes.URI_BASE.toString().equals(attribute.getNameFormat()) && !attrName.isAbsolute()) {
                c.setClaimType(URI.create(ClaimTypes.URI_BASE + "/" + attribute.getName()));
            } else {
                c.setClaimType(URI.create(attribute.getName()));
            }
            c.setIssuer(assertion.getIssuer().getNameQualifier());

            List<String> valueList = new ArrayList<String>();
            for (XMLObject attributeValue : attribute.getAttributeValues()) {
                Element attributeValueElement = attributeValue.getDOM();
                String value = attributeValueElement.getTextContent();
                LOG.debug(" [{}]", value);
                valueList.add(value);
            }
            mergeClaimToMap(claimsMap, c, valueList);
        }
    }
    collection.addAll(claimsMap.values());
    return collection;

}