cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r385303 - in /cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal: coplet/ layout/ tools/copletManagement/ util/
Date Sun, 12 Mar 2006 15:58:09 GMT
Author: cziegeler
Date: Sun Mar 12 07:58:07 2006
New Revision: 385303

URL: http://svn.apache.org/viewcvs?rev=385303&view=rev
Log:
Add some id checks and make some objects serializable

Modified:
    cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/CopletBaseData.java
    cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/CopletData.java
    cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/CopletInstanceData.java
    cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/layout/AbstractParameters.java
    cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/layout/Layout.java
    cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/tools/copletManagement/LayoutActions.java
    cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/util/PortalUtils.java

Modified: cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/CopletBaseData.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/CopletBaseData.java?rev=385303&r1=385302&r2=385303&view=diff
==============================================================================
--- cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/CopletBaseData.java
(original)
+++ cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/CopletBaseData.java
Sun Mar 12 07:58:07 2006
@@ -15,9 +15,12 @@
  */
 package org.apache.cocoon.portal.coplet;
 
+import java.io.Serializable;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.cocoon.portal.util.PortalUtils;
+
 /**
  * A coplet base data defines a coplet type, like a pipeline based coplet,
  * a JSR 168 portlet or a WSRP portlet. For each type exists a coplet base
@@ -26,7 +29,7 @@
  *
  * @version $Id$
  */
