You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by cr...@locus.apache.org on 2000/09/05 03:33:24 UTC
cvs commit: jakarta-struts/src/share/org/apache/struts/taglib/bean IncludeTag.java IncludeTei.java HeaderTei.java LocalStrings.properties ParameterTei.java ResourceTei.java
craigmcc 00/09/04 18:33:23
Modified: . build.xml
src/doc struts-bean.xml
src/share/org/apache/struts/taglib/bean HeaderTei.java
LocalStrings.properties ParameterTei.java
ResourceTei.java
Added: src/share/org/apache/struts/taglib/bean IncludeTag.java
IncludeTei.java
Log:
Add the initial version of the "include" tag.
Revision Changes Path
1.14 +1 -1 jakarta-struts/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-struts/build.xml,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- build.xml 2000/08/30 22:41:45 1.13
+++ build.xml 2000/09/05 01:33:18 1.14
@@ -60,7 +60,7 @@
<!-- BUILD: Compile documentation application components -->
<target name="compile.documentation"
- depends="compile.library,prepare.documentation">
+ depends="dist.library,prepare.documentation">
<!-- Compile beans and tags required by the documentation app -->
<!--
1.2 +3 -2 jakarta-struts/src/doc/struts-bean.xml
Index: struts-bean.xml
===================================================================
RCS file: /home/cvs/jakarta-struts/src/doc/struts-bean.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- struts-bean.xml 2000/08/30 02:28:35 1.1
+++ struts-bean.xml 2000/09/05 01:33:20 1.2
@@ -235,13 +235,14 @@
</summary>
<tagclass>org.apache.struts.taglib.bean.IncludeTag</tagclass>
<teiclass>org.apache.struts.taglib.bean.IncludeTei</teiclass>
- <bodycontent>JSP</bodycontent>
+ <bodycontent>empty</bodycontent>
<info>
<p>Perform an internal dispatch to the specified application component
and make the response data from that request available as a bean of
type <code>String</code>. This tag has a function similar to that of
the standard <code><jsp:include></code> tag, except that the
- response data is always buffered if this tag is nested inside another.</p>
+ response data is stored in a page scope attribute instead of being
+ written to the output stream.</p>
</info>
<attribute>
1.2 +4 -4 jakarta-struts/src/share/org/apache/struts/taglib/bean/HeaderTei.java
Index: HeaderTei.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/HeaderTei.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- HeaderTei.java 2000/08/30 02:15:05 1.1
+++ HeaderTei.java 2000/09/05 01:33:21 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/HeaderTei.java,v 1.1 2000/08/30 02:15:05 craigmcc Exp $
- * $Revision: 1.1 $
- * $Date: 2000/08/30 02:15:05 $
+ * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/HeaderTei.java,v 1.2 2000/09/05 01:33:21 craigmcc Exp $
+ * $Revision: 1.2 $
+ * $Date: 2000/09/05 01:33:21 $
*
* ====================================================================
*
@@ -69,11 +69,11 @@
/**
- * Implementation of <code>TagExtraInfo</code> for the <b>header/b>
+ * Implementation of <code>TagExtraInfo</code> for the <b>header</b>
* tag, identifying the scripting object(s) to be made visible.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.1 $ $Date: 2000/08/30 02:15:05 $
+ * @version $Revision: 1.2 $ $Date: 2000/09/05 01:33:21 $
*/
public final class HeaderTei extends TagExtraInfo {
1.4 +3 -0 jakarta-struts/src/share/org/apache/struts/taglib/bean/LocalStrings.properties
Index: LocalStrings.properties
===================================================================
RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/LocalStrings.properties,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- LocalStrings.properties 2000/08/31 00:11:15 1.3
+++ LocalStrings.properties 2000/09/05 01:33:21 1.4
@@ -8,3 +8,6 @@
getter.parameter=No parameter {0} was included in this request
getter.resource=No resource {0} available in this application
getter.scope=Invalid bean scope {0} specified
+include.format=Context relative name {0} must start with a '/' character
+include.open=Exception opening resource {0}: {1}
+include.read=Exception reading resource {0}: {1}
1.2 +4 -4 jakarta-struts/src/share/org/apache/struts/taglib/bean/ParameterTei.java
Index: ParameterTei.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/ParameterTei.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ParameterTei.java 2000/08/30 02:15:06 1.1
+++ ParameterTei.java 2000/09/05 01:33:21 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/ParameterTei.java,v 1.1 2000/08/30 02:15:06 craigmcc Exp $
- * $Revision: 1.1 $
- * $Date: 2000/08/30 02:15:06 $
+ * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/ParameterTei.java,v 1.2 2000/09/05 01:33:21 craigmcc Exp $
+ * $Revision: 1.2 $
+ * $Date: 2000/09/05 01:33:21 $
*
* ====================================================================
*
@@ -69,11 +69,11 @@
/**
- * Implementation of <code>TagExtraInfo</code> for the <b>parameter/b>
+ * Implementation of <code>TagExtraInfo</code> for the <b>parameter</b>
* tag, identifying the scripting object(s) to be made visible.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.1 $ $Date: 2000/08/30 02:15:06 $
+ * @version $Revision: 1.2 $ $Date: 2000/09/05 01:33:21 $
*/
public final class ParameterTei extends TagExtraInfo {
1.2 +4 -4 jakarta-struts/src/share/org/apache/struts/taglib/bean/ResourceTei.java
Index: ResourceTei.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/ResourceTei.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ResourceTei.java 2000/08/30 02:15:07 1.1
+++ ResourceTei.java 2000/09/05 01:33:22 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/ResourceTei.java,v 1.1 2000/08/30 02:15:07 craigmcc Exp $
- * $Revision: 1.1 $
- * $Date: 2000/08/30 02:15:07 $
+ * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/ResourceTei.java,v 1.2 2000/09/05 01:33:22 craigmcc Exp $
+ * $Revision: 1.2 $
+ * $Date: 2000/09/05 01:33:22 $
*
* ====================================================================
*
@@ -70,11 +70,11 @@
/**
- * Implementation of <code>TagExtraInfo</code> for the <b>resource/b>
+ * Implementation of <code>TagExtraInfo</code> for the <b>resource</b>
* tag, identifying the scripting object(s) to be made visible.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.1 $ $Date: 2000/08/30 02:15:07 $
+ * @version $Revision: 1.2 $ $Date: 2000/09/05 01:33:22 $
*/
public final class ResourceTei extends TagExtraInfo {
1.1 jakarta-struts/src/share/org/apache/struts/taglib/bean/IncludeTag.java
Index: IncludeTag.java
===================================================================
/*
* $Id: IncludeTag.java,v 1.1 2000/09/05 01:33:21 craigmcc Exp $
* ====================================================================
*
* 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 apache@apache.org.
*
* 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.struts.taglib.bean;
import java.io.BufferedInputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;
import org.apache.struts.util.MessageResources;
/**
* Define the contents of a specified intra-application request as a
* page scope attribute of type <code>java.lang.String</code>.
* <p>
* <strong>FIXME</strong>: In a servlet 2.3 environment, we can use a
* wrapped response passed to RequestDispatcher.include().
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2000/09/05 01:33:21 $
*/
public class IncludeTag extends TagSupport {
// ------------------------------------------------------------- Properties
/**
* The name of the scripting variable that will be exposed as a page
* scope attribute.
*/
private String id = null;
public String getId() {
return (this.id);
}
public void setId(String id) {
this.id = id;
}
/**
* The message resources for this package.
*/
private static MessageResources messages =
MessageResources.getMessageResources
("org.apache.struts.taglib.bean.LocalStrings");
/**
* The context-relative URI of the page or servlet to be included.
*/
private String name = null;
public String getName() {
return (this.name);
}
public void setName(String name) {
this.name = name;
}
// --------------------------------------------------------- Public Methods
/**
* Define the contents returned for the specified resource as a
* page scope attribute.
*
* @exception JspException if a JSP error occurs
*/
public int doStartTag() throws JspException {
// Validate the format of the "name" attribute
// FIXME - deal with relative URIs like <jsp:include> does
if (!name.startsWith("/"))
throw new JspException
(messages.getMessage("include.format", name));
// Set up a URLConnection to read the requested page
HttpServletRequest request =
(HttpServletRequest) pageContext.getRequest();
StringBuffer url = new StringBuffer();
url.append(request.getScheme());
url.append("://");
url.append(request.getServerName());
if (request.getServerPort() != 80) {
url.append(':');
url.append(request.getServerPort());
}
if (request.getContextPath() != null)
url.append(request.getContextPath());
url.append(name);
URLConnection conn = null;
try {
conn = (new URL(url.toString())).openConnection();
conn.setAllowUserInteraction(false);
conn.setDoInput(true);
conn.setDoOutput(false);
conn.connect();
} catch (Exception e) {
throw new JspException
(messages.getMessage("include.open", name, e.toString()));
}
// Copy the contents of this URL
StringBuffer sb = new StringBuffer();
try {
BufferedInputStream is =
new BufferedInputStream(conn.getInputStream());
InputStreamReader in = new InputStreamReader(is); // FIXME - encoding
while (true) {
int ch = in.read();
if (ch < 0)
break;
sb.append(ch);
}
in.close();
} catch (Exception e) {
throw new JspException
(messages.getMessage("include.read", name, e.toString()));
}
// Define the retrieved content as a page scope attribute
pageContext.setAttribute(id, sb.toString());
// Skip any body of this tag
return (SKIP_BODY);
}
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/bean/IncludeTei.java
Index: IncludeTei.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/IncludeTei.java,v 1.1 2000/09/05 01:33:21 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2000/09/05 01:33:21 $
*
* ====================================================================
*
* 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 apache@apache.org.
*
* 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/>.
*
*/
package org.apache.struts.taglib.bean;
import javax.servlet.jsp.tagext.TagData;
import javax.servlet.jsp.tagext.TagExtraInfo;
import javax.servlet.jsp.tagext.VariableInfo;
/**
* Implementation of <code>TagExtraInfo</code> for the <b>include</b>
* tag, identifying the scripting object(s) to be made visible.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2000/09/05 01:33:21 $
*/
public final class IncludeTei extends TagExtraInfo {
/**
* Return information about the scripting variables to be created.
*/
public VariableInfo[] getVariableInfo(TagData data) {
return new VariableInfo[] {
new VariableInfo(data.getAttributeString("id"),
"java.lang.String",
true,
VariableInfo.AT_BEGIN)
};
}
}