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.Mode;
025: import org.jboss.portal.WindowState;
026: import org.jboss.portal.core.admin.ui.PortalObjectManagerBean;
027: import org.jboss.portal.core.model.portal.Page;
028: import org.jboss.portal.core.model.portal.Portal;
029: import org.jboss.portal.core.model.portal.PortalContainer;
030: import org.jboss.portal.core.model.portal.PortalObject;
031: import org.jboss.portal.core.model.portal.PortalObjectPath;
032: import org.jboss.portal.core.model.portal.PortalObjectPermission;
033: import org.jboss.portal.security.RoleSecurityBinding;
034: import org.jboss.portal.security.SecurityConstants;
035: import org.jboss.portal.security.spi.provider.DomainConfigurator;
036: import org.jboss.portal.theme.ThemeConstants;
037:
038: import javax.faces.application.FacesMessage;
039: import javax.faces.component.UIComponent;
040: import javax.faces.context.FacesContext;
041: import javax.faces.validator.ValidatorException;
042: import java.util.Collections;
043: import java.util.HashSet;
044: import java.util.Set;
045:
046: /**
047: * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
048: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
049: * @version $Revision: 8785 $
050: */
051: public class PortalAction {
052:
053: /** . */
054: private PortalObjectManagerBean pomgr;
055:
056: /** . */
057: private String portalName;
058:
059: //private String defaultPageName;
060:
061: /** . */
062: private static final String ERROR_DUPE_NAME = "Duplicate Portal name found on this portal!";
063:
064: /** . */
065: private static final String ERROR_EMPTY_NAME = "Portal name cannot be blank!";
066:
067: public PortalObjectManagerBean getPortalObjectManager() {
068: return pomgr;
069: }
070:
071: public void setPortalObjectManager(
072: PortalObjectManagerBean portalObjectManager) {
073: this .pomgr = portalObjectManager;
074: }
075:
076: public String getPortalName() {
077: return portalName;
078: }
079:
080: public void setPortalName(String portalName) {
081: this .portalName = portalName;
082: }
083:
084: public String getDefaultObjectName() {
085: return pomgr.getSelectedObject().getDeclaredProperty(
086: PortalObject.PORTAL_PROP_DEFAULT_OBJECT_NAME);
087: }
088:
089: public void setDefaultObjectName(String defaultObjectName) {
090: if (defaultObjectName != null && !defaultObjectName.equals("")) {
091: pomgr.getSelectedObject().setDeclaredProperty(
092: PortalObject.PORTAL_PROP_DEFAULT_OBJECT_NAME,
093: defaultObjectName);
094: } else if (defaultObjectName == null
095: || defaultObjectName.equals("")) {
096: pomgr.getSelectedObject().setDeclaredProperty(
097: PortalObject.PORTAL_PROP_DEFAULT_OBJECT_NAME, null);
098: }
099:
100: }
101:
102: /**
103: * Checks for duplicate portal names on the portal instance. Blank page names are not allowed and are controlled by
104: * the required attribute in the presentation page.
105: *
106: * @param context
107: * @param toValidate
108: * @param value
109: */
110: public void validatePortalName(FacesContext context,
111: UIComponent toValidate, Object value) {
112: String portalName = (String) value;
113:
114: // check for empty string
115: if (portalName.startsWith(" ")) {
116: FacesMessage message = new FacesMessage(
117: FacesMessage.SEVERITY_ERROR,
118: PortalAction.ERROR_EMPTY_NAME,
119: PortalAction.ERROR_EMPTY_NAME);
120: throw new ValidatorException(message);
121: }
122:
123: // Check for duplicate child name
124: if (pomgr.getSelectedObject().getChild(portalName) != null) {
125: FacesMessage message = new FacesMessage(
126: FacesMessage.SEVERITY_ERROR,
127: PortalAction.ERROR_DUPE_NAME,
128: PortalAction.ERROR_DUPE_NAME);
129: throw new ValidatorException(message);
130: }
131: }
132:
133: public void addPortal() {
134: try {
135: PortalContainer portalContainer = (PortalContainer) pomgr
136: .getSelectedObject();
137: Portal portal = portalContainer.createPortal(portalName);
138: DomainConfigurator configurator = pomgr
139: .getDomainConfigurator();
140:
141: // Initial portal permissions
142: Set actions = new HashSet();
143: actions.add(PortalObjectPermission.VIEW_RECURSIVE_ACTION);
144: actions
145: .add(PortalObjectPermission.PERSONALIZE_RECURSIVE_ACTION);
146: RoleSecurityBinding binding = new RoleSecurityBinding(
147: actions, SecurityConstants.UNCHECKED_ROLE_NAME);
148: Set constraints = Collections.singleton(binding);
149: configurator.setSecurityBindings(portal.getId().toString(
150: PortalObjectPath.CANONICAL_FORMAT), constraints);
151:
152: // We need to add initial layout sets to avoid problems...
153: portal.setDeclaredProperty(
154: ThemeConstants.PORTAL_PROP_LAYOUT, "generic");
155: // portal.setDeclaredProperty(ThemeConstants.PORTAL_PROP_THEME, "Nphalanx");
156: portal
157: .setDeclaredProperty(
158: ThemeConstants.PORTAL_PROP_RENDERSET,
159: "divRenderer");
160:
161: //
162: portal.getSupportedWindowStates()
163: .add(WindowState.MAXIMIZED);
164: portal.getSupportedWindowStates()
165: .add(WindowState.MINIMIZED);
166: portal.getSupportedWindowStates().add(WindowState.NORMAL);
167:
168: //
169: portal.getSupportedModes().add(Mode.EDIT);
170: portal.getSupportedModes().add(Mode.HELP);
171: portal.getSupportedModes().add(Mode.VIEW);
172:
173: // Create the default page
174: Page page = portal.createPage("default");
175: constraints = Collections
176: .singleton(new RoleSecurityBinding(
177: PortalObjectPermission.VIEW_RECURSIVE_ACTION,
178: SecurityConstants.UNCHECKED_ROLE_NAME));
179: configurator.setSecurityBindings(page.getId().toString(
180: PortalObjectPath.CANONICAL_FORMAT), constraints);
181:
182: portal.setDeclaredProperty(
183: PortalObject.PORTAL_PROP_DEFAULT_OBJECT_NAME, page
184: .getName());
185:
186: } catch (Exception e) {
187: e.printStackTrace();
188: }
189: }
190: }
|