/**
   * 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;
  }
Esempio n. 2
0
File: Macro.java Progetto: bramk/bnd
  String ls(String args[], boolean relative) {
    if (args.length < 2)
      throw new IllegalArgumentException(
          "the ${ls} macro must at least have a directory as parameter");

    File dir = domain.getFile(args[1]);
    if (!dir.isAbsolute())
      throw new IllegalArgumentException(
          "the ${ls} macro directory parameter is not absolute: " + dir);

    if (!dir.exists())
      throw new IllegalArgumentException(
          "the ${ls} macro directory parameter does not exist: " + dir);

    if (!dir.isDirectory())
      throw new IllegalArgumentException(
          "the ${ls} macro directory parameter points to a file instead of a directory: " + dir);

    Collection<File> files = new ArrayList<File>(new SortedList<File>(dir.listFiles()));

    for (int i = 2; i < args.length; i++) {
      Instructions filters = new Instructions(args[i]);
      files = filters.select(files, true);
    }

    List<String> result = new ArrayList<String>();
    for (File file : files) result.add(relative ? file.getName() : file.getAbsolutePath());

    return Processor.join(result, ",");
  }
  /** Load the collection of CRLs. */
  protected Collection<? extends CRL> getCRLs(String crlf)
      throws IOException, CRLException, CertificateException {

    File crlFile = new File(crlf);
    if (!crlFile.isAbsolute()) {
      crlFile = new File(System.getProperty("catalina.base"), crlf);
    }
    Collection<? extends CRL> crls = null;
    InputStream is = null;
    try {
      CertificateFactory cf = CertificateFactory.getInstance("X.509");
      is = new FileInputStream(crlFile);
      crls = cf.generateCRLs(is);
    } catch (IOException iex) {
      throw iex;
    } catch (CRLException crle) {
      throw crle;
    } catch (CertificateException ce) {
      throw ce;
    } finally {
      if (is != null) {
        try {
          is.close();
        } catch (Exception ex) {
        }
      }
    }

    return crls;
  }
Esempio n. 4
0
 /**
  * Method to build an absolute path
  *
  * @param dir the root dir
  * @param name the name of the new directory
  * @return if name is an absolute directory, returns name, else returns dir+name
  */
 public static String getDir(String dir, String name) {
   if (!dir.endsWith(File.separator)) dir = dir + File.separator;
   File mv = new File(name);
   String new_dir = null;
   if (!mv.isAbsolute()) {
     new_dir = dir + name;
   } else new_dir = name;
   return new_dir;
 }
Esempio n. 5
0
  /** Create a FILE object to read from the specified filename. */
  public static FILE openFile(String filename) {
    try {
      FILE f = null;
      File file = new File(filename);

      if (file.isAbsolute()) {
        f = open(file);
      } else {
        if (documentBase != null) {
          String docBase = documentBase.toString();
          if (docBase.startsWith("file:/")) {
            docBase = docBase.substring(6);
            file = new File(docBase, filename);

            f = open(file);
          }
        }

        if (f == null && codeBase != null) {
          String cBase = codeBase.toString();
          if (cBase.startsWith("file:/")) {
            cBase = cBase.substring(6);
            file = new File(cBase, filename);

            f = open(file);
          }
        }

        if (f == null) {
          file = new File(filename);

          f = open(file);
        }
      }

      return f;
    } catch (Exception e) {
      setException(e);

      if (debug) {
        System.out.println("openFile: " + e);
      }
      return null;
    }
  }
  /**
   * Checks to see if the absolute path is availabe thru an application global static variable or
   * thru a system variable. If so, appends the relative path to the absolute path and returns the
   * String.
   */
  private String processSrcPath(String src) {
    String val = src;

    File imageFile = new File(src);
    if (imageFile.isAbsolute()) return src;

    // try to get application images path...
    if (MadChat.ApplicationImagePath != null) {
      String imagePath = MadChat.ApplicationImagePath;
      val = (new File(imagePath, imageFile.getPath())).toString();
    }
    // try to get system images path...
    else {
      String imagePath = System.getProperty("system.image.path.key");
      if (imagePath != null) {
        val = (new File(imagePath, imageFile.getPath())).toString();
      }
    }

    // System.out.println("src before: " + src + ", src after: " + val);
    return val;
  }