001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.core.admin.ui.actions;
023:
024: import org.jboss.portal.core.admin.ui.PortalObjectManagerBean;
025: import org.jboss.portal.core.admin.ui.dashboard.DashboardBean;
026: import org.jboss.portal.core.model.portal.DuplicatePortalObjectException;
027: import org.jboss.portal.core.model.portal.NoSuchPortalObjectException;
028: import org.jboss.portal.core.model.portal.PageContainer;
029: import org.jboss.portal.core.model.portal.PortalObject;
030: import org.jboss.portal.core.model.portal.PortalObjectPath;
031: import org.jboss.portal.security.spi.provider.DomainConfigurator;
032:
033: import javax.faces.application.FacesMessage;
034: import javax.faces.context.FacesContext;
035: import java.util.Set;
036:
037: /**
038: * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
039: * @version $Revision: 9087 $
040: */
041: public class RenameAction {
042: private String newName;
043:
044: /** The page container that will create the child. */
045: public PortalObject pageContainer;
046:
047: private DomainConfigurator domainConfigurator;
048:
049: public Object bean;
050:
051: public void setNewName(String newName) {
052: this .newName = newName;
053: }
054:
055: public String getNewName() {
056: if (newName == null) {
057: newName = pageContainer.getName();
058: }
059: return newName;
060: }
061:
062: public DomainConfigurator getDomainConfigurator() {
063: return domainConfigurator;
064: }
065:
066: public void setDomainConfigurator(
067: DomainConfigurator domainConfigurator) {
068: this .domainConfigurator = domainConfigurator;
069: }
070:
071: public PortalObject getPageContainer() {
072: return pageContainer;
073: }
074:
075: public void setPageContainer(PortalObject pageContainer) {
076: this .pageContainer = pageContainer;
077: }
078:
079: public String execute() {
080: PortalObject parent = pageContainer.getParent();
081: PortalObject newObject = null;
082: try {
083: // TODO: Should be in a tx
084:
085: // Clone portal object
086: newObject = pageContainer.copy(parent, newName, true);
087:
088: // Copy security settings
089: Set set = domainConfigurator
090: .getSecurityBindings(pageContainer
091: .getId()
092: .toString(PortalObjectPath.CANONICAL_FORMAT));
093: domainConfigurator.setSecurityBindings(newObject.getId()
094: .toString(PortalObjectPath.CANONICAL_FORMAT), set);
095:
096: String defaultObject = (String) parent
097: .getDeclaredProperties()
098: .get(PortalObject.PORTAL_PROP_DEFAULT_OBJECT_NAME);
099: if (pageContainer.getName().equals(defaultObject)) {
100: parent.setDeclaredProperty(
101: PortalObject.PORTAL_PROP_DEFAULT_OBJECT_NAME,
102: newName);
103: }
104:
105: // Destroy previous object
106: parent.destroyChild(pageContainer.getName());
107: } catch (IllegalArgumentException e) {
108: e.printStackTrace();
109: } catch (DuplicatePortalObjectException e) {
110: String message = "The name \""
111: + newName
112: + "\" is already used, please choose a different one";
113: FacesContext.getCurrentInstance().addMessage(
114: "renameForm:newName",
115: new FacesMessage(FacesMessage.SEVERITY_ERROR,
116: message, message));
117: return null;
118: } catch (NoSuchPortalObjectException e) {
119: e.printStackTrace();
120: }
121:
122: // TODO: This is not clean
123: if (bean instanceof PortalObjectManagerBean) {
124: ((PortalObjectManagerBean) bean).selectObject(parent);
125: return "objects";
126: } else if (bean instanceof DashboardBean) {
127: ((DashboardBean) bean).selectedPageName = newObject
128: .getName();
129: }
130:
131: return null;
132: }
133:
134: }
|