cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: rev 55960 - in cocoon/trunk/src/blocks/portal: conf java/org/apache/cocoon/portal/coplet/impl java/org/apache/cocoon/portal/layout java/org/apache/cocoon/portal/layout/impl
Date Fri, 29 Oct 2004 09:52:38 GMT
Author: cziegeler
Date: Fri Oct 29 02:52:37 2004
New Revision: 55960

Removed:
   cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/layout/impl/TabbedLayoutImpl.java
Modified:
   cocoon/trunk/src/blocks/portal/conf/portal.samplesxconf
   cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/coplet/impl/DefaultCopletFactory.java
   cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/layout/CompositeLayout.java
   cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/layout/LayoutDescription.java
   cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/layout/impl/CompositeLayoutImpl.java
   cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/layout/impl/DefaultLayoutDescription.java
   cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/layout/impl/DefaultLayoutFactory.java
Log:
Implementation of Items are now configurable. Improved id creation for coplets and layouts

Modified: cocoon/trunk/src/blocks/portal/conf/portal.samplesxconf
==============================================================================
--- cocoon/trunk/src/blocks/portal/conf/portal.samplesxconf	(original)
+++ cocoon/trunk/src/blocks/portal/conf/portal.samplesxconf	Fri Oct 29 02:52:37 2004
@@ -182,19 +182,22 @@
             </renderers>
         </layout>
         <layout name="tab" 
-                class="org.apache.cocoon.portal.layout.impl.TabbedLayoutImpl">
+                class="org.apache.cocoon.portal.layout.impl.CompositeLayoutImpl"
+                item-class="org.apache.cocoon.portal.layout.NamedItem">
             <renderers default="tab">
                 <renderer name="tab"/>
             </renderers>
         </layout>
         <layout name="rawtab" 
-                class="org.apache.cocoon.portal.layout.impl.TabbedLayoutImpl">
+                class="org.apache.cocoon.portal.layout.impl.CompositeLayoutImpl"
+                item-class="org.apache.cocoon.portal.layout.NamedItem">
             <renderers default="rawtab">
                 <renderer name="rawtab"/>
             </renderers>
         </layout>
         <layout name="linktab"
-                class="org.apache.cocoon.portal.layout.impl.TabbedLayoutImpl" >
+                class="org.apache.cocoon.portal.layout.impl.CompositeLayoutImpl"
+                item-class="org.apache.cocoon.portal.layout.NamedItem">
             <renderers default="linktab">
                 <renderer name="linktab"/>
             </renderers>

Modified: cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/coplet/impl/DefaultCopletFactory.java
==============================================================================
--- cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/coplet/impl/DefaultCopletFactory.java
(original)
+++ cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/coplet/impl/DefaultCopletFactory.java
Fri Oct 29 02:52:37 2004
@@ -61,6 +61,8 @@
     
     protected ServiceSelector storeSelector;
 
+    protected static long idCounter = System.currentTimeMillis();
+	
     /* (non-Javadoc)
      * @see org.apache.cocoon.portal.coplet.CopletFactory#prepare(org.apache.cocoon.portal.coplet.CopletData)
      */
@@ -127,8 +129,10 @@
         
         String id = null;
         if ( copletDescription.createId() ) {
-            // TODO - create unique id
-            id = name + '-' + System.currentTimeMillis();
+            synchronized (this) {
+                id = copletData.getId() + '-' + idCounter;
+                idCounter += 1;
+            }
         }
         instance.initialize( name, id );
         

Modified: cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/layout/CompositeLayout.java
==============================================================================
--- cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/layout/CompositeLayout.java
(original)
+++ cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/layout/CompositeLayout.java
Fri Oct 29 02:52:37 2004
@@ -72,5 +72,15 @@
      * This item is not added to the composite layout
      */
     Item createNewItem();
+
+    /**
+     * @return Returns the item class name.
+     */
+    String getItemClassName();
+    
+    /**
+     * @param itemClassName The item class name to set.
+     */
+    void setItemClassName(String value);
     
 }

Modified: cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/layout/LayoutDescription.java
==============================================================================
--- cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/layout/LayoutDescription.java
(original)
+++ cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/layout/LayoutDescription.java
Fri Oct 29 02:52:37 2004
@@ -19,14 +19,12 @@
 
 import org.apache.cocoon.portal.factory.ProducibleDescription;
 
-
-
 /**
  * A configured layout
  * 
  * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
  * 
- * @version CVS $Id: LayoutDescription.java,v 1.4 2004/03/05 13:02:13 bdelacretaz Exp $
+ * @version CVS $Id$
  */
 public interface LayoutDescription
     extends ProducibleDescription  {
@@ -40,4 +38,9 @@
      * @return the names of all allowed renderers
      */
     Iterator getRendererNames();
+    
+    /**
+     * @return The class name of the item
+     */
+    String getItemClassName();
 }

Modified: cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/layout/impl/CompositeLayoutImpl.java
==============================================================================
--- cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/layout/impl/CompositeLayoutImpl.java
(original)
+++ cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/layout/impl/CompositeLayoutImpl.java
Fri Oct 29 02:52:37 2004
@@ -23,6 +23,7 @@
 import org.apache.cocoon.portal.layout.CompositeLayout;
 import org.apache.cocoon.portal.layout.Item;
 import org.apache.cocoon.portal.layout.Layout;
