From 184be5c03badc06f6d50e5942370d54c6f498307 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Fri, 25 Apr 2014 21:10:52 +0000 Subject: [PATCH] Add a getEntryNames() method to POIFS/NPOIFS directory entries, to make listing easier git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1590148 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/poifs/filesystem/DirectoryEntry.java | 12 ++++++++++++ .../poi/poifs/filesystem/DirectoryNode.java | 15 +++++++++++++++ .../poifs/filesystem/FilteringDirectoryNode.java | 10 ++++++++++ 3 files changed, 37 insertions(+) diff --git a/src/java/org/apache/poi/poifs/filesystem/DirectoryEntry.java b/src/java/org/apache/poi/poifs/filesystem/DirectoryEntry.java index bb50a75571..7148fda3cf 100644 --- a/src/java/org/apache/poi/poifs/filesystem/DirectoryEntry.java +++ b/src/java/org/apache/poi/poifs/filesystem/DirectoryEntry.java @@ -23,6 +23,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.Iterator; +import java.util.Set; import org.apache.poi.hpsf.ClassID; @@ -49,6 +50,17 @@ public interface DirectoryEntry */ public Iterator getEntries(); + + /** + * get the names of all the Entries contained directly in this + * instance (in other words, names of children only; no grandchildren + * etc). + * + * @return the names of all the entries that may be retrieved with + * getEntry(String), which may be empty (if this + * DirectoryEntry is empty) + */ + public Set getEntryNames(); /** * is this DirectoryEntry empty? diff --git a/src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java b/src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java index cb705ff073..84eca0507c 100644 --- a/src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java +++ b/src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java @@ -27,6 +27,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import org.apache.poi.hpsf.ClassID; import org.apache.poi.poifs.dev.POIFSViewable; @@ -317,6 +318,20 @@ public class DirectoryNode { return _entries.iterator(); } + + /** + * get the names of all the Entries contained directly in this + * instance (in other words, names of children only; no grandchildren + * etc). + * + * @return the names of all the entries that may be retrieved with + * getEntry(String), which may be empty (if this + * DirectoryEntry is empty) + */ + public Set getEntryNames() + { + return _byname.keySet(); + } /** * is this DirectoryEntry empty? diff --git a/src/java/org/apache/poi/poifs/filesystem/FilteringDirectoryNode.java b/src/java/org/apache/poi/poifs/filesystem/FilteringDirectoryNode.java index 861768aee7..3296ddb888 100644 --- a/src/java/org/apache/poi/poifs/filesystem/FilteringDirectoryNode.java +++ b/src/java/org/apache/poi/poifs/filesystem/FilteringDirectoryNode.java @@ -114,6 +114,16 @@ public class FilteringDirectoryNode implements DirectoryEntry } return size; } + + public Set getEntryNames() { + Set names = new HashSet(); + for (String name : directory.getEntryNames()) { + if (!excludes.contains(name)) { + names.add(name); + } + } + return names; + } public boolean isEmpty() { return (getEntryCount() == 0); -- 2.39.5