1 18 package org.alfresco.web.bean; 19 20 import java.io.Serializable ; 21 import java.text.MessageFormat ; 22 import java.util.HashMap ; 23 import java.util.Map ; 24 25 import javax.faces.context.FacesContext; 26 import javax.transaction.UserTransaction ; 27 28 import org.alfresco.repo.action.executer.ExporterActionExecuter; 29 import org.alfresco.service.cmr.action.Action; 30 import org.alfresco.service.cmr.action.ActionService; 31 import org.alfresco.service.cmr.repository.NodeRef; 32 import org.alfresco.service.cmr.repository.NodeService; 33 import org.alfresco.web.app.Application; 34 import org.alfresco.web.bean.repository.Repository; 35 import org.alfresco.web.ui.common.Utils; 36 import org.apache.commons.logging.Log; 37 import org.apache.commons.logging.LogFactory; 38 39 44 public class ExportBean 45 { 46 private static final Log logger = LogFactory.getLog(ExportBean.class); 47 48 private static final String ALL_SPACES = "all"; 49 private static final String CURRENT_SPACE = "current"; 50 51 private static final String DEFAULT_OUTCOME = "dialog:close"; 52 53 private static final String MSG_ERROR = "error_export"; 54 55 protected BrowseBean browseBean; 56 protected NodeService nodeService; 57 protected ActionService actionService; 58 59 private String packageName; 60 private String encoding = "UTF-8"; 61 private String mode = CURRENT_SPACE; 62 private NodeRef destination; 63 private boolean includeChildren = true; 64 private boolean runInBackground = true; 65 private boolean includeSelf; 66 67 72 public String export() 73 { 74 if (logger.isDebugEnabled()) 75 logger.debug("Called export for " + this.mode + " with package name: " + this.packageName); 76 77 String outcome = DEFAULT_OUTCOME; 78 79 UserTransaction tx = null; 80 81 try 82 { 83 tx = Repository.getUserTransaction(FacesContext.getCurrentInstance()); 84 tx.begin(); 85 86 Map <String , Serializable > params = new HashMap <String , Serializable >(5); 88 params.put(ExporterActionExecuter.PARAM_STORE, Repository.getStoreRef().toString()); 89 params.put(ExporterActionExecuter.PARAM_PACKAGE_NAME, this.packageName); 90 params.put(ExporterActionExecuter.PARAM_ENCODING, this.encoding); 91 params.put(ExporterActionExecuter.PARAM_DESTINATION_FOLDER, this.destination); 92 params.put(ExporterActionExecuter.PARAM_INCLUDE_CHILDREN, new Boolean (includeChildren)); 93 params.put(ExporterActionExecuter.PARAM_INCLUDE_SELF, new Boolean (includeSelf)); 94 95 Action action = this.actionService.createAction(ExporterActionExecuter.NAME, params); 97 action.setExecuteAsynchronously(this.runInBackground); 98 99 NodeRef startNode = null; 101 if (this.mode.equals(ALL_SPACES)) 102 { 103 startNode = this.nodeService.getRootNode(Repository.getStoreRef()); 104 } 105 else 106 { 107 startNode = this.browseBean.getActionSpace().getNodeRef(); 108 } 109 110 this.actionService.executeAction(action, startNode); 112 113 if (logger.isDebugEnabled()) 114 { 115 logger.debug("Executed export action with action params of " + params); 116 } 117 118 tx.commit(); 120 121 reset(); 123 } 124 catch (Throwable e) 125 { 126 try { if (tx != null) {tx.rollback();} } catch (Exception ex) {} 128 Utils.addErrorMessage(MessageFormat.format(Application.getMessage( 129 FacesContext.getCurrentInstance(), MSG_ERROR), e.toString()), e); 130 outcome = null; 131 } 132 133 return outcome; 134 } 135 136 141 public String cancel() 142 { 143 reset(); 144 145 return DEFAULT_OUTCOME; 146 } 147 148 151 public void reset() 152 { 153 this.packageName = null; 154 this.mode = CURRENT_SPACE; 155 this.destination = null; 156 this.includeChildren = true; 157 this.includeSelf = false; 158 this.runInBackground = true; 159 } 160 161 166 public String getPackageName() 167 { 168 return this.packageName; 169 } 170 171 176 public void setPackageName(String packageName) 177 { 178 this.packageName = packageName; 179 } 180 181 186 public NodeRef getDestination() 187 { 188 return this.destination; 189 } 190 191 196 public void setDestination(NodeRef destination) 197 { 198 this.destination = destination; 199 } 200 201 206 public boolean getIncludeChildren() 207 { 208 return this.includeChildren; 209 } 210 211 216 public void setIncludeChildren(boolean includeChildren) 217 { 218 this.includeChildren = includeChildren; 219 } 220 221 226 public boolean getIncludeSelf() 227 { 228 return this.includeSelf; 229 } 230 231 236 public void setIncludeSelf(boolean includeSelf) 237 { 238 this.includeSelf = includeSelf; 239 } 240 241 246 public String getMode() 247 { 248 return this.mode; 249 } 250 251 256 public void setMode(String mode) 257 { 258 this.mode = mode; 259 } 260 261 266 public String getEncoding() 267 { 268 return this.encoding; 269 } 270 271 276 public void setEncoding(String encoding) 277 { 278 this.encoding = encoding; 279 } 280 281 286 public boolean getRunInBackground() 287 { 288 return this.runInBackground; 289 } 290 291 296 public void setRunInBackground(boolean runInBackground) 297 { 298 this.runInBackground = runInBackground; 299 } 300 301 306 public void setBrowseBean(BrowseBean browseBean) 307 { 308 this.browseBean = browseBean; 309 } 310 311 316 public void setActionService(ActionService actionService) 317 { 318 this.actionService = actionService; 319 } 320 321 326 public void setNodeService(NodeService nodeService) 327 { 328 this.nodeService = nodeService; 329 } 330 } 331 | Popular Tags |