protected Asset createAssetFromPage(MediaArchive inArchive, User inUser, Page inAssetPage) {
    Asset asset =
        getAssetUtilities().createAssetIfNeeded(inAssetPage.getContentItem(), inArchive, inUser);
    boolean existing = true;
    if (asset == null) {
      // Should never call this
      String originals = "/WEB-INF/data" + inArchive.getCatalogHome() + "/originals/";
      String sourcepath = inAssetPage.getPath().substring(originals.length());
      asset = inArchive.getAssetBySourcePath(sourcepath);
      return asset;
    }
    if (asset.get("recordmodificationdate") == null) {
      existing = false;
    }
    inArchive.saveAsset(asset, inUser);
    if (existing) {
      inArchive.fireMediaEvent("asset/originalmodified", inUser, asset);
    } else {
      inArchive.fireMediaEvent("asset/assetcreated", inUser, asset);
    }

    inArchive.fireMediaEvent("importing/assetsimported", inUser, asset);

    return asset;
  }
 /**
  * This only works if inSourcePath has an extension, i.e. newassets/admin/118/picture.jpg
  *
  * @param inSourcePath
  * @return
  */
 public String getDataAssetsPath(String inSourcePath) {
   String prefix = "/WEB-INF/data" + getMediaArchive().getCatalogHome() + "/originals/";
   String path = prefix + inSourcePath;
   Page page = getPageManager().getPage(path);
   ContentItem content = page.getContentItem();
   return content.getAbsolutePath();
 }
  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);
    }
  }
Example #4
0
 /**
  * @deprecated Use the more simple getXml(String) version
  * @param inId
  * @param path
  * @param inElementName
  * @return
  * @throws OpenEditException
  */
 public XmlFile getXml(String inId, String path, String inElementName) throws OpenEditException {
   try { // This can be specified within the page action with a <property
     // name="xmlfile">./data.xml</property>
     XmlFile element = null;
     if (path.startsWith("/WEB-INF/data")) {
       ContentItem input = getPageManager().getRepository().get(path);
       element = load(inId, path, inElementName, input);
     } else {
       Page input = getPageManager().getPage(path, true);
       if (element == null || element.getLastModified() != input.lastModified()) {
         element = load(inId, path, inElementName, input.getContentItem());
       }
     }
     return element;
   } catch (Exception e) {
     String actual = getPageManager().getPage(path).getContentItem().getAbsolutePath();
     if (actual == null) {
       actual = path;
     }
     throw new OpenEditException("Path was: " + actual + " Error:  " + e.getMessage(), e);
   }
 }
Example #5
0
 public void deleteXmlFile(XmlFile inSettings) throws OpenEditException {
   Page page = getPageManager().getPage(inSettings.getPath(), true);
   page.getContentItem().setMakeVersion(false);
   getPageManager().removePage(page);
 }