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 void saveXml(XmlFile inFile, User inUser, Lock lock) throws OpenEditException {

    // Lock lock = getLockManager().lock("system", inFile.getPath(), null ); //this will retry 10
    // times then timeout and throw an exception

    Page page = getPageManager().getPage(inFile.getPath(), false);

    ContentItem tmp = getPageManager().getRepository().getStub(inFile.getPath() + ".tmp.xml");
    tmp.setMakeVersion(false);
    getXmlUtil().saveXml(inFile.getRoot(), tmp.getOutputStream(), page.getCharacterEncoding());

    ContentItem xmlcontent = getPageManager().getRepository().getStub(inFile.getPath());
    xmlcontent.setMakeVersion(false);
    getPageManager()
        .getRepository()
        .remove(xmlcontent); // might be a little faster to remove it first
    getPageManager().getRepository().move(tmp, xmlcontent);
    getPageManager().firePageModified(page);

    xmlcontent = getPageManager().getRepository().getStub(inFile.getPath());
    inFile.setLastModified(xmlcontent.getLastModified());
    inFile.setExist(true);
    // log.info("Save " + inFile.getPath());

  }
  /* (non-Javadoc)
   * @see com.openedit.action.Command#execute(java.util.Map, java.util.Map)
   */
  public void execute(WebPageRequest inReq) throws OpenEditException {
    configure(inReq);
    Page page = (Page) inReq.getPage(); // urlUtils.requestPath();
    String requestPath = page.getPath();

    if (!inExcludeList(requestPath)) {
      Permission filter = inReq.getPage().getPermission("view");
      if ((filter != null)) {
        if (!filter.passes(inReq)) {
          if (isForbid()) {
            if (inReq.getResponse() != null) {
              inReq.getResponse().setStatus(HttpServletResponse.SC_FORBIDDEN);
              inReq.setHasRedirected(true);
            }
          } else {
            log.error("No view permission for " + page.getPath() + " sending redirect");
            inReq.putPageValue(
                "oe-exception", "You do not have permission to view " + page.getPath());

            // this is the original page someone might have been on. Used in login
            inReq.putSessionValue("originalEntryPage", inReq.getContentPage().getPath());
            String fullOriginalEntryPage = (String) inReq.getSessionValue("fullOriginalEntryPage");
            if (fullOriginalEntryPage == null) {
              inReq.putSessionValue("fullOriginalEntryPage", inReq.getPathUrlWithoutContext());
            }
            inReq.redirect(getLoginPath());
          }
        }
      } else {
        log.info("No view restrictions have been set for " + requestPath);
      }
    }
  }
  public InputStream getOriginalDocumentStream(Asset inAsset) throws OpenEditException {
    InputStream in = null;

    Page fullpath = getOriginalDocument(inAsset);
    if (fullpath == null) {
      return null;
    }
    return fullpath.getInputStream();
  }
 public void processOnAll(String inRootPath, final MediaArchive inArchive, User inUser) {
   for (Iterator iterator = getPageManager().getChildrenPaths(inRootPath).iterator();
       iterator.hasNext(); ) {
     String path = (String) iterator.next();
     Page topLevelPage = getPageManager().getPage(path);
     if (topLevelPage.isFolder()
         && !topLevelPage.getPath().endsWith("/CVS")
         && !topLevelPage.getPath().endsWith(".versions")) {
       processOn(inRootPath, path, inArchive, true, inUser);
     }
   }
 }
  public List removeExpiredAssets(MediaArchive archive, String sourcepath, User inUser) {
    AssetSearcher searcher = archive.getAssetSearcher();
    SearchQuery q = searcher.createSearchQuery();
    HitTracker assets = null;
    if (sourcepath == null) {
      assets = searcher.getAllHits();
    } else {
      q.addStartsWith("sourcepath", sourcepath);
      assets = searcher.search(q);
    }
    List<String> removed = new ArrayList<String>();
    List<String> sourcepaths = new ArrayList<String>();

    for (Object obj : assets) {
      Data hit = (Data) obj;
      sourcepaths.add(hit.get("sourcepath")); // TODO: Move to using page of hits
      if (sourcepaths.size() > 250000) {
        log.error("Should not load up so many paths");
        break;
      }
    }
    for (String path : sourcepaths) {
      Asset asset = archive.getAssetBySourcePath(path);
      if (asset == null) {
        continue;
      }
      String assetsource = asset.getSourcePath();
      String pathToOriginal =
          "/WEB-INF/data" + archive.getCatalogHome() + "/originals/" + assetsource;
      if (asset.isFolder() && asset.getPrimaryFile() != null) {
        pathToOriginal = pathToOriginal + "/" + asset.getPrimaryFile();
      }
      Page page = getPageManager().getPage(pathToOriginal);
      if (!page.exists()) {
        removed.add(asset.getSourcePath());
        archive.removeGeneratedImages(asset);
        archive.getAssetSearcher().delete(asset, inUser);
      }
    }
    return removed;
  }
 /**
  * @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);
   }
 }
  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);
    }
  }
 public void deleteXmlFile(XmlFile inSettings) throws OpenEditException {
   Page page = getPageManager().getPage(inSettings.getPath(), true);
   page.getContentItem().setMakeVersion(false);
   getPageManager().removePage(page);
 }