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 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; }