Example usage for java.net URI resolve

List of usage examples for java.net URI resolve

Introduction

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

Prototype

public URI resolve(String str) 

Source Link

Document

Constructs a new URI by parsing the given string and then resolving it against this URI.

Usage

From source file:org.sakaiproject.tool.assessment.qti.util.URIResolver.java

public Source resolve(String href, String base) throws TransformerException {
    Source source = null;/* ww w .j a  v  a  2  s .c o  m*/
    String path = null;
    try {
        URI uri = new URI(base);
        path = uri.resolve(href).toString();
        source = new StreamSource(path);
    } catch (URISyntaxException e) {
        log.error(e);
        throw new RuntimeException(e);
    }

    return source;
}

From source file:org.apache.ode.axis2.util.Axis2UriResolver.java

public InputSource resolveEntity(String targetNamespace, String schemaLocation, String baseUri) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("resolveEntity: targetNamespace=" + targetNamespace + " schemaLocation=" + schemaLocation
                + " baseUri=" + baseUri);
    }/* w  ww  . ja  va2s .  c  o m*/
    InputStream is;
    try {
        URI base = new URI(baseUri);
        URI uri = base.resolve(schemaLocation);
        is = uri.toURL().openStream();
        if (is == null) {
            LOG.error("Exception resolving entity: schemaLocation=" + schemaLocation + " baseUri=" + baseUri);
            return null;
        }
        InputSource source = new InputSource(is);
        source.setSystemId(uri.toString());
        source.setPublicId(schemaLocation);
        return new InputSource(is);
    } catch (Exception e) {
        LOG.error("Exception resolving entity: schemaLocation=" + schemaLocation + " baseUri=" + baseUri, e);
        return null;
    }
}

From source file:org.wso2.carbon.bpel.core.ode.integration.axis2.Axis2UriResolver.java

public InputSource resolveEntity(String targetNamespace, String schemaLocation, String baseUri) {
    if (log.isDebugEnabled()) {
        log.debug("resolveEntity: targetNamespace=" + targetNamespace + " schemaLocation=" + schemaLocation
                + " baseUri=" + baseUri);
    }// www .  j  a  v  a2  s .c om
    InputStream is;
    try {
        URI base = new URI(baseUri);
        URI uri = base.resolve(schemaLocation);
        is = uri.toURL().openStream();
        if (is == null) {
            log.error("Exception resolving entity: schemaLocation=" + schemaLocation + " baseUri=" + baseUri);
            return null;
        }
        InputSource source = new InputSource(is);
        source.setSystemId(uri.toString());
        source.setPublicId(schemaLocation);
        return new InputSource(is);
    } catch (Exception e) {
        log.error("Exception resolving entity: schemaLocation=" + schemaLocation + " baseUri=" + baseUri, e);
        return null;
    }
}

From source file:org.eclipse.orion.server.cf.commands.GetServiceByNameCommand.java

@Override
protected ServerStatus _doIt() {
    try {// ww w.j  a v  a 2  s  .c  om
        URI targetURI = URIUtil.toURI(target.getUrl());
        URI servicesURI = targetURI.resolve("/v2/spaces/" + target.getSpace().getGuid() + "/services"); //$NON-NLS-0$//$NON-NLS-1$

        GetMethod getServicesMethod = new GetMethod(servicesURI.toString());
        NameValuePair[] params = new NameValuePair[] { //
                new NameValuePair("q", "label:" + serviceName), //$NON-NLS-0$ //$NON-NLS-1$
                new NameValuePair("inline-relations-depth", "1") //$NON-NLS-0$ //$NON-NLS-1$
        };
        getServicesMethod.setQueryString(params);

        HttpUtil.configureHttpMethod(getServicesMethod, target.getCloud());
        return HttpUtil.executeMethod(getServicesMethod);
    } catch (Exception e) {
        String msg = NLS.bind("An error occured when performing operation {0}", commandName); //$NON-NLS-1$
        logger.error(msg, e);
        return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
    }
}

From source file:org.apache.taverna.scufl2.translator.t2flow.defaultactivities.WSDLActivityParser.java

@Override
public Configuration parseConfiguration(T2FlowParser t2FlowParser, ConfigBean configBean,
        ParserState parserState) throws ReaderException {
    WSDLConfig wsdlConfig = unmarshallConfig(t2FlowParser, configBean, "xstream", WSDLConfig.class);

    Configuration configuration = new Configuration();
    configuration.setType(WSDL.resolve("#Config"));

    URI wsdl;
    try {// w w  w  .  j av a 2s. com
        wsdl = URI.create(wsdlConfig.getWsdl());
        if (!wsdl.isAbsolute())
            throw new ReaderException("WSDL URI is not absolute: " + wsdlConfig.getWsdl());
    } catch (IllegalArgumentException ex) {
        throw new ReaderException("WSDL not a valid URI: " + wsdlConfig.getWsdl());
    } catch (NullPointerException ex) {
        throw new ReaderException("WSDL config has no wsdl set");
    }
    String operation = wsdlConfig.getOperation();
    if (operation == null || operation.equals(""))
        throw new ReaderException("WSDL config has no operation set");

    ObjectNode json = (ObjectNode) configuration.getJson();

    ObjectNode wsdlOperation = json.objectNode();
    json.put("operation", wsdlOperation);

    wsdlOperation.put("wsdl", wsdl.toString());
    wsdlOperation.put("name", operation);

    if (wsdlConfig.getSecurityProfile() != null && !wsdlConfig.getSecurityProfile().isEmpty()) {
        URI securityProfileURI = SECURITY.resolve("#" + wsdlConfig.getSecurityProfile());
        json.put("securityProfile", securityProfileURI.toString());
    }
    return configuration;
}

