From 83919a08f17ccffb2574ced479862ec4dbfcefec Mon Sep 17 00:00:00 2001 From: Derek Hulley Date: Tue, 13 Nov 2007 01:15:58 +0000 Subject: [PATCH] Merged V2.1 to HEAD 6975: Fix for WCM-883 - ZIP files with non-ascii characters, now gives the user an option for the encoding of the ZIP filenames 6978: Fixed test for 2.1 bean names. 6981: Fixes test failure. 6982: Integrity exception message carries full failure details. 6983: Added upgrade script for SQL Server. 6988: Replaced UserTransaction with RetryingTransactionHelper. 6989: Added org.hibernate.ObjectNotFoundException RetryingTransactionHelper. 6996: Added updated support for datetime tokens in the lucene index 7001: FIx for AR-1806 7015: Added missing post-create index script for QName columns on alf_child_assoc. 7022: Merged V2.0 to V2.1: 7013: Fixed primary child node status query git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@7371 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/messages/webclient.properties | 1 + .../web/bean/wcm/ImportWebsiteDialog.java | 162 ++++++++++-------- source/web/jsp/wcm/import-content-dialog.jsp | 9 +- 3 files changed, 102 insertions(+), 70 deletions(-) diff --git a/config/alfresco/messages/webclient.properties b/config/alfresco/messages/webclient.properties index 70daa5efec..5908dc2c6f 100644 --- a/config/alfresco/messages/webclient.properties +++ b/config/alfresco/messages/webclient.properties @@ -1118,6 +1118,7 @@ task_done_resubmit_all=Task Done & Re-Submit All title_import_content=Web Project Bulk Import import_website_content_title=Bulk Import import_website_content_desc=Use this dialog to import an archive of content into the web project. +import_high_byte_zip_file=ZIP file contains high-byte filename characters such as Japanese, Chinese or Korean. delete_avm_file_info=To remove this file from the sandbox, click OK. delete_avm_file_confirm=Are you sure you want to remove \"{0}\" from the sandbox? delete_form_instance_data_confirm=Are you sure you want to remove \"{0}\" and its {1} associated {1,choice,0#renditions|1#rendition|1 cb = + new RetryingTransactionHelper.RetryingTransactionCallback() + { + public String execute() + { + // get the AVM path that will contain the imported content + String rootPath = avmBrowseBean.getCurrentPath(); + + // convert the AVM path to a NodeRef so we can use the NodeService to perform import + NodeRef importRef = AVMNodeConverter.ToNodeRef(-1, rootPath); + processZipImport(file, importRef); + + // After a bulk import it's a good idea to snapshot the store + avmService.createSnapshot( + AVMUtil.getStoreName(rootPath), + "Import of file: " + fileName, null); + + return rootPath; + } + }; + String rootPath = Repository.getRetryingTransactionHelper(context).doInTransaction(cb); // Reload virtualisation server as required AVMUtil.updateVServerWebapp(rootPath, true); - + UIContextService.getInstance(context).notifyBeans(); - + outcome = AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME; } catch (Throwable e) { - // rollback the transaction - try { if (tx != null) {tx.rollback();} } catch (Exception ex) {} Utils.addErrorMessage(MessageFormat.format( - Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), + Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), e.getMessage()), e); } finally @@ -237,38 +261,38 @@ public class ImportWebsiteDialog this.isFinished = false; } } - + return outcome; } - + /** * Action handler called when the user wishes to remove an uploaded file */ public String removeUploadedFile() { clearUpload(); - + // also clear the file name this.fileName = null; - + // refresh the current page return null; } - + /** * Action handler called when the dialog is cancelled */ public String cancel() { clearUpload(); - + return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME; } - - + + // ------------------------------------------------------------------------------ // Helper Methods - + /** * Deletes the uploaded file and removes the FileUploadBean from the session */ @@ -279,9 +303,9 @@ public class ImportWebsiteDialog { this.file.delete(); } - + this.file = null; - + // remove the file upload bean from the session FacesContext ctx = FacesContext.getCurrentInstance(); ctx.getExternalContext().getSessionMap().remove(FileUploadBean.FILE_UPLOAD_BEAN_NAME); @@ -289,7 +313,7 @@ public class ImportWebsiteDialog /** * Process ZIP file for import into an AVM repository store location - * + * * @param file ZIP format file * @param rootRef Root reference of the AVM location to import into */ @@ -299,7 +323,7 @@ public class ImportWebsiteDialog { // NOTE: This encoding allows us to workaround bug: // http://bugs.sun.com/bugdatabase/view_bug.do;:WuuT?bug_id=4820807 - ZipFile zipFile = new ZipFile(file, "Cp437"); + ZipFile zipFile = new ZipFile(file, this.highByteZip ? "Cp437" : null); File alfTempDir = TempFileProvider.getTempDir(); // build a temp dir name based on the name of the file we are importing File tempDir = new File(alfTempDir.getPath() + File.separatorChar + file.getName() + "_unpack"); @@ -321,10 +345,10 @@ public class ImportWebsiteDialog throw new AlfrescoRuntimeException("Unable to process Zip file. File may not be of the expected format.", e); } } - + /** * Recursively import a directory structure into the specified root node - * + * * @param dir The directory of files and folders to import * @param root The root node to import into */ @@ -346,12 +370,12 @@ public class ImportWebsiteDialog List aspects = new ArrayList(); aspects.add(ContentModel.ASPECT_TITLED); Map properties = new HashMap(); - properties.put(ContentModel.PROP_TITLE, + properties.put(ContentModel.PROP_TITLE, new PropertyValue(DataTypeDefinition.TEXT, fileName)); this.avmService.createFile( avmPath, fileName,new BufferedInputStream(new FileInputStream(file), BUFFER_SIZE), aspects, properties); - + // TODO: restore this code once performance is acceptable // NodeRef fileRef = AVMNodeConverter.ToNodeRef(-1, filePath); // see AVMBrowseBean.setAVMNodeDescriptor @@ -359,19 +383,19 @@ public class ImportWebsiteDialog // Map titledProps = new HashMap(1, 1.0f); // titledProps.put(ContentModel.PROP_TITLE, fileName); // this.nodeService.addAspect(fileRef, ContentModel.ASPECT_TITLED, titledProps); - + // for now use the avm service directly // String filePath = avmPath + '/' + fileName; // this.avmService.addAspect(filePath, ContentModel.ASPECT_TITLED); // this.avmService.setNodeProperty(filePath, ContentModel.PROP_TITLE, // new PropertyValue(DataTypeDefinition.TEXT, fileName)); - + // create content node based on the filename /*FileInfo contentFile = fileFolderService.create(root, fileName, ContentModel.TYPE_AVM_PLAIN_CONTENT); NodeRef content = contentFile.getNodeRef(); - + InputStream contentStream = new BufferedInputStream(new FileInputStream(file), BUFFER_SIZE); - + ContentWriter writer = contentService.getWriter(content, ContentModel.PROP_CONTENT, true); writer.setMimetype(mimetypeService.guessMimetype(file.getAbsolutePath())); // TODO: what should we set this too? (definitely not Cp437...!) @@ -381,17 +405,17 @@ public class ImportWebsiteDialog else { //FileInfo fileInfo = fileFolderService.create(root, file.getName(), ContentModel.TYPE_AVM_PLAIN_FOLDER); - - // Create a directory in the AVM store + + // Create a directory in the AVM store String avmPath = AVMNodeConverter.ToAVMVersionPath(root).getSecond(); List aspects = new ArrayList(); aspects.add(ApplicationModel.ASPECT_UIFACETS); this.avmService.createDirectory(avmPath, file.getName(), aspects, null); - + String folderPath = avmPath + '/' + file.getName(); NodeRef folderRef = AVMNodeConverter.ToNodeRef(-1, folderPath); importDirectory(file.getPath(), folderRef); - + // TODO: restore this code once performance is acceptable // see AVMBrowseBean.setAVMNodeDescriptor // add the uifacets aspect for the read/edit properties screens diff --git a/source/web/jsp/wcm/import-content-dialog.jsp b/source/web/jsp/wcm/import-content-dialog.jsp index 8504313398..cb7ee3adee 100644 --- a/source/web/jsp/wcm/import-content-dialog.jsp +++ b/source/web/jsp/wcm/import-content-dialog.jsp @@ -177,8 +177,15 @@ + + + +   + + + + <% } %> - <% PanelGenerator.generatePanelEnd(out, request.getContextPath(), "white"); %>