mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
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:
@@ -40,6 +40,8 @@ import org.alfresco.service.cmr.avm.AVMWrongTypeException;
|
|||||||
import org.alfresco.service.cmr.avm.LayeringDescriptor;
|
import org.alfresco.service.cmr.avm.LayeringDescriptor;
|
||||||
import org.alfresco.service.cmr.avm.VersionDescriptor;
|
import org.alfresco.service.cmr.avm.VersionDescriptor;
|
||||||
import org.alfresco.service.cmr.repository.ContentData;
|
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.service.namespace.QName;
|
||||||
import org.alfresco.util.Pair;
|
import org.alfresco.util.Pair;
|
||||||
import org.apache.log4j.Logger;
|
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.
|
* Rename a node.
|
||||||
* @param srcPath Source containing directory.
|
* @param srcPath Source containing directory.
|
||||||
|
@@ -41,6 +41,8 @@ import org.alfresco.service.cmr.avm.AVMWrongTypeException;
|
|||||||
import org.alfresco.service.cmr.avm.LayeringDescriptor;
|
import org.alfresco.service.cmr.avm.LayeringDescriptor;
|
||||||
import org.alfresco.service.cmr.avm.VersionDescriptor;
|
import org.alfresco.service.cmr.avm.VersionDescriptor;
|
||||||
import org.alfresco.service.cmr.repository.ContentData;
|
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.service.namespace.QName;
|
||||||
import org.alfresco.util.Pair;
|
import org.alfresco.util.Pair;
|
||||||
import org.alfresco.util.TempFileProvider;
|
import org.alfresco.util.TempFileProvider;
|
||||||
@@ -105,6 +107,35 @@ public class AVMServiceImpl implements AVMService
|
|||||||
return fAVMRepository.getOutputStream(path);
|
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.
|
* Get a directory listing.
|
||||||
* @param version The version id to lookup.
|
* @param version The version id to lookup.
|
||||||
@@ -137,6 +168,47 @@ public class AVMServiceImpl implements AVMService
|
|||||||
return fAVMRepository.getListing(version, path, includeDeleted);
|
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.
|
* Get a listing of all the directly contained children of a directory.
|
||||||
* @param dir The directory descriptor.
|
* @param dir The directory descriptor.
|
||||||
|
@@ -2038,6 +2038,9 @@ public class AVMServiceTest extends AVMServiceTestBase
|
|||||||
list = new ArrayList<String>(listing.keySet());
|
list = new ArrayList<String>(listing.keySet());
|
||||||
assertEquals("bar.txt", list.get(0));
|
assertEquals("bar.txt", list.get(0));
|
||||||
assertEquals("foo.txt", list.get(1));
|
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.rename("main:/", "c", "main:/", "e");
|
||||||
fService.createSnapshot("main", null, null);
|
fService.createSnapshot("main", null, null);
|
||||||
System.out.println(recursiveList("main", -1, true));
|
System.out.println(recursiveList("main", -1, true));
|
||||||
|
@@ -30,6 +30,8 @@ import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
|
|||||||
import org.alfresco.service.cmr.avm.AVMStoreDescriptor;
|
import org.alfresco.service.cmr.avm.AVMStoreDescriptor;
|
||||||
import org.alfresco.service.cmr.avm.VersionDescriptor;
|
import org.alfresco.service.cmr.avm.VersionDescriptor;
|
||||||
import org.alfresco.service.cmr.repository.ContentData;
|
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.service.namespace.QName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -114,6 +116,14 @@ public interface AVMStore
|
|||||||
*/
|
*/
|
||||||
public InputStream getInputStream(int version, String path);
|
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.
|
* Get a listing of the designated directory.
|
||||||
* @param version The version to look under.
|
* @param version The version to look under.
|
||||||
@@ -149,6 +159,13 @@ public interface AVMStore
|
|||||||
*/
|
*/
|
||||||
public OutputStream getOutputStream(String path);
|
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.
|
* Remove a node and all of its contents.
|
||||||
* @param path The path to the node's parent directory.
|
* @param path The path to the node's parent directory.
|
||||||
|
@@ -277,7 +277,7 @@ public class AVMStoreImpl implements AVMStore, Serializable
|
|||||||
RawServices.Instance().getMimetypeService().guessMimetype(name),
|
RawServices.Instance().getMimetypeService().guessMimetype(name),
|
||||||
-1,
|
-1,
|
||||||
"UTF-8"));
|
"UTF-8"));
|
||||||
ContentWriter writer = getWriter(AVMNodeConverter.ExtendAVMPath(path, name));
|
ContentWriter writer = createContentWriter(AVMNodeConverter.ExtendAVMPath(path, name));
|
||||||
return writer.getContentOutputStream();
|
return writer.getContentOutputStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,7 +307,7 @@ public class AVMStoreImpl implements AVMStore, Serializable
|
|||||||
RawServices.Instance().getMimetypeService().guessMimetype(name),
|
RawServices.Instance().getMimetypeService().guessMimetype(name),
|
||||||
-1,
|
-1,
|
||||||
"UTF-8"));
|
"UTF-8"));
|
||||||
ContentWriter writer = getWriter(AVMNodeConverter.ExtendAVMPath(path, name));
|
ContentWriter writer = createContentWriter(AVMNodeConverter.ExtendAVMPath(path, name));
|
||||||
writer.putContent(data);
|
writer.putContent(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -345,7 +345,7 @@ public class AVMStoreImpl implements AVMStore, Serializable
|
|||||||
*/
|
*/
|
||||||
public InputStream getInputStream(int version, String path)
|
public InputStream getInputStream(int version, String path)
|
||||||
{
|
{
|
||||||
ContentReader reader = getReader(version, path);
|
ContentReader reader = getContentReader(version, path);
|
||||||
if (reader == null)
|
if (reader == null)
|
||||||
{
|
{
|
||||||
// TODO This is wrong, wrong, wrong. Do something about it
|
// 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.
|
* @param path The path to the file.
|
||||||
* @return A ContentReader.
|
* @return A ContentReader.
|
||||||
*/
|
*/
|
||||||
private ContentReader getReader(int version, String path)
|
public ContentReader getContentReader(int version, String path)
|
||||||
{
|
{
|
||||||
NodeRef nodeRef = AVMNodeConverter.ToNodeRef(version, fName + ":" + path);
|
NodeRef nodeRef = AVMNodeConverter.ToNodeRef(version, fName + ":" + path);
|
||||||
return RawServices.Instance().getContentService().getReader(nodeRef, ContentModel.PROP_CONTENT);
|
return RawServices.Instance().getContentService().getReader(nodeRef, ContentModel.PROP_CONTENT);
|
||||||
@@ -372,7 +372,7 @@ public class AVMStoreImpl implements AVMStore, Serializable
|
|||||||
* @param path The path to the file.
|
* @param path The path to the file.
|
||||||
* @return A ContentWriter.
|
* @return A ContentWriter.
|
||||||
*/
|
*/
|
||||||
private ContentWriter getWriter(String path)
|
public ContentWriter createContentWriter(String path)
|
||||||
{
|
{
|
||||||
NodeRef nodeRef = AVMNodeConverter.ToNodeRef(-1, fName + ":" + path);
|
NodeRef nodeRef = AVMNodeConverter.ToNodeRef(-1, fName + ":" + path);
|
||||||
ContentWriter writer =
|
ContentWriter writer =
|
||||||
@@ -466,7 +466,7 @@ public class AVMStoreImpl implements AVMStore, Serializable
|
|||||||
*/
|
*/
|
||||||
public OutputStream getOutputStream(String path)
|
public OutputStream getOutputStream(String path)
|
||||||
{
|
{
|
||||||
ContentWriter writer = getWriter(path);
|
ContentWriter writer = createContentWriter(path);
|
||||||
return writer.getContentOutputStream();
|
return writer.getContentOutputStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -26,6 +26,8 @@ import java.util.SortedMap;
|
|||||||
|
|
||||||
import org.alfresco.repo.domain.PropertyValue;
|
import org.alfresco.repo.domain.PropertyValue;
|
||||||
import org.alfresco.service.cmr.repository.ContentData;
|
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.service.namespace.QName;
|
||||||
import org.alfresco.util.Pair;
|
import org.alfresco.util.Pair;
|
||||||
|
|
||||||
@@ -59,6 +61,21 @@ public interface AVMService
|
|||||||
*/
|
*/
|
||||||
public OutputStream getFileOutputStream(String path);
|
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.
|
* Get a listing of a Folder by name.
|
||||||
* @param version The version id to look in.
|
* @param version The version id to look in.
|
||||||
@@ -116,6 +133,16 @@ public interface AVMService
|
|||||||
public SortedMap<String, AVMNodeDescriptor>
|
public SortedMap<String, AVMNodeDescriptor>
|
||||||
getDirectoryListingDirect(int version, String path, boolean includeDeleted);
|
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.
|
* Get a listing of all the directly contained children of a directory.
|
||||||
* @param dir The directory descriptor.
|
* @param dir The directory descriptor.
|
||||||
@@ -147,6 +174,15 @@ public interface AVMService
|
|||||||
public SortedMap<String, AVMNodeDescriptor> getDirectoryListing(AVMNodeDescriptor dir,
|
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.
|
* Get the names of nodes that have been deleted in a directory.
|
||||||
* @param version The version to look under.
|
* @param version The version to look under.
|
||||||
|
Reference in New Issue
Block a user