Added getContentReader and createContentWriter to AVMService. Also added convenience

getDirectoryListingArray() calls which return listings as arrays instead of Maps.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@4377 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-11-16 19:53:42 +00:00
parent b5f3167443
commit 4287b291d4
6 changed files with 187 additions and 8 deletions

View File

@@ -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.

View File

@@ -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<String, AVMNodeDescriptor> 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<String, AVMNodeDescriptor> 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.

View File

@@ -2038,6 +2038,9 @@ public class AVMServiceTest extends AVMServiceTestBase
list = new ArrayList<String>(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));

View File

@@ -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.

View File

@@ -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();
}

View File

@@ -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<String, AVMNodeDescriptor>
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<String, AVMNodeDescriptor> 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.