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:com.github.ukase.toolkit.WrappedUserAgentCallback.java

private String resolveUri(URI resolvingUri) {
    URI baseURI = transformUri(getBaseURL());
    if (baseURI == null) {
        return resolvingUri.toString();
    }/*from w  w w  . j  a v  a  2s  .  c o  m*/
    return baseURI.resolve(resolvingUri).toString();
}

From source file:org.jactr.entry.iterative.impl.GeneralPerformanceListener.java

/**
 * @see org.jactr.entry.iterative.IIterativeRunListener#postRun(int, int,
 *      java.util.Collection)//  w  w  w. ja  va 2  s .  c om
 */
public void postRun(int currentRunIndex, int totalRuns, @SuppressWarnings("unused") Collection<IModel> models)
        throws TerminateIterativeRunException {
    long delta = System.currentTimeMillis() - _startTime;
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Cycle " + currentRunIndex + "/" + totalRuns + "took " + delta + "ms");

    _blockSum += delta;

    if (currentRunIndex % _blockSize == 0) {
        _row.append(((double) _blockSum / (double) _blockSize)).append("\t");
        _blockSum = 0;
    }

    if (currentRunIndex == totalRuns && _fileName.length() != 0)
        try {
            /*
             * done, so we dump
             */
            URI root = new File(System.getProperty("user.dir")).toURI();
            File output = new File(root.resolve(_fileName));
            PrintWriter pw = new PrintWriter(new FileWriter(output, true));
            pw.println(_row.toString());
            if (LOGGER.isDebugEnabled())
                LOGGER.debug("Dumping row " + _row);
            pw.close();
        } catch (Exception e) {
            LOGGER.error("Could not write to " + _fileName, e);
        }
}

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

public ServerStatus _doIt() {
    try {//from ww  w . java2 s .  co m
        URI targetURI = URIUtil.toURI(target.getUrl());
        String spaceUrl = target.getOrg().getCFJSON().getJSONObject("entity").getString("spaces_url");
        URI spaceURI = targetURI.resolve(spaceUrl);

        GetMethod getMethod = new GetMethod(spaceURI.toString());
        HttpUtil.configureHttpMethod(getMethod, target);
        ServerStatus getStatus = HttpUtil.executeMethod(getMethod);
        if (!getStatus.isOK())
            return getStatus;

        JSONObject result = getStatus.getJsonData();
        JSONArray spaces = result.getJSONArray("resources");

        if (spaces.length() == 0) {
            return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, "Space not found", null);
        }

        if (this.space == null || "".equals(this.space)) {
            JSONObject space = spaces.getJSONObject(0);
            target.setSpace(new Space().setCFJSON(space));
        } else {
            for (int i = 0; i < spaces.length(); i++) {
                JSONObject spaceJSON = spaces.getJSONObject(i);
                if ((!isGuid && space.equals(spaceJSON.getJSONObject("entity").getString("name")))
                        || (isGuid && space.equals(spaceJSON.getJSONObject("metadata").getString("guid")))) {
                    target.setSpace(new Space().setCFJSON(spaceJSON));
                    break;
                }
            }
        }

        if (target.getSpace() == null) {
            return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, "Space not found", null);
        }

        return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, target.getSpace().toJSON());
    } 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:com.offbynull.portmapper.upnpigd.UpnpIgdServiceReference.java

/**
 * Constructs a {@link UpnpIgdServiceReference} object.
 * @param device device/*from w  ww.j a v  a2s  . co  m*/
 * @param serviceType service type
 * @param serviceId service ID
 * @param controlUrl control URL
 * @param scpdUrl SCPD URL
 * @throws MalformedURLException if any of the URL arguments are malformed
 * @throws NullPointerException if any argument is {@code null}
 */
public UpnpIgdServiceReference(UpnpIgdDevice device, String serviceType, String serviceId, String controlUrl,
        String scpdUrl) throws MalformedURLException {
    Validate.notNull(device);
    Validate.notNull(serviceType);
    Validate.notNull(serviceId);
    Validate.notNull(controlUrl);
    Validate.notNull(scpdUrl);

    URI baseUri = device.getUrl();

    this.device = device;
    this.serviceType = serviceType;
    this.serviceId = serviceId;
    this.controlUrl = baseUri.resolve(controlUrl);
    this.scpdUrl = baseUri.resolve(scpdUrl);
}

From source file:com.qwazr.extractor.UriInfoImpl.java

public UriInfoImpl(final URI base, final URI child) {
    baseUri = base;//from   w  w w .  j  a va 2 s  .c o  m
    absoluteUri = child.isAbsolute() ? child : base.resolve(child);
    relativeUri = base.relativize(child);
}

From source file:org.grouplens.lenskit.cli.ScriptEnvironment.java

/**
 * Get the class loader for this script environment.
 * @return The class loader.//from  w  w w.  j a  v  a2s.  c  o m
 */
public ClassLoader getClassLoader() {
    ClassLoader parent = Thread.currentThread().getContextClassLoader();
    if (parent == null) {
        parent = getClass().getClassLoader();
    }
    if (classpath.isEmpty()) {
        return parent;
    } else {
        URL[] urls = new URL[classpath.size()];
        URI base = new File(".").toURI();
        int i = 0;
        for (URI uri : classpath) {
            try {
                urls[i] = base.resolve(uri).toURL();
                logger.info("added to classpath: {}", urls[i]);
            } catch (MalformedURLException e) {
                throw new IllegalArgumentException("Invalid URL", e);
            }
            i += 1;
        }
        return new URLClassLoader(urls, parent);
    }
}

