cmlenz 02/01/27 09:16:22
Modified: src/taglib slide-jstl.tld slide-struts.tld
src/taglib/common/org/apache/slide/taglib/bean
RevisionBean.java
src/taglib/common/org/apache/slide/taglib/tag
ContentTagSupport.java
src/taglib/struts/org/apache/slide/taglib/tag/struts
ContentTag.java
Added: src/taglib/jstl/org/apache/slide/taglib/tag/jstl
ContentTag.java
Log:
Changed the semantics of the content tag: Now the revision content is either
inlined into the output, stored in a pagecontext string or a pagecontext
reader.
Corrected the slide-jstl.tld to conform to the JSP 1.2 DTD
Revision Changes Path
1.2 +44 -16 jakarta-slide/src/taglib/slide-jstl.tld
Index: slide-jstl.tld
===================================================================
RCS file: /home/cvs/jakarta-slide/src/taglib/slide-jstl.tld,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- slide-jstl.tld 27 Jan 2002 15:46:37 -0000 1.1
+++ slide-jstl.tld 27 Jan 2002 17:16:22 -0000 1.2
@@ -5,94 +5,122 @@
<taglib>
- <tlibversion>1.0</tlibversion>
- <jspversion>1.2</jspversion>
- <shortname>slide-jstl</shortname>
+ <tlib-version>1.0</tlib-version>
+ <jsp-version>1.2</jsp-version>
+ <short-name>slide-jstl</short-name>
<uri>http://jakarta.apache.org/slide/tags-jstl-1.0</uri>
- <info>
- JSTL (EA3) based JSP Tag Library for Jakarta Slide
- </info>
+ <display-name>Slide JSTL</display-name>
+ <description>JSTL based JSP Tag Library for Jakarta Slide</description>
<!-- The 'domain' Tag -->
<tag>
<name>domain</name>
- <tagclass>org.apache.slide.taglib.tag.jstl.DomainTag</tagclass>
- <bodycontent>JSP</bodycontent>
+ <tag-class>org.apache.slide.taglib.tag.jstl.DomainTag</tag-class>
+ <body-content>JSP</body-content>
<attribute>
<name>var</name>
<required>true</required>
+ <rtexprvalue>false</rtexprvalue>
</attribute>
</tag>
<!-- The 'namespace' Tag -->
<tag>
<name>namespace</name>
- <tagclass>org.apache.slide.taglib.tag.jstl.NamespaceTag</tagclass>
- <bodycontent>JSP</bodycontent>
+ <tag-class>org.apache.slide.taglib.tag.jstl.NamespaceTag</tag-class>
+ <body-content>JSP</body-content>
<attribute>
<name>name</name>
<required>false</required>
+ <rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>var</name>
<required>false</required>
+ <rtexprvalue>false</rtexprvalue>
</attribute>
</tag>
<!-- The 'node' Tag -->
<tag>
<name>node</name>
- <tagclass>org.apache.slide.taglib.tag.jstl.NodeTag</tagclass>
- <bodycontent>JSP</bodycontent>
+ <tag-class>org.apache.slide.taglib.tag.jstl.NodeTag</tag-class>
+ <body-content>JSP</body-content>
<attribute>
<name>uri</name>
<required>true</required>
+ <rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>resolveLinks</name>
<required>false</required>
+ <rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>var</name>
<required>false</required>
+ <rtexprvalue>false</rtexprvalue>
</attribute>
</tag>
<!-- The 'revision' Tag -->
<tag>
<name>revision</name>
- <tagclass>org.apache.slide.taglib.tag.jstl.RevisionTag</tagclass>
- <bodycontent>JSP</bodycontent>
+ <tag-class>org.apache.slide.taglib.tag.jstl.RevisionTag</tag-class>
+ <body-content>JSP</body-content>
<attribute>
<name>number</name>
<required>false</required>
+ <rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>branch</name>
<required>false</required>
+ <rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>var</name>
<required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ </attribute>
+ </tag>
+
+ <!-- The 'content' Tag -->
+ <tag>
+ <name>content</name>
+ <tag-class>org.apache.slide.taglib.tag.jstl.ContentTag</tag-class>
+ <body-content>JSP</body-content>
+ <attribute>
+ <name>var</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ </attribute>
+ <attribute>
+ <name>varReader</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
</attribute>
</tag>
<!-- The 'property' Tag -->
<tag>
<name>property</name>
- <tagclass>org.apache.slide.taglib.tag.jstl.PropertyTag</tagclass>
- <bodycontent>JSP</bodycontent>
+ <tag-class>org.apache.slide.taglib.tag.jstl.PropertyTag</tag-class>
+ <body-content>JSP</body-content>
<attribute>
<name>namespace</name>
<required>false</required>
+ <rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>name</name>
<required>true</required>
+ <rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>var</name>
<required>false</required>
+ <rtexprvalue>false</rtexprvalue>
</attribute>
</tag>
1.6 +8 -0 jakarta-slide/src/taglib/slide-struts.tld
Index: slide-struts.tld
===================================================================
RCS file: /home/cvs/jakarta-slide/src/taglib/slide-struts.tld,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- slide-struts.tld 3 Dec 2001 15:13:26 -0000 1.5
+++ slide-struts.tld 27 Jan 2002 17:16:22 -0000 1.6
@@ -92,6 +92,14 @@
<name>content</name>
<tagclass>org.apache.slide.taglib.tag.struts.ContentTag</tagclass>
<bodycontent>empty</bodycontent>
+ <attribute>
+ <name>id</name>
+ <required>false</required>
+ </attribute>
+ <attribute>
+ <name>idReader</name>
+ <required>false</required>
+ </attribute>
</tag>
<!-- The 'property' Tag -->
1.5 +23 -4
jakarta-slide/src/taglib/common/org/apache/slide/taglib/bean/RevisionBean.java
Index: RevisionBean.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/taglib/common/org/apache/slide/taglib/bean/RevisionBean.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- RevisionBean.java 3 Dec 2001 15:00:18 -0000 1.4
+++ RevisionBean.java 27 Jan 2002 17:16:22 -0000 1.5
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-slide/src/taglib/common/org/apache/slide/taglib/bean/RevisionBean.java,v
1.4 2001/12/03 15:00:18 cmlenz Exp $
- * $Revision: 1.4 $
- * $Date: 2001/12/03 15:00:18 $
+ * $Header:
/home/cvs/jakarta-slide/src/taglib/common/org/apache/slide/taglib/bean/RevisionBean.java,v
1.5 2002/01/27 17:16:22 cmlenz Exp $
+ * $Revision: 1.5 $
+ * $Date: 2002/01/27 17:16:22 $
*
* ====================================================================
*
@@ -65,6 +65,7 @@
import java.io.InputStream;
import java.io.IOException;
+import java.io.Reader;
import java.util.Enumeration;
import java.util.Vector;
@@ -85,7 +86,7 @@
* layer technologies such as JSP or Velocity.</p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Christopher Lenz</a>
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*/
public class RevisionBean
extends AbstractBean {
@@ -273,6 +274,24 @@
}
return null;
+ }
+
+
+ /**
+ * Returns a Reader for the content of the revision.
+ *
+ * @return the revision content as Reader
+ *
+ * @throw SlideException Exception occurred when trying to access the
+ * resource through Slide.
+ * @throw IOException IO exception occurred when trying to read the
+ * revision content
+ */
+ public Reader getReader()
+ throws SlideException, IOException {
+
+ Content content = nat.getContentHelper();
+ return content.retrieve(st, revisions, revision).readContent();
}
1.3 +102 -88
jakarta-slide/src/taglib/common/org/apache/slide/taglib/tag/ContentTagSupport.java
Index: ContentTagSupport.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/taglib/common/org/apache/slide/taglib/tag/ContentTagSupport.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ContentTagSupport.java 3 Dec 2001 15:53:37 -0000 1.2
+++ ContentTagSupport.java 27 Jan 2002 17:16:22 -0000 1.3
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-slide/src/taglib/common/org/apache/slide/taglib/tag/ContentTagSupport.java,v
1.2 2001/12/03 15:53:37 cmlenz Exp $
- * $Revision: 1.2 $
- * $Date: 2001/12/03 15:53:37 $
+ * $Header:
/home/cvs/jakarta-slide/src/taglib/common/org/apache/slide/taglib/tag/ContentTagSupport.java,v
1.3 2002/01/27 17:16:22 cmlenz Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/01/27 17:16:22 $
*
* ====================================================================
*
@@ -63,14 +63,17 @@
package org.apache.slide.taglib.tag;
+import java.io.BufferedReader;
import java.io.InputStream;
import java.io.IOException;
+import java.io.Reader;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;
+import javax.servlet.jsp.tagext.TryCatchFinally;
import org.apache.slide.common.SlideException;
import org.apache.slide.taglib.bean.NodeBean;
@@ -78,22 +81,19 @@
import org.apache.slide.taglib.bean.RevisionBean;
/**
- * Very simple implementation of a tag that sends the content of a revision of
- * a node to the client.
+ * Very simple implementation of a tag that includes the content of a revision
+ * in the response. Alternatively, the content may be stored as String or
+ * Reader in the page context
*
* <p>The node and revision is chosen based on the tags the content tag is
- * nested in. This tag must be used before the response is commited as HTML
- * content, because the response headers and content will be reset.</p>
- *
- * <ul>TODO:
- * <li>Support Content-Range</li>
- * </ul>
+ * nested in.</p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Christopher Lenz</a>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public abstract class ContentTagSupport
- extends TagSupport {
+ extends TagSupport
+ implements TryCatchFinally {
// ----------------------------------------------------- Instance Variables
@@ -105,6 +105,24 @@
protected RevisionBean revision;
+ /**
+ * Name of the PageContext attribute under which the String is stored.
+ **/
+ protected String attrName;
+
+
+ /**
+ * Name of the PageContext attribute under which the Reader is stored.
+ **/
+ protected String attrNameReader;
+
+
+ /**
+ *
+ */
+ private Reader reader;
+
+
// ----------------------------------------------------------- Construction
@@ -130,93 +148,88 @@
public int doStartTag()
throws JspException {
- HttpServletResponse response =
- (HttpServletResponse)pageContext.getResponse();
- if (response.isCommitted()) {
- // indicates improper use of this tag: should be used very close to
- // the beginning of a JSP, not after so much output has already
- // been written that part of the response has already been sent.
- throw new JspException("The Slide 'content' tag has to be used " +
- "before the response has been committed.");
- } else {
- response.reset();
- }
-
// revision not found
if (revision == null) {
- try {
- response.sendError(HttpServletResponse.SC_NOT_FOUND);
- // FIXME: ensure that the JSP engine does not reset the
- // status code after processing is finished
- return SKIP_PAGE;
- } catch (IOException e) {
- // ignore
- }
- }
-
- // set the HTTP response headers
- PropertyBean property;
- property = revision.getProperty("DAV:", "getcontenttype");
- if (property != null) {
- response.setHeader("Content-Type", property.getValue());
- }
- property = revision.getProperty("DAV:", "getcontentlength");
- if (property != null) {
- response.setHeader("Content-Length", property.getValue());
- }
- property = revision.getProperty("DAV:", "lastmodified");
- if (property != null) {
- response.setHeader("Last-Modified", property.getValue());
+ return SKIP_BODY;
}
- // stream the content
- ServletOutputStream os = null;
- InputStream is = null;
try {
- os = response.getOutputStream();
- try {
- is = revision.getInputStream();
- } catch (SlideException e) {
- System.out.println(e.getMessage());
- e.printStackTrace();
- }
-
- if (is != null) {
- byte buffer[] = new byte[2048];
- int len = buffer.length;
- while (true) {
- len = is.read(buffer);
- if (len == -1)
- break;
- os.write(buffer, 0, len);
- }
+ if (attrNameReader != null) {
+ reader = revision.getReader();
+ pageContext.setAttribute(attrNameReader, reader);
}
-
} catch (IOException e) {
- // ignore
- } finally {
- if (os != null) {
- try {
- os.flush();
- } catch (Exception e) {
- // ignore
+ throw new JspException(e.getMessage());
+ } catch (SlideException e) {
+ throw new JspException(e.getMessage());
+ }
+
+ return SKIP_BODY;
+ }
+
+
+ /**
+ * Called by the JSP Engine when closing this tag.
+ *
+ * @throws JspException
+ */
+ public int doEndTag()
+ throws JspException {
+
+ try {
+ if (attrNameReader == null) {
+ BufferedReader br = new BufferedReader(revision.getReader());
+ StringBuffer sb = new StringBuffer();
+ int i;
+ // under JIT, testing seems to show this simple loop is as fast
+ // as any of the alternatives
+ while ((i = reader.read()) != -1) {
+ sb.append((char)i);
}
- try {
- os.close();
- } catch (Exception e) {
- // ignore
+ if (attrName != null) {
+ pageContext.setAttribute(attrName, sb.toString());
+ } else {
+ pageContext.getOut().print(sb);
}
}
- if (is != null) {
- try {
- is.close();
- } catch (Exception e) {
- // ignore
+ } catch (IOException e) {
+ throw new JspException(e.getMessage());
+ } catch (SlideException e) {
+ throw new JspException(e.getMessage());
+ }
+
+ return EVAL_PAGE;
+ }
+
+
+ /**
+ * Simply rethrows its exception.
+ * @throws Throwable
+ */
+ public void doCatch(Throwable t)
+ throws Throwable {
+
+ throw t;
+ }
+
+
+ /**
+ * Cleans up if appropriate.
+ */
+ public void doFinally() {
+
+ try {
+ // If we exposed a Reader in doStartTag(), close it.
+ if (attrNameReader != null) {
+ // 'reader' can be null if an exception was thrown...
+ if (reader != null) {
+ reader.close();
}
+ pageContext.removeAttribute(attrNameReader);
}
+ } catch (IOException ex) {
+ // ignore - close() failed, but there's nothing more we can do
}
-
- return SKIP_PAGE;
}
@@ -239,9 +252,10 @@
private void init() {
revision = null;
+ attrName = null;
+ attrNameReader = null;
}
}
-
1.1
jakarta-slide/src/taglib/jstl/org/apache/slide/taglib/tag/jstl/ContentTag.java
Index: ContentTag.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-slide/src/taglib/jstl/org/apache/slide/taglib/tag/jstl/ContentTag.java,v
1.1 2002/01/27 17:16:22 cmlenz Exp $
* $Revision: 1.1 $
* $Date: 2002/01/27 17:16:22 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.slide.taglib.tag.jstl;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import org.apache.slide.taglib.bean.RevisionBean;
import org.apache.slide.taglib.tag.ContentTagSupport;
/**
* Tag class for tags that exposes the content of a revision to the JSP page.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Christopher Lenz</a>
* @version $Revision: 1.1 $
*/
public class ContentTag
extends ContentTagSupport {
// ------------------------------------------------------------ Tag Methods
/**
* Called by the JSP Engine when opening this tag.
*
* @throws JspException not thrown
*/
public int doStartTag()
throws JspException {
super.doStartTag();
revision = JstlTagUtils.findRevision(this, pageContext);
return super.doStartTag();
}
// ------------------------------------------------------------- Properties
/**
* Returns the 'var' attribute.
*
* @return value of the 'var' attribute
*/
public String getVar() {
return attrName;
}
/**
* Set the 'var' attribute.
*
* @param var the attribute value
*/
public void setVar(String var) {
attrName = var;
}
/**
* Returns the 'varReader' attribute.
*
* @return value of the 'varReader' attribute
*/
public String getVarReader() {
return attrNameReader;
}
/**
* Set the 'varReader' attribute.
*
* @param varReader the attribute value
*/
public void setVarReader(String varReader) {
attrNameReader = varReader;
}
}
1.3 +51 -4
jakarta-slide/src/taglib/struts/org/apache/slide/taglib/tag/struts/ContentTag.java
Index: ContentTag.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/taglib/struts/org/apache/slide/taglib/tag/struts/ContentTag.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ContentTag.java 3 Dec 2001 15:53:37 -0000 1.2
+++ ContentTag.java 27 Jan 2002 17:16:22 -0000 1.3
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-slide/src/taglib/struts/org/apache/slide/taglib/tag/struts/ContentTag.java,v
1.2 2001/12/03 15:53:37 cmlenz Exp $
- * $Revision: 1.2 $
- * $Date: 2001/12/03 15:53:37 $
+ * $Header:
/home/cvs/jakarta-slide/src/taglib/struts/org/apache/slide/taglib/tag/struts/ContentTag.java,v
1.3 2002/01/27 17:16:22 cmlenz Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/01/27 17:16:22 $
*
* ====================================================================
*
@@ -73,7 +73,7 @@
* Extends the ContentTagSupport to work in a Struts environment.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Christopher Lenz</a>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class ContentTag
extends ContentTagSupport {
@@ -95,6 +95,53 @@
StrutsTagUtils.findRevision(this, pageContext);
return super.doStartTag();
+ }
+
+
+ // ------------------------------------------------------------- Properties
+
+
+ /**
+ * Returns the 'id' attribute.
+ *
+ * @return value of the 'id' attribute
+ */
+ public String getId() {
+
+ return attrName;
+ }
+
+
+ /**
+ * Set the 'id' attribute.
+ *
+ * @param id the attribute value
+ */
+ public void setId(String id) {
+
+ attrName = id;
+ }
+
+
+ /**
+ * Returns the 'idReader' attribute.
+ *
+ * @return value of the 'idReader' attribute
+ */
+ public String getIdReader() {
+
+ return attrNameReader;
+ }
+
+
+ /**
+ * Set the 'idReader' attribute.
+ *
+ * @param idReader the attribute value
+ */
+ public void setIdReader(String idReader) {
+
+ attrNameReader = idReader;
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>