/* * Copyright (C) 2005-2010 Alfresco Software Limited. * * This file is part of Alfresco * * Alfresco is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Alfresco is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with Alfresco. If not, see . */ package org.alfresco.web.bean.wcm; import java.text.MessageFormat; import javax.faces.context.FacesContext; import org.alfresco.service.cmr.avm.AVMService; import org.alfresco.web.app.AlfrescoNavigationHandler; import org.alfresco.web.app.Application; import org.alfresco.web.bean.dialog.BaseDialogBean; import org.alfresco.web.bean.repository.Repository; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * Bean implementation for the AVM "Delete Folder" dialog * * @author kevinr */ public class DeleteFolderDialog extends BaseDialogBean { private static final long serialVersionUID = 4188977806570877462L; private static final Log logger = LogFactory.getLog(DeleteFolderDialog.class); transient private AVMService avmService; protected AVMBrowseBean avmBrowseBean; /** * @param avmBrowseBean The avmBrowseBean to set. */ public void setAvmBrowseBean(AVMBrowseBean avmBrowseBean) { this.avmBrowseBean = avmBrowseBean; } /** * @param avmService The avmService to set. */ public void setAvmService(AVMService avmService) { this.avmService = avmService; } protected AVMService getAvmService() { if (avmService == null) { avmService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getAVMService(); } return avmService; } // ------------------------------------------------------------------------------ // Dialog implementation @Override protected String finishImpl(FacesContext context, String outcome) throws Exception { // get the content to delete AVMNode node = this.avmBrowseBean.getAvmActionNode(); if (node != null) { if (logger.isDebugEnabled()) logger.debug("Trying to delete AVM node: " + node.getPath()); // delete the node this.getAvmService().removeNode( node.getPath().substring(0, node.getPath().lastIndexOf('/')), node.getPath().substring(node.getPath().lastIndexOf('/') + 1)); } else { logger.warn("WARNING: delete called without a current AVM Node!"); } return outcome; } @Override protected String doPostCommitProcessing(FacesContext context, String outcome) { return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME; } @Override protected String getErrorMessageId() { return "error_delete_folder"; } @Override public boolean getFinishButtonDisabled() { return false; } // ------------------------------------------------------------------------------ // Bean Getters and Setters /** * Returns the confirmation to display to the user before deleting the content. * * @return The formatted message to display */ public String getConfirmMessage() { String fileConfirmMsg = Application.getMessage(FacesContext.getCurrentInstance(), "delete_avm_folder_confirm"); return MessageFormat.format(fileConfirmMsg, new Object[] {this.avmBrowseBean.getAvmActionNode().getName()}); } }