From source file:com.sworddance.util.UriFactoryImpl.java

/**
 *
 * @param baseUri/*from  w  w w  . j av a2s. co m*/
 * @param relativeUriString may be an absolute uri when converted to a URI
 * @return absolute Uri
 */
public static String absolutize(URI baseUri, String relativeUriString) {
    URI relativeUri = UriFactoryImpl.createUri(relativeUriString);
    if (relativeUri != null && relativeUri.isAbsolute()) {
        return relativeUri.toString();
    }

    notNull(baseUri, "uri should not be null");
    if (relativeUriString == null) {
        ApplicationIllegalArgumentException.valid(baseUri.isAbsolute(), baseUri,
                ": uri must be absolute because there is no relativeUriString.");
        return baseUri.resolve(".").toString();
    }
    return baseUri.resolve(relativeUri).toString();
}

From source file:org.eel.kitchen.jsonschema.ref.SchemaRegistryTest.java

@Test
public void namespacesAreRespected() throws IOException, JsonSchemaException {
    final URI fullPath = URI.create("foo:/baz#");
    final URIManager manager = new URIManager();
    final URIDownloader downloader = spy(new URIDownloader() {
        @Override/*  w ww .j  a  va  2s . c  om*/
        public InputStream fetch(final URI source) throws IOException {
            if (!fullPath.equals(source))
                throw new IOException();
            return new ByteArrayInputStream(JsonNodeFactory.instance.objectNode().toString().getBytes());
        }
    });
    manager.registerScheme("foo", downloader);

    final URI rootns = URI.create("foo:///bar/../bar/");

    final SchemaRegistry registry = new SchemaRegistry(manager, rootns);

    final URI uri = URI.create("../baz");
    registry.get(uri);
    final JsonRef ref = JsonRef.fromURI(rootns.resolve(uri));
    verify(downloader).fetch(rootns.resolve(ref.toURI()));
}

From source file:org.jboss.as.test.clustering.cluster.web.shared.SharedSessionTestCase.java

@Test
public void test(@ArquillianResource @OperateOnDeployment(DEPLOYMENT_1) URL baseURLDep1,
        @ArquillianResource @OperateOnDeployment(DEPLOYMENT_2) URL baseURLDep2)
        throws URISyntaxException, IOException {
    URI baseURI1 = new URI(baseURLDep1.toExternalForm() + "/");
    URI baseURI2 = new URI(baseURLDep2.toExternalForm() + "/");

    URI uri11 = SimpleServlet.createURI(baseURI1.resolve(MODULE_1 + "/"));
    URI uri12 = SimpleServlet.createURI(baseURI1.resolve(MODULE_2 + "/"));
    URI uri21 = SimpleServlet.createURI(baseURI2.resolve(MODULE_1 + "/"));
    URI uri22 = SimpleServlet.createURI(baseURI2.resolve(MODULE_2 + "/"));

    try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) {
        int expected = 1;
        try (CloseableHttpResponse response = client.execute(new HttpGet(uri11))) {
            Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
            Assert.assertEquals(expected++,
                    Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue()));
        }/*  w w w.  ja v a  2  s .  c o  m*/

        try (CloseableHttpResponse response = client.execute(new HttpGet(uri12))) {
            Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
            Assert.assertEquals(expected++,
                    Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue()));
        }

        try (CloseableHttpResponse response = client.execute(new HttpGet(uri21))) {
            Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
            Assert.assertEquals(expected++,
                    Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue()));
        }

        try (CloseableHttpResponse response = client.execute(new HttpGet(uri22))) {
            Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
            Assert.assertEquals(expected++,
                    Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue()));
        }
    }
}

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

private ServerStatus setCrashedInstance(JSONObject jsonResp, String appUrl) {
    try {/*from   w  w  w.j a va 2  s .  c o m*/
        URI targetURI = URIUtil.toURI(target.getUrl());
        String crashedInstancesUrl = appUrl + "/crashes";
        URI crashedInstancesURI = targetURI.resolve(crashedInstancesUrl);

        GetMethod getCrashedInstancesMethod = new GetMethod(crashedInstancesURI.toString());
        HttpUtil.configureHttpMethod(getCrashedInstancesMethod, target);

        ServerStatus getStatus = HttpUtil.executeMethod(getCrashedInstancesMethod);
        if (!getStatus.isOK()) {
            return getStatus;
        }

        String response = getStatus.getJsonData().getString("response");
        JSONArray crashedInstances = new JSONArray(response);
        JSONArray logsJSON = new JSONArray();
        if (crashedInstances.length() > 0) {
            JSONObject crashedInstance = crashedInstances.getJSONObject(crashedInstances.length() - 1);
            prepareJSONResp(logsJSON, crashedInstance.getString("instance"), appUrl);
            jsonResp.put("Last Crash", logsJSON);
        }
    } catch (Exception e) {
        return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, null, e);
    }
    return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK);
}