[jboss-cvs] jboss-portal/core/src/main/org/jboss/portal/core/portlet/management/actions ...

Boleslaw Dawidowicz bdaw at o2.pl
Wed Jul 26 18:03:54 EDT 2006


  User: bdaw    
  Date: 06/07/26 18:03:54

  Added:       core/src/main/org/jboss/portal/core/portlet/management/actions 
                        AddPortalAction.java
  Log:
  management - adding portal and preview link
  
  Revision  Changes    Path
  1.1      date: 2006/07/26 22:03:54;  author: bdaw;  state: Exp;jboss-portal/core/src/main/org/jboss/portal/core/portlet/management/actions/AddPortalAction.java
  
  Index: AddPortalAction.java
  ===================================================================
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2005, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This 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 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software 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 this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
  package org.jboss.portal.core.portlet.management.actions;
  
  import org.jboss.portal.core.portlet.management.PortalObjectManagerBean;
  import org.jboss.portal.core.model.portal.PageContainer;
  import org.jboss.portal.core.model.portal.Page;
  import org.jboss.portal.core.model.portal.PortalObjectPermission;
  import org.jboss.portal.core.model.portal.Context;
  import org.jboss.portal.core.model.portal.Portal;
  import org.jboss.portal.security.spi.provider.DomainConfigurator;
  import org.jboss.portal.security.RoleSecurityBinding;
  import org.jboss.portal.security.SecurityConstants;
  import org.jboss.portal.theme.ThemeConstants;
  
  import javax.faces.context.FacesContext;
  import javax.faces.component.UIComponent;
  import javax.faces.application.FacesMessage;
  import javax.faces.validator.ValidatorException;
  import java.util.Set;
  import java.util.Collections;
  import java.util.HashSet;
  
  /**
   * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
   * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
   * @version $Revision: 1.1 $
   */
  public class AddPortalAction
  {
  
     /**
      * .
      */
     private PortalObjectManagerBean pomgr;
  
     /**
      * .
      */
     private String portalName;
  
     /**
      * .
      */
     private static final String ERROR_DUPE_NAME = "Duplicate Portal name found on this portal!";
  
     /**
      * .
      */
     private static final String ERROR_EMPTY_NAME = "Portal name cannot be blank!";
  
     public PortalObjectManagerBean getPortalObjectManager()
     {
        return pomgr;
     }
  
     public void setPortalObjectManager(PortalObjectManagerBean portalObjectManager)
     {
        this.pomgr = portalObjectManager;
     }
  
     public String getPortalName()
     {
        return portalName;
     }
  
     public void setPortalName(String portalName)
     {
        this.portalName = portalName;
     }
  
     /**
      * Checks for duplicate portal names on the portal instance. Blank page names are not allowed and are controlled by the
      * required attribute in the presentation page.
      *
      * @param context
      * @param toValidate
      * @param value
      */
     public void validatePortalName(FacesContext context, UIComponent toValidate, Object value)
     {
        String portalName = (String)value;
  
        // check for empty string
        if (portalName.startsWith(" "))
        {
           FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, AddPortalAction.ERROR_EMPTY_NAME, AddPortalAction.ERROR_EMPTY_NAME);
           throw new ValidatorException(message);
        }
  
        // Check for duplicate child name
        if (pomgr.getSelectedObject().getChild(portalName) != null)
        {
           FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, AddPortalAction.ERROR_DUPE_NAME, AddPortalAction.ERROR_DUPE_NAME);
           throw new ValidatorException(message);
        }
     }
  
     public void execute()
     {
        try
        {
           Context context = (Context)pomgr.getSelectedObject();
           Portal portal = context.createPortal(portalName);
           DomainConfigurator configurator = pomgr.getDomainConfigurator();
  
           //initial portal permissions
           Set actions = new HashSet();
           actions.add(PortalObjectPermission.VIEW_ACTION);
           actions.add(PortalObjectPermission.PERSONALIZE_RECURSIVE_ACTION);
           RoleSecurityBinding binding = new RoleSecurityBinding(actions, SecurityConstants.UNCHECKED_ROLE_NAME);
           Set constraints = Collections.singleton(binding);
           configurator.setBindings(portal.getId(), constraints);
  
           //we need to add initial layout sets to avoid problems...
           portal.setDeclaredProperty(ThemeConstants.PORTAL_PROP_LAYOUT, "generic");
           portal.setDeclaredProperty(ThemeConstants.PORTAL_PROP_THEME, "Nphalanx");
           portal.setDeclaredProperty(ThemeConstants.PORTAL_PROP_RENDERSET, "divRenderer");
           portal.setDeclaredProperty(ThemeConstants.PORTAL_PROP_STRATEGY, "maximizedRegion");
  
        }
        catch (Exception e)
        {
           e.printStackTrace();
        }
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list