DocUtil.java 2.32 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.aemfd.docmanager.Document
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.aemfd.watchfolder.util;

import com.adobe.aemfd.docmanager.Document;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/*
 * This class specifies class file version 49.0 but uses Java 6 signatures.  Assumed Java 6.
 */
public class DocUtil {
    private static final Logger logger = LoggerFactory.getLogger(DocUtil.class);

    public static Map<String, Document> pruneForDisposal(Map<String, Document> docs, Map<String, Document> liveDocs) {
        if (docs == null) {
            return null;
        }
        if (liveDocs == null) {
            return docs;
        }
        HashMap<String, Document> result = new HashMap<String, Document>(docs.size());
        for (Map.Entry<String, Document> de : docs.entrySet()) {
            String dName = de.getKey();
            Document d = de.getValue();
            if (liveDocs.containsValue((Object)d)) {
                logger.warn("Skipping document " + dName + " for disposal since it is still live!");
                continue;
            }
            result.put(dName, d);
        }
        return result;
    }

    public static void disposeAll(Map<String, Document> docs) {
        if (docs != null) {
            ArrayList<Document> disposed = new ArrayList<Document>();
            for (Map.Entry<String, Document> de : docs.entrySet()) {
                Document d = de.getValue();
                if (d == null || !(d instanceof Document)) continue;
                try {
                    Document doc = d;
                    if (!disposed.contains((Object)doc)) {
                        doc.dispose();
                        disposed.add(doc);
                        logger.info("Disposed document " + de.getKey());
                        continue;
                    }
                    logger.info("Document " + de.getKey() + " already disposed, ignoring...");
                }
                catch (Exception e) {
                    logger.warn("Error disposing document object " + de.getKey(), (Throwable)e);
                }
            }
            disposed.clear();
        }
    }
}