From c3072e1efc7da3e3d26c1efb50ea2a7194b1f2a1 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Mon, 28 Nov 2011 17:00:11 +0000 Subject: [PATCH] Convert POIFS EntryUtils.copyNodes(POFS,POIFS) to use FilteringDirectoryNode, so can exclude from copying nodes not just directly under the root git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1207445 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 1 + .../poi/poifs/filesystem/EntryUtils.java | 65 ++++++++++++++++--- 2 files changed, 58 insertions(+), 8 deletions(-) diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 367548933..ffee4df0d 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + POIFS EntryUtils.copyNodes(POFS,POIFS) now uses FilteringDirectoryNode, so can exclude from copying nodes not just directly under the root POIFS Helper FilteringDirectoryNode, which wraps a DirectoryEntry and allows certain parts to be ignored 52209 - fixed inserting multiple pictures in XSLF 51803 - fixed HSLF TextExtractor to extract content from master slide diff --git a/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java b/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java index b268fe0a3..2c9308bfe 100644 --- a/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java +++ b/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java @@ -59,15 +59,48 @@ public class EntryUtils } /** - * Copies nodes from one POIFS to the other minus the excepts + * Copies all the nodes from one POIFS Directory to another * * @param source - * is the source POIFS to copy from + * is the source Directory to copy from * @param target - * is the target POIFS to copy to + * is the target Directory to copy to * @param excepts * is a list of Strings specifying what nodes NOT to copy */ + public static void copyNodes(DirectoryEntry sourceRoot, + DirectoryEntry targetRoot) throws IOException + { + for (Entry entry : sourceRoot) { + copyNodeRecursively( entry, targetRoot ); + } + } + + /** + * Copies nodes from one Directory to the other minus the excepts + * + * @param source The filtering source Directory to copy from + * @param target The filtering target Directory to copy to + */ + public static void copyNodes( FilteringDirectoryNode filteredSource, + FilteringDirectoryNode filteredTarget ) throws IOException + { + // Nothing special here, just overloaded types to make the + // recommended new way to handle this clearer + copyNodes( (DirectoryEntry)filteredSource, (DirectoryEntry)filteredTarget ); + } + + /** + * Copies nodes from one Directory to the other minus the excepts + * + * @param source + * is the source Directory to copy from + * @param target + * is the target Directory to copy to + * @param excepts + * is a list of Strings specifying what nodes NOT to copy + * @deprecated use {@link FilteringDirectoryNode} instead + */ public static void copyNodes( DirectoryEntry sourceRoot, DirectoryEntry targetRoot, List excepts ) throws IOException @@ -84,20 +117,36 @@ public class EntryUtils } /** - * Copies nodes from one POIFS to the other minus the excepts + * Copies all nodes from one POIFS to the other * * @param source * is the source POIFS to copy from * @param target * is the target POIFS to copy to - * @param excepts - * is a list of Strings specifying what nodes NOT to copy + */ + public static void copyNodes( POIFSFileSystem source, + POIFSFileSystem target ) throws IOException + { + copyNodes( source.getRoot(), target.getRoot() ); + } + + /** + * Copies nodes from one POIFS to the other, minus the excepts. + * This delegates the filtering work to {@link FilteringDirectoryNode}, + * so excepts can be of the form "NodeToExclude" or + * "FilteringDirectory/ExcludedChildNode" + * + * @param source is the source POIFS to copy from + * @param target is the target POIFS to copy to + * @param excepts is a list of Entry Names to be excluded from the copy */ public static void copyNodes( POIFSFileSystem source, POIFSFileSystem target, List excepts ) throws IOException { - // System.err.println("CopyNodes called"); - copyNodes( source.getRoot(), target.getRoot(), excepts ); + copyNodes( + new FilteringDirectoryNode(source.getRoot(), excepts), + new FilteringDirectoryNode(target.getRoot(), excepts) + ); } /**