/**
   * Resolve COLLADA references relative to the COLLADA document. If the reference is relative then
   * it will resolved relative to the .dae file, not the kml file. If the COLLADA document may be
   * contained in a KMZ archive the resources will be resolved relative to the .dae file within the
   * archive. Normally references in a KMZ are resolved relative to the root of the archive, but
   * Model references are an exception. See
   * https://developers.google.com/kml/documentation/kmzarchives and
   * https://developers.google.com/kml/documentation/kmlreference#model
   *
   * <p>{@inheritDoc}.
   */
  public String resolveFilePath(String path) throws IOException {
    KMLLink link = this.model.getLink();

    // Check the resource map to see if an alias is defined for this resource.
    String alias = this.resourceMap.get(path);
    if (alias != null) path = alias;

    // If the path is relative then resolve it relative to the COLLADA file.
    File f = new File(path);
    if (!f.isAbsolute() && link != null && link.getHref() != null) {
      try {
        URI base = new URI(null, link.getHref(), null);
        URI ref = new URI(null, path, null);

        path = base.resolve(ref).getPath();
      } catch (URISyntaxException ignored) {
        // Ignored
      }
    }

    Object o = this.parent.getRoot().resolveReference(path);
    if (o instanceof URL || o instanceof String) return o.toString();

    return null;
  }
 private ModuleSource loadFromPathList(String moduleId, Object validator, Iterable<URI> paths)
     throws IOException, URISyntaxException {
   if (paths == null) {
     return null;
   }
   for (URI path : paths) {
     final ModuleSource moduleSource = loadFromUri(path.resolve(moduleId), path, validator);
     if (moduleSource != null) {
       return moduleSource;
     }
   }
   return null;
 }
예제 #3
0
 /**
  * Resolve a URI against a base URI. (Be sure to pay attention to the order or parameters.)
  *
  * @param href URI to resolve (accept human-readable URI)
  * @param base URI base (accept human-readable URI)
  * @return resolved URI
  */
 public static String resolveURI(String href, String base) {
   final String resolvedURIString;
   if (base != null) {
     final URI baseURI;
     try {
       baseURI = new URI(encodeHRRI(base, true));
     } catch (URISyntaxException e) {
       throw new OXFException(e);
     }
     resolvedURIString =
         baseURI
             .resolve(encodeHRRI(href, true))
             .normalize()
             .toString(); // normalize to remove "..", etc.
   } else {
     resolvedURIString = encodeHRRI(href, true);
   }
   return resolvedURIString;
 }