Ejemplo n.º 1
0
  /** Closes a Jar file and set its URLConnection to null. */
  private void closeJar(String path) {
    if (jarfiles.containsKey(path)) {
      JarHolder theJar = (JarHolder) jarfiles.get(path);

      theJar.close();
    }
  }
Ejemplo n.º 2
0
  private void loadJar(String path) {
    if (getLogger().isDebugEnabled()) {
      getLogger().debug("JarResourceLoader : trying to load \"" + path + "\"");
    }

    // Check path information
    if (path == null) {
      getLogger().error("JarResourceLoader : can not load JAR - JAR path is null");
    }
    if (!path.startsWith("jar:")) {
      getLogger()
          .error(
              "JarResourceLoader : JAR path must start with jar: -> "
                  + "see java.net.JarURLConnection for information");
    }
    if (!path.endsWith("!/")) {
      path += "!/";
    }

    // Close the jar if it's already open
    // this is useful for a reload
    closeJar(path);

    // Create a new JarHolder
    JarHolder temp = new JarHolder(path);

    // Add it's entries to the entryCollection
    addEntries(temp.getEntries());

    // Add it to the Jar table
    jarfiles.put(temp.getUrlPath(), temp);
  }
Ejemplo n.º 3
0
  /**
   * Get an InputStream so that the Runtime can build a template with it.
   *
   * @param source name of template to get
   * @return InputStream containing the template
   * @throws ResourceNotFoundException if template not found in the file template path.
   */
  public InputStream getResourceAsInputStream(String source) throws ResourceNotFoundException {
    InputStream results = null;

    if (source == null || source.length() == 0) {
      throw new ResourceNotFoundException("Need to have a resource!");
    }

    if (source == null || source.length() == 0) {
      String msg =
          "JAR resource error : argument "
              + source
              + " contains .. and may be trying to access "
              + "content outside of template root.  Rejected.";

      getLogger().error("JarResourceLoader : " + msg);

      throw new ResourceNotFoundException(msg);
    }

    /*
     *  if a / leads off, then just nip that :)
     */
    if (source.startsWith("/")) {
      source = source.substring(1);
    }

    if (entryDirectory.containsKey(source)) {
      String jarurl = (String) entryDirectory.get(source);

      if (jarfiles.containsKey(jarurl)) {
        JarHolder holder = (JarHolder) jarfiles.get(jarurl);

        results = holder.getResource(source);

        return results;
      }
    }

    throw new ResourceNotFoundException("JarResourceLoader Error: cannot find resource " + source);
  }