mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
1) Do not import copied from references
2) ACP zip file now contains content files with appropriate extension for easy viewing of content git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2018 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -37,6 +37,7 @@ import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
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.StoreRef;
|
||||
@@ -69,6 +70,11 @@ public class ExporterActionExecuter extends ActionExecuterAbstractBase
|
||||
*/
|
||||
private ExporterService exporterService;
|
||||
|
||||
/**
|
||||
* The Mime type service
|
||||
*/
|
||||
private MimetypeService mimetypeService;
|
||||
|
||||
/**
|
||||
* The node service
|
||||
*/
|
||||
@@ -89,6 +95,16 @@ public class ExporterActionExecuter extends ActionExecuterAbstractBase
|
||||
this.exporterService = exporterService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the MimetypeService to use
|
||||
*
|
||||
* @param mimetypeService
|
||||
*/
|
||||
public void setMimetypeService(MimetypeService mimetypeService)
|
||||
{
|
||||
this.mimetypeService = mimetypeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the NodeService to use
|
||||
*
|
||||
@@ -124,7 +140,7 @@ public class ExporterActionExecuter extends ActionExecuterAbstractBase
|
||||
// create a temporary file to hold the zip
|
||||
zipFile = TempFileProvider.createTempFile(TEMP_FILE_PREFIX, ACPExportPackageHandler.ACP_EXTENSION);
|
||||
ACPExportPackageHandler zipHandler = new ACPExportPackageHandler(new FileOutputStream(zipFile),
|
||||
dataFile, contentDir);
|
||||
dataFile, contentDir, mimetypeService);
|
||||
|
||||
ExporterCrawlerParameters params = new ExporterCrawlerParameters();
|
||||
boolean includeChildren = true;
|
||||
|
@@ -26,7 +26,9 @@ import java.io.OutputStream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.service.cmr.repository.ContentData;
|
||||
import org.alfresco.service.cmr.repository.MimetypeService;
|
||||
import org.alfresco.service.cmr.view.ExportPackageHandler;
|
||||
import org.alfresco.service.cmr.view.ExporterException;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
@@ -43,6 +45,7 @@ public class ACPExportPackageHandler
|
||||
/** ACP File Extension */
|
||||
public final static String ACP_EXTENSION = "acp";
|
||||
|
||||
protected MimetypeService mimetypeService;
|
||||
protected OutputStream outputStream;
|
||||
protected File dataFile;
|
||||
protected File contentDir;
|
||||
@@ -60,7 +63,7 @@ public class ACPExportPackageHandler
|
||||
* @param dataFile
|
||||
* @param contentDir
|
||||
*/
|
||||
public ACPExportPackageHandler(File destDir, File zipFile, File dataFile, File contentDir, boolean overwrite)
|
||||
public ACPExportPackageHandler(File destDir, File zipFile, File dataFile, File contentDir, boolean overwrite, MimetypeService mimetypeService)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -86,6 +89,7 @@ public class ACPExportPackageHandler
|
||||
this.outputStream = new FileOutputStream(absZipFile);
|
||||
this.dataFile = dataFile;
|
||||
this.contentDir = contentDir;
|
||||
this.mimetypeService = mimetypeService;
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
@@ -100,11 +104,12 @@ public class ACPExportPackageHandler
|
||||
* @param dataFile
|
||||
* @param contentDir
|
||||
*/
|
||||
public ACPExportPackageHandler(OutputStream outputStream, File dataFile, File contentDir)
|
||||
public ACPExportPackageHandler(OutputStream outputStream, File dataFile, File contentDir, MimetypeService mimetypeService)
|
||||
{
|
||||
this.outputStream = outputStream;
|
||||
this.dataFile = dataFile;
|
||||
this.contentDir = contentDir;
|
||||
this.mimetypeService = mimetypeService;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -143,7 +148,23 @@ public class ACPExportPackageHandler
|
||||
{
|
||||
contentDirPath = contentDirPath.substring(0, contentDirPath.indexOf("."));
|
||||
}
|
||||
File file = new File(contentDirPath, "content" + iFileCnt++ + ".bin");
|
||||
String extension = "bin";
|
||||
if (mimetypeService != null)
|
||||
{
|
||||
String mimetype = contentData.getMimetype();
|
||||
if (mimetype != null && mimetype.length() > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
extension = mimetypeService.getExtension(mimetype);
|
||||
}
|
||||
catch(AlfrescoRuntimeException e)
|
||||
{
|
||||
// use default extension
|
||||
}
|
||||
}
|
||||
}
|
||||
File file = new File(contentDirPath, "content" + iFileCnt++ + "." + extension);
|
||||
|
||||
try
|
||||
{
|
||||
|
@@ -23,7 +23,9 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.service.cmr.repository.ContentData;
|
||||
import org.alfresco.service.cmr.repository.MimetypeService;
|
||||
import org.alfresco.service.cmr.view.ExportPackageHandler;
|
||||
import org.alfresco.service.cmr.view.ExporterException;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
@@ -37,6 +39,7 @@ import org.alfresco.util.TempFileProvider;
|
||||
public class FileExportPackageHandler
|
||||
implements ExportPackageHandler
|
||||
{
|
||||
protected MimetypeService mimetypeService = null;
|
||||
protected File contentDir;
|
||||
protected File absContentDir;
|
||||
protected File absDataFile;
|
||||
@@ -50,13 +53,15 @@ public class FileExportPackageHandler
|
||||
* @param dataFile filename of data file (relative to destDir)
|
||||
* @param packageDir directory for content (relative to destDir)
|
||||
* @param overwrite force overwrite of existing package directory
|
||||
* @param mimetypeService (optional) mimetype service
|
||||
*/
|
||||
public FileExportPackageHandler(File destDir, File dataFile, File contentDir, boolean overwrite)
|
||||
public FileExportPackageHandler(File destDir, File dataFile, File contentDir, boolean overwrite, MimetypeService mimetypeService)
|
||||
{
|
||||
this.contentDir = contentDir;
|
||||
this.absContentDir = new File(destDir, contentDir.getPath());
|
||||
this.absDataFile = new File(destDir, dataFile.getPath());
|
||||
this.overwrite = overwrite;
|
||||
this.mimetypeService = mimetypeService;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -119,7 +124,23 @@ public class FileExportPackageHandler
|
||||
}
|
||||
|
||||
// Create file in package directory to hold exported content
|
||||
File outputFile = TempFileProvider.createTempFile("export", ".bin", absContentDir);
|
||||
String extension = "bin";
|
||||
if (mimetypeService != null)
|
||||
{
|
||||
String mimetype = contentData.getMimetype();
|
||||
if (mimetype != null && mimetype.length() > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
extension = mimetypeService.getExtension(mimetype);
|
||||
}
|
||||
catch(AlfrescoRuntimeException e)
|
||||
{
|
||||
// use default extension
|
||||
}
|
||||
}
|
||||
}
|
||||
File outputFile = TempFileProvider.createTempFile("export", "." + extension, absContentDir);
|
||||
|
||||
try
|
||||
{
|
||||
|
@@ -137,16 +137,15 @@ public class NodeContext extends ElementContext
|
||||
*/
|
||||
public void addPropertyCollection(QName property)
|
||||
{
|
||||
// Do not import properties of sys:referenceable or cm:versionable
|
||||
// Do not import properties of sys:referenceable or cm:versionable or cm:copiedfrom
|
||||
// TODO: Make this configurable...
|
||||
PropertyDefinition propDef = getDictionaryService().getProperty(property);
|
||||
ClassDefinition classDef = (propDef == null) ? null : propDef.getContainerClass();
|
||||
if (classDef != null)
|
||||
{
|
||||
if (classDef.getName().equals(ContentModel.ASPECT_REFERENCEABLE) ||
|
||||
classDef.getName().equals(ContentModel.ASPECT_VERSIONABLE))
|
||||
if (!isImportableClass(classDef.getName()))
|
||||
{
|
||||
return;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,10 +169,9 @@ public class NodeContext extends ElementContext
|
||||
ClassDefinition classDef = (propDef == null) ? null : propDef.getContainerClass();
|
||||
if (classDef != null)
|
||||
{
|
||||
if (classDef.getName().equals(ContentModel.ASPECT_REFERENCEABLE) ||
|
||||
classDef.getName().equals(ContentModel.ASPECT_VERSIONABLE))
|
||||
if (!isImportableClass(classDef.getName()))
|
||||
{
|
||||
return;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,7 +232,10 @@ public class NodeContext extends ElementContext
|
||||
*/
|
||||
public void addAspect(AspectDefinition aspect)
|
||||
{
|
||||
nodeAspects.put(aspect.getName(), aspect);
|
||||
if (isImportableClass(aspect.getName()))
|
||||
{
|
||||
nodeAspects.put(aspect.getName(), aspect);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -328,6 +329,19 @@ public class NodeContext extends ElementContext
|
||||
return def;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the provided class name is to be imported
|
||||
*
|
||||
* @param className class to check (type or aspect)
|
||||
* @return true => import, false => ignore on import
|
||||
*/
|
||||
private boolean isImportableClass(QName className)
|
||||
{
|
||||
return !(className.equals(ContentModel.ASPECT_REFERENCEABLE) ||
|
||||
className.equals(ContentModel.ASPECT_COPIEDFROM) ||
|
||||
className.equals(ContentModel.ASPECT_VERSIONABLE));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
|
@@ -23,6 +23,7 @@ import java.util.Collection;
|
||||
import org.alfresco.repo.exporter.FileExportPackageHandler;
|
||||
import org.alfresco.repo.exporter.ACPExportPackageHandler;
|
||||
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.StoreRef;
|
||||
import org.alfresco.service.cmr.view.ExportPackageHandler;
|
||||
@@ -212,16 +213,17 @@ public final class Export extends Tool
|
||||
void execute() throws ToolException
|
||||
{
|
||||
ExporterService exporter = getServiceRegistry().getExporterService();
|
||||
MimetypeService mimetypeService = getServiceRegistry().getMimetypeService();
|
||||
|
||||
// create export package handler
|
||||
ExportPackageHandler exportHandler = null;
|
||||
if (context.zipped)
|
||||
{
|
||||
exportHandler = new ZipHandler(context.getDestDir(), context.getZipFile(), context.getPackageFile(), context.getPackageDir(), context.overwrite);
|
||||
exportHandler = new ZipHandler(context.getDestDir(), context.getZipFile(), context.getPackageFile(), context.getPackageDir(), context.overwrite, mimetypeService);
|
||||
}
|
||||
else
|
||||
{
|
||||
exportHandler = new FileHandler(context.getDestDir(), context.getPackageFile(), context.getPackageDir(), context.overwrite);
|
||||
exportHandler = new FileHandler(context.getDestDir(), context.getPackageFile(), context.getPackageDir(), context.overwrite, mimetypeService);
|
||||
}
|
||||
|
||||
// export Repository content to export package
|
||||
@@ -255,9 +257,9 @@ public final class Export extends Tool
|
||||
* @param contentDir
|
||||
* @param overwrite
|
||||
*/
|
||||
public FileHandler(File destDir, File dataFile, File contentDir, boolean overwrite)
|
||||
public FileHandler(File destDir, File dataFile, File contentDir, boolean overwrite, MimetypeService mimetypeService)
|
||||
{
|
||||
super(destDir, dataFile, contentDir, overwrite);
|
||||
super(destDir, dataFile, contentDir, overwrite, mimetypeService);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -286,9 +288,9 @@ public final class Export extends Tool
|
||||
* @param dataFile
|
||||
* @param contentDir
|
||||
*/
|
||||
public ZipHandler(File destDir, File zipFile, File dataFile, File contentDir, boolean overwrite)
|
||||
public ZipHandler(File destDir, File zipFile, File dataFile, File contentDir, boolean overwrite, MimetypeService mimetypeService)
|
||||
{
|
||||
super(destDir, zipFile, dataFile, contentDir, overwrite);
|
||||
super(destDir, zipFile, dataFile, contentDir, overwrite, mimetypeService);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user