-public final class CopletBaseData { 
+public final class CopletBaseData implements Serializable { 
 
 	private Map copletConfig = new HashMap();
 
@@ -37,9 +40,13 @@
     /**
      * Create a new coplet base data object. 
      * @param id The unique id of the object.
+     * @see PortalUtils#testId(String)
      */
     public CopletBaseData(String id) {
-        // TODO - Check for valid id's
+        final String idErrorMsg = PortalUtils.testId(id);
+        if ( idErrorMsg != null ) {
+            throw new IllegalArgumentException(idErrorMsg);
+        }
         this.id = id;
     }
 
@@ -59,11 +66,16 @@
 		this.copletConfig.put(key, value);
 	}
 
+    public Object removeCopletConfig(String key) {
+        return this.copletConfig.remove(key);
+    }
+
 	public Map getCopletConfig() {
 		return this.copletConfig;
 	}
 
 	public void setCopletConfig(Map config) {
+        // TODO remove this method
 		this.copletConfig = config;
 	}
 

Modified: cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/CopletData.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/CopletData.java?rev=385303&r1=385302&r2=385303&view=diff
==============================================================================
--- cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/CopletData.java
(original)
+++ cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/CopletData.java
Sun Mar 12 07:58:07 2006
@@ -15,6 +15,7 @@
  */
 package org.apache.cocoon.portal.coplet;
 
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -22,6 +23,7 @@
 import java.util.Map;
 import java.util.StringTokenizer;
 
+import org.apache.cocoon.portal.util.PortalUtils;
 import org.apache.commons.lang.StringUtils;
 
 /**
@@ -31,7 +33,7 @@
  *
  * @version $Id$
  */
-public class CopletData {
+public class CopletData implements Serializable {
 
     /** The unique identifier. */
     protected final String id;
@@ -49,9 +51,13 @@
     /**
      * Constructor to instantiate a new coplet data object.
      * @param id The unique id of the object.
+     * @see PortalUtils#testId(String)
      */
     public CopletData(String id) {
-        // TODO - Check for valid id's
+        final String idErrorMsg = PortalUtils.testId(id);
+        if ( idErrorMsg != null ) {
+            throw new IllegalArgumentException(idErrorMsg);
+        }
         this.id = id;
     }
 

Modified: cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/CopletInstanceData.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/CopletInstanceData.java?rev=385303&r1=385302&r2=385303&view=diff
==============================================================================
--- cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/CopletInstanceData.java
(original)
+++ cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/coplet/CopletInstanceData.java
Sun Mar 12 07:58:07 2006
@@ -15,12 +15,22 @@
  */
 package org.apache.cocoon.portal.coplet;
 
+import java.io.Serializable;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.cocoon.portal.util.PortalUtils;
+
 /**
  * A coplet instance data describes an instance of a coplet.
  *
+ * Attributes and temporary attributes
+ * An attribute is a key-value pair consisting of a string for
+ * the key and any object for the value. While the attributes are persisted,
+ * the temporary attributes have only the life-time of a
+ * session. As both, attributes and temporary attributes, are stored
+ * in the session, it is advisable to use serializable objects only.
+ *
  * Sizing:
  *   A coplet can have different sizes:
  *   SIZE_NORMAL - this is the normal size, it means that the coplet shares it's
@@ -33,7 +43,7 @@
  *
  * @version $Id$
  */
-public final class CopletInstanceData {
+public final class CopletInstanceData implements Serializable {
 
     public final static int SIZE_MINIMIZED  = 0;
     public final static int SIZE_NORMAL     = 1;
@@ -41,10 +51,11 @@
     public final static int SIZE_FULLSCREEN = 3;
 
     protected final String id;
-    
+
+    /** The corresponding {@link CopletData}. */
 	protected CopletData copletData;
 
-    /** Persistet attributes. */
+    /** Persisted attributes. */
     protected Map attributes = new HashMap();
 
     /** Temporary attributes are not persisted. */
@@ -61,9 +72,13 @@
      * Never create a coplet instance data object directly. Use the
      * {@link CopletFactory} instead.
      * @param id The unique id of the object.
+     * @see PortalUtils#testId(String)
 	 */
 	public CopletInstanceData(String id) {
-        // TODO - Check for valid id's
+        final String idErrorMsg = PortalUtils.testId(id);
+        if ( idErrorMsg != null ) {
+            throw new IllegalArgumentException(idErrorMsg);
+        }
         this.id = id;
 	}
 

Modified: cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/layout/AbstractParameters.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/layout/AbstractParameters.java?rev=385303&r1=385302&r2=385303&view=diff
==============================================================================
--- cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/layout/AbstractParameters.java
(original)
+++ cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/layout/AbstractParameters.java
Sun Mar 12 07:58:07 2006
@@ -15,6 +15,7 @@
  */
 package org.apache.cocoon.portal.layout;
 
+import java.io.Serializable;
 import java.util.Map;
 import java.util.Iterator;
 import java.util.HashSet;
@@ -29,7 +30,7 @@
  * @version $Id$
  */
 public abstract class AbstractParameters 
-    implements Cloneable {
+    implements Cloneable, Serializable {
 
     protected Map parameters = new LinkedMap();
 

Modified: cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/layout/Layout.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/layout/Layout.java?rev=385303&r1=385302&r2=385303&view=diff
==============================================================================
--- cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/layout/Layout.java
(original)
+++ cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/layout/Layout.java
Sun Mar 12 07:58:07 2006
@@ -18,12 +18,10 @@
 import java.util.Map;
 
 import org.apache.cocoon.portal.PortalRuntimeException;
+import org.apache.cocoon.portal.util.PortalUtils;
 import org.apache.commons.collections.map.LinkedMap;
 
 /**
- * TODO - Convert this in an abstract class which all implementations
- * have to extend (we can use AbstractLayout for this).
- *
  * A layout describes a graphical element on the portal page. This can
  * be an element containing others ({@link CompositeLayout}) or a final
  * element, like a window for a coplet.
@@ -33,6 +31,8 @@
  * both key and value. While the parameters are persisted,
  * the temporary attributes have only the life-time of a
  * session, but can contain any object.
+ * As both, parameters and temporary attributes, are stored
+ * in the session, it is advisable to use serializable objects only.
  *
  * If you are implementing your own layout object make sure that your
  * class provides a two string constructor which calls {@link #Layout(String, String)}.
@@ -70,9 +70,13 @@
      * {@link LayoutFactory} instead.
      * @param id The unique identifier of the layout object or null.
      * @param name The name of the layout.
+     * @see PortalUtils#testId(String)
      */
     public Layout(String id, String name) {
-        // TODO - Check for valid id's
+        final String idErrorMsg = PortalUtils.testId(id);
+        if ( idErrorMsg != null ) {
+            throw new IllegalArgumentException(idErrorMsg);
+        }
         this.id = id;
         this.name = name;
     }

Modified: cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/tools/copletManagement/LayoutActions.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/tools/copletManagement/LayoutActions.java?rev=385303&r1=385302&r2=385303&view=diff
==============================================================================
--- cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/tools/copletManagement/LayoutActions.java
(original)
+++ cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/tools/copletManagement/LayoutActions.java
Sun Mar 12 07:58:07 2006
@@ -54,9 +54,6 @@
         this.cf = cf;
     }
 
-    // FIXME - where is this used?
-    public static int line = 1;
-
     /**
      * Delets the Object with the id in the layout
      * @param id 

Modified: cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/util/PortalUtils.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/util/PortalUtils.java?rev=385303&r1=385302&r2=385303&view=diff
==============================================================================
--- cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/util/PortalUtils.java
(original)
+++ cocoon/trunk/cocoon-portal/cocoon-portal-impl/src/main/java/org/apache/cocoon/portal/util/PortalUtils.java
Sun Mar 12 07:58:07 2006
@@ -24,11 +24,24 @@
  */
 public class PortalUtils {
 
+    /**
+     * Tests if the string represents a correct id for any portal object.
+     */
     public static String testId(String id) {
+        if ( id == null || id.length() == 0 ) {
+            return "Id must not be null or empty.";
+        }
         if ( !StringUtils.containsOnly(id, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789
") ) {
             return "Id contains invalid characters (only a-z,A-Z,0-9, space and '-' are allowed):
" + id;
         }
-        return null;
+        final char firstChar = id.charAt(0);
+        if ( firstChar >= 'a' && firstChar <= 'z' ) {
+            return null;
+        }
+        if ( firstChar >= 'A' && firstChar <= 'Z' ) {
+            return null;
+        }
+        return "Id must start with a character : " + id;
     }
 
 }



Mime
View raw message