예제 #1
0
  public static FsEntry createElement(FsFolder parent, File file) {
    FsEntry element;

    if (file.isDirectory()) {
      element = FsFolder.createFolder(parent, file);
    } else {
      String filename = file.getName();
      int idx = filename.lastIndexOf('.');
      String ext = (idx == -1) ? null : filename.substring(idx + 1);
      boolean zipped = "zip".equals(ext) || "jar".equals(ext);
      element = zipped ? FsFolder.createFolder(parent, file) : FsFile.createFile(parent, file);
    }
    return element;
  }
예제 #2
0
    public FsEntry getInstance(FsFolder parent, ZipEntry subEntry) {
      FsEntry elem = null;

      if (_zipfile != null) {
        elem = parent.getInstance(_zipfile, subEntry);
      } else if (_url != null) {
        elem = parent.getInstance(null, subEntry);

        // elem = parent.getInstance(_url, subEntry);
      } else {
        elem = null;
      }

      return elem;
    }
예제 #3
0
  private File createTemporaryFile(FsFolder folderRef, ZipFile zipfile, ZipEntry entry)
      throws IOException {
    String prefix = entry.getName();
    int len = prefix.length();
    Enumeration<? extends ZipEntry> enu = zipfile.entries();

    while (enu.hasMoreElements()) {
      ZipEntry e = enu.nextElement();
      String name = e.getName();
      if (!name.equals(prefix) && name.startsWith(prefix)) {
        String suffix = name.substring(len);
        File file = new File(folderRef.m_file, suffix);
        if (e.isDirectory()) {
          file.mkdirs();
        } else {
          file.createNewFile();
          InputStream input = zipfile.getInputStream(entry);
          unzipTo(input, file);
        }
      }
    } // end while

    List<FsEntry> elements = folderRef.getFolderElements();

    String entryname = entry.getName();
    String resourceURL = "jar:file:" + zipfile.getName() + "!/" + entryname;
    File tmlFile = JarUtil.createTemporaryFile(resourceURL);
    return tmlFile;
  }
예제 #4
0
  // resource can be a URL or a folder
  public static FsFolder createRoot(String resource) {
    FsFolder root = null;

    // is it a URL?
    try {
      URL url = new URL(resource);
      root = FsFolder.createRoot(url);
    } catch (MalformedURLException ex) {
      // no, it is a file?
      File file = new File(resource);
      if (file.exists() && file.isDirectory()) {
        root = FsFolder.createRoot(file);
      }
    } // end try

    return root;
  }
예제 #5
0
  //
  // private constructors
  //
  private FsFolder(FsFolder parent, File file) {
    if (parent != null) {
      String name = file.getName();
      parent.addChild(name, this);
      m_parent = parent;
    }

    m_file = file;
    // buildChildren();
  }
예제 #6
0
  public FsEntry getNamedDescendent(String resourceName) {
    FsEntry namedChild = null;
    FsFolder folder = this;
    boolean directory = resourceName.endsWith("/");
    StringTokenizer st = new StringTokenizer(resourceName, "/");

    while (st.hasMoreTokens()) {
      String name = st.nextToken();
      if (st.hasMoreTokens() || directory) {
        name += "/";
      }

      namedChild = folder.getNamedChild(name);
      if (namedChild instanceof FsFolder) {
        folder = (FsFolder) namedChild;
      }
    }

    return namedChild;
  }
예제 #7
0
 private FsFolder(
     FsFolder parent, String folderName, ZipFileAndURLUnion composite, ZipEntry entry) {
   if (parent != null) {
     parent.addChild(folderName, this);
     m_parent = parent;
   }
   // parent.addChild(folderName, folder); //important
   m_composite = composite;
   m_entry = entry;
   // buildChildren();
 }
