cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sylv...@apache.org
Subject svn commit: r328136 - /cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java
Date Mon, 24 Oct 2005 19:11:52 GMT
Author: sylvain
Date: Mon Oct 24 12:11:48 2005
New Revision: 328136

URL: http://svn.apache.org/viewcvs?rev=328136&view=rev
Log:
Add <ft:repeater> and <ft:repeater-rows> to forms transformer

Modified:
    cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java

Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java?rev=328136&r1=328135&r2=328136&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java
(original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java
Mon Oct 24 12:11:48 2005
@@ -78,6 +78,8 @@
     private static final String FORM_TEMPLATE_EL = "form-template";
     private static final String GROUP = "group";
     private static final String NEW = "new";
+    private static final String REPEATER = "repeater";
+    private static final String REPEATER_ROWS = "repeater-rows";
     private static final String REPEATER_SIZE = "repeater-size";
     private static final String REPEATER_WIDGET = "repeater-widget";
     private static final String REPEATER_WIDGET_LABEL = "repeater-widget-label";
@@ -99,6 +101,8 @@
     private final NestedHandler                    hNested          = new NestedHandler();
     private final NewHandler                       hNew             = new NewHandler();
     private final RepeaterSizeHandler              hRepeaterSize    = new RepeaterSizeHandler();
+    private final RepeaterHandler                  hRepeater        = new RepeaterHandler();
+    private final RepeaterRowsHandler              hRepeaterRows    = new RepeaterRowsHandler();
     private final RepeaterWidgetHandler            hRepeaterWidget  = new RepeaterWidgetHandler();
     private final RepeaterWidgetLabelHandler       hRepeaterWidgetLabel = new RepeaterWidgetLabelHandler();
     private final SkipHandler                      hSkip            = new SkipHandler();
@@ -145,6 +149,8 @@
         templates.put(CONTINUATION_ID, hContinuationId);
         templates.put(GROUP, hGroup);
         templates.put(NEW, hNew);
+        templates.put(REPEATER, hRepeater);
+        templates.put(REPEATER_ROWS, hRepeaterRows);
         templates.put(REPEATER_SIZE, hRepeaterSize);
         templates.put(REPEATER_WIDGET, hRepeaterWidget);
         templates.put(REPEATER_WIDGET_LABEL, hRepeaterWidgetLabel);
@@ -555,20 +561,93 @@
     protected class RepeaterWidgetLabelHandler extends ErrorHandler {
         public Handler startElement(String uri, String loc, String raw, Attributes attrs)
         throws SAXException {
-            setTypedWidget(loc, attrs, Repeater.class, "repeater");
+            Repeater repeater;
+            if (contextWidget instanceof Repeater) {
+                repeater = (Repeater)contextWidget;
+            } else {
+                setTypedWidget(loc, attrs, Repeater.class, "repeater");
+                repeater = (Repeater)widget;
+                widget = null;
+            }
             String path = getRequiredAttributeValue(loc, attrs, "widget-id");
-            ((Repeater) widget).generateWidgetLabel(path, getContentHandler());
-            widget = null;
+            repeater.generateWidgetLabel(path, getContentHandler());
+            return this;
+        }
+
+        public void endElement(String uri, String loc, String raw)
+        throws SAXException {
+        }
+    }
+
+    /**
+     * Handles <code>ft:repeater</code> element. Should contain repeater-rows
+     */
+    protected class RepeaterHandler extends NestedHandler {
+        protected Class getWidgetClass() {
+            return Repeater.class;
+        }
+
+        protected String getWidgetName() {
+            return "repeater";
+        }
+
+        public Handler startElement(String uri, String loc, String raw, Attributes attrs)
+        throws SAXException {
+            setTypedWidget(loc, attrs, getWidgetClass(), getWidgetName());
+            if (!isVisible(widget)) {
+                return hNull;
+            }
+
+            contextWidgets.addFirst(contextWidget);
+            contextWidget = widget;
+            return this;
+        }
+
+        public void endElement(String uri, String loc, String raw)
+        throws SAXException {
+            contextWidget = (Widget) contextWidgets.removeFirst();
+        }
+    }
+
+    /**
+     * Handles <code>ft:repeater-rows</code> element.
+     */
+    protected class RepeaterRowsHandler extends BufferHandler {
+        public Handler startElement(String uri, String loc, String raw, Attributes attrs)
+        throws SAXException {
+            if (!(contextWidget instanceof Repeater)) {
+                throw new SAXException("<repeater-rows> cannot be used with " + contextWidget
+ ", at " + getLocation());
+            }
+            beginBuffer();
             return this;
         }
 
+        public Handler nestedElement(String uri, String loc, String raw, Attributes attrs)
+        throws SAXException {
+            return hBuffer;
+        }
+
         public void endElement(String uri, String loc, String raw)
         throws SAXException {
+            SaxBuffer buffer = endBuffer();
+            final Repeater repeater = (Repeater) contextWidget;
+            final int rowCount = repeater.getSize();
+            pushHandler(hNested);
+            contextWidgets.addFirst(contextWidget);
+            for (int i = 0; i < rowCount; i++) {
+                contextWidget = repeater.getRow(i);
+                if (isVisible(contextWidget)) {
+                    buffer.toSAX(EffectWidgetReplacingPipe.this);
+                }
+            }
+            contextWidget = (Widget) contextWidgets.removeFirst();
+            popHandler();
+            widget = null;
         }
     }
 
     /**
-     * Handles <code>ft:repeater</code> element.
+     * Handles <code>ft:repeater-widget</code> element: a single element for
both the repeater and its rows
      */
     protected class RepeaterWidgetHandler extends BufferHandler {
         public Handler startElement(String uri, String loc, String raw, Attributes attrs)



Mime
View raw message