Author: julien(a)jboss.com
Date: 2007-03-08 16:55:40 -0500 (Thu, 08 Mar 2007)
New Revision: 6605
Added:
trunk/core/src/main/org/jboss/portal/core/impl/model/content/AbstractContent.java
Modified:
trunk/common/src/main/org/jboss/portal/common/util/ParameterMap.java
trunk/common/src/main/org/jboss/portal/common/util/TypedMap.java
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/AssignWindowsAction.java
trunk/core-cms/src/main/org/jboss/portal/core/cms/content/CMSContent.java
trunk/core/src/main/org/jboss/portal/core/impl/model/content/generic/GenericContent.java
trunk/core/src/main/org/jboss/portal/core/impl/model/content/generic/GenericContentHandler.java
trunk/core/src/main/org/jboss/portal/core/impl/model/content/portlet/PortletContent.java
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/WindowImpl.java
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/content/GenericPortletContentRenderer.java
trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/PersistentRegistration.java
trunk/core/src/main/org/jboss/portal/core/model/content/Content.java
trunk/core/src/main/org/jboss/portal/core/model/content/spi/ContentState.java
trunk/core/src/main/org/jboss/portal/test/core/model/content/NullContent.java
trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectContainerTestCase.java
trunk/portlet/src/main/org/jboss/portal/portlet/PortletParameters.java
trunk/portlet/src/main/org/jboss/portal/portlet/state/AbstractPropertyMap.java
trunk/widget/src/main/org/jboss/portal/widget/Widget.java
trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java
trunk/widget/src/main/org/jboss/portal/widget/google/GGWidget.java
Log:
better support for widget configuration
Modified: trunk/common/src/main/org/jboss/portal/common/util/ParameterMap.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/ParameterMap.java 2007-03-08
20:14:20 UTC (rev 6604)
+++ trunk/common/src/main/org/jboss/portal/common/util/ParameterMap.java 2007-03-08
21:55:40 UTC (rev 6605)
@@ -36,15 +36,10 @@
/**
* Only accept non null string objects.
*
- * @throws NullPointerException if the value is null
* @throws ClassCastException if the value is not an instance of string
*/
- protected void assertKeyValidity(Object value) throws NullPointerException,
ClassCastException
+ protected void assertKeyValidity(Object value) throws ClassCastException
{
- if (value == null)
- {
- throw new NullPointerException("Key must not be null");
- }
if (value instanceof String == false)
{
throw new ClassCastException("Key should be a String");
@@ -62,10 +57,6 @@
*/
protected Object getInternalValue(Object value) throws NullPointerException,
ClassCastException, IllegalArgumentException
{
- if (value == null)
- {
- throw new NullPointerException("Value must not be null");
- }
if (value instanceof String[] == false)
{
throw new ClassCastException("Value should be a String[]");
@@ -85,11 +76,6 @@
return strings;
}
- protected Object getExternalValue(Object value)
- {
- return value;
- }
-
protected boolean internalValueEquals(Object left, Object right)
{
String[] valuesL = (String[])left;
Modified: trunk/common/src/main/org/jboss/portal/common/util/TypedMap.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/TypedMap.java 2007-03-08 20:14:20
UTC (rev 6604)
+++ trunk/common/src/main/org/jboss/portal/common/util/TypedMap.java 2007-03-08 21:55:40
UTC (rev 6605)
@@ -43,68 +43,143 @@
protected abstract Map getDelegate();
/**
- * @throws ClassCastException if the key is of an inappropriate type for this map
+ * Override to check the validity of the key, the default implementation is an empty
method.
+ *
+ * @throws ClassCastException if the class of the specified key prevents it from being
stored in this map
+ * @throws IllegalArgumentException if some aspect of this key prevents it from being
stored in this map
*/
- protected abstract void assertKeyValidity(Object key) throws ClassCastException;
+ protected void assertKeyValidity(Object key) throws IllegalArgumentException,
ClassCastException
+ {
+ }
/**
+ * Unwraps the key to the the internal key that will be stored in the map.
+ * This method calls the <code>assertKeyValidity(Object key)</code> and
returns
+ * the same key. It can be overriden to provide a customized key that will be used
+ * instead of the external key.
+ *
+ * @param key the key to unwrap
+ * @return the unwrapped key
+ * @throws ClassCastException if the class of the specified key prevents it from being
stored in this map
+ * @throws IllegalArgumentException if some aspect of this key prevents it from being
stored in this map
+ */
+ protected Object getInternalKey(Object key) throws IllegalArgumentException,
ClassCastException
+ {
+ assertKeyValidity(key);
+
+ //
+ return key;
+ }
+
+ /**
+ * Wrap the internal key into its external representation, by default returns the same
key.
+ * It can be overriden to provide a customized key that will be used instead of the
internal
+ * key.
+ */
+ protected Object getExternalKey(Object key)
+ {
+ return key;
+ }
+
+ private Object unwrapKey(Object externalKey) throws IllegalArgumentException,
ClassCastException, NullPointerException
+ {
+ if (externalKey == null)
+ {
+ throw new NullPointerException("No null key accepted");
+ }
+
+ //
+ Object internalKey = getInternalKey(externalKey);
+
+ //
+ if (internalKey == null)
+ {
+ throw new IllegalArgumentException("The provided key " + externalKey +
" was converted to a null key");
+ }
+
+ //
+ return internalKey;
+ }
+
+ private Object wrapKey(Object internalKey) throws IllegalStateException
+ {
+ if (internalKey == null)
+ {
+ throw new IllegalStateException("Got an internal null key");
+ }
+
+ //
+ Object externalKey = getExternalKey(internalKey);
+
+ //
+ if (externalKey == null)
+ {
+ throw new IllegalStateException("Converted an internal key to a null key
" + internalKey);
+ }
+
+ //
+ return externalKey;
+ }
+
+ /**
* Unwrap the value to the the internal value that will be stored in the map.
*
* @param value the value to unwrap
* @return the unwrapped value
* @throws ClassCastException if the class of the specified value prevents it from
being stored in this map
- * @throws IllegalArgumentException if some aspect of this key prevents it from being
stored in this map
+ * @throws IllegalArgumentException if some aspect of this value prevents it from
being stored in this map
*/
- protected abstract Object getInternalValue(Object value) throws
IllegalArgumentException, ClassCastException;
+ protected Object getInternalValue(Object value) throws IllegalArgumentException,
ClassCastException
+ {
+ return value;
+ }
/**
* Wrap the internal value into its external representation.
*/
- protected abstract Object getExternalValue(Object value);
-
- private void validateKey(Object key)
+ protected Object getExternalValue(Object value)
{
- if (key == null)
- {
- throw new NullPointerException("No null value accepted");
- }
- assertKeyValidity(key);
+ return value;
}
- private Object unwrapValue(Object value) throws IllegalArgumentException,
ClassCastException, NullPointerException
+ private Object unwrapValue(Object externalValue) throws IllegalArgumentException,
ClassCastException, NullPointerException
{
- if (value == null)
+ if (externalValue == null)
{
throw new NullPointerException("No null value accepted");
}
//
- value = getInternalValue(value);
- if (value == null)
+ Object internalValue = getInternalValue(externalValue);
+
+ //
+ if (internalValue == null)
{
- throw new IllegalArgumentException("The provided value " + value +
" was converted to a null value");
+ throw new IllegalArgumentException("The provided value " +
externalValue + " was converted to a null value");
}
//
- return value;
+ return internalValue;
}
- private Object wrapValue(Object value) throws IllegalStateException
+ private Object wrapValue(Object internalValue) throws IllegalStateException
{
- if (value == null)
+ if (internalValue == null)
{
- return null;
+ throw new IllegalStateException("Received an internal null value");
}
//
- Object wrappedValue = getExternalValue(value);
- if (wrappedValue == null)
+ Object externalValue = getExternalValue(internalValue);
+
+ //
+ if (externalValue == null)
{
- throw new IllegalStateException("Converted an internal value to a null
value " + value);
+ throw new IllegalStateException("Converted an internal value to a null
value " + internalValue);
}
//
- return wrappedValue;
+ return externalValue;
}
/**
@@ -137,7 +212,7 @@
public boolean containsKey(Object key)
{
- validateKey(key);
+ key = unwrapKey(key);
return getDelegate().containsKey(key);
}
@@ -149,49 +224,45 @@
public Collection values()
{
- throw new NotYetImplemented("TypedMap.values()");
+ return new ValueCollection();
}
public void putAll(Map t)
{
- Map tmp = new HashMap(t);
- validate(tmp, true);
+ t = convert(t);
getDelegate().putAll(t);
}
public Set entrySet()
{
- return new TypedMap.TypedEntrySet(getDelegate().entrySet());
+ return new TypedMap.TypedEntrySet();
}
public Set keySet()
{
- return getDelegate().keySet();
+ return new KeySet();
}
public Object get(Object key)
{
- validateKey(key);
+ key = unwrapKey(key);
Object value = getDelegate().get(key);
- value = wrapValue(value);
- return value;
+ return value == null ? null : wrapValue(value);
}
public Object remove(Object key)
{
- validateKey(key);
+ key = unwrapKey(key);
Object value = getDelegate().remove(key);
- value = wrapValue(value);
- return value;
+ return value == null ? null : wrapValue(value);
}
public Object put(Object key, Object value)
{
- validateKey(key);
+ key = unwrapKey(key);
value = unwrapValue(value);
value = getDelegate().put(key, value);
- value = wrapValue(value);
- return value;
+ return value == null ? null : wrapValue(value);
}
// Overriden methods
@@ -224,29 +295,23 @@
//
try
{
- // We don't support null values
- if (thatValue == null)
- {
- return false;
- }
+ // Unwrap key
+ thatKey = unwrapKey(thatKey);
- // Check key validity
- validateKey(thatKey);
+ // Unwrap value
+ thatValue = unwrapValue(thatValue);
- // Unwrap
- Object thatInternalValue = unwrapValue(thatValue);
-
// Get the internal value
Object internalValue = delegate.get(thatKey);
- // Check the internal value
+ // Check the internal value, it should not be null
if (internalValue == null)
{
return false;
}
// Perform value comparison
- if (internalValueEquals(internalValue, thatInternalValue) == false)
+ if (internalValueEquals(internalValue, thatValue) == false)
{
return false;
}
@@ -285,7 +350,7 @@
*/
public void replace(Map t) throws ClassCastException, NullPointerException,
IllegalArgumentException
{
- validate(t, false);
+ t = convert(t);
//
Map delegate = getDelegate();
@@ -302,39 +367,48 @@
*/
public void validate() throws ClassCastException, NullPointerException,
IllegalArgumentException
{
- validate(this, false);
+ validate(this);
}
+ public void validate(Map m) throws ClassCastException, NullPointerException,
IllegalArgumentException
+ {
+ for (Iterator i = m.entrySet().iterator(); i.hasNext();)
+ {
+ Entry entry = (Entry)i.next();
+ wrapKey(entry.getKey());
+ wrapValue(entry.getValue());
+ }
+ }
+
/**
* Validate the map and unwrap it if necessary.
*/
- protected final void validate(Map t, boolean unwrap) throws IllegalArgumentException,
NullPointerException, ClassCastException
+ protected final Map convert(Map t) throws IllegalArgumentException,
NullPointerException, ClassCastException
{
if (t == null)
{
throw new NullPointerException("No null map can be accepted");
}
+ Map u = new HashMap(t.size());
for (Iterator i = t.entrySet().iterator(); i.hasNext();)
{
Entry entry = (Entry)i.next();
- validateKey(entry.getKey());
+ Object key = unwrapKey(entry.getKey());
Object value = unwrapValue(entry.getValue());
- if (unwrap)
- {
- entry.setValue(value);
- }
+ u.put(key, value);
}
+ return u;
}
- public class TypedEntrySet implements Set
+ public class ValueCollection implements Collection
{
-
+
/** . */
- private final Set delegate;
+ private final Collection delegate;
- public TypedEntrySet(Set delegate)
+ public ValueCollection()
{
- this.delegate = delegate;
+ this.delegate = getDelegate().values();
}
public int size()
@@ -394,85 +468,315 @@
public Iterator iterator()
{
- return new TypedMap.TypedEntryIterator(delegate.iterator());
+ return new ValueIterator();
}
public Object[] toArray(Object a[])
{
throw new NotYetImplemented("TypedEntrySet.toArray(Object a[])");
}
+
+ public class ValueIterator implements Iterator
+ {
+
+ /** . */
+ private final Iterator delegate;
+
+ public ValueIterator()
+ {
+ this.delegate = ValueCollection.this.delegate.iterator();
+ }
+
+ public void remove()
+ {
+ delegate.remove();
+ }
+
+ public boolean hasNext()
+ {
+ return delegate.hasNext();
+ }
+
+ public Object next()
+ {
+ Object value = delegate.next();
+ value = wrapValue(value);
+ return value;
+ }
+ }
}
- public class TypedEntryIterator implements Iterator
+ public class KeySet implements Set
{
/** . */
- private final Iterator delegate;
+ private final Set delegate;
- public TypedEntryIterator(Iterator delegate)
+ public KeySet()
{
- this.delegate = delegate;
+ this.delegate = getDelegate().keySet();
}
- public void remove()
+ public int size()
{
- delegate.remove();
+ return delegate.size();
}
- public boolean hasNext()
+ public void clear()
{
- return delegate.hasNext();
+ delegate.clear();
}
- public Object next()
+ public boolean isEmpty()
{
- Entry entry = (Entry)delegate.next();
- return new TypedMap.TypedEntry(entry);
+ return delegate.isEmpty();
}
+
+ public boolean contains(Object o)
+ {
+ try
+ {
+ Object key = unwrapKey(o);
+ return getDelegate().containsKey(key);
+ }
+ catch (IllegalArgumentException e)
+ {
+ return false;
+ }
+ catch (ClassCastException e)
+ {
+ return false;
+ }
+ catch (NullPointerException e)
+ {
+ return false;
+ }
+ }
+
+ public Object[] toArray()
+ {
+ throw new NotYetImplemented("TypedEntrySet.toArray()");
+ }
+
+ public boolean add(Object o)
+ {
+ throw new NotYetImplemented("TypedEntrySet.add(Object o)");
+ }
+
+ public boolean remove(Object o)
+ {
+ throw new NotYetImplemented("TypedEntrySet.remove(Object o)");
+ }
+
+ public boolean addAll(Collection c)
+ {
+ throw new NotYetImplemented("TypedEntrySet.addAll(Collection c)");
+ }
+
+ public boolean containsAll(Collection c)
+ {
+ throw new NotYetImplemented("TypedEntrySet.containsAll(Collection
c)");
+ }
+
+ public boolean removeAll(Collection c)
+ {
+ throw new NotYetImplemented("TypedEntrySet.removeAll(Collection c)");
+ }
+
+ public boolean retainAll(Collection c)
+ {
+ throw new NotYetImplemented("TypedEntrySet.retainAll(Collection c)");
+ }
+
+ public Iterator iterator()
+ {
+ return new KeyIterator();
+ }
+
+ public Object[] toArray(Object a[])
+ {
+ throw new NotYetImplemented("TypedEntrySet.toArray(Object a[])");
+ }
+
+ public class KeyIterator implements Iterator
+ {
+
+ /** . */
+ private final Iterator delegate;
+
+ public KeyIterator()
+ {
+ this.delegate = KeySet.this.delegate.iterator();
+ }
+
+ public void remove()
+ {
+ delegate.remove();
+ }
+
+ public boolean hasNext()
+ {
+ return delegate.hasNext();
+ }
+
+ public Object next()
+ {
+ Object key = delegate.next();
+ key = wrapKey(key);
+ return key;
+ }
+ }
}
- public class TypedEntry implements Entry
+ public class TypedEntrySet implements Set
{
/** . */
- private final Entry delegate;
+ private final Set delegate;
- public TypedEntry(Entry delegate)
+ public TypedEntrySet()
{
- this.delegate = delegate;
+ this.delegate = getDelegate().entrySet();
}
- public int hashCode()
+ public int size()
{
- return delegate.hashCode();
+ return delegate.size();
}
- public boolean equals(Object obj)
+ public void clear()
{
- return delegate.equals(obj);
+ delegate.clear();
}
- public String toString()
+ public boolean isEmpty()
{
- return delegate.toString();
+ return delegate.isEmpty();
}
- public Object getKey()
+ public Object[] toArray()
{
- return delegate.getKey();
+ throw new NotYetImplemented("TypedEntrySet.toArray()");
}
- public Object getValue()
+ public boolean add(Object o)
{
- Object value = delegate.getValue();
- value = wrapValue(value);
- return value;
+ throw new NotYetImplemented("TypedEntrySet.add(Object o)");
}
- public Object setValue(Object value)
+ public boolean contains(Object o)
{
- value = unwrapValue(value);
- return delegate.setValue(value);
+ throw new NotYetImplemented("TypedEntrySet.contains(Object o)");
}
+
+ public boolean remove(Object o)
+ {
+ throw new NotYetImplemented("TypedEntrySet.remove(Object o)");
+ }
+
+ public boolean addAll(Collection c)
+ {
+ throw new NotYetImplemented("TypedEntrySet.addAll(Collection c)");
+ }
+
+ public boolean containsAll(Collection c)
+ {
+ throw new NotYetImplemented("TypedEntrySet.containsAll(Collection
c)");
+ }
+
+ public boolean removeAll(Collection c)
+ {
+ throw new NotYetImplemented("TypedEntrySet.removeAll(Collection c)");
+ }
+
+ public boolean retainAll(Collection c)
+ {
+ throw new NotYetImplemented("TypedEntrySet.retainAll(Collection c)");
+ }
+
+ public Iterator iterator()
+ {
+ return new TypedEntryIterator();
+ }
+
+ public Object[] toArray(Object a[])
+ {
+ throw new NotYetImplemented("TypedEntrySet.toArray(Object a[])");
+ }
+
+ public class TypedEntryIterator implements Iterator
+ {
+
+ /** . */
+ private final Iterator delegate;
+
+ public TypedEntryIterator()
+ {
+ this.delegate = TypedEntrySet.this.delegate.iterator();
+ }
+
+ public void remove()
+ {
+ delegate.remove();
+ }
+
+ public boolean hasNext()
+ {
+ return delegate.hasNext();
+ }
+
+ public Object next()
+ {
+ Entry entry = (Entry)delegate.next();
+ return new TypedEntry(entry);
+ }
+ }
+
+ public class TypedEntry implements Entry
+ {
+
+ /** . */
+ private final Entry delegate;
+
+ public TypedEntry(Entry delegate)
+ {
+ this.delegate = delegate;
+ }
+
+ public int hashCode()
+ {
+ return delegate.hashCode();
+ }
+
+ public boolean equals(Object obj)
+ {
+ return delegate.equals(obj);
+ }
+
+ public String toString()
+ {
+ return delegate.toString();
+ }
+
+ public Object getKey()
+ {
+ Object key = delegate.getKey();
+ key = wrapKey(key);
+ return key;
+ }
+
+ public Object getValue()
+ {
+ Object value = delegate.getValue();
+ value = wrapValue(value);
+ return value;
+ }
+
+ public Object setValue(Object value)
+ {
+ value = unwrapValue(value);
+ return delegate.setValue(value);
+ }
+ }
}
}
Added: trunk/core/src/main/org/jboss/portal/core/impl/model/content/AbstractContent.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/model/content/AbstractContent.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/impl/model/content/AbstractContent.java 2007-03-08
21:55:40 UTC (rev 6605)
@@ -0,0 +1,79 @@
+/******************************************************************************
+ * 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 *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.impl.model.content;
+
+import org.jboss.portal.core.model.content.Content;
+import org.jboss.portal.core.model.content.spi.ContentState;
+
+import java.util.Iterator;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractContent implements Content
+{
+
+ /** . */
+ protected final ContentState state;
+
+ public AbstractContent(ContentState state)
+ {
+ this.state = state;
+ }
+
+ public boolean isMutable()
+ {
+ return true;
+ }
+
+ public String getURI()
+ {
+ return state.getURI();
+ }
+
+ public void setURI(String uri)
+ {
+ state.setURI(uri);
+ }
+
+ public void clearParameters()
+ {
+ state.clearParameters();
+ }
+
+ public String getParameter(String name) throws IllegalArgumentException
+ {
+ return state.getParameter(name);
+ }
+
+ public void setParameter(String name, String value) throws IllegalArgumentException
+ {
+ state.setParameter(name, value);
+ }
+
+ public Iterator getParameterNames()
+ {
+ return state.getParameterNames();
+ }
+}
Modified:
trunk/core/src/main/org/jboss/portal/core/impl/model/content/generic/GenericContent.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/impl/model/content/generic/GenericContent.java 2007-03-08
20:14:20 UTC (rev 6604)
+++
trunk/core/src/main/org/jboss/portal/core/impl/model/content/generic/GenericContent.java 2007-03-08
21:55:40 UTC (rev 6605)
@@ -22,9 +22,8 @@
******************************************************************************/
package org.jboss.portal.core.impl.model.content.generic;
-import org.jboss.portal.core.model.content.Content;
import org.jboss.portal.core.model.content.spi.ContentState;
-import org.jboss.portal.core.impl.model.content.portlet.PortletContentHandler;
+import org.jboss.portal.core.impl.model.content.AbstractContent;
import org.jboss.portal.common.util.LocalizedString;
import java.util.Locale;
@@ -33,42 +32,16 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-public class GenericContent implements Content
+public class GenericContent extends AbstractContent
{
- /** . */
- private final ContentState state;
-
- /** . */
- private final GenericContentHandler handler;
-
- /** . */
- private final String contextId;
-
- public GenericContent(GenericContentHandler handler, String contextId, ContentState
state)
+ public GenericContent(ContentState state)
{
- this.handler = handler;
- this.contextId = contextId;
- this.state = state;
+ super(state);
}
public LocalizedString getDisplayName()
{
return new LocalizedString(state.getURI() + " portlet", Locale.ENGLISH);
}
-
- public boolean isMutable()
- {
- return true;
- }
-
- public String getURI()
- {
- return state.getURI();
- }
-
- public void setURI(String uri)
- {
- state.setURI(uri);
- }
}
Modified:
trunk/core/src/main/org/jboss/portal/core/impl/model/content/generic/GenericContentHandler.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/impl/model/content/generic/GenericContentHandler.java 2007-03-08
20:14:20 UTC (rev 6604)
+++
trunk/core/src/main/org/jboss/portal/core/impl/model/content/generic/GenericContentHandler.java 2007-03-08
21:55:40 UTC (rev 6605)
@@ -35,6 +35,6 @@
{
public Content newContent(String contextId, ContentState state)
{
- return new GenericContent(this, contextId, state);
+ return new GenericContent(state);
}
}
Modified:
trunk/core/src/main/org/jboss/portal/core/impl/model/content/portlet/PortletContent.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/impl/model/content/portlet/PortletContent.java 2007-03-08
20:14:20 UTC (rev 6604)
+++
trunk/core/src/main/org/jboss/portal/core/impl/model/content/portlet/PortletContent.java 2007-03-08
21:55:40 UTC (rev 6605)
@@ -22,8 +22,8 @@
******************************************************************************/
package org.jboss.portal.core.impl.model.content.portlet;
-import org.jboss.portal.core.model.content.Content;
import org.jboss.portal.core.model.content.spi.ContentState;
+import org.jboss.portal.core.impl.model.content.AbstractContent;
import org.jboss.portal.common.util.LocalizedString;
import java.util.Locale;
@@ -32,23 +32,20 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-public class PortletContent implements Content
+public class PortletContent extends AbstractContent
{
/** . */
- private final ContentState state;
+ private final String contextId;
/** . */
private final PortletContentHandler handler;
- /** . */
- private final String contextId;
-
public PortletContent(PortletContentHandler handler, String contextId, ContentState
state)
{
- this.handler = handler;
+ super(state);
this.contextId = contextId;
- this.state = state;
+ this.handler = handler;
}
public LocalizedString getDisplayName()
@@ -56,50 +53,27 @@
return new LocalizedString(state.getURI() + " portlet", Locale.ENGLISH);
}
- public ContentState getState()
+ public void setURI(String uri)
{
- return state;
- }
+ String currentInstanceRef = state.getURI();
- public boolean isMutable()
- {
- return true;
- }
+ //
+ if (currentInstanceRef != null && currentInstanceRef.equals(uri) == false)
+ {
+ handler.contentDestroyed(contextId, state);
+ }
- public String getURI()
- {
- return getInstanceRef();
+ //
+ state.setURI(uri);
}
- public void setURI(String uri)
- {
- setInstanceRef(uri);
- }
-
- /**
- *
- * @return
- */
public String getInstanceRef()
{
- return state.getURI();
+ return getURI();
}
- /**
- *
- * @param instanceRef
- */
public void setInstanceRef(String instanceRef)
{
- String currentInstanceRef = state.getURI();
-
- //
- if (currentInstanceRef != null && currentInstanceRef.equals(instanceRef) ==
false)
- {
- handler.contentDestroyed(contextId, state);
- }
-
- //
- state.setURI(instanceRef);
+ setURI(instanceRef);
}
}
Modified: trunk/core/src/main/org/jboss/portal/core/impl/model/portal/WindowImpl.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/model/portal/WindowImpl.java 2007-03-08
20:14:20 UTC (rev 6604)
+++ trunk/core/src/main/org/jboss/portal/core/impl/model/portal/WindowImpl.java 2007-03-08
21:55:40 UTC (rev 6605)
@@ -31,6 +31,10 @@
import org.jboss.portal.jems.hibernate.ContextObject;
import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.Iterator;
+import java.util.HashSet;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -179,28 +183,6 @@
instanceRef = uri;
}
- public void setProperty(String name, String value)
- {
- if (name == null)
- {
- throw new IllegalArgumentException("No null name accepted");
- }
- if (name.startsWith("content.") == false)
- {
- throw new IllegalArgumentException("Property name must be prefixed by
'content.'");
- }
- setDeclaredProperty(name, value);
- }
-
- public String getProperty(String name)
- {
- if (name == null)
- {
- throw new IllegalArgumentException("No null name accepted");
- }
- return getDeclaredProperty(name);
- }
-
private void destroy()
{
ContentHandler handler = getContentHandler();
@@ -241,5 +223,65 @@
//
return handler;
}
+
+ public Iterator getParameterNames()
+ {
+ return new Iterator()
+ {
+ Iterator i = getDeclaredProperties().keySet().iterator();
+ String next;
+ {
+ findNext();
+ }
+ public boolean hasNext()
+ {
+ return next != null;
+ }
+ public Object next()
+ {
+ String tmp = next;
+ findNext();
+ return tmp;
+ }
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+ void findNext()
+ {
+ next = null;
+ while (i.hasNext() && next == null)
+ {
+ String propertyName = (String)i.next();
+ if (propertyName.startsWith("content."))
+ {
+ next = propertyName.substring(8);
+ }
+ }
+ }
+ };
+ }
+
+ public void setParameter(String name, String value) throws
IllegalArgumentException
+ {
+ setDeclaredProperty("content." + name, value);
+ }
+
+ public String getParameter(String name) throws IllegalArgumentException
+ {
+ return getDeclaredProperty("content." + name);
+ }
+
+ public void clearParameters()
+ {
+ for (Iterator i = getDeclaredProperties().keySet().iterator();i.hasNext();)
+ {
+ String propertyName = (String)i.next();
+ if (propertyName.startsWith("content."))
+ {
+ i.remove();
+ }
+ }
+ }
}
}
Modified:
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/content/GenericPortletContentRenderer.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/content/GenericPortletContentRenderer.java 2007-03-08
20:14:20 UTC (rev 6604)
+++
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/content/GenericPortletContentRenderer.java 2007-03-08
21:55:40 UTC (rev 6605)
@@ -38,6 +38,7 @@
import java.util.Map;
import java.util.HashMap;
+import java.util.Iterator;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -117,9 +118,21 @@
PortletParametersStateString navigationalState =
(PortletParametersStateString)context.getAttribute(RenderWindowCommand.NAVIGATIONAL_STATE_SCOPE,
windowId);
if (navigationalState == null)
{
+ navigationalState = new PortletParametersStateString();
+
+ //
+ for (Iterator i = content.getParameterNames();i.hasNext();)
+ {
+ String paramName = (String)i.next();
+ String paramValue = content.getParameter(paramName);
+ navigationalState.setValue(paramName, paramValue);
+ }
+
+ //
String uri = content.getURI();
- navigationalState = new PortletParametersStateString();
navigationalState.setValue("uri", uri);
+
+ //
context.setAttribute(RenderWindowCommand.NAVIGATIONAL_STATE_SCOPE, windowId,
navigationalState);
}
Modified:
trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/PersistentRegistration.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/PersistentRegistration.java 2007-03-08
20:14:20 UTC (rev 6604)
+++
trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/PersistentRegistration.java 2007-03-08
21:55:40 UTC (rev 6605)
@@ -257,24 +257,16 @@
return persistentProperties;
}
- protected void assertKeyValidity(Object key) throws ClassCastException,
NullPointerException
+ protected void assertKeyValidity(Object key) throws ClassCastException
{
- if (key == null)
- {
- throw new NullPointerException();
- }
if (key instanceof QName == false)
{
throw new ClassCastException();
}
}
- protected Object getInternalValue(Object value) throws IllegalArgumentException,
ClassCastException, NullPointerException
+ protected Object getInternalValue(Object value) throws ClassCastException
{
- if (value == null)
- {
- throw new NullPointerException();
- }
if (value instanceof String == false)
{
throw new ClassCastException();
@@ -282,11 +274,6 @@
return value;
}
- protected Object getExternalValue(Object value)
- {
- return value;
- }
-
public void setProperty(String propertyName, Object value)
{
if (propertyName == null)
Modified: trunk/core/src/main/org/jboss/portal/core/model/content/Content.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/model/content/Content.java 2007-03-08
20:14:20 UTC (rev 6604)
+++ trunk/core/src/main/org/jboss/portal/core/model/content/Content.java 2007-03-08
21:55:40 UTC (rev 6605)
@@ -24,6 +24,11 @@
import org.jboss.portal.common.util.LocalizedString;
+import java.util.Map;
+import java.util.Set;
+import java.util.Collection;
+import java.util.Iterator;
+
/**
* Defines the base interface for content.
*
@@ -60,4 +65,12 @@
* @throws IllegalStateException if the content cannot be changed for some reason
*/
void setURI(String uri) throws IllegalStateException;
+
+ Iterator getParameterNames();
+
+ void setParameter(String name, String value) throws IllegalArgumentException;
+
+ String getParameter(String name) throws IllegalArgumentException;
+
+ void clearParameters();
}
Modified: trunk/core/src/main/org/jboss/portal/core/model/content/spi/ContentState.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/content/spi/ContentState.java 2007-03-08
20:14:20 UTC (rev 6604)
+++
trunk/core/src/main/org/jboss/portal/core/model/content/spi/ContentState.java 2007-03-08
21:55:40 UTC (rev 6605)
@@ -22,6 +22,8 @@
******************************************************************************/
package org.jboss.portal.core.model.content.spi;
+import java.util.Iterator;
+
/**
* Represents the state of the content which consist in an URI and a set of properties.
*
@@ -39,25 +41,16 @@
/**
* Set the URI value.
+ *
+ * @param uri the URI
*/
void setURI(String uri);
- /**
- * Set a content property, the property name must be prefixed by the litteral
'content.'.
- *
- * @param name the property name
- * @param value the property value
- * @throws IllegalArgumentException if the name is null or is not prefixed by the
litteral 'content.'.
- */
- void setProperty(String name, String value) throws IllegalArgumentException;
+ Iterator getParameterNames();
- /**
- * Return a property of the content state.
- *
- * @param name the property name
- * @return the property value or null if it does not exist
- * @throws IllegalArgumentException if the name is null or is not prefixed by the
litteral 'content.'.
- * @see #setProperty(String, String)
- */
- String getProperty(String name) throws IllegalArgumentException;
+ void setParameter(String name, String value) throws IllegalArgumentException;
+
+ String getParameter(String name) throws IllegalArgumentException;
+
+ void clearParameters();
}
Modified: trunk/core/src/main/org/jboss/portal/test/core/model/content/NullContent.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/test/core/model/content/NullContent.java 2007-03-08
20:14:20 UTC (rev 6604)
+++
trunk/core/src/main/org/jboss/portal/test/core/model/content/NullContent.java 2007-03-08
21:55:40 UTC (rev 6605)
@@ -22,8 +22,8 @@
******************************************************************************/
package org.jboss.portal.test.core.model.content;
-import org.jboss.portal.core.model.content.Content;
import org.jboss.portal.core.model.content.spi.ContentState;
+import org.jboss.portal.core.impl.model.content.AbstractContent;
import org.jboss.portal.common.util.LocalizedString;
import java.util.Locale;
@@ -32,26 +32,18 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-public class NullContent implements Content
+public class NullContent extends AbstractContent
{
/** . */
- private String contextId;
+ private final String contextId;
- /** . */
- private ContentState state;
-
public NullContent(String contextId, ContentState state)
{
+ super(state);
this.contextId = contextId;
- this.state = state;
}
- public boolean isMutable()
- {
- return true;
- }
-
public String getContextId()
{
return contextId;
@@ -66,14 +58,4 @@
{
return new LocalizedString("Null content", Locale.ENGLISH);
}
-
- public String getURI()
- {
- return state.getURI();
- }
-
- public void setURI(String uri)
- {
- state.setURI(uri);
- }
}
Modified:
trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectContainerTestCase.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectContainerTestCase.java 2007-03-08
20:14:20 UTC (rev 6604)
+++
trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectContainerTestCase.java 2007-03-08
21:55:40 UTC (rev 6605)
@@ -316,7 +316,7 @@
assertNotNull(content);
ContentState contentState = content.getState();
assertNotNull(contentState);
- contentState.setProperty("content.abc", "def");
+ contentState.setParameter("abc", "def");
TransactionAssert.commitTransaction();
//
@@ -340,7 +340,7 @@
assertNotNull(content);
contentState = content.getState();
assertNotNull(contentState);
- assertEquals("def", contentState.getProperty("content.abc"));
+ assertEquals("def", contentState.getParameter("abc"));
TransactionAssert.commitTransaction();
}
Modified:
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java
===================================================================
---
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java 2007-03-08
20:14:20 UTC (rev 6604)
+++
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java 2007-03-08
21:55:40 UTC (rev 6605)
@@ -115,6 +115,9 @@
private String selectedContentURI;
/** . */
+ private Map selectedContentParameters = new HashMap();
+
+ /** . */
private Map renderParameters;
// Runtime state
@@ -287,6 +290,16 @@
this.renderParameters = renderParameters;
}
+ public Map getSelectedContentParameters()
+ {
+ return selectedContentParameters;
+ }
+
+ public void setSelectedContentParameters(Map selectedContentParameters)
+ {
+ this.selectedContentParameters = selectedContentParameters;
+ }
+
// Runtime state
public AbstractAuthorizationBean getAuth()
@@ -641,6 +654,18 @@
break;
case PortalObject.TYPE_PAGE:
selectedContentURI = uri;
+ selectedContentParameters.clear();
+ for (Iterator i = actionParams.entrySet().iterator();i.hasNext();)
+ {
+ Map.Entry entry = (Map.Entry)i.next();
+ String name = (String)entry.getKey();
+ if (name.startsWith("param."))
+ {
+ String paramName = name.substring(6);
+ String paramValue = ((String[])entry.getValue())[0];
+ selectedContentParameters.put(paramName, paramValue);
+ }
+ }
break;
}
Modified:
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/AssignWindowsAction.java
===================================================================
---
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/AssignWindowsAction.java 2007-03-08
20:14:20 UTC (rev 6604)
+++
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/AssignWindowsAction.java 2007-03-08
21:55:40 UTC (rev 6605)
@@ -25,6 +25,7 @@
import org.jboss.portal.faces.el.dynamic.DynamicBean;
import org.jboss.portal.faces.el.PropertyValue;
import org.jboss.portal.core.model.content.ContentType;
+import org.jboss.portal.core.model.content.Content;
import org.jboss.portal.core.model.portal.Window;
import org.jboss.portal.core.model.portal.Page;
import org.jboss.portal.core.model.portal.NoSuchPortalObjectException;
@@ -173,11 +174,26 @@
{
ContentType contentType = pomgr.getSelectedContentType();
String contentURI = pomgr.getSelectedContentURI();
+ Map contentParameters = pomgr.getSelectedContentParameters();
//
Window window = page.createWindow(windowName, contentType, contentURI);
+
+ //
+ Content content = window.getContent();
+ for (Iterator i = contentParameters.entrySet().iterator();i.hasNext();)
+ {
+ Map.Entry entry = (Map.Entry)i.next();
+ String paramName = (String)entry.getKey();
+ String paramValue = (String)entry.getValue();
+ content.setParameter(paramName, paramValue);
+ }
+
+ //
window.setDeclaredProperty(ThemeConstants.PORTAL_PROP_REGION,
regionName);
window.setDeclaredProperty(ThemeConstants.PORTAL_PROP_ORDER, ""
+ Integer.MAX_VALUE);
+
+ //
windows.add(window);
}
catch (DuplicatePortalObjectException unexpected)
Modified: trunk/core-cms/src/main/org/jboss/portal/core/cms/content/CMSContent.java
===================================================================
--- trunk/core-cms/src/main/org/jboss/portal/core/cms/content/CMSContent.java 2007-03-08
20:14:20 UTC (rev 6604)
+++ trunk/core-cms/src/main/org/jboss/portal/core/cms/content/CMSContent.java 2007-03-08
21:55:40 UTC (rev 6605)
@@ -22,8 +22,8 @@
******************************************************************************/
package org.jboss.portal.core.cms.content;
-import org.jboss.portal.core.model.content.Content;
import org.jboss.portal.core.model.content.spi.ContentState;
+import org.jboss.portal.core.impl.model.content.AbstractContent;
import org.jboss.portal.common.util.LocalizedString;
import java.util.Locale;
@@ -32,42 +32,16 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-public class CMSContent implements Content
+public class CMSContent extends AbstractContent
{
- /** . */
- private final ContentState state;
-
public CMSContent(ContentState state)
{
- this.state = state;
+ super(state);
}
public LocalizedString getDisplayName()
{
return new LocalizedString(state.getURI() + " cms", Locale.ENGLISH);
}
-
- public boolean isMutable()
- {
- return true;
- }
-
- /**
- *
- * @return
- */
- public String getURI()
- {
- return state.getURI();
- }
-
- /**
- *
- * @param uri
- */
- public void setURI(String uri)
- {
- state.setURI(uri);
- }
}
Modified: trunk/portlet/src/main/org/jboss/portal/portlet/PortletParameters.java
===================================================================
--- trunk/portlet/src/main/org/jboss/portal/portlet/PortletParameters.java 2007-03-08
20:14:20 UTC (rev 6604)
+++ trunk/portlet/src/main/org/jboss/portal/portlet/PortletParameters.java 2007-03-08
21:55:40 UTC (rev 6605)
@@ -110,7 +110,7 @@
*/
public void append(Map params) throws ClassCastException, NullPointerException,
IllegalArgumentException
{
- validate(params, false);
+ validate(params);
//
internalAppend(params);
Modified: trunk/portlet/src/main/org/jboss/portal/portlet/state/AbstractPropertyMap.java
===================================================================
---
trunk/portlet/src/main/org/jboss/portal/portlet/state/AbstractPropertyMap.java 2007-03-08
20:14:20 UTC (rev 6604)
+++
trunk/portlet/src/main/org/jboss/portal/portlet/state/AbstractPropertyMap.java 2007-03-08
21:55:40 UTC (rev 6605)
@@ -38,15 +38,10 @@
/**
* Only accept non null string objects.
*
- * @throws NullPointerException if the value is null
* @throws ClassCastException if the value is not an instance of string
*/
protected void assertKeyValidity(Object value)
{
- if (value == null)
- {
- throw new ClassCastException("Key must not be null");
- }
if (value instanceof String == false)
{
throw new ClassCastException("Key must be a String");
Modified: trunk/widget/src/main/org/jboss/portal/widget/Widget.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/Widget.java 2007-03-08 20:14:20 UTC (rev
6604)
+++ trunk/widget/src/main/org/jboss/portal/widget/Widget.java 2007-03-08 21:55:40 UTC (rev
6605)
@@ -24,6 +24,8 @@
import org.jboss.portal.common.util.LocalizedString;
+import java.util.Map;
+
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
@@ -37,6 +39,6 @@
LocalizedString getDescription();
- String render();
+ String render(Map parameters);
}
Modified: trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java 2007-03-08 20:14:20
UTC (rev 6604)
+++ trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java 2007-03-08 21:55:40
UTC (rev 6605)
@@ -77,7 +77,7 @@
Widget widget = provider.getWidget(uri);
if (widget != null)
{
- writer.print(widget.render());
+ writer.print(widget.render(req.getParameterMap()));
}
else
{
@@ -105,7 +105,7 @@
writer.println("<p><a href=\"" + selectURL +
"\">Select</a> widget</p>");
// Prefs
- writer.println("<from>");
+ writer.println("<form action=\"" + selectURL +
"\" method=\"post\">");
for (Iterator i =
widget.getPreferencesInfo().getPreferencesInfo().iterator();i.hasNext();)
{
GGPreferenceInfo prefInfo = (GGPreferenceInfo)i.next();
@@ -115,9 +115,11 @@
// Todo
break;
default:
- writer.println("<div>" + prefInfo.getName() +
": <input type=\"text\" name=\"" + prefInfo.getName() +
"\"/></div>");
+ writer.println("<div>" + prefInfo.getName() +
": <input type=\"text\" name=\"param." + prefInfo.getName() +
"\"" +
+ (prefInfo.getDefaultValue() != null ? ("
value=\"" + prefInfo.getDefaultValue() + "\"") : "") +
"/></div>");
}
}
+ writer.println("<input type=\"submit\"/>");
writer.println("</form>");
}
}
Modified: trunk/widget/src/main/org/jboss/portal/widget/google/GGWidget.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GGWidget.java 2007-03-08 20:14:20
UTC (rev 6604)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/GGWidget.java 2007-03-08 21:55:40
UTC (rev 6605)
@@ -27,6 +27,7 @@
import org.jboss.portal.widget.Widget;
import java.util.Iterator;
+import java.util.Map;
/**
* Getting list :
@@ -134,7 +135,7 @@
return description;
}
- public String render()
+ public String render(Map parameters)
{
String id = generator.generateKey();
StringBuffer tmp = new
StringBuffer("http://gmodules.com/ig/ifr?url=").append(url);
@@ -151,7 +152,9 @@
for (Iterator i = prefsInfo.getPreferencesInfo().iterator();i.hasNext();)
{
GGPreferenceInfo prefInfo = (GGPreferenceInfo)i.next();
- if (prefInfo.getDefaultValue() != null)
+ String[] values = (String[])parameters.get(prefInfo.getName());
+ String value = values != null ? values[0] : prefInfo.getDefaultValue();
+ if (value != null)
{
tmp.append("&_up").append(prefInfo.getName()).append("=").append(prefInfo.getDefaultValue());
}