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:fr.ign.cogit.geoxygene.appli.gl.program.GLProgramBuilder.java

static void append(GLProgram program, RenderingMethodDescriptor method) throws Exception {
    for (ShaderRef shader_ref : method.getShadersReferences()) {
        Shader shader = null;/*from ww w.  j av  a  2 s .c om*/
        try {
            if (shader_ref.location != null) {
                URL location_resolved = null;
                String shader_name = FilenameUtils.getName(shader_ref.location.toString());
                if (shader_ref.location.isAbsolute()) {
                    location_resolved = shader_ref.location.toURL();
                    shader = new Shader(shader_name, shader_ref.type, shader_ref.location.toURL());
                } else {
                    // Is this a relative path?
                    URI mlocation = method.getLocation().toURI();
                    location_resolved = mlocation.resolve(shader_ref.location).toURL();
                    if (!testURLValid(location_resolved)) {
                        location_resolved = Shader.DEFAULT_SHADERS_LOCATION_DIR.toURI()
                                .resolve(shader_ref.location).toURL();
                        if (!testURLValid(location_resolved))
                            location_resolved = null;
                    }
                }
                if (location_resolved != null) {
                    shader = new Shader(shader_name, shader_ref.type, location_resolved);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (shader == null) {
            logger.error("Failed to load the shader " + shader_ref + " for the redering method " + method
                    + ". Rendering with this method may cause unexpected behaviors.");
            throw new Exception("SHADER " + shader_ref.toString() + " at location " + shader_ref.location
                    + " WAS NOT FOUND : failed to build the program " + program.getName());
        }
        shader.addToGLProgram(program);
    }
}

From source file:org.wso2.carbon.transport.http.netty.util.TestUtil.java

public static HttpURLConnection request(URI baseURI, String path, String method, boolean keepAlive)
        throws IOException {
    URL url = baseURI.resolve(path).toURL();
    HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
    if (method.equals(HttpMethod.POST.name()) || method.equals(HttpMethod.PUT.name())) {
        urlConn.setDoOutput(true);/*from w w  w  .java  2  s  .  com*/
    }
    urlConn.setRequestMethod(method);
    if (!keepAlive) {
        urlConn.setRequestProperty("Connection", "Keep-Alive");
    }

    return urlConn;
}

From source file:xworker.app.model.tree.http.HttpExtjsJsonTreeModelActions.java

@SuppressWarnings("unchecked")
public static void checkImageUrl(Map<String, Object> node, URI root) {
    String iconPath = (String) node.get("icon");
    if (iconPath != null && !"".equals(iconPath)) {
        URI iconUri = root.resolve(iconPath);
        node.put("icon", iconUri.toString());
    }/*from  w  w w.jav  a  2s  . c  o m*/

    List<Map<String, Object>> childs = (List<Map<String, Object>>) node.get("childs");
    if (childs != null) {
        checkImageUrl(childs, root);
    }
}

From source file:org.eclipse.orion.internal.server.servlets.workspace.ProjectInfoResourceHandler.java

public static JSONObject toJSON(WorkspaceInfo workspace, ProjectInfo project, URI parentLocation) {
    JSONObject result = MetadataInfoResourceHandler.toJSON(project);
    try {//from   w w  w  . ja v  a  2 s  .co  m
        result.put(ProtocolConstants.KEY_LOCATION,
                URIUtil.append(parentLocation, "project/" + project.getFullName())); //$NON-NLS-1$
        URI base = parentLocation.resolve(""); //$NON-NLS-1$
        result.put(ProtocolConstants.KEY_CONTENT_LOCATION,
                WorkspaceResourceHandler.computeProjectURI(base, workspace, project));
    } catch (JSONException e) {
        //can't happen because key and value are well-formed
    }
    return result;
}

From source file:org.wso2.siddhi.extension.input.transport.http.Util.ServerUtil.java

public static HttpURLConnection request(URI baseURI, String path, String method, boolean keepAlive)
        throws IOException {
    URL url = baseURI.resolve(path).toURL();
    HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
    if (method.equals(HttpMethod.POST.name()) || method.equals(HttpMethod.PUT.name())) {
        urlConn.setDoOutput(true);//from  www  .j  a  va 2  s  . co  m
    }
    urlConn.setRequestMethod(method);
    if (!keepAlive) {
        urlConn.setRequestProperty("Connection", "Keep-Alive");
    }
    return urlConn;
}

From source file:com.splunk.shuttl.archiver.archive.ArchiveConfiguration.java

private static URI getChildToArchivingRoot(URI archivingRoot, String childNameToArchivingRoot) {
    if (archivingRoot != null) {
        String rootName = FilenameUtils.getName(archivingRoot.getPath());
        return archivingRoot.resolve(rootName + "/" + childNameToArchivingRoot);
    } else {// w  w w  .j av a  2 s  .  com
        return null;
    }
}

From source file:org.apache.maven.wagon.shared.http.HtmlFileListParser.java

private static String cleanLink(URI baseURI, String link) {
    if (StringUtils.isEmpty(link)) {
        return "";
    }//from   w  w w  .  j  a v  a  2  s .c  o m

    String ret = link;

    try {
        URI linkuri = new URI(ret);
        if (link.startsWith("/")) {
            linkuri = baseURI.resolve(linkuri);
        }
        URI relativeURI = baseURI.relativize(linkuri).normalize();
        ret = relativeURI.toASCIIString();
        if (ret.startsWith(baseURI.getPath())) {
            ret = ret.substring(baseURI.getPath().length());
        }

        ret = URLDecoder.decode(ret, "UTF-8");
    } catch (URISyntaxException e) {
    } catch (UnsupportedEncodingException e) {
    }

    return ret;
}

From source file:com.basho.riak.presto.RiakClient.java

private static Function<URI, URI> uriResolver(final URI baseUri) {
    return new Function<URI, URI>() {
        @Override/*from   www .j  ava2s  .c  om*/
        public URI apply(URI source) {
            return baseUri.resolve(source);
        }
    };
}

From source file:bpelg.packaging.ode.util.BgSchemaCollection.java

protected static URI resolve(URI base, String location) {
    if ("jar".equals(base.getScheme())) {
        String str = base.toString();
        String[] parts = str.split("!");
        parts[1] = URI.create(parts[1]).resolve(location).toString();
        return URI.create(parts[0] + "!" + parts[1]);
    }//from  w  w  w . j av a 2 s .co  m
    return base.resolve(location);
}

From source file:org.lenskit.data.dao.file.TextEntitySource.java

/**
 * Create a file reader.//from   ww w. j a  v  a2  s.c  om
 * @param name The reader name.
 * @param object The configuring object.
 * @param base The base URI for source data.
 * @return The new entity reader.
 */
static TextEntitySource fromJSON(String name, JsonNode object, URI base, ClassLoader loader) {
    TextEntitySource source = new TextEntitySource(name);
    URI uri = base.resolve(object.get("file").asText());
    try {
        source.setURI(uri.toURL());
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException("Cannot resolve URI " + uri, e);
    }
    logger.info("loading text file source {} to read from {}", name, source.getURL());

    String fmt = object.path("format").asText("delimited").toLowerCase();
    String delim;
    switch (fmt) {
    case "csv":
        delim = ",";
        break;
    case "tsv":
    case "delimited":
        delim = "\t";
        break;
    default:
        throw new IllegalArgumentException("unsupported data format " + fmt);
    }
    JsonNode delimNode = object.path("delimiter");
    if (delimNode.isValueNode()) {
        delim = delimNode.asText();
    }

    DelimitedColumnEntityFormat format = new DelimitedColumnEntityFormat();
    format.setDelimiter(delim);
    logger.debug("{}: using delimiter {}", name, delim);
    JsonNode header = object.path("header");
    boolean canUseColumnMap = false;
    if (header.isBoolean() && header.asBoolean()) {
        logger.debug("{}: reading header", name);
        format.setHeader(true);
        canUseColumnMap = true;
    } else if (header.isNumber()) {
        format.setHeaderLines(header.asInt());
        logger.debug("{}: skipping {} header lines", format.getHeaderLines());
    }

    String eTypeName = object.path("entity_type").asText("rating").toLowerCase();
    EntityType etype = EntityType.forName(eTypeName);
    logger.debug("{}: reading entities of type {}", name, etype);
    EntityDefaults entityDefaults = EntityDefaults.lookup(etype);
    format.setEntityType(etype);
    format.setEntityBuilder(
            entityDefaults != null ? entityDefaults.getDefaultBuilder() : BasicEntityBuilder.class);

    JsonNode columns = object.path("columns");
    if (columns.isMissingNode() || columns.isNull()) {
        List<TypedName<?>> defColumns = entityDefaults != null ? entityDefaults.getDefaultColumns() : null;
        if (defColumns == null) {
            throw new IllegalArgumentException("no columns specified and no default columns available");
        }

        for (TypedName<?> attr : entityDefaults.getDefaultColumns()) {
            format.addColumn(attr);
        }
    } else if (columns.isObject()) {
        if (!canUseColumnMap) {
            throw new IllegalArgumentException("cannot use column map without file header");
        }
        Iterator<Map.Entry<String, JsonNode>> colIter = columns.fields();
        while (colIter.hasNext()) {
            Map.Entry<String, JsonNode> col = colIter.next();
            format.addColumn(col.getKey(), parseAttribute(entityDefaults, col.getValue()));
        }
    } else if (columns.isArray()) {
        for (JsonNode col : columns) {
            format.addColumn(parseAttribute(entityDefaults, col));
        }
    } else {
        throw new IllegalArgumentException("invalid format for columns");
    }

    JsonNode ebNode = object.path("builder");
    if (ebNode.isTextual()) {
        String ebName = ebNode.asText();
        if (ebName.equals("basic")) {
            format.setEntityBuilder(BasicEntityBuilder.class);
        } else {
            Class bld;
            try {
                bld = ClassUtils.getClass(loader, ebName);
            } catch (ClassNotFoundException e) {
                throw new IllegalArgumentException("cannot load class " + ebName, e);
            }
            format.setEntityBuilder(bld);
        }
    }
    logger.debug("{}: using entity builder {}", format.getEntityBuilder());

    source.setFormat(format);
    return source;
}