diff --git a/source/java/org/alfresco/repo/avm/AVMRepository.java b/source/java/org/alfresco/repo/avm/AVMRepository.java index 37e17d1830..0cf12cd32f 100644 --- a/source/java/org/alfresco/repo/avm/AVMRepository.java +++ b/source/java/org/alfresco/repo/avm/AVMRepository.java @@ -40,6 +40,8 @@ import org.alfresco.service.cmr.avm.AVMWrongTypeException; import org.alfresco.service.cmr.avm.LayeringDescriptor; import org.alfresco.service.cmr.avm.VersionDescriptor; import org.alfresco.service.cmr.repository.ContentData; +import org.alfresco.service.cmr.repository.ContentReader; +import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.namespace.QName; import org.alfresco.util.Pair; import org.apache.log4j.Logger; @@ -398,6 +400,55 @@ public class AVMRepository } } + /** + * Get a content reader from a file node. + * @param version The version of the file. + * @param path The path to the file. + * @return A ContentReader. + */ + public ContentReader getContentReader(int version, String path) + { + fLookupCount.set(1); + try + { + String [] pathParts = SplitPath(path); + AVMStore store = getAVMStoreByName(pathParts[0]); + if (store == null) + { + throw new AVMNotFoundException("Store not found: " + pathParts[0]); + } + return store.getContentReader(version, pathParts[1]); + } + finally + { + fLookupCount.set(null); + } + } + + /** + * Get a ContentWriter to a file node. + * @param path The path to the file. + * @return A ContentWriter. + */ + public ContentWriter createContentWriter(String path) + { + fLookupCount.set(1); + try + { + String [] pathParts = SplitPath(path); + AVMStore store = getAVMStoreByName(pathParts[0]); + if (store == null) + { + throw new AVMNotFoundException("Store not found: " + pathParts[0]); + } + return store.createContentWriter(pathParts[1]); + } + finally + { + fLookupCount.set(null); + } + } + /** * Rename a node. * @param srcPath Source containing directory. diff --git a/source/java/org/alfresco/repo/avm/AVMServiceImpl.java b/source/java/org/alfresco/repo/avm/AVMServiceImpl.java index 788a815564..91c89bc74f 100644 --- a/source/java/org/alfresco/repo/avm/AVMServiceImpl.java +++ b/source/java/org/alfresco/repo/avm/AVMServiceImpl.java @@ -41,6 +41,8 @@ import org.alfresco.service.cmr.avm.AVMWrongTypeException; import org.alfresco.service.cmr.avm.LayeringDescriptor; import org.alfresco.service.cmr.avm.VersionDescriptor; import org.alfresco.service.cmr.repository.ContentData; +import org.alfresco.service.cmr.repository.ContentReader; +import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.namespace.QName; import org.alfresco.util.Pair; import org.alfresco.util.TempFileProvider; @@ -105,6 +107,35 @@ public class AVMServiceImpl implements AVMService return fAVMRepository.getOutputStream(path); } + /** + * Get a content reader from a file node. + * @param version The version of the file. + * @param path The path to the file. + * @return A ContentReader. + */ + public ContentReader getContentReader(int version, String path) + { + if (path == null) + { + throw new AVMBadArgumentException("Null path."); + } + return fAVMRepository.getContentReader(version, path); + } + + /** + * Get a ContentWriter to a file node. + * @param path The path to the file. + * @return A ContentWriter. + */ + public ContentWriter createContentWriter(String path) + { + if (path == null) + { + throw new AVMBadArgumentException("Null path."); + } + return fAVMRepository.createContentWriter(path); + } + /** * Get a directory listing. * @param version The version id to lookup. @@ -137,6 +168,47 @@ public class AVMServiceImpl implements AVMService return fAVMRepository.getListing(version, path, includeDeleted); } + /** + * Get a directory listing as an Array of AVMNodeDescriptors. + * @param version The version to look under. + * @param path The path to the directory to be listed. + * @param includeDeleted Whether to include ghosts. + * @return An array of AVMNodeDescriptors. + */ + public AVMNodeDescriptor [] getDirectoryListingArray(int version, String path, + boolean includeDeleted) + { + Map listing = + getDirectoryListing(version, path, includeDeleted); + AVMNodeDescriptor [] result = new AVMNodeDescriptor[listing.size()]; + int off = 0; + for (AVMNodeDescriptor desc : listing.values()) + { + result[off++] = desc; + } + return result; + } + + /** + * Get a directory listing as an Array of node descriptors. + * @param dir The descriptor pointing at the directory to list. + * @param includeDeleted Whether to show ghosts. + * @return An array of AVMNodeDescriptors. + */ + public AVMNodeDescriptor [] getDirectoryListingArray(AVMNodeDescriptor dir, + boolean includeDeleted) + { + Map listing = + getDirectoryListing(dir, includeDeleted); + AVMNodeDescriptor [] result = new AVMNodeDescriptor[listing.size()]; + int off = 0; + for (AVMNodeDescriptor desc : listing.values()) + { + result[off++] = desc; + } + return result; + } + /** * Get a listing of all the directly contained children of a directory. * @param dir The directory descriptor. diff --git a/source/java/org/alfresco/repo/avm/AVMServiceTest.java b/source/java/org/alfresco/repo/avm/AVMServiceTest.java index d2d94fd11c..245d526248 100644 --- a/source/java/org/alfresco/repo/avm/AVMServiceTest.java +++ b/source/java/org/alfresco/repo/avm/AVMServiceTest.java @@ -2038,6 +2038,9 @@ public class AVMServiceTest extends AVMServiceTestBase list = new ArrayList(listing.keySet()); assertEquals("bar.txt", list.get(0)); assertEquals("foo.txt", list.get(1)); + AVMNodeDescriptor [] arrayListing = fService.getDirectoryListingArray(-1, "main:/d/b", false); + assertEquals("bar.txt", arrayListing[0].getName()); + assertEquals("foo.txt", arrayListing[1].getName()); fService.rename("main:/", "c", "main:/", "e"); fService.createSnapshot("main", null, null); System.out.println(recursiveList("main", -1, true)); diff --git a/source/java/org/alfresco/repo/avm/AVMStore.java b/source/java/org/alfresco/repo/avm/AVMStore.java index 55d3b50949..c82686de4a 100644 --- a/source/java/org/alfresco/repo/avm/AVMStore.java +++ b/source/java/org/alfresco/repo/avm/AVMStore.java @@ -30,6 +30,8 @@ import org.alfresco.service.cmr.avm.AVMNodeDescriptor; import org.alfresco.service.cmr.avm.AVMStoreDescriptor; import org.alfresco.service.cmr.avm.VersionDescriptor; import org.alfresco.service.cmr.repository.ContentData; +import org.alfresco.service.cmr.repository.ContentReader; +import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.namespace.QName; /** @@ -114,6 +116,14 @@ public interface AVMStore */ public InputStream getInputStream(int version, String path); + /** + * Get a ContentReader from a file. + * @param version The version to look under. + * @param path The path to the file. + * @return A ContentReader + */ + public ContentReader getContentReader(int version, String path); + /** * Get a listing of the designated directory. * @param version The version to look under. @@ -149,6 +159,13 @@ public interface AVMStore */ public OutputStream getOutputStream(String path); + /** + * Get a ContentWriter to a file. + * @param path The path to the file. + * @return A ContentWriter. + */ + public ContentWriter createContentWriter(String path); + /** * Remove a node and all of its contents. * @param path The path to the node's parent directory. diff --git a/source/java/org/alfresco/repo/avm/AVMStoreImpl.java b/source/java/org/alfresco/repo/avm/AVMStoreImpl.java index e1e23c0664..4d8d27ed0f 100644 --- a/source/java/org/alfresco/repo/avm/AVMStoreImpl.java +++ b/source/java/org/alfresco/repo/avm/AVMStoreImpl.java @@ -277,7 +277,7 @@ public class AVMStoreImpl implements AVMStore, Serializable RawServices.Instance().getMimetypeService().guessMimetype(name), -1, "UTF-8")); - ContentWriter writer = getWriter(AVMNodeConverter.ExtendAVMPath(path, name)); + ContentWriter writer = createContentWriter(AVMNodeConverter.ExtendAVMPath(path, name)); return writer.getContentOutputStream(); } @@ -307,7 +307,7 @@ public class AVMStoreImpl implements AVMStore, Serializable RawServices.Instance().getMimetypeService().guessMimetype(name), -1, "UTF-8")); - ContentWriter writer = getWriter(AVMNodeConverter.ExtendAVMPath(path, name)); + ContentWriter writer = createContentWriter(AVMNodeConverter.ExtendAVMPath(path, name)); writer.putContent(data); } @@ -345,7 +345,7 @@ public class AVMStoreImpl implements AVMStore, Serializable */ public InputStream getInputStream(int version, String path) { - ContentReader reader = getReader(version, path); + ContentReader reader = getContentReader(version, path); if (reader == null) { // TODO This is wrong, wrong, wrong. Do something about it @@ -361,7 +361,7 @@ public class AVMStoreImpl implements AVMStore, Serializable * @param path The path to the file. * @return A ContentReader. */ - private ContentReader getReader(int version, String path) + public ContentReader getContentReader(int version, String path) { NodeRef nodeRef = AVMNodeConverter.ToNodeRef(version, fName + ":" + path); return RawServices.Instance().getContentService().getReader(nodeRef, ContentModel.PROP_CONTENT); @@ -372,14 +372,14 @@ public class AVMStoreImpl implements AVMStore, Serializable * @param path The path to the file. * @return A ContentWriter. */ - private ContentWriter getWriter(String path) + public ContentWriter createContentWriter(String path) { NodeRef nodeRef = AVMNodeConverter.ToNodeRef(-1, fName + ":" + path); ContentWriter writer = RawServices.Instance().getContentService().getWriter(nodeRef, ContentModel.PROP_CONTENT, true); return writer; } - + /** * Get a listing from a directory. * @param version The version to look under. @@ -466,7 +466,7 @@ public class AVMStoreImpl implements AVMStore, Serializable */ public OutputStream getOutputStream(String path) { - ContentWriter writer = getWriter(path); + ContentWriter writer = createContentWriter(path); return writer.getContentOutputStream(); } diff --git a/source/java/org/alfresco/service/cmr/avm/AVMService.java b/source/java/org/alfresco/service/cmr/avm/AVMService.java index 619898a474..46d076e2c6 100644 --- a/source/java/org/alfresco/service/cmr/avm/AVMService.java +++ b/source/java/org/alfresco/service/cmr/avm/AVMService.java @@ -26,6 +26,8 @@ import java.util.SortedMap; import org.alfresco.repo.domain.PropertyValue; import org.alfresco.service.cmr.repository.ContentData; +import org.alfresco.service.cmr.repository.ContentReader; +import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.namespace.QName; import org.alfresco.util.Pair; @@ -59,6 +61,21 @@ public interface AVMService */ public OutputStream getFileOutputStream(String path); + /** + * Get a content reader from a file node. + * @param version The version of the file. + * @param path The path to the file. + * @return A ContentReader. + */ + public ContentReader getContentReader(int version, String path); + + /** + * Get a ContentWriter to a file node. + * @param path The path to the file. + * @return A ContentWriter. + */ + public ContentWriter createContentWriter(String path); + /** * Get a listing of a Folder by name. * @param version The version id to look in. @@ -116,6 +133,16 @@ public interface AVMService public SortedMap getDirectoryListingDirect(int version, String path, boolean includeDeleted); + /** + * Get a directory listing as an Array of AVMNodeDescriptors. + * @param version The version to look under. + * @param path The path to the directory to be listed. + * @param includeDeleted Whether to include ghosts. + * @return An array of AVMNodeDescriptors. + */ + public AVMNodeDescriptor [] getDirectoryListingArray(int version, String path, + boolean includeDeleted); + /** * Get a listing of all the directly contained children of a directory. * @param dir The directory descriptor. @@ -145,7 +172,16 @@ public interface AVMService * @throws AVMWrongTypeException If the descriptor does not point at a directory. */ public SortedMap getDirectoryListing(AVMNodeDescriptor dir, - boolean includeDeleted); + boolean includeDeleted); + + /** + * Get a directory listing as an Array of node descriptors. + * @param dir The descriptor pointing at the directory to list. + * @param includeDeleted Whether to show ghosts. + * @return An array of AVMNodeDescriptors. + */ + public AVMNodeDescriptor [] getDirectoryListingArray(AVMNodeDescriptor dir, + boolean includeDeleted); /** * Get the names of nodes that have been deleted in a directory.