husted 2004/01/18 20:43:10
Modified: contrib/struts-el/doc/userGuide struts-html-el.xml
doc/userGuide struts-html.xml
src/share/org/apache/struts/taglib TagUtils.java
src/share/org/apache/struts/taglib/html ImgTag.java
web/examples/exercise html-img.jsp
Log:
Apply #18107 "contextRelative enhancement to <html:img...> tag" submitted by James
CE Johnson.
Revision Changes Path
1.26 +6 -0
jakarta-struts/contrib/struts-el/doc/userGuide/struts-html-el.xml
Index: struts-html-el.xml
===================================================================
RCS file:
/home/cvs/jakarta-struts/contrib/struts-el/doc/userGuide/struts-html-el.xml,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- struts-html-el.xml 18 Jan 2004 13:15:08 -0000 1.25
+++ struts-html-el.xml 19 Jan 2004 04:43:09 -0000 1.26
@@ -2805,6 +2805,12 @@
</info>
</attribute>
+ <attribute>
+ <name>contextRelative</name>
+ <required>false</required>
+ <rtexprvalue>true</rtexprvalue>
+ </attribute>
+
<attribute>
<name>height</name>
<required>false</required>
1.71 +6 -0 jakarta-struts/doc/userGuide/struts-html.xml
Index: struts-html.xml
===================================================================
RCS file: /home/cvs/jakarta-struts/doc/userGuide/struts-html.xml,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -r1.70 -r1.71
--- struts-html.xml 18 Jan 2004 13:14:42 -0000 1.70
+++ struts-html.xml 19 Jan 2004 04:43:09 -0000 1.71
@@ -2790,6 +2790,12 @@
</attribute>
<attribute>
+ <name>contextRelative</name>
+ <required>false</required>
+ <rtexprvalue>true</rtexprvalue>
+ </attribute>
+
+ <attribute>
<name>height</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
1.30 +14 -5 jakarta-struts/src/share/org/apache/struts/taglib/TagUtils.java
Index: TagUtils.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/TagUtils.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- TagUtils.java 13 Jan 2004 12:48:45 -0000 1.29
+++ TagUtils.java 19 Jan 2004 04:43:10 -0000 1.30
@@ -773,16 +773,25 @@
return value.startsWith("/") ? value : ("/" + value);
}
+
/**
* Return the form action converted into a server-relative URL.
*/
public String getActionMappingURL(String action, PageContext pageContext) {
+ return getActionMappingURL(action,pageContext,false);
+ }
+
+
+ /**
+ * Return the form action converted into a server-relative URL.
+ */
+ public String getActionMappingURL(String action, PageContext pageContext,
boolean contextRelative) {
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
StringBuffer value = new StringBuffer(request.getContextPath());
ModuleConfig config = ModuleUtils.getInstance().getModuleConfig(request);
- if (config != null) {
+ if ((config != null) && (!contextRelative)) {
value.append(config.getPrefix());
}
1.36 +81 -19
jakarta-struts/src/share/org/apache/struts/taglib/html/ImgTag.java
Index: ImgTag.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/ImgTag.java,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- ImgTag.java 13 Jan 2004 12:48:47 -0000 1.35
+++ ImgTag.java 19 Jan 2004 04:43:10 -0000 1.36
@@ -72,6 +72,7 @@
import org.apache.struts.config.ModuleConfig;
import org.apache.struts.taglib.TagUtils;
import org.apache.struts.util.MessageResources;
+import org.apache.struts.util.RequestUtils;
/**
* Generate an IMG tag to the specified image URI.
@@ -89,7 +90,7 @@
// ------------------------------------------------------------- Properties
- /**
+ /**
* The property to specify where to align the image.
*/
protected String align = null;
@@ -116,6 +117,32 @@
}
/**
+ * The property to specify how to root the image.
+ * If 'true' or if there is no current module the image is
+ * rooted to the application context path
+ * If 'false' or absent the image is rooted to the current
+ * module's context path.
+ */
+ protected String contextRelative = null;
+
+ public String getContextRelative() {
+ return (this.contextRelative);
+ }
+
+ public void setContextRelative(String contextRelative) {
+ this.contextRelative = contextRelative;
+ }
+
+
+ /**
+ * Convenience method to return true if contextRelative set to "true".
+ * @return True if contextRelative set to "true"
+ */
+ public boolean isContextRelativeSet() {
+ return Boolean.valueOf(this.contextRelative).booleanValue();
+ }
+
+ /**
* The image height.
*/
protected String height = null;
@@ -234,6 +261,21 @@
}
/**
+ * The module-relative action (beginning with a slash) which will be
+ * used as the source for this image.
+ */
+ protected String action = null;
+
+ public String getAction() {
+ return (this.action);
+ }
+
+ public void setAction(String action) {
+ this.action = action;
+ }
+
+
+ /**
* In situations where an image is dynamically generated (such as to create
* a chart graph), this specifies the single-parameter request parameter
* name to generate.
@@ -497,6 +539,7 @@
name = null;
page = null;
pageKey = null;
+ action = null;
paramId = null;
paramName = null;
paramProperty = null;
@@ -514,6 +557,26 @@
// ------------------------------------------------------ Protected Methods
/**
+ * Convenience method to throw a "imgTag.src" exception.
+ * @throws JspException
+ */
+ private void throwImgTagSrcException() throws JspException {
+ JspException e = new JspException(messages.getMessage("imgTag.src"));
+ TagUtils.getInstance().saveException(pageContext, e);
+ throw e;
+ }
+
+ /**
+ * Convenience method to test whether this is the default module
+ * or if contestRelative has been set.
+ * @param config Our Moduleconfig
+ * @return True if this is the default module or contextRelative is set
+ */
+ private boolean srcDefaultReference(ModuleConfig config) {
+ return (config == null || isContextRelativeSet());
+ }
+
+ /**
* Return the base source URL that will be rendered in the <code>src</code>
* property for this generated element, or <code>null</code> if there is
* no such URL.
@@ -525,14 +588,12 @@
// Deal with a direct context-relative page that has been specified
if (this.page != null) {
if ((this.src != null) || (this.srcKey != null) || (this.pageKey !=
null)) {
- JspException e = new
JspException(messages.getMessage("imgTag.src"));
- TagUtils.getInstance().saveException(pageContext, e);
- throw e;
+ throwImgTagSrcException();
}
ModuleConfig config =
(ModuleConfig)
pageContext.getRequest().getAttribute(Globals.MODULE_KEY);
HttpServletRequest request = (HttpServletRequest)
pageContext.getRequest();
- if (config == null) {
+ if (srcDefaultReference(config)) {
return (request.getContextPath() + this.page);
} else {
return (request.getContextPath() + config.getPrefix() + this.page);
@@ -542,14 +603,12 @@
// Deal with an indirect context-relative page that has been specified
if (this.pageKey != null) {
if ((this.src != null) || (this.srcKey != null)) {
- JspException e = new
JspException(messages.getMessage("imgTag.src"));
- TagUtils.getInstance().saveException(pageContext, e);
- throw e;
+ throwImgTagSrcException();
}
ModuleConfig config =
(ModuleConfig)
pageContext.getRequest().getAttribute(Globals.MODULE_KEY);
HttpServletRequest request = (HttpServletRequest)
pageContext.getRequest();
- if (config == null) {
+ if (srcDefaultReference(config)) {
return (
request.getContextPath()
+ TagUtils.getInstance().message(
@@ -569,21 +628,24 @@
}
}
+ if (this.action != null) {
+ if ((this.src != null) || (this.srcKey != null)) {
+ throwImgTagSrcException();
+ }
+ return TagUtils.getInstance().getActionMappingURL(action, pageContext,
isContextRelativeSet());
+ }
+
// Deal with an absolute source that has been specified
if (this.src != null) {
if (this.srcKey != null) {
- JspException e = new
JspException(messages.getMessage("imgTag.src"));
- TagUtils.getInstance().saveException(pageContext, e);
- throw e;
+ throwImgTagSrcException();
}
return (this.src);
}
// Deal with an indirect source that has been specified
if (this.srcKey == null) {
- JspException e = new JspException(messages.getMessage("imgTag.src"));
- TagUtils.getInstance().saveException(pageContext, e);
- throw e;
+ throwImgTagSrcException();
}
return TagUtils.getInstance().message(
1.3 +8 -0 jakarta-struts/web/examples/exercise/html-img.jsp
Index: html-img.jsp
===================================================================
RCS file: /home/cvs/jakarta-struts/web/examples/exercise/html-img.jsp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- html-img.jsp 18 Jan 2004 13:14:03 -0000 1.2
+++ html-img.jsp 19 Jan 2004 04:43:10 -0000 1.3
@@ -32,5 +32,13 @@
<html:img action="/html-img-action" />
</td>
</tr>
+ <tr>
+ <td>
+ Struts img tag via page attribute, context relative
+ </td>
+ <td>
+ <html:img page="/exercise/struts-power.gif" contextRelative="true"/>
+ </td>
+ </tr>
</body>
</html>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]