1 17 package org.alfresco.repo.action.executer; 18 19 import java.io.File ; 20 import java.util.List ; 21 22 import org.alfresco.model.ContentModel; 23 import org.alfresco.repo.action.ParameterDefinitionImpl; 24 import org.alfresco.repo.content.MimetypeMap; 25 import org.alfresco.repo.importer.ACPImportPackageHandler; 26 import org.alfresco.service.cmr.action.Action; 27 import org.alfresco.service.cmr.action.ParameterDefinition; 28 import org.alfresco.service.cmr.dictionary.DataTypeDefinition; 29 import org.alfresco.service.cmr.repository.ContentReader; 30 import org.alfresco.service.cmr.repository.ContentService; 31 import org.alfresco.service.cmr.repository.NodeRef; 32 import org.alfresco.service.cmr.repository.NodeService; 33 import org.alfresco.service.cmr.view.ImporterService; 34 import org.alfresco.service.cmr.view.Location; 35 import org.alfresco.util.TempFileProvider; 36 37 42 public class ImporterActionExecuter extends ActionExecuterAbstractBase 43 { 44 public static final String NAME = "import"; 45 public static final String PARAM_ENCODING = "encoding"; 46 public static final String PARAM_DESTINATION_FOLDER = "destination"; 47 48 private static final String TEMP_FILE_PREFIX = "alf"; 49 private static final String TEMP_FILE_SUFFIX = ".acp"; 50 51 54 private ImporterService importerService; 55 56 59 private NodeService nodeService; 60 61 64 private ContentService contentService; 65 66 71 public void setImporterService(ImporterService importerService) 72 { 73 this.importerService = importerService; 74 } 75 76 81 public void setNodeService(NodeService nodeService) 82 { 83 this.nodeService = nodeService; 84 } 85 86 91 public void setContentService(ContentService contentService) 92 { 93 this.contentService = contentService; 94 } 95 96 99 public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) 100 { 101 if (this.nodeService.exists(actionedUponNodeRef) == true) 102 { 103 ContentReader reader = this.contentService.getReader(actionedUponNodeRef, ContentModel.PROP_CONTENT); 105 if (reader != null) 106 { 107 if (MimetypeMap.MIMETYPE_ACP.equals(reader.getMimetype())) 108 { 109 File zipFile = null; 110 try 111 { 112 zipFile = TempFileProvider.createTempFile(TEMP_FILE_PREFIX, TEMP_FILE_SUFFIX); 115 reader.getContent(zipFile); 116 117 ACPImportPackageHandler importHandler = new ACPImportPackageHandler(zipFile, 118 (String )ruleAction.getParameterValue(PARAM_ENCODING)); 119 NodeRef importDest = (NodeRef)ruleAction.getParameterValue(PARAM_DESTINATION_FOLDER); 120 121 this.importerService.importView(importHandler, new Location(importDest), null, null); 122 } 123 finally 124 { 125 if (zipFile != null) 127 { 128 zipFile.delete(); 129 } 130 } 131 } 132 } 133 } 134 } 135 136 139 protected void addParameterDefintions(List <ParameterDefinition> paramList) 140 { 141 paramList.add(new ParameterDefinitionImpl(PARAM_DESTINATION_FOLDER, DataTypeDefinition.NODE_REF, 142 true, getParamDisplayLabel(PARAM_DESTINATION_FOLDER))); 143 paramList.add(new ParameterDefinitionImpl(PARAM_ENCODING, DataTypeDefinition.TEXT, 144 true, getParamDisplayLabel(PARAM_ENCODING))); 145 } 146 147 } 148 | Popular Tags |