mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Option to export content as node folder hierarchy inside ACP
- enable with following setters on ACPExportPackageHandler ACPExportPackageHandler acpHandler = new ACPExportPackageHandler(...); acpHandler.setNodeService(nodeService); acpHandler.setExportAsFolders(true); - results in ACP contents as follows: /export.xml /content /a /b.txt /b /c.pdf git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@16078 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -33,8 +33,14 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ContentData;
|
||||
import org.alfresco.service.cmr.repository.MimetypeService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.Path;
|
||||
import org.alfresco.service.cmr.repository.Path.ChildAssocElement;
|
||||
import org.alfresco.service.cmr.view.ExportPackageHandler;
|
||||
import org.alfresco.service.cmr.view.ExporterException;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
@@ -54,6 +60,7 @@ public class ACPExportPackageHandler
|
||||
public final static String ACP_EXTENSION = "acp";
|
||||
|
||||
protected MimetypeService mimetypeService;
|
||||
protected NodeService nodeService;
|
||||
protected OutputStream outputStream;
|
||||
protected File dataFile;
|
||||
protected File contentDir;
|
||||
@@ -61,7 +68,8 @@ public class ACPExportPackageHandler
|
||||
protected OutputStream tempDataFileStream;
|
||||
protected ZipOutputStream zipStream;
|
||||
protected int iFileCnt = 0;
|
||||
|
||||
protected boolean exportAsFolders;
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
@@ -120,6 +128,25 @@ public class ACPExportPackageHandler
|
||||
this.mimetypeService = mimetypeService;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param nodeService
|
||||
*/
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Export content into folder structure of nodes
|
||||
*
|
||||
* @param exportAsFolders
|
||||
*/
|
||||
public void setExportAsFolders(boolean exportAsFolders)
|
||||
{
|
||||
this.exportAsFolders = exportAsFolders;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.view.ExportPackageHandler#startExport()
|
||||
*/
|
||||
@@ -165,23 +192,33 @@ public class ACPExportPackageHandler
|
||||
{
|
||||
contentDirPath = contentDirPath.substring(0, contentDirPath.lastIndexOf("."));
|
||||
}
|
||||
String extension = "bin";
|
||||
if (mimetypeService != null)
|
||||
|
||||
File file;
|
||||
if (exportAsFolders && nodeService != null && contentData instanceof NodeContentData)
|
||||
{
|
||||
String mimetype = contentData.getMimetype();
|
||||
if (mimetype != null && mimetype.length() > 0)
|
||||
NodeContentData nodeContentData = (NodeContentData)contentData;
|
||||
file = new File(contentDirPath + toDisplayPath(nodeService.getPath(nodeContentData.getNodeRef())));
|
||||
}
|
||||
else
|
||||
{
|
||||
String extension = "bin";
|
||||
if (mimetypeService != null)
|
||||
{
|
||||
try
|
||||
String mimetype = contentData.getMimetype();
|
||||
if (mimetype != null && mimetype.length() > 0)
|
||||
{
|
||||
extension = mimetypeService.getExtension(mimetype);
|
||||
}
|
||||
catch(AlfrescoRuntimeException e)
|
||||
{
|
||||
// use default extension
|
||||
try
|
||||
{
|
||||
extension = mimetypeService.getExtension(mimetype);
|
||||
}
|
||||
catch(AlfrescoRuntimeException e)
|
||||
{
|
||||
// use default extension
|
||||
}
|
||||
}
|
||||
}
|
||||
file = new File(contentDirPath, "content" + iFileCnt++ + "." + extension);
|
||||
}
|
||||
File file = new File(contentDirPath, "content" + iFileCnt++ + "." + extension);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -267,4 +304,32 @@ public class ACPExportPackageHandler
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param path
|
||||
* @return display path
|
||||
*/
|
||||
private String toDisplayPath(Path path)
|
||||
{
|
||||
StringBuffer displayPath = new StringBuffer();
|
||||
if (path.size() == 1)
|
||||
{
|
||||
displayPath.append("/");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 1; i < path.size(); i++)
|
||||
{
|
||||
Path.Element element = path.get(i);
|
||||
if (element instanceof ChildAssocElement)
|
||||
{
|
||||
ChildAssociationRef assocRef = ((ChildAssocElement)element).getRef();
|
||||
NodeRef node = assocRef.getChildRef();
|
||||
displayPath.append("/");
|
||||
displayPath.append(nodeService.getProperty(node, ContentModel.PROP_NAME));
|
||||
}
|
||||
}
|
||||
}
|
||||
return displayPath.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -111,7 +111,14 @@ public class ExporterComponentTest extends BaseSpringTest
|
||||
parameters.setExportFrom(location);
|
||||
// parameters.setExcludeAspects(new QName[] { ContentModel.ASPECT_AUDITABLE });
|
||||
// parameters.setExcludeChildAssocs(new QName[] { ContentModel.ASSOC_CONTAINS });
|
||||
exporterService.exportView(output, parameters, testProgress);
|
||||
|
||||
File acpFile = TempFileProvider.createTempFile("alf", ACPExportPackageHandler.ACP_EXTENSION);
|
||||
File dataFile = new File("test");
|
||||
File contentDir = new File("test");
|
||||
ACPExportPackageHandler acpHandler = new ACPExportPackageHandler(new FileOutputStream(acpFile), dataFile, contentDir, null);
|
||||
acpHandler.setNodeService(nodeService);
|
||||
acpHandler.setExportAsFolders(true);
|
||||
exporterService.exportView(acpHandler, parameters, testProgress);
|
||||
output.close();
|
||||
}
|
||||
|
||||
|
@@ -224,7 +224,7 @@ import org.alfresco.util.ParameterCheck;
|
||||
public void content(NodeRef nodeRef, QName property, InputStream content, ContentData contentData, int index)
|
||||
{
|
||||
// Handle the stream by converting it to a URL and export the URL
|
||||
ContentData exportedContentData = streamHandler.exportContent(content, contentData);
|
||||
ContentData exportedContentData = streamHandler.exportContent(content, new NodeContentData(nodeRef, contentData));
|
||||
value(nodeRef, property, exportedContentData, index);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user