コード例 #1
0
  public Data createAssetFromExistingFile(
      MediaArchive inArchive, User inUser, boolean unzip, String inSourcepath) {
    String catalogid = inArchive.getCatalogId();

    String originalspath = "/WEB-INF/data/" + catalogid + "/originals/";
    Page page = getPageManager().getPage(originalspath + inSourcepath);
    if (!page.exists()) {
      return null;
    }

    String ext = PathUtilities.extractPageType(page.getName());
    if (unzip && "zip".equalsIgnoreCase(ext)) {
      // unzip and create
      List assets = new ArrayList();
      // the folder we are in
      Page parentfolder = getPageManager().getPage(page.getParentPath());
      File dest = new File(parentfolder.getContentItem().getAbsolutePath());
      String destpath = dest.getAbsolutePath();
      ZipUtil zip = new ZipUtil();
      zip.setPageManager(getPageManager());
      try {
        List files = zip.unzip(page.getContentItem().getInputStream(), dest);
        for (Object o : files) {
          File f = (File) o;
          String path = f.getAbsolutePath().substring(destpath.length());
          path = path.replace('\\', '/');
          path = parentfolder.getPath() + path; // fix slashes
          Page p = getPageManager().getPage(path);
          Asset asset = createAssetFromPage(inArchive, inUser, p);
          if (asset != null) {
            assets.add(asset);
          }
        }

        getPageManager().removePage(page);
        CompositeAsset results = new CompositeAsset(inArchive, new ListHitTracker(assets));

        return results;
      } catch (Exception e) {
        throw new OpenEditException(e);
      }
    } else {
      return createAssetFromPage(inArchive, inUser, page);
    }
  }