Author: chris.laprun(a)jboss.com
Date: 2008-12-17 18:27:39 -0500 (Wed, 17 Dec 2008)
New Revision: 12400
Added:
branches/JBoss_Portal_Branch_2_6/faces/src/main/org/jboss/portal/faces/util/JSFFunctor.java
Modified:
branches/JBoss_Portal_Branch_2_6/core-admin/src/main/org/jboss/portal/core/admin/ui/InstanceManagerBean.java
branches/JBoss_Portal_Branch_2_6/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/instances.xhtml
Log:
- JBPORTAL-2264, JBPORTAL-2259: Added id sanitization before using them as HTML ids, users
can still use names
with . or spaces... Display performance of instance list seems to suffer from it so
should investigate
optimization.
Modified:
branches/JBoss_Portal_Branch_2_6/core-admin/src/main/org/jboss/portal/core/admin/ui/InstanceManagerBean.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core-admin/src/main/org/jboss/portal/core/admin/ui/InstanceManagerBean.java 2008-12-17
20:38:08 UTC (rev 12399)
+++
branches/JBoss_Portal_Branch_2_6/core-admin/src/main/org/jboss/portal/core/admin/ui/InstanceManagerBean.java 2008-12-17
23:27:39 UTC (rev 12400)
@@ -25,6 +25,7 @@
import org.apache.commons.lang.StringEscapeUtils;
import org.jboss.portal.Mode;
+import org.jboss.portal.faces.util.JSFFunctor;
import org.jboss.portal.common.value.Value;
import org.jboss.portal.core.model.instance.Instance;
import org.jboss.portal.core.model.instance.InstanceContainer;
@@ -109,6 +110,20 @@
/** . */
private AuthorizationBean auth = new InstanceAuthorizationBean();
+ /** Removes white spaces from identifiers so that we can assign them to HTML id
attributes. */
+ private JSFFunctor idSanitizer = new JSFFunctor()
+ {
+ public Object get(Object parameter)
+ {
+ if (parameter instanceof String)
+ {
+ String id = (String)parameter;
+ return id.replaceAll("\\W|\\.", "_");
+ }
+ return null;
+ }
+ };
+
// Services accessors
public RoleModule getRoleModule()
@@ -141,6 +156,16 @@
this.domainConfigurator = domainConfigurator;
}
+ /**
+ * Functor acccess to sanitize identifiers.
+ *
+ * @return
+ */
+ public JSFFunctor getIdSanitizer()
+ {
+ return idSanitizer;
+ }
+
// Navigational state accessor
public int getPaginationSize()
Modified:
branches/JBoss_Portal_Branch_2_6/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/instances.xhtml
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/instances.xhtml 2008-12-17
20:38:08 UTC (rev 12399)
+++
branches/JBoss_Portal_Branch_2_6/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/instances.xhtml 2008-12-17
23:27:39 UTC (rev 12400)
@@ -26,8 +26,8 @@
<tr
class="#{instance.id == instancemgr.selectedId ?
'portlet-section-selected' : (status.index % 2 == 0 ?
'portlet-section-body' : 'portlet-section-alternate')}">
<td>
- <img src="#{instance.portlet.smallIconLocation}"
align="middle" style="margin:0 4px 0 0"/>
- <h:commandLink id="#{instance.id}"
action="#{instancemgr.selectInstance}">
+ <img src="#{instance.portlet.smallIconLocation}"
alt="icon" align="middle" style="margin:0 4px 0 0"/>
+ <h:commandLink
id="#{instancemgr.idSanitizer[instance.id]}"
action="#{instancemgr.selectInstance}">
<h:outputText value="#{instance.id}"/>
<f:param name="id"
value="#{instance.id}"/>
<f:param name="plugin" value="info"/>
@@ -36,18 +36,18 @@
<td>
<h:outputText value="#{instance.displayName}"/>
</td>
- <td><h:commandLink id="security-#{instance.id}"
action="#{instancemgr.selectInstance}"
styleClass="actionSecurity">
+ <td><h:commandLink
id="security-#{instancemgr.idSanitizer[instance.id]}"
action="#{instancemgr.selectInstance}"
styleClass="actionSecurity">
<f:param name="id"
value="#{instance.id}"/>
<f:param name="plugin" value="security"/>
#{bundle.SECURITY}
</h:commandLink> | <h:panelGroup
rendered="#{!
empty(instancemgr.selectedInstancesPrefs[instance.id])}">
- <h:commandLink id="preference-#{instance.id}"
+ <h:commandLink
id="preference-#{instancemgr.idSanitizer[instance.id]}"
action="#{instancemgr.selectInstance}"
styleClass="actionPreferences">
<f:param name="id"
value="#{instance.id}"/>
<f:param name="plugin"
value="preferences"/>
#{bundle.PREFERENCES}
- </h:commandLink> | </h:panelGroup><h:commandLink
id="delete-#{instance.id}" action="confirmDeleteInstance"
+ </h:commandLink> | </h:panelGroup><h:commandLink
id="delete-#{instancemgr.idSanitizer[instance.id]}"
action="confirmDeleteInstance"
styleClass="actionDelete"
actionListener="#{instancemgr.selectInstance}">
<f:param name="id"
value="#{instance.id}"/>
Added:
branches/JBoss_Portal_Branch_2_6/faces/src/main/org/jboss/portal/faces/util/JSFFunctor.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/faces/src/main/org/jboss/portal/faces/util/JSFFunctor.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_6/faces/src/main/org/jboss/portal/faces/util/JSFFunctor.java 2008-12-17
23:27:39 UTC (rev 12400)
@@ -0,0 +1,100 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2008, 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.faces.util;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.Collection;
+
+/**
+ * Allows to call a parameterized function in JSF EL expressions. See <a
href="http://wiki.apache.org/myfaces/Parameters_In_EL_Functions"...
+ * for more details. A better alternative would be to use JBoss-EL if it was available
from the standard JBoss
+ * repository...
+ *
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public abstract class JSFFunctor implements Map
+{
+ public int size()
+ {
+ return 0;
+ }
+
+ public boolean isEmpty()
+ {
+ return false;
+ }
+
+ public boolean containsKey(Object key)
+ {
+ return false;
+ }
+
+ public boolean containsValue(Object value)
+ {
+ return false;
+ }
+
+ /**
+ * This is where the functor works. Subclasses need to implement the function logic
here, the parameter being the
+ * specified parameter.
+ *
+ * @param parameter the value that will be used to compute the result of the function
we want to implement
+ * @return the result of the funtion for the specified value
+ */
+ public abstract Object get(Object parameter);
+
+ public Object put(Object key, Object value)
+ {
+ return null;
+ }
+
+ public Object remove(Object key)
+ {
+ return null;
+ }
+
+ public void putAll(Map m)
+ {
+ }
+
+ public void clear()
+ {
+ }
+
+ public Set keySet()
+ {
+ return null;
+ }
+
+ public Collection values()
+ {
+ return null;
+ }
+
+ public Set entrySet()
+ {
+ return null;
+ }
+}