The Import dialog now allows ZIP file structure import into the repo from the web-client by any user with Write access to a folder - this is nice quick way for any user to import bulk data without using an FTP client or CIFS folder access.

Import action moved to top-level in the main browse screen now it is useful on a day-to-day basis.
The 'import' repository action (ImporterActionExecuter) extended to support import of any zip flavour file.
More zip flavour filetypes added to mimetype map.
Improved debugging output added to BasePathResultsMap for xpaths executed in templates.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5760 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2007-05-23 12:25:04 +00:00
parent 9f44f6d23f
commit 7644596c74
7 changed files with 46 additions and 116 deletions

View File

@@ -41,6 +41,7 @@ import org.alfresco.service.cmr.action.ActionService;
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.namespace.NamespaceService;
@@ -70,6 +71,7 @@ public class ImportBean
protected NodeService nodeService;
protected ActionService actionService;
protected ContentService contentService;
protected MimetypeService mimetypeService;
private File file;
private String fileName;
@@ -101,14 +103,14 @@ public class ImportBean
tx = Repository.getUserTransaction(context);
tx.begin();
// first of all we need to add the uploaded ACP file to the repository
NodeRef acpNodeRef = addACPToRepository(context);
// first of all we need to add the uploaded ACP/ZIP file to the repository
NodeRef acpNodeRef = addFileToRepository(context);
// build the action params map based on the bean's current state
Map<String, Serializable> params = new HashMap<String, Serializable>(3);
Map<String, Serializable> params = new HashMap<String, Serializable>(2, 1.0f);
params.put(ImporterActionExecuter.PARAM_DESTINATION_FOLDER, this.browseBean.getActionSpace().getNodeRef());
params.put(ImporterActionExecuter.PARAM_ENCODING, this.encoding);
// build the action to execute
Action action = this.actionService.createAction(ImporterActionExecuter.NAME, params);
action.setExecuteAsynchronously(this.runInBackground);
@@ -292,12 +294,22 @@ public class ImportBean
}
/**
* Adds the uploaded ACP file to the repository
* Sets the mimetype sevice
*
* @param mimetypeService the mimetype service
*/
public void setMimetypeService(MimetypeService mimetypeService)
{
this.mimetypeService = mimetypeService;
}
/**
* Adds the uploaded ACP/ZIP file to the repository
*
* @param context Faces context
* @return NodeRef representing the ACP file in the repository
* @return NodeRef representing the ACP/ZIP file in the repository
*/
private NodeRef addACPToRepository(FacesContext context)
private NodeRef addFileToRepository(FacesContext context)
{
// set the name for the new node
Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>(1);
@@ -311,19 +323,23 @@ public class ImportBean
ContentModel.TYPE_CONTENT, contentProps);
NodeRef acpNodeRef = assocRef.getChildRef();
// apply the titled aspect to behave in the web client
Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>(3, 1.0f);
String mimetype = this.mimetypeService.guessMimetype(this.fileName);
Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>(2, 1.0f);
titledProps.put(ContentModel.PROP_TITLE, this.fileName);
titledProps.put(ContentModel.PROP_DESCRIPTION, Application.getMessage(context, "import_package_description"));
titledProps.put(ContentModel.PROP_DESCRIPTION,
MimetypeMap.MIMETYPE_ACP.equals(mimetype) ?
Application.getMessage(context, "import_acp_description") :
Application.getMessage(context, "import_zip_description"));
this.nodeService.addAspect(acpNodeRef, ContentModel.ASPECT_TITLED, titledProps);
// add the content to the node
ContentWriter writer = this.contentService.getWriter(acpNodeRef, ContentModel.PROP_CONTENT, true);
writer.setEncoding(this.encoding);
writer.setMimetype(MimetypeMap.MIMETYPE_ACP);
writer.setMimetype(mimetype);
writer.putContent(this.file);
return acpNodeRef;
}
}

View File

@@ -25,17 +25,11 @@
package org.alfresco.web.bean.wcm;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.MessageFormat;
import java.util.Enumeration;
import java.util.zip.ZipException;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
@@ -44,6 +38,7 @@ import javax.transaction.UserTransaction;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ApplicationModel;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.executer.ImporterActionExecuter;
import org.alfresco.repo.avm.AVMNodeConverter;
import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.service.ServiceRegistry;
@@ -62,7 +57,6 @@ import org.alfresco.web.app.context.UIContextService;
import org.alfresco.web.bean.FileUploadBean;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.ui.common.Utils;
import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipFile;
/**
@@ -306,14 +300,12 @@ public class ImportWebsiteDialog
File tempDir = new File(alfTempDir.getPath() + File.separatorChar + file.getName() + "_unpack");
try
{
// TODO: improve this code to directly pipe the zip stream output into the repo objects -
// to remove the need to expand to the filesystem first.
extractFile(zipFile, tempDir.getPath());
ImporterActionExecuter.extractFile(zipFile, tempDir.getPath());
importDirectory(tempDir.getPath(), rootRef);
}
finally
{
deleteDir(tempDir);
ImporterActionExecuter.deleteDir(tempDir);
}
}
catch (IOException e)
@@ -322,66 +314,6 @@ public class ImportWebsiteDialog
}
}
/**
* Extract the file and folder structure of a ZIP file into the specified directory
*
* @param archive The ZIP archive to extract
* @param extractDir The directory to extract into
*/
private void extractFile(ZipFile archive, String extractDir)
{
String fileName;
String destFileName;
byte[] buffer = new byte[BUFFER_SIZE];
extractDir = extractDir + File.separator;
try
{
for (Enumeration e = archive.getEntries(); e.hasMoreElements();)
{
ZipEntry entry = (ZipEntry) e.nextElement();
if (!entry.isDirectory())
{
fileName = entry.getName();
fileName = fileName.replace('/', File.separatorChar);
destFileName = extractDir + fileName;
File destFile = new File(destFileName);
String parent = destFile.getParent();
if (parent != null)
{
File parentFile = new File(parent);
if (!parentFile.exists()) parentFile.mkdirs();
}
InputStream in = new BufferedInputStream(archive.getInputStream(entry), BUFFER_SIZE);
OutputStream out = new BufferedOutputStream(new FileOutputStream(destFileName), BUFFER_SIZE);
int count;
while ((count = in.read(buffer)) != -1)
{
out.write(buffer, 0, count);
}
in.close();
out.close();
}
else
{
File newdir = new File(extractDir + entry.getName());
newdir.mkdir();
}
}
}
catch (ZipException e)
{
throw new AlfrescoRuntimeException("Failed to process ZIP file.", e);
}
catch (FileNotFoundException e)
{
throw new AlfrescoRuntimeException("Failed to process ZIP file.", e);
}
catch (IOException e)
{
throw new AlfrescoRuntimeException("Failed to process ZIP file.", e);
}
}
/**
* Recursively import a directory structure into the specified root node
*
@@ -464,20 +396,4 @@ public class ImportWebsiteDialog
}
}
}
/**
* Recursively delete a dir of files and directories
*
* @param dir directory to delete
*/
private void deleteDir(File dir)
{
File elenco = new File(dir.getPath());
for (File file : elenco.listFiles())
{
if (file.isFile()) file.delete();
else deleteDir(file);
}
dir.delete();
}
}