예제 #8
0
  @Override
  public void copyTo(FsFolder destFolder) throws IOException {
    // copy = null;

    // create file
    if (m_file != null) {
      // String foldername = m_file.getName();
      // File target = new File(destFolder.m_file, foldername);
      // copy = createFolder(destFolder, destFolder.m_file);

      List<FsEntry> elements = getFolderElements();
      for (FsEntry element : elements) {
        String foldername = element.getSimpleName();
        File destParent = destFolder.m_file;
        File newFile = new File(destParent, foldername);

        if (element instanceof FsFolder) {
          FsFolder copy = createFolder(destFolder, newFile);
          element.copyTo(copy);
        } else {
          // FileRef copy = FileRef.createFile(destFolder, newFile);
          element.copyTo(destFolder);
        }
      }

    } else if (m_composite != null) {
      // create folder
      String entryName = m_entry.getName();
      int len = entryName.length();
      int idx = entryName.lastIndexOf('/', len - 2);
      String suffix = entryName.substring(idx + 1, len - 1);
      File folder = new File(destFolder.m_file, suffix);
      folder.mkdirs();
      FsFolder copy = FsFolder.createFolder(destFolder, folder);

      // unzip in folder
      List<FsEntry> entries = getFolderElements();
      for (FsEntry entry : entries) {
        entry.copyTo(copy);
      }

      // unzipEntries(folderRef);

      // new ZipInputStream();

      /*
      File f = createTemporaryFile(folderRef, m_zipfile, m_entry);
      f.createNewFile();
      FileRef tempfile = FileRef.createFile(destFolder, f);
      */
    }
  }
예제 #9
0
  public static FsFolder createFolder(FsFolder parent, File folder) {

    FsFolder folderRef = (FsFolder) parent.getInstance(folder);
    if (folderRef == null) {
      if (!folder.exists()) {
        folder.mkdirs();
      }

      folderRef = new FsFolder(parent, folder);
      String name = folder.getName();
      // parent.addChild(name, folderRef);
    }

    return folderRef;
  }
예제 #10
0
 private static FsFolder createFolder(
     FsFolder parent, String foldername, ZipFileAndURLUnion composite, ZipEntry entry) {
   FsFolder element = FsFolder.createFolder(parent, foldername, composite, entry);
   return element;
 }
예제 #11
0
  public static FsEntry createElement(
      FsFolder parent, ZipFileAndURLUnion composite, ZipEntry entry) {
    FsEntry element = null;

    String prefix = parent.getQualifiedName();

    boolean directory = entry.isDirectory();
    String entryName = entry.getName();

    if (entryName.startsWith(prefix)) {
      String subEntryName = prefix;

      String suffix = entryName.substring(prefix.length());
      StringTokenizer st = new StringTokenizer(suffix, "/");

      while (st.hasMoreTokens()) {
        String token = st.nextToken();
        String elementName = (st.hasMoreTokens() || directory) ? (token + "/") : token;
        subEntryName += elementName;

        if (st.hasMoreTokens()) {
          ZipEntry subEntry = composite.getEntry(subEntryName);
          if (subEntry == null) {
            int i = 0;
            i++;
          }
          FsEntry elem = composite.getInstance(parent, subEntry);

          if (elem == null) {
            elem = createFolder(parent, subEntryName, composite, subEntry);
          }

          if (elem instanceof FsFolder) {
            parent = (FsFolder) elem;
          }
        } else {
          // boolean directory = entry.isDirectory();
          element =
              directory
                  ? createFolder(parent, elementName, composite, entry)
                  : FsFile.createFile(parent, elementName, composite, entry);
        }
      }
    } else {

      String subEntryName = "";
      ;

      StringTokenizer st = new StringTokenizer(entryName, "/");

      while (st.hasMoreTokens()) {
        String token = st.nextToken();
        String elementName = (st.hasMoreTokens() || directory) ? (token + "/") : token;
        subEntryName += elementName;

        if (st.hasMoreTokens()) {
          ZipEntry subEntry = composite.getEntry(subEntryName);
          FsEntry elem = composite.getInstance(parent, subEntry);

          if (elem == null) {
            elem = createFolder(parent, subEntryName, composite, subEntry);
          }

          if (elem instanceof FsFolder) {
            parent = (FsFolder) elem;
          }
        } else {
          // boolean directory = entry.isDirectory();
          element =
              directory
                  ? createFolder(parent, elementName, composite, entry)
                  : FsFile.createFile(parent, elementName, composite, entry);
        }
      } // end while
    }

    return element;
  }