From source file:org.eclipse.orion.server.cf.commands.GetServiceCommand.java

@Override
protected ServerStatus _doIt() {
    try {//from  w w w .  ja  va2 s .  c  o  m

        URI targetURI = URIUtil.toURI(target.getUrl());
        URI serviceInstanceURI = targetURI.resolve("/v2/services/" + serviceGuid); //$NON-NLS-1$//$NON-NLS-2$

        GetMethod getServiceMethod = new GetMethod(serviceInstanceURI.toString());
        HttpUtil.configureHttpMethod(getServiceMethod, target);

        ServerStatus getStatus = HttpUtil.executeMethod(getServiceMethod);
        if (!getStatus.isOK())
            return getStatus;

        JSONObject service = getStatus.getJsonData();
        return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, service);

    } catch (Exception e) {
        String msg = NLS.bind("An error occured when performing operation {0}", commandName); //$NON-NLS-1$
        logger.error(msg, e);
        return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
    }
}

From source file:org.isisaddons.app.kitchensink.webapp.ro.tck.IsisWebServerRule.java

private URI resolveUri(final String path) {
    final WebServer webServer = getWebServer();
    final URI base = webServer.getBase();
    return path != null ? base.resolve(path) : base;
}

From source file:org.eurekastreams.server.service.actions.strategies.activity.plugins.StandardFeedBookmarkMapper.java

/**
 * Gets the base object.//  w  w  w . ja v  a2s.c  om
 *
 * @param inFeed
 *            Feed the entry was taken from.
 * @param entry
 *            the entry.
 * @return the object.
 */
protected HashMap<String, String> getBaseObject(final Feed inFeed, final SyndEntry entry) {
    HashMap<String, String> object = new HashMap<String, String>();
    // TODO: Strip markup
    object.put("title", InputCleaner.stripHtml(entry.getTitle(), MAXLENGTH));
    if (entry.getDescription() != null) {
        object.put("description", InputCleaner.stripHtml(entry.getDescription().getValue(), MAXLENGTH));
    } else {
        object.put("description", "");
    }

    // fix URLs missing hostnames
    String url = InputCleaner.stripHtml(entry.getLink(), MAXLENGTH);
    try {
        URI uri = new URI(url);
        if (!uri.isAbsolute()) {
            URI feedUri = new URI(inFeed.getUrl());
            url = feedUri.resolve(uri).toString();
        }
        object.put("targetUrl", url);
    } catch (Exception ex) {
        log.warn("Omitting invalid target URL '" + url + "' from bookmark activity generated from feed.", ex);
    }

    object.put("targetTitle", InputCleaner.stripHtml(entry.getTitle(), MAXLENGTH));

    MediaModule media = (MediaModuleImpl) entry.getModule(MediaModule.URI);
    if (media != null && media.getMetadata().getThumbnail().length > 0) {
        object.put("thumbnail",
                InputCleaner.stripHtml(media.getMetadata().getThumbnail()[0].getUrl().toString(), MAXLENGTH));
    }

    return object;
}

From source file:org.ldp4j.server.data.TripleResolverTest.java

@Test
public void testRoundtrip() throws ContentTransformationException {
    URI application = URI.create("http://www.example.org/target/");
    URI endpoint = application.resolve("resource/");
    URI alternative = URI.create("http://www.ldp4j.org/target/resource/");

    String rawEntity = loadResource("/data/example_without_base.ttl");
    TripleResolver safeResolver = TripleResolver.builder().withApplication(application).withEndpoint(endpoint)
            .withAlternative(alternative).withEntity(rawEntity, this.mediaType).build();
    int count = 0;
    for (TripleResolution resolution : safeResolver.tripleResolutions()) {
        System.out.printf("[%03d] %s%n  - Subject: %s%n  - Object.: %s%n", ++count, resolution.triple(),
                resolution.subjectResolution(), resolution.objectResolution());
    }/*w  ww . jav  a2  s .co  m*/
}

From source file:org.eclipse.orion.server.cf.commands.DeleteRouteCommand.java

@Override
protected ServerStatus _doIt() {
    try {/*from  ww w  .j a v  a  2s. co  m*/
        URI targetURI = URIUtil.toURI(target.getUrl());

        /* delete the route */
        URI routeURI = targetURI.resolve("/v2/routes/" + route.getGuid()); //$NON-NLS-1$

        DeleteMethod deleteRouteMethod = new DeleteMethod(routeURI.toString());
        HttpUtil.configureHttpMethod(deleteRouteMethod, target);
        deleteRouteMethod.setQueryString("recursive=true"); //$NON-NLS-1$

        ServerStatus status = HttpUtil.executeMethod(deleteRouteMethod);
        return status;

    } catch (Exception e) {
        String msg = NLS.bind("An error occured when performing operation {0}", commandName);
        logger.error(msg, e);
        return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
    }
}