You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2004/09/16 22:06:28 UTC

svn commit: rev 46206 - in cocoon/branches/BRANCH_2_1_X: . src/blocks/taglib/java/org/apache/cocoon/taglib src/blocks/taglib/java/org/apache/cocoon/transformation

Author: vgritsenko
Date: Thu Sep 16 13:06:28 2004
New Revision: 46206

Added:
   cocoon/branches/BRANCH_2_1_X/src/blocks/taglib/java/org/apache/cocoon/taglib/BodyContent.java
   cocoon/branches/BRANCH_2_1_X/src/blocks/taglib/java/org/apache/cocoon/taglib/BodyTag.java
Modified:
   cocoon/branches/BRANCH_2_1_X/src/blocks/taglib/java/org/apache/cocoon/taglib/Tag.java
   cocoon/branches/BRANCH_2_1_X/src/blocks/taglib/java/org/apache/cocoon/transformation/TagTransformer.java
   cocoon/branches/BRANCH_2_1_X/status.xml
Log:
Taglib block: Initial implementation of BodyTag.



Added: cocoon/branches/BRANCH_2_1_X/src/blocks/taglib/java/org/apache/cocoon/taglib/BodyContent.java
==============================================================================
--- (empty file)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/taglib/java/org/apache/cocoon/taglib/BodyContent.java	Thu Sep 16 13:06:28 2004
@@ -0,0 +1,46 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.taglib;
+
+import org.apache.cocoon.xml.XMLConsumer;
+import org.apache.cocoon.xml.SaxBuffer;
+
+/**
+ * @version CVS $Id: IterationTag.java 30932 2004-07-29 17:35:38Z vgritsenko $
+ */
+public class BodyContent {
+
+    private SaxBuffer content;
+    private XMLConsumer consumer;
+
+
+    public BodyContent(SaxBuffer content, XMLConsumer consumer) {
+        this.content = content;
+        this.consumer = consumer;
+    }
+
+    public void clearBody() {
+        this.content.recycle();
+    }
+
+    public SaxBuffer getContent() {
+        return this.content;
+    }
+
+    public String getString() {
+        return this.content.toString();
+    }
+}

Added: cocoon/branches/BRANCH_2_1_X/src/blocks/taglib/java/org/apache/cocoon/taglib/BodyTag.java
==============================================================================
--- (empty file)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/taglib/java/org/apache/cocoon/taglib/BodyTag.java	Thu Sep 16 13:06:28 2004
@@ -0,0 +1,43 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.taglib;
+
+import org.xml.sax.SAXException;
+
+/**
+ * The BodyTag interface extends IterationTag.
+ *
+ * @version CVS $Id: IterationTag.java 30932 2004-07-29 17:35:38Z vgritsenko $
+ */
+public interface BodyTag extends IterationTag {
+
+    /**
+     * Evaluate and buffer body content.
+     * Valid return value for doStartTag.
+     */
+    int EVAL_BODY_BUFFERED = 2;
+
+    /**
+     * Invoked only when doStartTag returns EVAL_BODY_BUFFERED and tag has content
+     */
+    void setBodyContent(BodyContent bodyContent) throws SAXException;
+
+    /**
+     * Invoked after setBodyContent only when doStartTag returns EVAL_BODY_BUFFERED
+     * and tag has content
+     */
+    void doInitBody() throws SAXException;
+}

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/taglib/java/org/apache/cocoon/taglib/Tag.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/taglib/java/org/apache/cocoon/taglib/Tag.java	(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/taglib/java/org/apache/cocoon/taglib/Tag.java	Thu Sep 16 13:06:28 2004
@@ -1,12 +1,12 @@
 /*
  * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -29,14 +29,14 @@
  * The Tag implementation works like a JSP Tag but generate SAX output
  * instead of writing to a OutputStream. The equivalent to the JSPEngine
  * is implemented as a Transformer.
- * 
+ *
  * @see org.apache.cocoon.transformation.TagTransformer
- * 
+ *
  * @author <a href="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
- * @version CVS $Id: Tag.java,v 1.3 2004/03/05 13:02:24 bdelacretaz Exp $
+ * @version CVS $Id$
  */
 public interface Tag extends Component {
-    
+
     String ROLE = Tag.class.getName();
 
     /**
@@ -53,7 +53,7 @@
 
     /**
      * Continue evaluating the page.
-     * Valid return value for doEndTag().
+     * Valid return value for doEndTag.
      */
     int EVAL_PAGE = 2;
 

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/taglib/java/org/apache/cocoon/transformation/TagTransformer.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/taglib/java/org/apache/cocoon/transformation/TagTransformer.java	(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/taglib/java/org/apache/cocoon/transformation/TagTransformer.java	Thu Sep 16 13:06:28 2004
@@ -32,9 +32,12 @@
 import org.apache.cocoon.environment.SourceResolver;
 import org.apache.cocoon.taglib.IterationTag;
 import org.apache.cocoon.taglib.Tag;
+import org.apache.cocoon.taglib.BodyTag;
+import org.apache.cocoon.taglib.BodyContent;
 import org.apache.cocoon.xml.AbstractXMLProducer;
 import org.apache.cocoon.xml.XMLConsumer;
 import org.apache.cocoon.xml.XMLProducer;
+import org.apache.cocoon.xml.SaxBuffer;
 
 import org.apache.commons.collections.ArrayStack;
 import org.apache.commons.collections.map.StaticBucketMap;
@@ -389,9 +392,25 @@
                     try {
                         xmlDeserializer = (XMLDeserializer) manager.lookup(XMLDeserializer.ROLE);
                         xmlDeserializer.setConsumer(this);
+
+                        // BodyTag Support
+                        XMLConsumer backup = this.currentConsumer;
+                        if (tag instanceof BodyTag) {
+                            SaxBuffer content = new SaxBuffer();
+                            this.currentConsumer = content;
+                            ((BodyTag)tag).setBodyContent(new BodyContent(content, backup));
+                            ((BodyTag)tag).doInitBody();
+                        }
+
                         do {
                             xmlDeserializer.deserialize(saxFragment);
                         } while (iterTag.doAfterBody() != Tag.SKIP_BODY);
+
+                        // BodyTag Support
+                        if (tag instanceof BodyTag) {
+                            this.currentConsumer = backup;
+                        }
+
                     } catch (ServiceException e) {
                         throw new SAXException("Can't obtain XMLDeserializer", e);
                     } finally {

Modified: cocoon/branches/BRANCH_2_1_X/status.xml
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml	(original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml	Thu Sep 16 13:06:28 2004
@@ -204,6 +204,13 @@
 
   <changes>
  <release version="@version@" date="@date@">
+   <action dev="VG" type="add">
+     Taglib block: Initial implementation of BodyTag.
+   </action>
+   <action dev="VG" type="update">
+     Portal block: Changed pathInfo and servletPath logic. pathInfo always starts
+     with '/', while servletPath always has no '/' at the end.
+   </action>
    <action dev="AG" type="fix" fixes-bug="31134" due-to="Ralph Goers" due-to-email="Ralph_Goers@dslextreme.com">
      JXPathMetaModule incorrectly checks for null parameter (can't happen) instead of empty string.
    </action>