+import org.apache.cocoon.util.ClassUtils;
 
 
 /**
@@ -37,8 +38,11 @@
     extends AbstractLayout
     implements CompositeLayout {
 
-	protected List items = new ArrayList();
+    protected List items = new ArrayList();
 
+    /** The class name of the items */
+    protected String itemClassName;
+    
     /**
      * Constructor
      */
@@ -98,9 +102,30 @@
      * @see org.apache.cocoon.portal.layout.CompositeLayout#createNewItem()
      */
     public Item createNewItem() {
-        return new Item();
+        if ( this.itemClassName == null ) {
+            return new Item();
+        }
+        try {
+            return (Item)ClassUtils.newInstance(this.itemClassName);
+        } catch (Exception ignore) {
+            return new Item();
+        }
     }
         
+    /**
+     * @return Returns the item class name.
+     */
+    public String getItemClassName() {
+        return this.itemClassName;
+    }
+    
+    /**
+     * @param itemClassName The item class name to set.
+     */
+    public void setItemClassName(String value) {
+        this.itemClassName = value;
+    }
+    
     /* (non-Javadoc)
      * @see java.lang.Object#clone()
      */

Modified: cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/layout/impl/DefaultLayoutDescription.java
==============================================================================
--- cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/layout/impl/DefaultLayoutDescription.java
(original)
+++ cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/layout/impl/DefaultLayoutDescription.java
Fri Oct 29 02:52:37 2004
@@ -28,7 +28,7 @@
  * 
  * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
  * 
- * @version CVS $Id: DefaultLayoutDescription.java,v 1.5 2004/03/05 13:02:13 bdelacretaz
Exp $
+ * @version CVS $Id$
  */
 public class DefaultLayoutDescription
     extends AbstractProducibleDescription
@@ -38,6 +38,8 @@
     
     protected List rendererNames = new ArrayList(2);
     
+    protected String itemClassName;
+    
     public String getDefaultRendererName() {
         return defaultRendererName;
     }
@@ -58,5 +60,18 @@
 
     public void addRendererName(String name) {
         this.rendererNames.add( name );
+    }
+    
+    /**
+     * @return Returns the itemClassName.
+     */
+    public String getItemClassName() {
+        return this.itemClassName;
+    }
+    /**
+     * @param itemClassName The itemClassName to set.
+     */
+    public void setItemClassName(String itemClassName) {
+        this.itemClassName = itemClassName;
     }
 }

Modified: cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/layout/impl/DefaultLayoutFactory.java
==============================================================================
--- cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/layout/impl/DefaultLayoutFactory.java
(original)
+++ cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portal/layout/impl/DefaultLayoutFactory.java
Fri Oct 29 02:52:37 2004
@@ -143,7 +143,9 @@
     protected ServiceManager manager;
     
     protected Configuration[] layoutsConf;
-    
+
+    protected static long idCounter = System.currentTimeMillis();
+
     /* (non-Javadoc)
      * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
      */
@@ -167,7 +169,8 @@
         desc.setName(name);
         desc.setClassName(layoutConf.getAttribute("class"));        
         desc.setCreateId(layoutConf.getAttributeAsBoolean("create-id", false));
-                
+        desc.setItemClassName(layoutConf.getAttribute("item-class", null));
+        
         // the renderers
         final String defaultRenderer = layoutConf.getChild("renderers").getAttribute("default");
         desc.setDefaultRendererName(defaultRenderer); 
@@ -253,6 +256,9 @@
         }
     }
     
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.portal.layout.LayoutFactory#prepareLayout(org.apache.cocoon.portal.layout.Layout)
+     */
     public void prepareLayout(Layout layout) 
     throws ProcessingException {
         if ( layout != null ) {
@@ -272,10 +278,12 @@
 
             layout.setDescription( layoutDescription );
             layout.setAspectDataHandler((AspectDataHandler)o[1]);
-            
+
             // recursive
             if ( layout instanceof CompositeLayout ) {
                 CompositeLayout composite = (CompositeLayout)layout;
+                composite.setItemClassName(layoutDescription.getItemClassName());
+                
                 Iterator items = composite.getItems().iterator();
                 while ( items.hasNext() ) {
                     this.prepareLayout( ((Item)items.next()).getLayout() );
@@ -309,13 +317,20 @@
         
         String id = null;
         if ( layoutDescription.createId() ) {
-            // TODO - set unique id
-            id = layoutName + '-' + System.currentTimeMillis();
+            synchronized (this) {
+                id = layoutName + '-' + idCounter;
+                idCounter += 1;
+            }
         }
         layout.initialize( layoutName, id ); 
         layout.setDescription( layoutDescription );
         layout.setAspectDataHandler((AspectDataHandler)o[1]);
 
+        if ( layout instanceof CompositeLayout ) {
+            CompositeLayout composite = (CompositeLayout)layout;
+            composite.setItemClassName(layoutDescription.getItemClassName());
+        }
+        
         PortalService service = null;
         try {
             service = (PortalService)this.manager.lookup(PortalService.ROLE);
@@ -328,6 +343,9 @@
         return layout;
     }
     
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.portal.layout.LayoutFactory#getLayoutDescriptions()
+     */
     public List getLayoutDescriptions() {
         this.init();
         return this.descriptions;

Mime
View raw message