Author: chris.laprun(a)jboss.com
Date: 2009-02-18 19:48:22 -0500 (Wed, 18 Feb 2009)
New Revision: 12834
Added:
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/Action.java
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/DisplayNameAction.java
Modified:
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/AddPageAction.java
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/CreateInstanceAction.java
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/PortalAction.java
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/PortalInstanceDisplayNameAction.java
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/PortalObjectDisplayNameAction.java
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/PropertyAction.java
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/RenameAction.java
branches/JBoss_Portal_Branch_2_7/core-admin/src/resources/portal-admin-war/WEB-INF/classes/Resource.properties
branches/JBoss_Portal_Branch_2_7/core-admin/src/resources/portal-admin-war/WEB-INF/faces-config.xml
Log:
- JBPORTAL-2317: Added more validation to prevent creating objects with invalid names
+ What constitutes an invalid name should be documented somewhere... Right now valid
names match ParameterValidation.XSS_CHECK.
+ Re-factor JSF actions so that validation behavior and error message handling can be
factored in Action superclass.
+ Behavior associated with display names has been generified into DisplayNameAction with
PortalInstanceDNA and PortalObjectDNA
as children, which are not much simpler
+ More localization of error messages
- Needs more test, in particular, it doesn't seem like targeted error messages are
currently working (JSF id seems to be interfering)
Modified:
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java 2009-02-19
00:40:10 UTC (rev 12833)
+++
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java 2009-02-19
00:48:22 UTC (rev 12834)
@@ -1,6 +1,6 @@
/******************************************************************************
* JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * Copyright 2009, Red Hat Middleware, LLC, and individual *
* contributors as indicated by the @authors tag. See the *
* copyright.txt in the distribution for a full listing of *
* individual contributors. *
@@ -45,6 +45,7 @@
import org.jboss.portal.core.model.portal.PortalObjectPermission;
import org.jboss.portal.core.model.portal.Window;
import org.jboss.portal.faces.component.portlet.PortletEventEvent;
+import org.jboss.portal.faces.gui.JSFBeanContext;
import org.jboss.portal.identity.RoleModule;
import org.jboss.portal.portlet.Portlet;
import org.jboss.portal.portlet.PortletInvoker;
@@ -486,7 +487,7 @@
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO,
"Success",
- "'" + name + "' " + typeName + " was
successfully set as default " + typeName);
+ "'" + name + "' " + typeName + " was
successfully set as default " + typeName);
FacesContext.getCurrentInstance().addMessage("status", message);
}
}
@@ -559,7 +560,7 @@
// set the state from the id
PortalObjectId portalObjectId = null;
- if(id != null)
+ if (id != null)
{
portalObjectId = PortalObjectId.parse(id,
PortalObjectPath.LEGACY_BASE64_FORMAT);
}
@@ -681,7 +682,10 @@
//
selectedProperties = new PropertiesBean(this);
controlProperties = new ControlPropertiesBean(this);
+
+ // it'd be better if propertyAction was injected in faces-config.xml so that we
can also inject the shared beanContext
propertyAction = new PropertyAction(this);
+ propertyAction.setBeanContext(new JSFBeanContext());
//
theme = new ThemeBean(selectedObject);
@@ -800,10 +804,10 @@
public SelectItem[] getAvailableActions()
{
return new SelectItem[]{
- new SelectItem("view", "View"),
- new SelectItem("viewrecursive", "View Recursive"),
- new SelectItem("personalize", "Personalize"),
- new SelectItem("personalizerecursive", "Personalize
Recursive")
+ new SelectItem("view", "View"),
+ new SelectItem("viewrecursive", "View Recursive"),
+ new SelectItem("personalize", "Personalize"),
+ new SelectItem("personalizerecursive", "Personalize
Recursive")
};
}
Added:
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/Action.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/Action.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/Action.java 2009-02-19
00:48:22 UTC (rev 12834)
@@ -0,0 +1,97 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2009, Red Hat Middleware, LLC, 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.admin.ui.actions;
+
+import org.jboss.portal.common.util.ParameterValidation;
+import org.jboss.portal.faces.gui.ManagedBean;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public abstract class Action extends ManagedBean
+{
+ public static final String INVALID_NAME = "INVALID_NAME_ERROR";
+ public static final String DUPLICATE = "DUPLICATE_ERROR";
+ protected static final String INSTANCE_TYPE = "INSTANCE_TYPE";
+ protected static final String PAGE_TYPE = "PAGE_TYPE";
+ protected static final String PORTAL_TYPE = "PORTAL_TYPE";
+ protected static final String DISPLAY_NAME_TYPE = "DISPLAY_NAME_TYPE";
+ protected static final String PROPERTY_TYPE = "PROPERTY_TYPE";
+ protected static final String PORTAL_OBJECT_TYPE = "PORTAL_OBJECT_TYPE";
+
+ public String checkNameValidity(String name, String targetForErrorMessage)
+ {
+ if (ParameterValidation.isNullOrEmpty(name))
+ {
+ beanContext.createTargetedErrorMessage(targetForErrorMessage, INVALID_NAME,
name, getLocalizedType());
+ return null;
+ }
+ else
+ {
+ // Trim name
+ name = name.trim();
+
+ ParameterValidation.sanitizeFromPatternWithHandler(name,
ParameterValidation.XSS_CHECK,
+ new MessageValidationHandler(null, targetForErrorMessage, name));
+
+ // Check for duplicate
+ if (isAlreadyExisting(name))
+ {
+ beanContext.createTargetedErrorMessage(targetForErrorMessage, DUPLICATE,
name, getLocalizedType());
+ return null;
+ }
+
+ return name;
+ }
+ }
+
+ private String getLocalizedType()
+ {
+ return beanContext.getMessageFromBundle(getObjectTypeName());
+ }
+
+ protected abstract String getObjectTypeName();
+
+ public abstract boolean isAlreadyExisting(String objectName);
+
+ private class MessageValidationHandler extends
ParameterValidation.ValidationErrorHandler
+ {
+ private String targetForErrorMessage;
+ private String validatedName;
+
+ private MessageValidationHandler(String defaultValue, String targetForErrorMessage,
String validatedName)
+ {
+ super(defaultValue);
+ this.targetForErrorMessage = targetForErrorMessage;
+ this.validatedName = validatedName;
+ }
+
+ protected String internalValidationErrorHandling(String s)
+ {
+ beanContext.createTargetedErrorMessage(targetForErrorMessage, INVALID_NAME,
validatedName, getLocalizedType());
+ return null;
+ }
+ }
+}
Modified:
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/AddPageAction.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/AddPageAction.java 2009-02-19
00:40:10 UTC (rev 12833)
+++
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/AddPageAction.java 2009-02-19
00:48:22 UTC (rev 12834)
@@ -1,6 +1,6 @@
/******************************************************************************
* JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * Copyright 2009, Red Hat Middleware, LLC, and individual *
* contributors as indicated by the @authors tag. See the *
* copyright.txt in the distribution for a full listing of *
* individual contributors. *
@@ -26,31 +26,16 @@
import org.jboss.portal.core.model.portal.Page;
import org.jboss.portal.core.model.portal.PageContainer;
-import javax.faces.application.FacesMessage;
-import javax.faces.context.FacesContext;
-
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision$
*/
-public class AddPageAction
+public class AddPageAction extends Action
{
/** . */
private static final Logger log = Logger.getLogger(AddPageAction.class);
- /** . */
- private static final String ERROR_DUPE_NAME = "Duplicate Page name found on this
portal!";
-
- /** . */
- private static final String ERROR_EMPTY_NAME = "Page name cannot be
blank!";
-
- /** . */
- private static final String ERROR_NO_NAME = "Page name not specified!";
-
- /** . */
- private static final String ERROR_INTERNAL_ERROR = "An internal error
happened!";
-
/** The page container that will create the child. */
public PageContainer pageContainer;
@@ -65,31 +50,9 @@
public void execute()
{
- FacesMessage message = null;
-
- //
- if (pageName == null)
+ pageName = checkNameValidity(pageName, messageTarget);
+ if (pageName != null)
{
- message = new FacesMessage(FacesMessage.SEVERITY_ERROR, ERROR_NO_NAME,
ERROR_NO_NAME);
- }
- else
- {
- pageName = pageName.trim();
-
- //
- if (pageName.length() == 0)
- {
- message = new FacesMessage(FacesMessage.SEVERITY_ERROR, ERROR_EMPTY_NAME,
ERROR_EMPTY_NAME);
- }
- else if (pageContainer.getChild(pageName) != null)
- {
- message = new FacesMessage(FacesMessage.SEVERITY_ERROR, ERROR_DUPE_NAME,
ERROR_DUPE_NAME);
- }
- }
-
- //
- if (message == null)
- {
try
{
Page page = pageContainer.createPage(pageName);
@@ -102,16 +65,10 @@
}
catch (Exception e)
{
- log.error("An error happened during page creation", e);
- message = new FacesMessage(FacesMessage.SEVERITY_ERROR, ERROR_INTERNAL_ERROR,
ERROR_INTERNAL_ERROR);
+ log.error("An error occurred during page creation", e);
+ beanContext.createErrorMessageFrom(messageTarget, e);
}
}
-
- //
- if (message != null && messageTarget != null)
- {
- FacesContext.getCurrentInstance().addMessage(messageTarget, message);
- }
}
public interface Listener
@@ -148,4 +105,14 @@
{
this.listener = listener;
}
+
+ protected String getObjectTypeName()
+ {
+ return PAGE_TYPE;
+ }
+
+ public boolean isAlreadyExisting(String objectName)
+ {
+ return pageContainer.getChild(objectName) != null;
+ }
}
Modified:
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/CreateInstanceAction.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/CreateInstanceAction.java 2009-02-19
00:40:10 UTC (rev 12833)
+++
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/CreateInstanceAction.java 2009-02-19
00:48:22 UTC (rev 12834)
@@ -1,6 +1,6 @@
/******************************************************************************
* JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * Copyright 2009, Red Hat Middleware, LLC, and individual *
* contributors as indicated by the @authors tag. See the *
* copyright.txt in the distribution for a full listing of *
* individual contributors. *
@@ -31,8 +31,6 @@
import org.jboss.portal.security.SecurityConstants;
import org.jboss.portal.security.spi.provider.DomainConfigurator;
-import javax.faces.application.FacesMessage;
-import javax.faces.context.FacesContext;
import java.util.Collections;
import java.util.Set;
@@ -40,7 +38,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision$
*/
-public class CreateInstanceAction
+public class CreateInstanceAction extends Action
{
/** . */
@@ -51,6 +49,7 @@
/** . */
private InstanceManagerBean instanceMgr;
+ private static final String MESSAGE_TARGET =
"add_instance_form:instanceId";
public String getInstanceId()
{
@@ -84,40 +83,10 @@
public String execute()
{
- FacesContext faces = FacesContext.getCurrentInstance();
-
// Validate instance id
+ instanceId = checkNameValidity(instanceId, MESSAGE_TARGET);
if (instanceId == null)
{
- FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "No
instance id!", null);
- faces.addMessage("add_instance_form:instanceId", message);
- }
- else
- {
- // Trim name
- instanceId = instanceId.trim();
-
- // Check for empty string
- if (instanceId.length() == 0)
- {
- FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
"Instance id cannot be blank!", null);
- faces.addMessage("add_instance_form:instanceId", message);
- }
- else
- {
- // Check for duplicate instance
- Instance instance =
instanceMgr.getInstanceContainer().getDefinition(instanceId);
- if (instance != null)
- {
- FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
"An instance with the id " + instanceId + " already exist!", null);
- faces.addMessage("add_instance_form:instanceId", message);
- }
- }
- }
-
- //
- if (faces.getMessages().hasNext())
- {
return null;
}
@@ -125,8 +94,7 @@
Portlet portlet = portletMgr.getSelectedPortlet();
if (portlet == null)
{
- FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "No
portlet was selected!", null);
- faces.addMessage("add_instance_form:instanceId", message);
+ beanContext.createTargetedErrorMessage(MESSAGE_TARGET,
"NO_SELECTED_PORTLET_ERROR");
return null;
}
else
@@ -152,10 +120,20 @@
}
catch (Exception e)
{
- FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "An
unexpected error happened!", null);
- faces.addMessage("add_instance_form:instanceId", message);
+ log.error("An error occurred during instance creation.", e);
+ beanContext.createErrorMessageFrom(MESSAGE_TARGET, e);
return null;
}
}
}
+
+ protected String getObjectTypeName()
+ {
+ return INSTANCE_TYPE;
+ }
+
+ public boolean isAlreadyExisting(String objectName)
+ {
+ return instanceMgr.getInstanceContainer().getDefinition(objectName) != null;
+ }
}
Added:
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/DisplayNameAction.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/DisplayNameAction.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/DisplayNameAction.java 2009-02-19
00:48:22 UTC (rev 12834)
@@ -0,0 +1,182 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2009, Red Hat Middleware, LLC, 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.admin.ui.actions;
+
+import org.jboss.portal.common.i18n.LocaleFormat;
+import org.jboss.portal.common.i18n.LocalizedString;
+import org.jboss.portal.common.util.ConversionException;
+import org.jboss.portal.core.admin.ui.DisplayNameBean;
+import org.jboss.portal.core.model.HasDisplayName;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.SortedMap;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public abstract class DisplayNameAction extends Action
+{
+ protected Object managerBean;
+ protected String newLocale;
+ protected String newText;
+ protected DisplayNameBean displayNameBean;
+ protected HasDisplayName target;
+
+ public Object getManagerBean()
+ {
+ return managerBean;
+ }
+
+ public void setManagerBean(Object managerBean)
+ {
+ checkManagerBean(managerBean);
+ this.managerBean = managerBean;
+ }
+
+ public String getNewText()
+ {
+ return newText;
+ }
+
+ public void setNewText(String newText)
+ {
+ this.newText = newText;
+ }
+
+ public SortedMap getLocales()
+ {
+ return getDisplayNameBean().getLocales();
+ }
+
+ public String getNewLocale()
+ {
+ return newLocale;
+ }
+
+ public void setNewLocale(String newLocale)
+ {
+ this.newLocale = newLocale;
+ }
+
+ public DisplayNameBean getDisplayNameBean()
+ {
+ if (displayNameBean == null)
+ {
+ displayNameBean = new DisplayNameBean();
+ }
+ return displayNameBean;
+ }
+
+ public void setDisplayNameBean(DisplayNameBean displayNameBean)
+ {
+ this.displayNameBean = displayNameBean;
+ }
+
+ public void addDisplayName() throws ConversionException
+ {
+ newText = checkNameValidity(newText, null);
+ if (newText != null)
+ {
+ HasDisplayName hasDisplayName = getTarget();
+ Map map =
getDisplayNameBean().createLocalizedStringMap(LocaleFormat.DEFAULT.getLocale(newLocale),
hasDisplayName.getDisplayName(), newText);
+ LocalizedString newLocalizedString = new LocalizedString(map, Locale.ENGLISH);
+ target.setDisplayName(newLocalizedString);
+ }
+ }
+
+ public List<DisplayNameBean.Value> getCurrentLocales()
+ {
+ target = getTarget();
+ if (target != null && target.getDisplayName() != null)
+ {
+ return
(List<DisplayNameBean.Value>)getDisplayNameBean().populateCurrentLocales(target.getDisplayName().getValues());
+ }
+ return null;
+ }
+
+ public void editDisplayName()
+ {
+ String locale = beanContext.getParameter("locale");
+ String editAction = beanContext.getParameter("editAction");
+
+ target = getTarget();
+ LocalizedString displayName = target.getDisplayName();
+ Map<Locale, String> map = new HashMap<Locale, String>();
+ if (displayName != null)
+ {
+ Map<Locale, LocalizedString.Value> oldMap = displayName.getValues();
+ Collection<LocalizedString.Value> values = oldMap.values();
+ if (editAction.equals("delete"))
+ {
+ for (LocalizedString.Value value : values)
+ {
+ if (!value.getLocale().toString().equals(locale))
+ {
+ map.put(value.getLocale(), value.getString());
+ }
+ }
+ }
+ if (editAction.equals("rename"))
+ {
+ for (LocalizedString.Value value : values)
+ {
+ map.put(value.getLocale(), value.getString());
+ if (value.getLocale().toString().equals(locale))
+ {
+ newText = value.getString();
+ newLocale = value.getLocale().getLanguage();
+ }
+ }
+ }
+ }
+ LocalizedString newLocalizedString = new LocalizedString(map, Locale.ENGLISH);
+ target.setDisplayName(newLocalizedString);
+ }
+
+ public String editDisplayNames() throws ConversionException
+ {
+ getTarget();
+ getCurrentLocales();
+ return "editDisplayNames";
+ }
+
+ protected String getObjectTypeName()
+ {
+ return DISPLAY_NAME_TYPE;
+ }
+
+ public boolean isAlreadyExisting(String objectName)
+ {
+ return false; // we don't check for duplicates here
+ }
+
+ protected abstract HasDisplayName getTarget();
+
+ protected abstract void checkManagerBean(Object managerBean);
+}
Modified:
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/PortalAction.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/PortalAction.java 2009-02-19
00:40:10 UTC (rev 12833)
+++
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/PortalAction.java 2009-02-19
00:48:22 UTC (rev 12834)
@@ -1,6 +1,6 @@
/******************************************************************************
* JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * Copyright 2009, Red Hat Middleware, LLC, and individual *
* contributors as indicated by the @authors tag. See the *
* copyright.txt in the distribution for a full listing of *
* individual contributors. *
@@ -24,6 +24,7 @@
import org.jboss.portal.Mode;
import org.jboss.portal.WindowState;
+import org.jboss.portal.common.util.ParameterValidation;
import org.jboss.portal.core.admin.ui.PortalObjectManagerBean;
import org.jboss.portal.core.model.portal.Page;
import org.jboss.portal.core.model.portal.Portal;
@@ -36,10 +37,6 @@
import org.jboss.portal.security.spi.provider.DomainConfigurator;
import org.jboss.portal.theme.ThemeConstants;
-import javax.faces.application.FacesMessage;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.validator.ValidatorException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@@ -49,7 +46,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision$
*/
-public class PortalAction
+public class PortalAction extends Action
{
/** . */
@@ -58,14 +55,8 @@
/** . */
private String portalName;
- //private String defaultPageName;
+ private static final String MESSAGE_TARGET = "create-portal-form:name";
- /** . */
- 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;
@@ -93,87 +84,73 @@
public void setDefaultObjectName(String defaultObjectName)
{
- if (defaultObjectName != null && !defaultObjectName.equals(""))
+ if (!ParameterValidation.isNullOrEmpty(defaultObjectName))
{
pomgr.getSelectedObject().setDeclaredProperty(PortalObject.PORTAL_PROP_DEFAULT_OBJECT_NAME,
defaultObjectName);
}
- else if (defaultObjectName == null || defaultObjectName.equals(""))
+ else
{
pomgr.getSelectedObject().setDeclaredProperty(PortalObject.PORTAL_PROP_DEFAULT_OBJECT_NAME,
null);
}
}
-
- /**
- * 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,
PortalAction.ERROR_EMPTY_NAME, PortalAction.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,
PortalAction.ERROR_DUPE_NAME, PortalAction.ERROR_DUPE_NAME);
- throw new ValidatorException(message);
- }
- }
-
public void addPortal()
{
try
{
PortalContainer portalContainer = (PortalContainer)pomgr.getSelectedObject();
- Portal portal = portalContainer.createPortal(portalName);
- DomainConfigurator configurator = pomgr.getDomainConfigurator();
- // Initial portal permissions
- Set actions = new HashSet();
- actions.add(PortalObjectPermission.VIEW_RECURSIVE_ACTION);
- actions.add(PortalObjectPermission.PERSONALIZE_RECURSIVE_ACTION);
- RoleSecurityBinding binding = new RoleSecurityBinding(actions,
SecurityConstants.UNCHECKED_ROLE_NAME);
- Set constraints = Collections.singleton(binding);
-
configurator.setSecurityBindings(portal.getId().toString(PortalObjectPath.CANONICAL_FORMAT),
constraints);
+ portalName = checkNameValidity(portalName, MESSAGE_TARGET);
+ if (portalName != null)
+ {
+ Portal portal = portalContainer.createPortal(portalName);
+ DomainConfigurator configurator = pomgr.getDomainConfigurator();
- // 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");
+ // Initial portal permissions
+ Set actions = new HashSet();
+ actions.add(PortalObjectPermission.VIEW_RECURSIVE_ACTION);
+ actions.add(PortalObjectPermission.PERSONALIZE_RECURSIVE_ACTION);
+ RoleSecurityBinding binding = new RoleSecurityBinding(actions,
SecurityConstants.UNCHECKED_ROLE_NAME);
+ Set constraints = Collections.singleton(binding);
+
configurator.setSecurityBindings(portal.getId().toString(PortalObjectPath.CANONICAL_FORMAT),
constraints);
- //
- portal.getSupportedWindowStates().add(WindowState.MAXIMIZED);
- portal.getSupportedWindowStates().add(WindowState.MINIMIZED);
- portal.getSupportedWindowStates().add(WindowState.NORMAL);
+ // We need to add initial layout sets to avoid problems...
+ portal.setDeclaredProperty(ThemeConstants.PORTAL_PROP_LAYOUT,
"generic");
+ portal.setDeclaredProperty(ThemeConstants.PORTAL_PROP_RENDERSET,
"divRenderer");
- //
- portal.getSupportedModes().add(Mode.EDIT);
- portal.getSupportedModes().add(Mode.HELP);
- portal.getSupportedModes().add(Mode.VIEW);
+ //
+ portal.getSupportedWindowStates().add(WindowState.MAXIMIZED);
+ portal.getSupportedWindowStates().add(WindowState.MINIMIZED);
+ portal.getSupportedWindowStates().add(WindowState.NORMAL);
- // Create the default page
- Page page = portal.createPage("default");
- constraints = Collections.singleton(new
RoleSecurityBinding(PortalObjectPermission.VIEW_RECURSIVE_ACTION,
SecurityConstants.UNCHECKED_ROLE_NAME));
-
configurator.setSecurityBindings(page.getId().toString(PortalObjectPath.CANONICAL_FORMAT),
constraints);
+ //
+ portal.getSupportedModes().add(Mode.EDIT);
+ portal.getSupportedModes().add(Mode.HELP);
+ portal.getSupportedModes().add(Mode.VIEW);
- portal.setDeclaredProperty(PortalObject.PORTAL_PROP_DEFAULT_OBJECT_NAME,
page.getName());
+ // Create the default page
+ Page page = portal.createPage("default");
+ constraints = Collections.singleton(new
RoleSecurityBinding(PortalObjectPermission.VIEW_RECURSIVE_ACTION,
SecurityConstants.UNCHECKED_ROLE_NAME));
+
configurator.setSecurityBindings(page.getId().toString(PortalObjectPath.CANONICAL_FORMAT),
constraints);
+ portal.setDeclaredProperty(PortalObject.PORTAL_PROP_DEFAULT_OBJECT_NAME,
page.getName());
+ }
}
catch (Exception e)
{
- e.printStackTrace();
+ log.error("An error occurred during portal creation.", e);
+ beanContext.createErrorMessageFrom(MESSAGE_TARGET, e);
}
}
+
+ protected String getObjectTypeName()
+ {
+ return PORTAL_TYPE;
+ }
+
+ public boolean isAlreadyExisting(String objectName)
+ {
+ return pomgr.getSelectedObject().getChild(objectName) != null;
+ }
}
Modified:
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/PortalInstanceDisplayNameAction.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/PortalInstanceDisplayNameAction.java 2009-02-19
00:40:10 UTC (rev 12833)
+++
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/PortalInstanceDisplayNameAction.java 2009-02-19
00:48:22 UTC (rev 12834)
@@ -1,6 +1,6 @@
/******************************************************************************
* JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * Copyright 2009, Red Hat Middleware, LLC, and individual *
* contributors as indicated by the @authors tag. See the *
* copyright.txt in the distribution for a full listing of *
* individual contributors. *
@@ -22,199 +22,27 @@
******************************************************************************/
package org.jboss.portal.core.admin.ui.actions;
-import org.jboss.portal.common.i18n.LocaleFormat;
-import org.jboss.portal.common.i18n.LocalizedString;
-import org.jboss.portal.common.util.ConversionException;
-import org.jboss.portal.core.admin.ui.DisplayNameBean;
import org.jboss.portal.core.admin.ui.InstanceManagerBean;
-import org.jboss.portal.core.model.instance.Instance;
+import org.jboss.portal.core.model.HasDisplayName;
-import javax.faces.application.FacesMessage;
-import javax.faces.context.FacesContext;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.SortedMap;
-
/**
* @author <a href="mailto:whales@redhat.com">Wesley Hales</a>
* @version $Revision: 630 $
*/
-public class PortalInstanceDisplayNameAction
+public class PortalInstanceDisplayNameAction extends DisplayNameAction
{
- private Instance selectedInstance;
-
- public Object bean;
-
- private String newLocale;
-
- private String newText;
-
- private SortedMap locales;
-
- private String displayNameByLocale;
-
- private InstanceManagerBean instanceManager;
-
- private DisplayNameBean displayNameBean;
-
- public Object getBean()
+ protected HasDisplayName getTarget()
{
- return bean;
- }
+ target = ((InstanceManagerBean)managerBean).getSelectedInstance();
- public void setBean(Object bean)
- {
- this.bean = bean;
+ return target;
}
- public void addDisplayName() throws ConversionException
+ protected void checkManagerBean(Object managerBean)
{
- if (newText != null)
+ if (!(managerBean instanceof InstanceManagerBean))
{
- Instance instance = getSelectedInstance();
- Map map =
getDisplayNameBean().createLocalizedStringMap(LocaleFormat.DEFAULT.getLocale(newLocale),instance.getDisplayName(),newText);
- LocalizedString newLocalizedString = new LocalizedString(map, Locale.ENGLISH);
- selectedInstance.setDisplayName(newLocalizedString);
+ throw new IllegalArgumentException("Illegal manager bean property for
PortalInstanceDisplayNameAction. Expecting an InstanceManagerBean instance. Got " +
managerBean);
}
- else
- {
- FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "You
must enter a name", "You must enter a name");
- FacesContext.getCurrentInstance().addMessage("status", message);
- }
}
-
- public Instance getSelectedInstance()
- {
- if (instanceManager instanceof InstanceManagerBean)
- {
- selectedInstance = instanceManager.getSelectedInstance();
- }
- return selectedInstance;
- }
-
- public void setSelectedInstance(Instance selectedInstance)
- {
- this.selectedInstance = selectedInstance;
- }
-
- public String getNewText()
- {
- return newText;
- }
-
- public void setNewText(String newText)
- {
- this.newText = newText;
- }
-
- public SortedMap getLocales()
- {
- return getDisplayNameBean().getLocales();
- }
-
- public void setLocales(SortedMap locales)
- {
- this.locales = locales;
- }
-
- public String getNewLocale()
- {
- return newLocale;
- }
-
- public void setNewLocale(String newLocale)
- {
- this.newLocale = newLocale;
- }
-
- public List<DisplayNameBean.Value> getCurrentLocales()
- {
- selectedInstance = getSelectedInstance();
- if (selectedInstance != null && selectedInstance.getDisplayName() != null)
- {
- List<DisplayNameBean.Value> currentLocales =
getDisplayNameBean().populateCurrentLocales(selectedInstance.getDisplayName().getValues());
-
- return currentLocales;
- }
- return null;
- }
-
- public void editDisplayName()
- {
- String locale = getFacesParam("locale");
- String editAction = getFacesParam("editAction");
-
- Instance selectedInstance = getSelectedInstance();
- LocalizedString displayName = selectedInstance.getDisplayName();
- Map<Locale, String> map = new HashMap<Locale, String>();
- if (displayName != null)
- {
- Map<Locale, LocalizedString.Value> oldMap = displayName.getValues();
- Collection<LocalizedString.Value> values = oldMap.values();
- if (editAction.equals("delete"))
- {
- for (LocalizedString.Value value : values)
- {
- if (!value.getLocale().toString().equals(locale.toString()))
- {
- map.put(value.getLocale(), value.getString());
- }
- }
- }
- if (editAction.equals("rename"))
- {
- for (LocalizedString.Value value : values)
- {
- map.put(value.getLocale(), value.getString());
- if (value.getLocale().toString().equals(locale.toString()))
- {
- newText = value.getString();
- newLocale = value.getLocale().getLanguage();
- }
- }
- }
- }
- LocalizedString newLocalizedString = new LocalizedString(map, Locale.ENGLISH);
- selectedInstance.setDisplayName(newLocalizedString);
- }
-
-
- public String getFacesParam(String param)
- {
- return
FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(param);
- }
-
-
- public String editDisplayNames() throws ConversionException
- {
- getSelectedInstance();
- getCurrentLocales();
- return "editDisplayNames";
- }
-
- public InstanceManagerBean getInstanceManager()
- {
- return instanceManager;
- }
-
- public void setInstanceManager(InstanceManagerBean instanceManager)
- {
- this.instanceManager = instanceManager;
- }
-
- public DisplayNameBean getDisplayNameBean()
- {
- if(displayNameBean == null){
- displayNameBean = new DisplayNameBean();
- }
- return displayNameBean;
- }
-
- public void setDisplayNameBean(DisplayNameBean displayNameBean)
- {
- this.displayNameBean = displayNameBean;
- }
}
Modified:
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/PortalObjectDisplayNameAction.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/PortalObjectDisplayNameAction.java 2009-02-19
00:40:10 UTC (rev 12833)
+++
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/PortalObjectDisplayNameAction.java 2009-02-19
00:48:22 UTC (rev 12834)
@@ -1,6 +1,6 @@
/******************************************************************************
* JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * Copyright 2009, Red Hat Middleware, LLC, and individual *
* contributors as indicated by the @authors tag. See the *
* copyright.txt in the distribution for a full listing of *
* individual contributors. *
@@ -22,188 +22,28 @@
******************************************************************************/
package org.jboss.portal.core.admin.ui.actions;
-import org.jboss.portal.common.i18n.LocaleFormat;
-import org.jboss.portal.common.i18n.LocalizedString;
-import org.jboss.portal.common.util.ConversionException;
-import org.jboss.portal.core.admin.ui.DisplayNameBean;
import org.jboss.portal.core.admin.ui.PortalObjectManagerBean;
-import org.jboss.portal.core.model.portal.PortalObject;
+import org.jboss.portal.core.model.HasDisplayName;
-import javax.faces.application.FacesMessage;
-import javax.faces.context.FacesContext;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.SortedMap;
-
/**
* @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
* @author <a href="mailto:whales@redhat.com">Wesley Hales</a>
* @version $Revision$
*/
-public class PortalObjectDisplayNameAction {
-
- private PortalObject selectedObject;
-
- public Object bean;
-
- private String newLocale;
-
- private String newText;
-
- private SortedMap locales;
-
- private String displayNameByLocale;
-
- private DisplayNameBean displayNameBean;
-
- public Object getBean()
+public class PortalObjectDisplayNameAction extends DisplayNameAction
+{
+ protected HasDisplayName getTarget()
{
- return bean;
+ target = ((PortalObjectManagerBean)managerBean).getSelectedObject();
+ return target;
}
- public void setBean(Object bean)
+ protected void checkManagerBean(Object managerBean)
{
- this.bean = bean;
- }
-
- public void addDisplayName() throws ConversionException
- {
- if (newText != null)
+ if (!(managerBean instanceof PortalObjectManagerBean))
{
- PortalObject portalObject = getSelectedObject();
- Map map =
getDisplayNameBean().createLocalizedStringMap(LocaleFormat.DEFAULT.getLocale(newLocale),portalObject.getDisplayName(),newText);
- LocalizedString newLocalizedString = new LocalizedString(map, Locale.ENGLISH);
- portalObject.setDisplayName(newLocalizedString);
+ throw new IllegalArgumentException("Illegal manager bean property for
PortalObjectDisplayNameAction. Expecting a PortalObjectManagerBean instance. Got " +
managerBean);
}
- else
- {
- FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "You
must enter a name", "You must enter a name");
- FacesContext.getCurrentInstance().addMessage("status", message);
- }
}
-
-
- public PortalObject getSelectedObject()
- {
- if (bean instanceof PortalObjectManagerBean)
- {
- selectedObject = ((PortalObjectManagerBean) bean).getSelectedObject();
- }
- return selectedObject;
- }
-
- public void setSelectedObject(PortalObject selectedObject)
- {
- this.selectedObject = selectedObject;
- }
-
- public String getNewText()
- {
- return newText;
- }
-
- public void setNewText(String newText)
- {
- this.newText = newText;
- }
-
- public String getNewLocale()
- {
- return newLocale;
- }
-
- public void setNewLocale(String newLocale)
- {
- this.newLocale = newLocale;
- }
-
- public SortedMap getLocales()
- {
- return getDisplayNameBean().getLocales();
- }
-
- public void setLocales(SortedMap locales)
- {
- this.locales = locales;
- }
-
- public List<DisplayNameBean.Value> getCurrentLocales()
- {
- selectedObject = getSelectedObject();
- if (selectedObject != null && selectedObject.getDisplayName() != null)
- {
- List<DisplayNameBean.Value> currentLocales =
getDisplayNameBean().populateCurrentLocales(selectedObject.getDisplayName().getValues());
- return currentLocales;
- }
- return null;
- }
-
- public void editDisplayName()
- {
- String locale = getFacesParam("locale");
- String editAction = getFacesParam("editAction");
-
- PortalObject portalObject = getSelectedObject();
- LocalizedString displayName = portalObject.getDisplayName();
- Map<Locale, String> map = new HashMap<Locale, String>();
- if (displayName != null)
- {
- Map<Locale, LocalizedString.Value> oldMap = displayName.getValues();
- Collection<LocalizedString.Value> values = oldMap.values();
- if (editAction.equals("delete"))
- {
- for (LocalizedString.Value value : values)
- {
- if (!value.getLocale().toString().equals(locale.toString()))
- {
- map.put(value.getLocale(), value.getString());
- }
- }
- }
- if (editAction.equals("rename"))
- {
- for (LocalizedString.Value value : values)
- {
- map.put(value.getLocale(), value.getString());
- if (value.getLocale().toString().equals(locale.toString()))
- {
- newText = value.getString();
- newLocale = value.getLocale().getLanguage();
- }
- }
- }
- }
- LocalizedString newLocalizedString = new LocalizedString(map, Locale.ENGLISH);
- selectedObject.setDisplayName(newLocalizedString);
- }
-
- public String getFacesParam(String param){
- return
FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(param);
- }
-
-
- public String editDisplayNames() throws ConversionException
- {
- getSelectedObject();
- getCurrentLocales();
- return "editDisplayNames";
- }
-
- public DisplayNameBean getDisplayNameBean()
- {
- if(displayNameBean == null){
- displayNameBean = new DisplayNameBean();
- }
- return displayNameBean;
- }
-
- public void setDisplayNameBean(DisplayNameBean displayNameBean)
- {
- this.displayNameBean = displayNameBean;
- }
-
}
Modified:
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/PropertyAction.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/PropertyAction.java 2009-02-19
00:40:10 UTC (rev 12833)
+++
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/PropertyAction.java 2009-02-19
00:48:22 UTC (rev 12834)
@@ -1,6 +1,6 @@
/******************************************************************************
* JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * Copyright 2009, Red Hat Middleware, LLC, and individual *
* contributors as indicated by the @authors tag. See the *
* copyright.txt in the distribution for a full listing of *
* individual contributors. *
@@ -24,18 +24,13 @@
import org.jboss.portal.core.admin.ui.PortalObjectManagerBean;
import org.jboss.portal.core.impl.model.portal.PortalObjectImpl;
+import org.jboss.portal.faces.gui.BeanContext;
-import javax.faces.application.FacesMessage;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.validator.ValidatorException;
-import java.util.Map;
-
/**
* @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
* @version $Revision$
*/
-public class PropertyAction
+public class PropertyAction extends Action
{
/** . */
@@ -50,8 +45,6 @@
/** . */
private String otherPropertyName;
- /** . */
- private static final String ERROR_EMPTY_NAME = "Property name cannot be
blank!";
public PropertyAction(PortalObjectManagerBean pomgr)
{
@@ -78,33 +71,19 @@
this.propertyValue = propertyValue;
}
-
- public void validatePropertyName(FacesContext context, UIComponent toValidate, Object
value)
- {
- String propertyName = (String)value;
-
- // check for empty string
- if (propertyName == null || propertyName.startsWith(" ") ||
propertyName.equals(""))
- {
- FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
PropertyAction.ERROR_EMPTY_NAME, PropertyAction.ERROR_EMPTY_NAME);
- throw new ValidatorException(message);
- }
- }
-
public void selectProperty()
{
}
public void removeProperty()
{
- Map pmap =
FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
- String name = (String)pmap.get("name");
+ String name = beanContext.getParameter("name");
((PortalObjectImpl)pomgr.getSelectedObject()).setDeclaredProperty(name, null);
}
public void updateProperty()
{
- String propertyName = otherPropertyName.trim();
+ String propertyName = checkNameValidity(otherPropertyName, BeanContext.STATUS);
String value = "";
//
if (propertyName.length() == 0 && selectedProperty != null)
@@ -115,7 +94,8 @@
//
if (propertyName.length() > 0)
{
- if (getPropertyValue() != null){
+ if (getPropertyValue() != null)
+ {
value = getPropertyValue().trim();
}
pomgr.getSelectedObject().setDeclaredProperty(propertyName, value);
@@ -131,4 +111,14 @@
{
this.otherPropertyName = otherPropertyName;
}
+
+ protected String getObjectTypeName()
+ {
+ return PROPERTY_TYPE;
+ }
+
+ public boolean isAlreadyExisting(String objectName)
+ {
+ return pomgr.getSelectedObject().getDeclaredProperty(objectName) != null;
+ }
}
Modified:
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/RenameAction.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/RenameAction.java 2009-02-19
00:40:10 UTC (rev 12833)
+++
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/RenameAction.java 2009-02-19
00:48:22 UTC (rev 12834)
@@ -1,6 +1,6 @@
/******************************************************************************
* JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * Copyright 2009, Red Hat Middleware, LLC, and individual *
* contributors as indicated by the @authors tag. See the *
* copyright.txt in the distribution for a full listing of *
* individual contributors. *
@@ -24,22 +24,17 @@
import org.jboss.portal.core.admin.ui.PortalObjectManagerBean;
import org.jboss.portal.core.admin.ui.dashboard.DashboardBean;
-import org.jboss.portal.core.model.portal.DuplicatePortalObjectException;
-import org.jboss.portal.core.model.portal.NoSuchPortalObjectException;
-import org.jboss.portal.core.model.portal.PageContainer;
import org.jboss.portal.core.model.portal.PortalObject;
import org.jboss.portal.core.model.portal.PortalObjectPath;
import org.jboss.portal.security.spi.provider.DomainConfigurator;
-import javax.faces.application.FacesMessage;
-import javax.faces.context.FacesContext;
import java.util.Set;
/**
* @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
* @version $Revision$
*/
-public class RenameAction
+public class RenameAction extends Action
{
private String newName;
@@ -49,6 +44,7 @@
private DomainConfigurator domainConfigurator;
private Object bean;
+ private static final String MESSAGE_TARGET = "renameForm:newName";
public void setNewName(String newName)
{
@@ -87,54 +83,49 @@
public String execute()
{
- PortalObject parent = pageContainer.getParent();
- PortalObject newObject = null;
- try
+ newName = checkNameValidity(newName, MESSAGE_TARGET);
+ if (newName != null)
{
- // TODO: Should be in a tx
+ PortalObject parent = pageContainer.getParent();
+ PortalObject newObject = null;
+ try
+ {
+ // TODO: Should be in a tx
- // Clone portal object
- newObject = pageContainer.copy(parent, newName, true);
+ // Clone portal object
+ newObject = pageContainer.copy(parent, newName, true);
- // Copy security settings
- Set set =
domainConfigurator.getSecurityBindings(pageContainer.getId().toString(PortalObjectPath.CANONICAL_FORMAT));
-
domainConfigurator.setSecurityBindings(newObject.getId().toString(PortalObjectPath.CANONICAL_FORMAT),
set);
+ // Copy security settings
+ Set set =
domainConfigurator.getSecurityBindings(pageContainer.getId().toString(PortalObjectPath.CANONICAL_FORMAT));
+
domainConfigurator.setSecurityBindings(newObject.getId().toString(PortalObjectPath.CANONICAL_FORMAT),
set);
- String defaultObject =
(String)parent.getDeclaredProperties().get(PortalObject.PORTAL_PROP_DEFAULT_OBJECT_NAME);
- if (pageContainer.getName().equals(defaultObject))
+ String defaultObject =
parent.getDeclaredProperties().get(PortalObject.PORTAL_PROP_DEFAULT_OBJECT_NAME);
+ if (pageContainer.getName().equals(defaultObject))
+ {
+ parent.setDeclaredProperty(PortalObject.PORTAL_PROP_DEFAULT_OBJECT_NAME,
newName);
+ }
+
+ // Destroy previous object
+ parent.destroyChild(pageContainer.getName());
+ }
+ catch (Exception e)
{
- parent.setDeclaredProperty(PortalObject.PORTAL_PROP_DEFAULT_OBJECT_NAME,
newName);
+ log.error("An error occurred while attempting to rename " +
pageContainer + "to " + newName);
+ beanContext.createErrorMessageFrom(MESSAGE_TARGET, e);
}
- // Destroy previous object
- parent.destroyChild(pageContainer.getName());
+ // TODO: This is not clean
+ if (bean instanceof PortalObjectManagerBean)
+ {
+ ((PortalObjectManagerBean)bean).selectObject(parent);
+ return "objects";
+ }
+ else if (bean instanceof DashboardBean)
+ {
+ ((DashboardBean)bean).selectedPageName = newObject.getName();
+ }
}
- catch (IllegalArgumentException e)
- {
- e.printStackTrace();
- }
- catch (DuplicatePortalObjectException e)
- {
- String message = "The name \"" + newName + "\" is
already used, please choose a different one";
- FacesContext.getCurrentInstance().addMessage("renameForm:newName", new
FacesMessage(FacesMessage.SEVERITY_ERROR, message, message));
- return null;
- }
- catch (NoSuchPortalObjectException e)
- {
- e.printStackTrace();
- }
- // TODO: This is not clean
- if (bean instanceof PortalObjectManagerBean)
- {
- ((PortalObjectManagerBean)bean).selectObject(parent);
- return "objects";
- }
- else if (bean instanceof DashboardBean)
- {
- ((DashboardBean)bean).selectedPageName = newObject.getName();
- }
-
return null;
}
@@ -148,5 +139,13 @@
this.bean = bean;
}
+ protected String getObjectTypeName()
+ {
+ return PORTAL_OBJECT_TYPE;
+ }
+ public boolean isAlreadyExisting(String objectName)
+ {
+ return pageContainer.getChild(objectName) != null;
+ }
}
Modified:
branches/JBoss_Portal_Branch_2_7/core-admin/src/resources/portal-admin-war/WEB-INF/classes/Resource.properties
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core-admin/src/resources/portal-admin-war/WEB-INF/classes/Resource.properties 2009-02-19
00:40:10 UTC (rev 12833)
+++
branches/JBoss_Portal_Branch_2_7/core-admin/src/resources/portal-admin-war/WEB-INF/classes/Resource.properties 2009-02-19
00:48:22 UTC (rev 12834)
@@ -1,6 +1,6 @@
################################################################################
# JBoss, a division of Red Hat #
-# Copyright 2006, Red Hat Middleware, LLC, and individual #
+# Copyright 2009, Red Hat Middleware, LLC, and individual #
# contributors as indicated by the @authors tag. See the #
# copyright.txt in the distribution for a full listing of #
# individual contributors. #
@@ -21,48 +21,7 @@
# 02110-1301 USA, or see the FSF site:
http://www.fsf.org. #
################################################################################
-PORTLET_INSTANCES=Portlet Instances
-INSTANCE_DELETE=instance Delete
-PORTLET_CAUSING_REFERENCING_NOT_ABLE=portlet instance causing windows referencing it to
not be able to display their content anymore
-ARE_YOU_SURE_DELETE=Are you sure you want to delete this portlet instance ?
-DASHBOARD_THEME_PROPERTIES=Dashboard theme properties
-CONFIGURE_DASHBOARD_SETTINGS=Configure dashboards settings
-DASHBOARDS=Dashboards
-ADD_DISPLAY_NAMES=Add Display Names
-CURRENT_DISPLAY_NAMES=Current Display Names
-SAVE=Save
-MANAGE=Manage
-PORTALS_NO_CAP=portals
-PORTAL=portal
-SUB_PORTALS=sub-portals
-PAGES_WITHIN=pages within
-CREATE_PORTAL_NAMED=Create a portal named
-PAGE_LAYOUT=Page layout
-SECURITY=Security
-THEME=Theme
-RENAME=Rename
-DISPLAY_NAMES=Display Names
-MANAGE_SUB_PAGES_WITHIN=Manage sub-pages within
-CREATE_PAGE_NAMED=Create a page named
-SET_PAGE_PERMISSIONS=Please set the page permissions
-PAGE_THEME_PROPERTIES=Page theme properties
-SET_PORTAL_PERMISSIONS=Please set the portal permissions
-PORTAL_THEME_PROPERTIES=Portal theme properties
-SETTINGS_ARE_INHERITED_BY_ALL_PAGES=These settings are inherited by all the pages and
windows of this portal. You may override these settings by selecting the appropriate value
on the respective Theme settings pages
-EVENT_LISTENER_BINDING=Event Listener Binding
-CHOOSE_ID_PORTALEVENTLISTENER=Choose the id of the PortalEventListener to bind to this
-SET_PERMISSIONS_FOR=Please set the permissions for the
-WINDOW_NO_CAP=window
-WINDOW_THEME_PROPERTIES=Window theme properties
-INSTANCE_ID=Instance id
-INSTANCE_NAME=Instance name
-ACTIONS=Actions
-PREFERENCES=Preferences
-PORTLET_DETAILS=portlet details
-ASSOCIATED_PORTLET_NOT_AVAILABLE=The associated portlet is not available
-PREFERENCES_NO_CAP=preferences
-SECURITY_SETTINGS=security settings
-MAKE_DEFAULT=Make Default
+ Default
MANAGE_WINDOWS_WITHIN=Manage windows within
PORTAL_OBJECTS=Portal Objects
PORTALS=Portals
@@ -320,8 +279,16 @@
COORDINATION_EVENT_CREATE_PREVIEW_STEP3=The produced window events will be wired to the
following destination event:
COORDINATION_EVENT_CREATE_PREVIEW_STEP4=for the following destination windows:
-
-
COORDINATION_WIRING=event wiring
COORDINATION_PARAMETER=parameter binding
COORDINATION_ALIAS=alias binding
+
+INVALID_NAME_ERROR=''{0}'' is an invalid {1} name: Cannot be null, empty
or contain '\' or '%5c'
+NO_SELECTED_PORTLET_ERROR=No portlet was selected!
+DUPLICATE_ERROR=A(n) {1} named ''{0}'' already exists!
+bean_support_unexpected_error=Unexpected error:
+bean_support_cause=Cause:
+
+INSTANCE_TYPE=instance
+PAGE_TYPE=page
+PORTAL_TYPE=portal
Modified:
branches/JBoss_Portal_Branch_2_7/core-admin/src/resources/portal-admin-war/WEB-INF/faces-config.xml
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core-admin/src/resources/portal-admin-war/WEB-INF/faces-config.xml 2009-02-19
00:40:10 UTC (rev 12833)
+++
branches/JBoss_Portal_Branch_2_7/core-admin/src/resources/portal-admin-war/WEB-INF/faces-config.xml 2009-02-19
00:48:22 UTC (rev 12834)
@@ -1,24 +1,24 @@
<?xml version="1.0"?>
<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ JBoss, a division of Red Hat ~
- ~ Copyright 2006, Red Hat Middleware, LLC, 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 ~
+ ~ Copyright 2009, Red Hat Middleware, LLC, 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. ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
@@ -29,7 +29,7 @@
<application>
<view-handler>
- org.jboss.portletbridge.application.PortletViewHandler
+ org.jboss.portletbridge.application.PortletViewHandler
</view-handler>
<state-manager>org.jboss.portletbridge.application.PortletStateManager</state-manager>
<message-bundle>Resource</message-bundle>
@@ -112,6 +112,11 @@
<property-name>portalObjectManager</property-name>
<value>#{sessionScope.portalobjectmgr}</value>
</managed-property>
+ <managed-property>
+ <property-name>beanContext</property-name>
+
<property-class>org.jboss.portal.faces.gui.BeanContext</property-class>
+ <value>#{beanContext}</value>
+ </managed-property>
</managed-bean>
<managed-bean>
<managed-bean-name>addPageAction</managed-bean-name>
@@ -129,6 +134,11 @@
<property-name>listener</property-name>
<value>#{sessionScope.dashboard}</value>
</managed-property>
+ <managed-property>
+ <property-name>beanContext</property-name>
+
<property-class>org.jboss.portal.faces.gui.BeanContext</property-class>
+ <value>#{beanContext}</value>
+ </managed-property>
</managed-bean>
<managed-bean>
<managed-bean-name>assignContentToWindowAction</managed-bean-name>
@@ -266,13 +276,17 @@
<property-name>instanceManager</property-name>
<value>#{sessionScope.instancemgr}</value>
</managed-property>
+ <managed-property>
+ <property-name>beanContext</property-name>
+
<property-class>org.jboss.portal.faces.gui.BeanContext</property-class>
+ <value>#{beanContext}</value>
+ </managed-property>
</managed-bean>
-
<!--
- | Dashboard beans
- -->
+ | Dashboard beans
+ -->
<managed-bean>
<managed-bean-name>dashboard</managed-bean-name>
@@ -336,9 +350,14 @@
<managed-bean-class>org.jboss.portal.core.admin.ui.actions.PortalObjectDisplayNameAction</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
- <property-name>bean</property-name>
+ <property-name>managerBean</property-name>
<value>#{portalobjectmgr}</value>
</managed-property>
+ <managed-property>
+ <property-name>beanContext</property-name>
+
<property-class>org.jboss.portal.faces.gui.BeanContext</property-class>
+ <value>#{beanContext}</value>
+ </managed-property>
</managed-bean>
<managed-bean>
@@ -346,9 +365,14 @@
<managed-bean-class>org.jboss.portal.core.admin.ui.actions.PortalInstanceDisplayNameAction</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
- <property-name>instanceManager</property-name>
+ <property-name>managerBean</property-name>
<value>#{sessionScope.instancemgr}</value>
</managed-property>
+ <managed-property>
+ <property-name>beanContext</property-name>
+
<property-class>org.jboss.portal.faces.gui.BeanContext</property-class>
+ <value>#{beanContext}</value>
+ </managed-property>
</managed-bean>
<managed-bean>
@@ -599,7 +623,7 @@
<component-type>org.jboss.portal.Portlet</component-type>
<component-class>org.jboss.portal.faces.component.portlet.UIPortlet</component-class>
</component>
-
+
<render-kit>
<renderer>
<component-family>javax.faces.Input</component-family>