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:
David Caruana
2005-12-09 13:44:37 +00:00
parent 7be4e3ef83
commit f89817cf12
6 changed files with 97 additions and 20 deletions

View File

@@ -288,6 +288,9 @@
<property name="exporterService"> <property name="exporterService">
<ref bean="ExporterService"/> <ref bean="ExporterService"/>
</property> </property>
<property name="mimetypeService">
<ref bean="mimetypeMap"/>
</property>
<property name="nodeService"> <property name="nodeService">
<ref bean="nodeService"></ref> <ref bean="nodeService"></ref>
</property> </property>

View File

@@ -37,6 +37,7 @@ import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentService; import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter; 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.NodeRef;
import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.repository.StoreRef;
@@ -69,6 +70,11 @@ public class ExporterActionExecuter extends ActionExecuterAbstractBase
*/ */
private ExporterService exporterService; private ExporterService exporterService;
/**
* The Mime type service
*/
private MimetypeService mimetypeService;
/** /**
* The node service * The node service
*/ */
@@ -89,6 +95,16 @@ public class ExporterActionExecuter extends ActionExecuterAbstractBase
this.exporterService = exporterService; this.exporterService = exporterService;
} }
/**
* Sets the MimetypeService to use
*
* @param mimetypeService
*/
public void setMimetypeService(MimetypeService mimetypeService)
{
this.mimetypeService = mimetypeService;
}
/** /**
* Sets the NodeService to use * Sets the NodeService to use
* *
@@ -124,7 +140,7 @@ public class ExporterActionExecuter extends ActionExecuterAbstractBase
// create a temporary file to hold the zip // create a temporary file to hold the zip
zipFile = TempFileProvider.createTempFile(TEMP_FILE_PREFIX, ACPExportPackageHandler.ACP_EXTENSION); zipFile = TempFileProvider.createTempFile(TEMP_FILE_PREFIX, ACPExportPackageHandler.ACP_EXTENSION);
ACPExportPackageHandler zipHandler = new ACPExportPackageHandler(new FileOutputStream(zipFile), ACPExportPackageHandler zipHandler = new ACPExportPackageHandler(new FileOutputStream(zipFile),
dataFile, contentDir); dataFile, contentDir, mimetypeService);
ExporterCrawlerParameters params = new ExporterCrawlerParameters(); ExporterCrawlerParameters params = new ExporterCrawlerParameters();
boolean includeChildren = true; boolean includeChildren = true;

View File

@@ -26,7 +26,9 @@ import java.io.OutputStream;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.service.cmr.repository.ContentData; 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.ExportPackageHandler;
import org.alfresco.service.cmr.view.ExporterException; import org.alfresco.service.cmr.view.ExporterException;
import org.alfresco.util.TempFileProvider; import org.alfresco.util.TempFileProvider;
@@ -43,6 +45,7 @@ public class ACPExportPackageHandler
/** ACP File Extension */ /** ACP File Extension */
public final static String ACP_EXTENSION = "acp"; public final static String ACP_EXTENSION = "acp";
protected MimetypeService mimetypeService;
protected OutputStream outputStream; protected OutputStream outputStream;
protected File dataFile; protected File dataFile;
protected File contentDir; protected File contentDir;
@@ -60,7 +63,7 @@ public class ACPExportPackageHandler
* @param dataFile * @param dataFile
* @param contentDir * @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 try
{ {
@@ -86,6 +89,7 @@ public class ACPExportPackageHandler
this.outputStream = new FileOutputStream(absZipFile); this.outputStream = new FileOutputStream(absZipFile);
this.dataFile = dataFile; this.dataFile = dataFile;
this.contentDir = contentDir; this.contentDir = contentDir;
this.mimetypeService = mimetypeService;
} }
catch (FileNotFoundException e) catch (FileNotFoundException e)
{ {
@@ -100,11 +104,12 @@ public class ACPExportPackageHandler
* @param dataFile * @param dataFile
* @param contentDir * @param contentDir
*/ */
public ACPExportPackageHandler(OutputStream outputStream, File dataFile, File contentDir) public ACPExportPackageHandler(OutputStream outputStream, File dataFile, File contentDir, MimetypeService mimetypeService)
{ {
this.outputStream = outputStream; this.outputStream = outputStream;
this.dataFile = dataFile; this.dataFile = dataFile;
this.contentDir = contentDir; this.contentDir = contentDir;
this.mimetypeService = mimetypeService;
} }
/* (non-Javadoc) /* (non-Javadoc)
@@ -143,7 +148,23 @@ public class ACPExportPackageHandler
{ {
contentDirPath = contentDirPath.substring(0, contentDirPath.indexOf(".")); 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 try
{ {

View File

@@ -23,7 +23,9 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.service.cmr.repository.ContentData; 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.ExportPackageHandler;
import org.alfresco.service.cmr.view.ExporterException; import org.alfresco.service.cmr.view.ExporterException;
import org.alfresco.util.TempFileProvider; import org.alfresco.util.TempFileProvider;
@@ -37,6 +39,7 @@ import org.alfresco.util.TempFileProvider;
public class FileExportPackageHandler public class FileExportPackageHandler
implements ExportPackageHandler implements ExportPackageHandler
{ {
protected MimetypeService mimetypeService = null;
protected File contentDir; protected File contentDir;
protected File absContentDir; protected File absContentDir;
protected File absDataFile; protected File absDataFile;
@@ -50,13 +53,15 @@ public class FileExportPackageHandler
* @param dataFile filename of data file (relative to destDir) * @param dataFile filename of data file (relative to destDir)
* @param packageDir directory for content (relative to destDir) * @param packageDir directory for content (relative to destDir)
* @param overwrite force overwrite of existing package directory * @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.contentDir = contentDir;
this.absContentDir = new File(destDir, contentDir.getPath()); this.absContentDir = new File(destDir, contentDir.getPath());
this.absDataFile = new File(destDir, dataFile.getPath()); this.absDataFile = new File(destDir, dataFile.getPath());
this.overwrite = overwrite; this.overwrite = overwrite;
this.mimetypeService = mimetypeService;
} }
/* (non-Javadoc) /* (non-Javadoc)
@@ -119,7 +124,23 @@ public class FileExportPackageHandler
} }
// Create file in package directory to hold exported content // 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 try
{ {

View File

@@ -137,14 +137,13 @@ public class NodeContext extends ElementContext
*/ */
public void addPropertyCollection(QName property) 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... // TODO: Make this configurable...
PropertyDefinition propDef = getDictionaryService().getProperty(property); PropertyDefinition propDef = getDictionaryService().getProperty(property);
ClassDefinition classDef = (propDef == null) ? null : propDef.getContainerClass(); ClassDefinition classDef = (propDef == null) ? null : propDef.getContainerClass();
if (classDef != null) if (classDef != null)
{ {
if (classDef.getName().equals(ContentModel.ASPECT_REFERENCEABLE) || if (!isImportableClass(classDef.getName()))
classDef.getName().equals(ContentModel.ASPECT_VERSIONABLE))
{ {
return; return;
} }
@@ -170,8 +169,7 @@ public class NodeContext extends ElementContext
ClassDefinition classDef = (propDef == null) ? null : propDef.getContainerClass(); ClassDefinition classDef = (propDef == null) ? null : propDef.getContainerClass();
if (classDef != null) if (classDef != null)
{ {
if (classDef.getName().equals(ContentModel.ASPECT_REFERENCEABLE) || if (!isImportableClass(classDef.getName()))
classDef.getName().equals(ContentModel.ASPECT_VERSIONABLE))
{ {
return; return;
} }
@@ -234,7 +232,10 @@ public class NodeContext extends ElementContext
*/ */
public void addAspect(AspectDefinition aspect) public void addAspect(AspectDefinition aspect)
{ {
nodeAspects.put(aspect.getName(), aspect); if (isImportableClass(aspect.getName()))
{
nodeAspects.put(aspect.getName(), aspect);
}
} }
/* (non-Javadoc) /* (non-Javadoc)
@@ -328,6 +329,19 @@ public class NodeContext extends ElementContext
return def; 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) /* (non-Javadoc)
* @see java.lang.Object#toString() * @see java.lang.Object#toString()
*/ */

View File

@@ -23,6 +23,7 @@ import java.util.Collection;
import org.alfresco.repo.exporter.FileExportPackageHandler; import org.alfresco.repo.exporter.FileExportPackageHandler;
import org.alfresco.repo.exporter.ACPExportPackageHandler; import org.alfresco.repo.exporter.ACPExportPackageHandler;
import org.alfresco.service.cmr.repository.ContentData; 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.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.view.ExportPackageHandler; import org.alfresco.service.cmr.view.ExportPackageHandler;
@@ -212,16 +213,17 @@ public final class Export extends Tool
void execute() throws ToolException void execute() throws ToolException
{ {
ExporterService exporter = getServiceRegistry().getExporterService(); ExporterService exporter = getServiceRegistry().getExporterService();
MimetypeService mimetypeService = getServiceRegistry().getMimetypeService();
// create export package handler // create export package handler
ExportPackageHandler exportHandler = null; ExportPackageHandler exportHandler = null;
if (context.zipped) 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 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 // export Repository content to export package
@@ -255,9 +257,9 @@ public final class Export extends Tool
* @param contentDir * @param contentDir
* @param overwrite * @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 dataFile
* @param contentDir * @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);
} }
/** /**