/* * Copyright (C) 2005 Alfresco, Inc. * * Licensed under the Mozilla Public License version 1.1 * with a permitted attribution clause. You may obtain a * copy of the License at * * http://www.alfresco.org/legal/license.txt * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific * language governing permissions and limitations under the * License. */ package org.alfresco.web.bean.wcm; import java.text.MessageFormat; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.faces.application.FacesMessage; import javax.faces.context.FacesContext; import javax.faces.event.ActionEvent; import javax.transaction.UserTransaction; import org.alfresco.model.ContentModel; import org.alfresco.service.cmr.avm.AVMService; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.TemplateImageResolver; import org.alfresco.service.cmr.security.OwnableService; import org.alfresco.web.app.Application; import org.alfresco.web.bean.repository.Node; import org.alfresco.web.bean.repository.Repository; import org.alfresco.web.ui.common.Utils; import org.alfresco.web.ui.common.Utils.URLMode; import org.alfresco.web.ui.common.component.UIActionLink; import org.alfresco.web.ui.common.component.UIPanel.ExpandedEvent; /** * Base backing bean provided access to the details of an AVM item * * @author Kevin Roast */ public abstract class AVMDetailsBean { /** NodeService bean reference */ protected NodeService nodeService; /** AVM service bean reference */ protected AVMService avmService; /** AVMBrowseBean bean reference */ protected AVMBrowseBean avmBrowseBean; protected Map panels = new HashMap(4, 1.0f); // ------------------------------------------------------------------------------ // Bean property getters and setters /** * @param nodeService The NodeService to set */ public void setNodeService(NodeService nodeService) { this.nodeService = nodeService; } /** * @param avmService The AVMService to set. */ public void setAvmService(AVMService avmService) { this.avmService = avmService; } /** * @param avmBrowseBean The AVMBrowseBean to set. */ public void setAvmBrowseBean(AVMBrowseBean avmBrowseBean) { this.avmBrowseBean = avmBrowseBean; } /** * @return Returns the panels expanded state map. */ public Map getPanels() { return this.panels; } /** * @param panels The panels expanded state map. */ public void setPanels(Map panels) { this.panels = panels; } /** * @return the AVM node to display the details for */ public abstract AVMNode getAvmNode(); /** * Returns the Path of the current node * * @return The path */ public String getPath() { return getAvmNode().getPath(); } /** * Returns the name of the current node * * @return Name of the current node */ public String getName() { return getAvmNode().getName(); } /** * Return the Alfresco NodeRef URL for the current node * * @return the Alfresco NodeRef URL */ public String getNodeRefUrl() { return getAvmNode().getNodeRef().toString(); } /** * @return if we are currently within the context of a Browse list (otherwise we are * probably looking at an item in the Modified File list) */ public boolean getIsBrowseList() { return !this.avmBrowseBean.isCurrentPathNull(); } /** * @return the sibling nodes for this item */ protected abstract List getNodes(); // ------------------------------------------------------------------------------ // Action event handlers /** * Save the state of the panel that was expanded/collapsed */ public void expandPanel(ActionEvent event) { if (event instanceof ExpandedEvent) { String id = event.getComponent().getId(); this.panels.put(id, ((ExpandedEvent)event).State); } } /** * Navigates to next item in the list of items for the current folder */ public void nextItem(ActionEvent event) { UIActionLink link = (UIActionLink)event.getComponent(); Map params = link.getParameterMap(); String path = params.get("id"); if (path != null && path.length() != 0) { List nodes = getNodes(); if (nodes.size() > 1) { // perform a linear search - this is slow but stateless // otherwise we would have to manage state of last selected node // this gets very tricky as this bean is instantiated once and never // reset - it does not know when the item has changed etc. for (int i=0; i params = link.getParameterMap(); String path = params.get("id"); if (path != null && path.length() != 0) { List nodes = getNodes(); if (nodes.size() > 1) { // see above for (int i=0; i