You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by hu...@apache.org on 2006/02/10 22:01:32 UTC
svn commit: r376841 [2/6] -
/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/
Modified: struts/taglib/trunk/src/java/org/apache/struts/taglib/html/ErrorsTag.java
URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/ErrorsTag.java?rev=376841&r1=376840&r2=376841&view=diff
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/ErrorsTag.java (original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/ErrorsTag.java Fri Feb 10 13:01:28 2006
@@ -1,58 +1,68 @@
/*
- * $Id$
+ * $Id$
*
* 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.struts.taglib.html;
-import java.util.Iterator;
-import java.util.Locale;
-
-import javax.servlet.jsp.JspException;
-import javax.servlet.jsp.tagext.TagSupport;
-
import org.apache.struts.Globals;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.taglib.TagUtils;
import org.apache.struts.util.MessageResources;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.TagSupport;
+
+import java.util.Iterator;
+
/**
* Custom tag that renders error messages if an appropriate request attribute
* has been created. The tag looks for a request attribute with a reserved
* key, and assumes that it is either a String, a String array, containing
- * message keys to be looked up in the module's MessageResources, or
- * an object of type <code>org.apache.struts.action.ActionErrors</code>.
- * <p>
- * The following optional message keys will be utilized if corresponding
- * messages exist for them in the application resources:
+ * message keys to be looked up in the module's MessageResources, or an object
+ * of type <code>org.apache.struts.action.ActionErrors</code>. <p> The
+ * following optional message keys will be utilized if corresponding messages
+ * exist for them in the application resources:
+ *
* <ul>
+ *
* <li><b>errors.header</b> - If present, the corresponding message will be
- * rendered prior to the individual list of error messages.</li>
+ * rendered prior to the individual list of error messages.</li>
+ *
* <li><b>errors.footer</b> - If present, the corresponding message will be
- * rendered following the individual list of error messages.</li>
+ * rendered following the individual list of error messages.</li>
+ *
* <li><b>errors.prefix</b> - If present, the corresponding message will be
- * rendered before each individual error message.</li>
+ * rendered before each individual error message.</li>
+ *
* <li><b>errors.suffix</b> - If present, the corresponding message will be
- * rendered after each individual error message.</li>
+ * rendered after each individual error message.</li>
+ *
* </ul>
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2005-08-21 19:08:45 -0400 (Sun, 21 Aug 2005)
+ * $
*/
public class ErrorsTag extends TagSupport {
+ /**
+ * The message resources for this package.
+ */
+ protected static MessageResources messages =
+ MessageResources.getMessageResources(Constants.Package
+ + ".LocalStrings");
// ----------------------------------------------------------- Properties
@@ -61,6 +71,42 @@
*/
protected String bundle = null;
+ /**
+ * The session attribute key for our locale.
+ */
+ protected String locale = Globals.LOCALE_KEY;
+
+ /**
+ * The request attribute key for our error messages (if any).
+ */
+ protected String name = Globals.ERROR_KEY;
+
+ /**
+ * The name of the property for which error messages should be returned,
+ * or <code>null</code> to return all errors.
+ */
+ protected String property = null;
+
+ /**
+ * The message resource key for errors header.
+ */
+ protected String header = null;
+
+ /**
+ * The message resource key for errors footer.
+ */
+ protected String footer = null;
+
+ /**
+ * The message resource key for errors prefix.
+ */
+ protected String prefix = null;
+
+ /**
+ * The message resource key for errors suffix.
+ */
+ protected String suffix = null;
+
public String getBundle() {
return (this.bundle);
}
@@ -69,11 +115,6 @@
this.bundle = bundle;
}
- /**
- * The session attribute key for our locale.
- */
- protected String locale = Globals.LOCALE_KEY;
-
public String getLocale() {
return (this.locale);
}
@@ -82,17 +123,6 @@
this.locale = locale;
}
- /**
- * The message resources for this package.
- */
- protected static MessageResources messages =
- MessageResources.getMessageResources(Constants.Package + ".LocalStrings");
-
- /**
- * The request attribute key for our error messages (if any).
- */
- protected String name = Globals.ERROR_KEY;
-
public String getName() {
return (this.name);
}
@@ -101,12 +131,6 @@
this.name = name;
}
- /**
- * The name of the property for which error messages should be returned,
- * or <code>null</code> to return all errors.
- */
- protected String property = null;
-
public String getProperty() {
return (this.property);
}
@@ -115,56 +139,36 @@
this.property = property;
}
- /**
- * The message resource key for errors header.
- */
- protected String header = null;
-
public String getHeader() {
- return header == null ? "errors.header" : header;
+ return (header == null) ? "errors.header" : header;
}
public void setHeader(String header) {
this.header = header;
}
- /**
- * The message resource key for errors footer.
- */
- protected String footer = null;
-
public String getFooter() {
- return footer == null ? "errors.footer" : footer;
+ return (footer == null) ? "errors.footer" : footer;
}
public void setFooter(String footer) {
this.footer = footer;
}
- /**
- * The message resource key for errors prefix.
- */
- protected String prefix= null;
-
public String getPrefix() {
- return prefix == null ? "errors.prefix" : prefix;
+ return (prefix == null) ? "errors.prefix" : prefix;
}
public void setPrefix(String prefix) {
- this.prefix= prefix;
+ this.prefix = prefix;
}
- /**
- * The message resource key for errors suffix.
- */
- protected String suffix= null;
-
public String getSuffix() {
- return suffix == null ? "errors.suffix" : suffix;
+ return (suffix == null) ? "errors.suffix" : suffix;
}
public void setSuffix(String suffix) {
- this.suffix= suffix;
+ this.suffix = suffix;
}
// ------------------------------------------------------- Public Methods
@@ -172,14 +176,15 @@
/**
* Render the specified error messages if there are any.
*
- * @exception JspException if a JSP exception has occurred
+ * @throws JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
-
// Were any error messages specified?
ActionMessages errors = null;
+
try {
- errors = TagUtils.getInstance().getActionMessages(pageContext, name);
+ errors =
+ TagUtils.getInstance().getActionMessages(pageContext, name);
} catch (JspException e) {
TagUtils.getInstance().saveException(pageContext, e);
throw e;
@@ -190,86 +195,80 @@
}
boolean headerPresent =
- TagUtils.getInstance().present(pageContext, bundle, locale, getHeader());
+ TagUtils.getInstance().present(pageContext, bundle, locale,
+ getHeader());
boolean footerPresent =
- TagUtils.getInstance().present(pageContext, bundle, locale, getFooter());
+ TagUtils.getInstance().present(pageContext, bundle, locale,
+ getFooter());
boolean prefixPresent =
- TagUtils.getInstance().present(pageContext, bundle, locale, getPrefix());
+ TagUtils.getInstance().present(pageContext, bundle, locale,
+ getPrefix());
boolean suffixPresent =
- TagUtils.getInstance().present(pageContext, bundle, locale, getSuffix());
+ TagUtils.getInstance().present(pageContext, bundle, locale,
+ getSuffix());
// Render the error messages appropriately
StringBuffer results = new StringBuffer();
boolean headerDone = false;
String message = null;
- Iterator reports = (property == null) ? errors.get() : errors.get(property);
+ Iterator reports =
+ (property == null) ? errors.get() : errors.get(property);
while (reports.hasNext()) {
ActionMessage report = (ActionMessage) reports.next();
+
if (!headerDone) {
if (headerPresent) {
message =
- TagUtils.getInstance().message(
- pageContext,
- bundle,
- locale,
- getHeader());
-
+ TagUtils.getInstance().message(pageContext, bundle,
+ locale, getHeader());
+
results.append(message);
}
+
headerDone = true;
}
-
+
if (prefixPresent) {
message =
- TagUtils.getInstance().message(
- pageContext,
- bundle,
- locale,
+ TagUtils.getInstance().message(pageContext, bundle, locale,
getPrefix());
results.append(message);
}
-
+
if (report.isResource()) {
message =
- TagUtils.getInstance().message(
- pageContext,
- bundle,
- locale,
- report.getKey(),
- report.getValues());
+ TagUtils.getInstance().message(pageContext, bundle, locale,
+ report.getKey(), report.getValues());
} else {
message = report.getKey();
}
-
+
if (message != null) {
results.append(message);
}
-
+
if (suffixPresent) {
message =
- TagUtils.getInstance().message(
- pageContext,
- bundle,
- locale,
+ TagUtils.getInstance().message(pageContext, bundle, locale,
getSuffix());
results.append(message);
}
}
-
+
if (headerDone && footerPresent) {
message =
- TagUtils.getInstance().message(pageContext, bundle, locale, getFooter());
+ TagUtils.getInstance().message(pageContext, bundle, locale,
+ getFooter());
results.append(message);
}
TagUtils.getInstance().write(pageContext, results.toString());
return (EVAL_BODY_INCLUDE);
-
}
/**
@@ -286,5 +285,4 @@
prefix = null;
suffix = null;
}
-
}
Modified: struts/taglib/trunk/src/java/org/apache/struts/taglib/html/FileTag.java
URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/FileTag.java?rev=376841&r1=376840&r2=376841&view=diff
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/FileTag.java (original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/FileTag.java Fri Feb 10 13:01:28 2006
@@ -1,43 +1,35 @@
/*
- * $Id$
+ * $Id$
*
* 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.struts.taglib.html;
/**
* Custom tag for input fields of type "file".
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2004-10-16 12:38:42 -0400 (Sat, 16 Oct 2004)
+ * $
*/
-
public class FileTag extends BaseFieldTag {
-
-
/**
* Construct a new instance of this tag.
*/
public FileTag() {
-
- super();
- this.type = "file";
-
+ super();
+ this.type = "file";
}
-
-
}
Modified: struts/taglib/trunk/src/java/org/apache/struts/taglib/html/FormTag.java
URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/FormTag.java?rev=376841&r1=376840&r2=376841&view=diff
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/FormTag.java (original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/FormTag.java Fri Feb 10 13:01:28 2006
@@ -1,33 +1,22 @@
/*
- * $Id$
+ * $Id$
*
* 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.struts.taglib.html;
-import java.io.IOException;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpSession;
-import javax.servlet.jsp.JspException;
-import javax.servlet.jsp.JspWriter;
-import javax.servlet.jsp.PageContext;
-import javax.servlet.jsp.tagext.TagSupport;
-
import org.apache.struts.Globals;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
@@ -38,13 +27,35 @@
import org.apache.struts.util.MessageResources;
import org.apache.struts.util.RequestUtils;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.JspWriter;
+import javax.servlet.jsp.PageContext;
+import javax.servlet.jsp.tagext.TagSupport;
+
+import java.io.IOException;
+
/**
* Custom tag that represents an input form, associated with a bean whose
* properties correspond to the various fields of the form.
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2005-06-22 12:23:18 -0400 (Wed, 22 Jun 2005)
+ * $
*/
public class FormTag extends TagSupport {
+ /**
+ * The line ending string.
+ */
+ protected static String lineEnd = System.getProperty("line.separator");
+
+ /**
+ * The message resources for this package.
+ */
+ protected static MessageResources messages =
+ MessageResources.getMessageResources(Constants.Package
+ + ".LocalStrings");
// ----------------------------------------------------- Instance Variables
@@ -69,31 +80,22 @@
protected String focus = null;
/**
- * The index in the focus field array to receive focus. This only applies if the field
- * given in the focus attribute is actually an array of fields. This allows a specific
- * field in a radio button array to receive focus while still allowing indexed field
- * names like "myRadioButtonField[1]" to be passed in the focus attribute.
+ * The index in the focus field array to receive focus. This only applies
+ * if the field given in the focus attribute is actually an array of
+ * fields. This allows a specific field in a radio button array to
+ * receive focus while still allowing indexed field names like
+ * "myRadioButtonField[1]" to be passed in the focus attribute.
+ *
* @since Struts 1.1
*/
protected String focusIndex = null;
/**
- * The line ending string.
- */
- protected static String lineEnd = System.getProperty("line.separator");
-
- /**
* The ActionMapping defining where we will be submitting this form
*/
protected ActionMapping mapping = null;
/**
- * The message resources for this package.
- */
- protected static MessageResources messages =
- MessageResources.getMessageResources(Constants.Package + ".LocalStrings");
-
- /**
* The request method used when submitting this form.
*/
protected String method = null;
@@ -109,16 +111,17 @@
protected String onsubmit = null;
/**
- * Include language attribute in the focus script's <script> element. This
- * property is ignored in XHTML mode.
+ * Include language attribute in the focus script's <script>
+ * element. This property is ignored in XHTML mode.
+ *
* @since Struts 1.2
*/
protected boolean scriptLanguage = true;
/**
* The ActionServlet instance we are associated with (so that we can
- * initialize the <code>servlet</code> property on any form bean that
- * we create).
+ * initialize the <code>servlet</code> property on any form bean that we
+ * create).
*/
protected ActionServlet servlet = null;
@@ -151,8 +154,8 @@
/**
* The scope of the form bean to (create and) use. This is either the same
- * as the 'scope' attribute, if that was specified, or is obtained from the
- * associated <code>ActionMapping</code> otherwise.
+ * as the 'scope' attribute, if that was specified, or is obtained from
+ * the associated <code>ActionMapping</code> otherwise.
*/
protected String beanScope = null;
@@ -169,33 +172,33 @@
*/
protected String acceptCharset = null;
- /** Controls whether child controls should be 'disabled'. */
+ /**
+ * Controls whether child controls should be 'disabled'.
+ */
private boolean disabled = false;
- /** Controls whether child controls should be 'readonly'. */
+ /**
+ * Controls whether child controls should be 'readonly'.
+ */
protected boolean readonly = false;
// ------------------------------------------------------------- Properties
/**
- * Return the name of the form bean corresponding to this tag. There is
- * no corresponding setter method; this method exists so that the nested
- * tag classes can obtain the actual bean name derived from other
- * attributes of the tag.
+ * Return the name of the form bean corresponding to this tag. There is no
+ * corresponding setter method; this method exists so that the nested tag
+ * classes can obtain the actual bean name derived from other attributes
+ * of the tag.
*/
public String getBeanName() {
-
return beanName;
-
}
/**
* Return the action URL to which this form should be submitted.
*/
public String getAction() {
-
return (this.action);
-
}
/**
@@ -204,18 +207,14 @@
* @param action The new action URL
*/
public void setAction(String action) {
-
this.action = action;
-
}
/**
* Return the content encoding used when submitting this form.
*/
public String getEnctype() {
-
return (this.enctype);
-
}
/**
@@ -224,18 +223,14 @@
* @param enctype The new content encoding
*/
public void setEnctype(String enctype) {
-
this.enctype = enctype;
-
}
/**
* Return the focus field name for this form.
*/
public String getFocus() {
-
return (this.focus);
-
}
/**
@@ -244,18 +239,14 @@
* @param focus The new focus field name
*/
public void setFocus(String focus) {
-
this.focus = focus;
-
}
/**
* Return the request method used when submitting this form.
*/
public String getMethod() {
-
return (this.method);
-
}
/**
@@ -264,18 +255,14 @@
* @param method The new request method
*/
public void setMethod(String method) {
-
this.method = method;
-
}
/**
* Return the onReset event script.
*/
public String getOnreset() {
-
return (this.onreset);
-
}
/**
@@ -284,18 +271,14 @@
* @param onReset The new event script
*/
public void setOnreset(String onReset) {
-
this.onreset = onReset;
-
}
/**
* Return the onSubmit event script.
*/
public String getOnsubmit() {
-
return (this.onsubmit);
-
}
/**
@@ -304,18 +287,14 @@
* @param onSubmit The new event script
*/
public void setOnsubmit(String onSubmit) {
-
this.onsubmit = onSubmit;
-
}
/**
* Return the style attribute for this tag.
*/
public String getStyle() {
-
return (this.style);
-
}
/**
@@ -324,18 +303,14 @@
* @param style The new style attribute
*/
public void setStyle(String style) {
-
this.style = style;
-
}
/**
* Return the style class for this tag.
*/
public String getStyleClass() {
-
return (this.styleClass);
-
}
/**
@@ -344,18 +319,14 @@
* @param styleClass The new style class
*/
public void setStyleClass(String styleClass) {
-
this.styleClass = styleClass;
-
}
/**
* Return the style identifier for this tag.
*/
public String getStyleId() {
-
return (this.styleId);
-
}
/**
@@ -364,18 +335,14 @@
* @param styleId The new style identifier
*/
public void setStyleId(String styleId) {
-
this.styleId = styleId;
-
}
/**
* Return the window target.
*/
public String getTarget() {
-
return (this.target);
-
}
/**
@@ -384,18 +351,14 @@
* @param target The new window target
*/
public void setTarget(String target) {
-
this.target = target;
-
}
/**
* Return the list of character encodings accepted.
*/
public String getAcceptCharset() {
-
return acceptCharset;
-
}
/**
@@ -404,47 +367,51 @@
* @param acceptCharset The list of character encodings
*/
public void setAcceptCharset(String acceptCharset) {
-
- this.acceptCharset= acceptCharset;
-
+ this.acceptCharset = acceptCharset;
}
- /** Sets the disabled event handler. */
+ /**
+ * Sets the disabled event handler.
+ */
public void setDisabled(boolean disabled) {
this.disabled = disabled;
}
- /** Returns the disabled event handler. */
+ /**
+ * Returns the disabled event handler.
+ */
public boolean isDisabled() {
return disabled;
}
- /** Sets the readonly event handler. */
+ /**
+ * Sets the readonly event handler.
+ */
public void setReadonly(boolean readonly) {
this.readonly = readonly;
}
- /** Returns the readonly event handler. */
+ /**
+ * Returns the readonly event handler.
+ */
public boolean isReadonly() {
return readonly;
}
-
// --------------------------------------------------------- Public Methods
/**
* Render the beginning of this form.
*
- * @exception JspException if a JSP exception has occurred
+ * @throws JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
-
// Look up the form bean name, scope, and type if necessary
this.lookup();
// Create an appropriate "form" element based on our parameters
StringBuffer results = new StringBuffer();
-
+
results.append(this.renderFormStartElement());
results.append(this.renderToken());
@@ -452,58 +419,68 @@
TagUtils.getInstance().write(pageContext, results.toString());
// Store this tag itself as a page attribute
- pageContext.setAttribute(Constants.FORM_KEY, this, PageContext.REQUEST_SCOPE);
+ pageContext.setAttribute(Constants.FORM_KEY, this,
+ PageContext.REQUEST_SCOPE);
this.initFormBean();
return (EVAL_BODY_INCLUDE);
-
}
/**
* Locate or create the bean associated with our form.
+ *
* @throws JspException
* @since Struts 1.1
*/
- protected void initFormBean() throws JspException {
+ protected void initFormBean()
+ throws JspException {
int scope = PageContext.SESSION_SCOPE;
+
if ("request".equalsIgnoreCase(beanScope)) {
scope = PageContext.REQUEST_SCOPE;
}
-
+
Object bean = pageContext.getAttribute(beanName, scope);
+
if (bean == null) {
// New and improved - use the values from the action mapping
bean =
- RequestUtils.createActionForm(
- (HttpServletRequest) pageContext.getRequest(),
- mapping,
- moduleConfig,
- servlet);
+ RequestUtils.createActionForm((HttpServletRequest) pageContext
+ .getRequest(), mapping, moduleConfig, servlet);
+
if (bean instanceof ActionForm) {
- ((ActionForm) bean).reset(mapping, (HttpServletRequest) pageContext.getRequest());
+ ((ActionForm) bean).reset(mapping,
+ (HttpServletRequest) pageContext.getRequest());
}
+
if (bean == null) {
- throw new JspException(messages.getMessage("formTag.create", beanType));
+ throw new JspException(messages.getMessage("formTag.create",
+ beanType));
}
+
pageContext.setAttribute(beanName, bean, scope);
}
- pageContext.setAttribute(Constants.BEAN_KEY, bean, PageContext.REQUEST_SCOPE);
+
+ pageContext.setAttribute(Constants.BEAN_KEY, bean,
+ PageContext.REQUEST_SCOPE);
}
/**
- * Generates the opening <code><form></code> element with appropriate
- * attributes.
+ * Generates the opening <code><form></code> element with
+ * appropriate attributes.
+ *
* @since Struts 1.1
*/
- protected String renderFormStartElement() throws JspException {
-
+ protected String renderFormStartElement()
+ throws JspException {
StringBuffer results = new StringBuffer("<form");
// render attributes
renderName(results);
-
- renderAttribute(results, "method", getMethod() == null ? "post" : getMethod());
+
+ renderAttribute(results, "method",
+ (getMethod() == null) ? "post" : getMethod());
renderAction(results);
renderAttribute(results, "accept-charset", getAcceptCharset());
renderAttribute(results, "class", getStyleClass());
@@ -517,6 +494,7 @@
renderOtherAttributes(results);
results.append(">");
+
return results.toString();
}
@@ -524,40 +502,38 @@
* Renders the name of the form. If XHTML is set to true, the name will
* be rendered as an 'id' attribute, otherwise as a 'name' attribute.
*/
- protected void renderName(StringBuffer results) throws JspException {
+ protected void renderName(StringBuffer results)
+ throws JspException {
if (this.isXhtml()) {
if (getStyleId() == null) {
renderAttribute(results, "id", beanName);
} else {
throw new JspException(messages.getMessage("formTag.ignoredId"));
}
- } else {
+ } else {
renderAttribute(results, "name", beanName);
renderAttribute(results, "id", getStyleId());
- }
+ }
}
/**
* Renders the action attribute
*/
protected void renderAction(StringBuffer results) {
-
HttpServletResponse response =
(HttpServletResponse) this.pageContext.getResponse();
results.append(" action=\"");
- results.append(
- response.encodeURL(
- TagUtils.getInstance().getActionMappingURL(
- this.action,
+ results.append(response.encodeURL(
+ TagUtils.getInstance().getActionMappingURL(this.action,
this.pageContext)));
-
+
results.append("\"");
}
/**
- * 'Hook' to enable this tag to be extended and
- * additional attributes added.
+ * 'Hook' to enable this tag to be extended and additional attributes
+ * added.
*/
protected void renderOtherAttributes(StringBuffer results) {
}
@@ -565,6 +541,7 @@
/**
* Generates a hidden input field with token information, if any. The
* field is added within a div element for HTML 4.01 Strict compliance.
+ *
* @return A hidden input field containing the token.
* @since Struts 1.1
*/
@@ -575,17 +552,19 @@
if (session != null) {
String token =
(String) session.getAttribute(Globals.TRANSACTION_TOKEN_KEY);
-
+
if (token != null) {
results.append("<div><input type=\"hidden\" name=\"");
results.append(Constants.TOKEN_KEY);
results.append("\" value=\"");
results.append(token);
+
if (this.isXhtml()) {
results.append("\" />");
} else {
results.append("\">");
}
+
results.append("</div>");
}
}
@@ -596,7 +575,8 @@
/**
* Renders attribute="value" if not null
*/
- protected void renderAttribute(StringBuffer results, String attribute, String value) {
+ protected void renderAttribute(StringBuffer results, String attribute,
+ String value) {
if (value != null) {
results.append(" ");
results.append(attribute);
@@ -609,13 +589,14 @@
/**
* Render the end of this form.
*
- * @exception JspException if a JSP exception has occurred
+ * @throws JspException if a JSP exception has occurred
*/
public int doEndTag() throws JspException {
-
// Remove the page scope attributes we created
- pageContext.removeAttribute(Constants.BEAN_KEY, PageContext.REQUEST_SCOPE);
- pageContext.removeAttribute(Constants.FORM_KEY, PageContext.REQUEST_SCOPE);
+ pageContext.removeAttribute(Constants.BEAN_KEY,
+ PageContext.REQUEST_SCOPE);
+ pageContext.removeAttribute(Constants.FORM_KEY,
+ PageContext.REQUEST_SCOPE);
// Render a tag representing the end of our current form
StringBuffer results = new StringBuffer("</form>");
@@ -627,6 +608,7 @@
// Print this value to our output writer
JspWriter writer = pageContext.getOut();
+
try {
writer.print(results.toString());
} catch (IOException e) {
@@ -635,12 +617,12 @@
// Continue processing this page
return (EVAL_PAGE);
-
}
/**
- * Generates javascript to set the initial focus to the form element given in the
- * tag's "focus" attribute.
+ * Generates javascript to set the initial focus to the form element given
+ * in the tag's "focus" attribute.
+ *
* @since Struts 1.1
*/
protected String renderFocusJavascript() {
@@ -648,9 +630,11 @@
results.append(lineEnd);
results.append("<script type=\"text/javascript\"");
+
if (!this.isXhtml() && this.scriptLanguage) {
results.append(" language=\"JavaScript\"");
}
+
results.append(">");
results.append(lineEnd);
@@ -663,6 +647,7 @@
// Construct the control name that will receive focus.
// This does not include any index.
StringBuffer focusControl = new StringBuffer("document.forms[\"");
+
focusControl.append(beanName);
focusControl.append("\"].elements[\"");
focusControl.append(this.focus);
@@ -674,17 +659,21 @@
results.append(lineEnd);
results.append(lineEnd);
- results.append(" if (focusControl.type != \"hidden\" && !focusControl.disabled) {");
+ results.append(
+ " if (focusControl.type != \"hidden\" && !focusControl.disabled) {");
results.append(lineEnd);
// Construct the index if needed and insert into focus statement
String index = "";
+
if (this.focusIndex != null) {
StringBuffer sb = new StringBuffer("[");
+
sb.append(this.focusIndex);
sb.append("]");
index = sb.toString();
}
+
results.append(" focusControl");
results.append(index);
results.append(".focus();");
@@ -700,6 +689,7 @@
results.append("</script>");
results.append(lineEnd);
+
return results.toString();
}
@@ -707,7 +697,6 @@
* Release any acquired resources.
*/
public void release() {
-
super.release();
action = null;
moduleConfig = null;
@@ -726,62 +715,74 @@
styleId = null;
target = null;
acceptCharset = null;
-
}
// ------------------------------------------------------ Protected Methods
-
/**
* Look up values for the <code>name</code>, <code>scope</code>, and
* <code>type</code> properties if necessary.
*
- * @exception JspException if a required value cannot be looked up
+ * @throws JspException if a required value cannot be looked up
*/
protected void lookup() throws JspException {
-
// If the action is not specified, use the original request uri
if (this.action == null) {
- HttpServletRequest request =
- (HttpServletRequest) pageContext.getRequest();
- String uri = (String)request.getAttribute(Globals.ORIGINAL_URI_KEY);
+ HttpServletRequest request =
+ (HttpServletRequest) pageContext.getRequest();
+ String uri =
+ (String) request.getAttribute(Globals.ORIGINAL_URI_KEY);
+
setAction(uri);
-
- }
+ }
// Look up the module configuration information we need
moduleConfig = TagUtils.getInstance().getModuleConfig(pageContext);
if (moduleConfig == null) {
- JspException e = new JspException(messages.getMessage("formTag.collections"));
- pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE);
+ JspException e =
+ new JspException(messages.getMessage("formTag.collections"));
+
+ pageContext.setAttribute(Globals.EXCEPTION_KEY, e,
+ PageContext.REQUEST_SCOPE);
throw e;
}
+
servlet =
- (ActionServlet) pageContext.getServletContext().getAttribute(
- Globals.ACTION_SERVLET_KEY);
+ (ActionServlet) pageContext.getServletContext().getAttribute(Globals.ACTION_SERVLET_KEY);
// Look up the action mapping we will be submitting to
- String mappingName = TagUtils.getInstance().getActionMappingName(action);
+ String mappingName =
+ TagUtils.getInstance().getActionMappingName(action);
+
mapping = (ActionMapping) moduleConfig.findActionConfig(mappingName);
+
if (mapping == null) {
- JspException e = new JspException(messages.getMessage("formTag.mapping", mappingName));
- pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE);
+ JspException e =
+ new JspException(messages.getMessage("formTag.mapping",
+ mappingName));
+
+ pageContext.setAttribute(Globals.EXCEPTION_KEY, e,
+ PageContext.REQUEST_SCOPE);
throw e;
}
// Look up the form bean definition
- FormBeanConfig formBeanConfig = moduleConfig.findFormBeanConfig(mapping.getName());
+ FormBeanConfig formBeanConfig =
+ moduleConfig.findFormBeanConfig(mapping.getName());
+
if (formBeanConfig == null) {
- JspException e = null;
+ JspException e = null;
- if (mapping.getName() == null) {
- e = new JspException(messages.getMessage("formTag.name", action));
+ if (mapping.getName() == null) {
+ e = new JspException(messages.getMessage("formTag.name", action));
} else {
- e = new JspException(messages.getMessage("formTag.formBean", mapping.getName(), action));
- }
-
- pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE);
+ e = new JspException(messages.getMessage("formTag.formBean",
+ mapping.getName(), action));
+ }
+
+ pageContext.setAttribute(Globals.EXCEPTION_KEY, e,
+ PageContext.REQUEST_SCOPE);
throw e;
}
@@ -800,6 +801,7 @@
/**
* Returns the focusIndex.
+ *
* @return String
*/
public String getFocusIndex() {
@@ -808,6 +810,7 @@
/**
* Sets the focusIndex.
+ *
* @param focusIndex The focusIndex to set
*/
public void setFocusIndex(String focusIndex) {
@@ -815,8 +818,9 @@
}
/**
- * Gets whether or not the focus script's <script> element will include the
- * language attribute.
+ * Gets whether or not the focus script's <script> element will
+ * include the language attribute.
+ *
* @return true if language attribute will be included.
* @since Struts 1.2
*/
@@ -825,12 +829,12 @@
}
/**
- * Sets whether or not the focus script's <script> element will include the
- * language attribute.
+ * Sets whether or not the focus script's <script> element will
+ * include the language attribute.
+ *
* @since Struts 1.2
*/
public void setScriptLanguage(boolean scriptLanguage) {
this.scriptLanguage = scriptLanguage;
}
-
}
Modified: struts/taglib/trunk/src/java/org/apache/struts/taglib/html/FrameTag.java
URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/FrameTag.java?rev=376841&r1=376840&r2=376841&view=diff
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/FrameTag.java (original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/FrameTag.java Fri Feb 10 13:01:28 2006
@@ -1,58 +1,84 @@
/*
- * $Id$
+ * $Id$
*
* 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.struts.taglib.html;
-import javax.servlet.jsp.JspException;
-
import org.apache.struts.taglib.TagUtils;
+import javax.servlet.jsp.JspException;
+
/**
* Generate an HTML <code><frame></code> tag with similar capabilities
* as those the <code><html:link></code> tag provides for hyperlink
- * elements. The <code>src</code> element is rendered using the same technique
- * that {@link LinkTag} uses to render the <code>href</code> attribute of a
- * hyperlink. Additionall, the HTML 4.0
- * frame tag attributes <code>noresize</code>, <code>scrolling</code>,
- * <code>marginheight</code>, <code>marginwidth</code>,
- * <code>frameborder</code>, and <code>longdesc</code> are supported.
- * The frame
- * <code>name</code> attribute is rendered based on the <code>frameName</code>
- * property.
+ * elements. The <code>src</code> element is rendered using the same
+ * technique that {@link LinkTag} uses to render the <code>href</code>
+ * attribute of a hyperlink. Additionall, the HTML 4.0 frame tag attributes
+ * <code>noresize</code>, <code>scrolling</code>, <code>marginheight</code>,
+ * <code>marginwidth</code>, <code>frameborder</code>, and
+ * <code>longdesc</code> are supported. The frame <code>name</code> attribute
+ * is rendered based on the <code>frameName</code> property.
*
* Note that the value of <code>longdesc</code> is intended to be a URI, but
* currently no rewriting is supported. The attribute is set directly from
* the property value.
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2004-10-16 12:38:42 -0400 (Sat, 16 Oct 2004)
+ * $
* @since Struts 1.1
*/
public class FrameTag extends LinkTag {
-
-
// ------------------------------------------------------------- Properties
-
/**
* The frameborder attribute that should be rendered (1, 0).
*/
protected String frameborder = null;
+ /**
+ * The <code>name</code> attribute that should be rendered for this
+ * frame.
+ */
+ protected String frameName = null;
+
+ /**
+ * URI of a long description of this frame (complements title).
+ */
+ protected String longdesc = null;
+
+ /**
+ * The margin height in pixels, or zero for no setting.
+ */
+ protected Integer marginheight = null;
+
+ /**
+ * The margin width in pixels, or null for no setting.
+ */
+ protected Integer marginwidth = null;
+
+ /**
+ * Should users be disallowed to resize the frame?
+ */
+ protected boolean noresize = false;
+
+ /**
+ * What type of scrolling should be supported (yes, no, auto)?
+ */
+ protected String scrolling = null;
+
public String getFrameborder() {
return (this.frameborder);
}
@@ -61,12 +87,6 @@
this.frameborder = frameborder;
}
-
- /**
- * The <code>name</code> attribute that should be rendered for this frame.
- */
- protected String frameName = null;
-
public String getFrameName() {
return (this.frameName);
}
@@ -75,12 +95,6 @@
this.frameName = frameName;
}
-
- /**
- * URI of a long description of this frame (complements title).
- */
- protected String longdesc = null;
-
public String getLongdesc() {
return (this.longdesc);
}
@@ -89,12 +103,6 @@
this.longdesc = longdesc;
}
-
- /**
- * The margin height in pixels, or zero for no setting.
- */
- protected Integer marginheight = null;
-
public Integer getMarginheight() {
return (this.marginheight);
}
@@ -103,12 +111,6 @@
this.marginheight = marginheight;
}
-
- /**
- * The margin width in pixels, or null for no setting.
- */
- protected Integer marginwidth = null;
-
public Integer getMarginwidth() {
return (this.marginwidth);
}
@@ -117,12 +119,6 @@
this.marginwidth = marginwidth;
}
-
- /**
- * Should users be disallowed to resize the frame?
- */
- protected boolean noresize = false;
-
public boolean getNoresize() {
return (this.noresize);
}
@@ -131,12 +127,6 @@
this.noresize = noresize;
}
-
- /**
- * What type of scrolling should be supported (yes, no, auto)?
- */
- protected String scrolling = null;
-
public String getScrolling() {
return (this.scrolling);
}
@@ -145,18 +135,15 @@
this.scrolling = scrolling;
}
-
// --------------------------------------------------------- Public Methods
-
/**
* Render the appropriately encoded URI.
*
- * @exception JspException if a JSP exception has occurred
+ * @throws JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
-
- // Print this element to our output writer
+ // Print this element to our output writer
StringBuffer results = new StringBuffer("<frame");
prepareAttribute(results, "src", calculateURL());
@@ -165,6 +152,7 @@
if (noresize) {
results.append(" noresize=\"noresize\"");
}
+
prepareAttribute(results, "scrolling", getScrolling());
prepareAttribute(results, "marginheight", getMarginheight());
prepareAttribute(results, "marginwidth", getMarginwidth());
@@ -173,30 +161,24 @@
results.append(prepareStyles());
prepareOtherAttributes(results);
results.append(getElementClose());
- TagUtils.getInstance().write(pageContext,results.toString());
+ TagUtils.getInstance().write(pageContext, results.toString());
return (SKIP_BODY);
-
}
-
/**
* Ignore the end of this tag.
*
- * @exception JspException if a JSP exception has occurred
+ * @throws JspException if a JSP exception has occurred
*/
public int doEndTag() throws JspException {
-
return (EVAL_PAGE);
-
}
-
/**
* Release any acquired resources.
*/
public void release() {
-
super.release();
frameborder = null;
frameName = null;
@@ -205,8 +187,5 @@
marginwidth = null;
noresize = false;
scrolling = null;
-
}
-
-
}
Modified: struts/taglib/trunk/src/java/org/apache/struts/taglib/html/HiddenTag.java
URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/HiddenTag.java?rev=376841&r1=376840&r2=376841&view=diff
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/HiddenTag.java (original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/HiddenTag.java Fri Feb 10 13:01:28 2006
@@ -1,34 +1,39 @@
/*
- * $Id$
+ * $Id$
*
* 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.struts.taglib.html;
-import javax.servlet.jsp.JspException;
-
import org.apache.struts.taglib.TagUtils;
+import javax.servlet.jsp.JspException;
+
/**
* Custom tag for input fields of type "hidden".
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2004-10-16 12:38:42 -0400 (Sat, 16 Oct 2004)
+ * $
*/
public class HiddenTag extends BaseFieldTag {
+ // ------------------------------------------------------------- Properties
+ /**
+ * Should the value of this field also be rendered to the response?
+ */
+ protected boolean write = false;
// ----------------------------------------------------------- Constructors
@@ -36,21 +41,10 @@
* Construct a new instance of this tag.
*/
public HiddenTag() {
-
- super();
- this.type = "hidden";
-
+ super();
+ this.type = "hidden";
}
-
- // ------------------------------------------------------------- Properties
-
-
- /**
- * Should the value of this field also be rendered to the response?
- */
- protected boolean write = false;
-
public boolean getWrite() {
return (this.write);
}
@@ -59,18 +53,15 @@
this.write = write;
}
-
// --------------------------------------------------------- Public Methods
-
/**
- * Generate the required input tag, followed by the optional rendered text.
- * Support for <code>write</code> property since Struts 1.1.
+ * Generate the required input tag, followed by the optional rendered
+ * text. Support for <code>write</code> property since Struts 1.1.
*
- * @exception JspException if a JSP exception has occurred
+ * @throws JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
-
// Render the <html:input type="hidden"> tag as before
super.doStartTag();
@@ -79,15 +70,16 @@
return (EVAL_BODY_TAG);
}
-
// Calculate the value to be rendered separately
// * @since Struts 1.1
String results = null;
+
if (value != null) {
results = TagUtils.getInstance().filter(value);
} else {
- Object value = TagUtils.getInstance().lookup(pageContext, name, property,
- null);
+ Object value =
+ TagUtils.getInstance().lookup(pageContext, name, property, null);
+
if (value == null) {
results = "";
} else {
@@ -96,20 +88,15 @@
}
TagUtils.getInstance().write(pageContext, results);
- return (EVAL_BODY_TAG);
+ return (EVAL_BODY_TAG);
}
-
/**
* Release any acquired resources.
*/
public void release() {
-
super.release();
write = false;
-
}
-
-
}
Modified: struts/taglib/trunk/src/java/org/apache/struts/taglib/html/HtmlTag.java
URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/HtmlTag.java?rev=376841&r1=376840&r2=376841&view=diff
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/HtmlTag.java (original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/HtmlTag.java Fri Feb 10 13:01:28 2006
@@ -1,59 +1,57 @@
/*
- * $Id$
+ * $Id$
*
* 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.struts.taglib.html;
-import java.util.Locale;
+import org.apache.struts.Globals;
+import org.apache.struts.taglib.TagUtils;
+import org.apache.struts.util.MessageResources;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;
-import org.apache.struts.Globals;
-import org.apache.struts.taglib.TagUtils;
-import org.apache.struts.util.MessageResources;
+import java.util.Locale;
/**
* Renders an HTML <html> element with appropriate language attributes if
* there is a current Locale available in the user's session.
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2005-08-21 19:08:45 -0400 (Sun, 21 Aug 2005)
+ * $
*/
public class HtmlTag extends TagSupport {
-
-
// ------------------------------------------------------------- Properties
-
/**
* The message resources for this package.
*/
protected static MessageResources messages =
- MessageResources.getMessageResources(Constants.Package + ".LocalStrings");
-
+ MessageResources.getMessageResources(Constants.Package
+ + ".LocalStrings");
/**
* Are we rendering an xhtml page?
*/
protected boolean xhtml = false;
-
+
/**
* Are we rendering a lang attribute?
+ *
* @since Struts 1.2
*/
protected boolean lang = false;
@@ -65,9 +63,10 @@
public void setXhtml(boolean xhtml) {
this.xhtml = xhtml;
}
-
+
/**
* Returns true if the tag should render a lang attribute.
+ *
* @since Struts 1.2
*/
public boolean getLang() {
@@ -76,6 +75,7 @@
/**
* Sets whether the tag should render a lang attribute.
+ *
* @since Struts 1.2
*/
public void setLang(boolean lang) {
@@ -85,17 +85,18 @@
/**
* Process the start of this tag.
*
- * @exception JspException if a JSP exception has occurred
+ * @throws JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
-
- TagUtils.getInstance().write(this.pageContext, this.renderHtmlStartElement());
+ TagUtils.getInstance().write(this.pageContext,
+ this.renderHtmlStartElement());
return EVAL_BODY_INCLUDE;
}
/**
* Renders an <html> element with appropriate language attributes.
+ *
* @since Struts 1.2
*/
protected String renderHtmlStartElement() {
@@ -103,7 +104,7 @@
String language = null;
String country = "";
-
+
Locale currentLocale =
TagUtils.getInstance().getUserLocale(pageContext, Globals.LOCALE_KEY);
@@ -114,31 +115,33 @@
boolean validCountry = country.length() > 0;
if (this.xhtml) {
- this.pageContext.setAttribute(
- Globals.XHTML_KEY,
- "true",
+ this.pageContext.setAttribute(Globals.XHTML_KEY, "true",
PageContext.PAGE_SCOPE);
-
+
sb.append(" xmlns=\"http://www.w3.org/1999/xhtml\"");
}
if ((this.lang || this.xhtml) && validLanguage) {
sb.append(" lang=\"");
sb.append(language);
+
if (validCountry) {
sb.append("-");
sb.append(country);
}
+
sb.append("\"");
}
if (this.xhtml && validLanguage) {
sb.append(" xml:lang=\"");
sb.append(language);
+
if (validCountry) {
sb.append("-");
sb.append(country);
}
+
sb.append("\"");
}
@@ -147,19 +150,16 @@
return sb.toString();
}
-
/**
* Process the end of this tag.
*
- * @exception JspException if a JSP exception has occurred
+ * @throws JspException if a JSP exception has occurred
*/
public int doEndTag() throws JspException {
-
TagUtils.getInstance().write(pageContext, "</html>");
// Evaluate the remainder of this page
return (EVAL_PAGE);
-
}
/**
@@ -167,8 +167,6 @@
*/
public void release() {
this.xhtml = false;
- this.lang=false;
+ this.lang = false;
}
-
-
}
Modified: struts/taglib/trunk/src/java/org/apache/struts/taglib/html/ImageTag.java
URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/ImageTag.java?rev=376841&r1=376840&r2=376841&view=diff
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/ImageTag.java (original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/ImageTag.java Fri Feb 10 13:01:28 2006
@@ -1,52 +1,76 @@
/*
- * $Id$
+ * $Id$
*
* Copyright 1999-2005 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.struts.taglib.html;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.jsp.JspException;
-
import org.apache.struts.Globals;
import org.apache.struts.config.ModuleConfig;
import org.apache.struts.taglib.TagUtils;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.jsp.JspException;
/**
* Tag for input fields of type "image".
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2005-04-26 20:11:47 -0400 (Tue, 26 Apr 2005)
+ * $
*/
-
public class ImageTag extends SubmitTag {
-
-
// ------------------------------------------------------------- Properties
-
/**
* The alignment for this image.
*/
protected String align = null;
/**
+ * The border size around the image.
+ */
+ protected String border = null;
+
+ /**
+ * The module-relative URI of the image.
+ */
+ protected String page = null;
+
+ /**
+ * The message resources key of the module-relative URI of the image.
+ */
+ protected String pageKey = null;
+
+ /**
+ * The URL of this image.
+ */
+ protected String src = null;
+
+ /**
+ * The message resources key for the URL of this image.
+ */
+ protected String srcKey = null;
+
+ // --------------------------------------------------------- Constructor
+ public ImageTag() {
+ super();
+ property = "";
+ }
+
+ /**
* @deprecated Align attribute is deprecated in HTML 4.x.
*/
public String getAlign() {
@@ -60,12 +84,6 @@
this.align = align;
}
-
- /**
- * The border size around the image.
- */
- protected String border = null;
-
public String getBorder() {
return (this.border);
}
@@ -74,12 +92,6 @@
this.border = border;
}
-
- /**
- * The module-relative URI of the image.
- */
- protected String page = null;
-
public String getPage() {
return (this.page);
}
@@ -88,12 +100,6 @@
this.page = page;
}
-
- /**
- * The message resources key of the module-relative URI of the image.
- */
- protected String pageKey = null;
-
public String getPageKey() {
return (this.pageKey);
}
@@ -102,11 +108,6 @@
this.pageKey = pageKey;
}
- /**
- * The URL of this image.
- */
- protected String src = null;
-
public String getSrc() {
return (this.src);
}
@@ -115,12 +116,6 @@
this.src = src;
}
-
- /**
- * The message resources key for the URL of this image.
- */
- protected String srcKey = null;
-
public String getSrcKey() {
return (this.srcKey);
}
@@ -129,14 +124,6 @@
this.srcKey = srcKey;
}
-
- // --------------------------------------------------------- Constructor
-
- public ImageTag() {
- super();
- property = "";
- }
-
// --------------------------------------------------------- Protected Methods
/**
@@ -150,16 +137,20 @@
/**
* Render the button attributes
+ *
* @param results The StringBuffer that output will be appended to.
*/
protected void prepareButtonAttributes(StringBuffer results)
- throws JspException {
+ throws JspException {
String tmp = src();
+
if (tmp != null) {
HttpServletResponse response =
(HttpServletResponse) pageContext.getResponse();
+
prepareAttribute(results, "src", response.encodeURL(tmp));
}
+
prepareAttribute(results, "align", getAlign());
prepareAttribute(results, "border", getBorder());
prepareAttribute(results, "value", getValue());
@@ -167,113 +158,106 @@
prepareAttribute(results, "tabindex", getTabindex());
}
-
/**
* Release any acquired resources.
*/
public void release() {
-
super.release();
page = null;
pageKey = null;
property = "";
src = null;
srcKey = null;
-
}
-
// ------------------------------------------------------ Protected Methods
-
/**
- * 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.
+ * 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.
*
- * @exception JspException if an error occurs
+ * @throws JspException if an error occurs
*/
protected String src() throws JspException {
-
// 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"));
+ 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;
}
-
- ModuleConfig config = (ModuleConfig)
- pageContext.getRequest().getAttribute(Globals.MODULE_KEY);
-
+
+ ModuleConfig config =
+ (ModuleConfig) pageContext.getRequest().getAttribute(Globals.MODULE_KEY);
+
HttpServletRequest request =
(HttpServletRequest) pageContext.getRequest();
-
+
String pageValue = this.page;
+
if (config != null) {
- pageValue = TagUtils.getInstance().pageURL(request,
- this.page,
- config);
+ pageValue =
+ TagUtils.getInstance().pageURL(request, this.page, config);
}
+
return (request.getContextPath() + pageValue);
}
// 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"));
+ JspException e =
+ new JspException(messages.getMessage("imgTag.src"));
+
TagUtils.getInstance().saveException(pageContext, e);
throw e;
}
-
- ModuleConfig config = (ModuleConfig)
- pageContext.getRequest().getAttribute(Globals.MODULE_KEY);
-
+
+ ModuleConfig config =
+ (ModuleConfig) pageContext.getRequest().getAttribute(Globals.MODULE_KEY);
+
HttpServletRequest request =
(HttpServletRequest) pageContext.getRequest();
-
- String pageValue = TagUtils.getInstance().message(
- pageContext,
- getBundle(),
- getLocale(),
- this.pageKey);
+
+ String pageValue =
+ TagUtils.getInstance().message(pageContext, getBundle(),
+ getLocale(), this.pageKey);
+
if (config != null) {
- pageValue = TagUtils.getInstance().pageURL(request,
- pageValue,
- config);
+ pageValue =
+ TagUtils.getInstance().pageURL(request, pageValue, config);
}
+
return (request.getContextPath() + pageValue);
}
// 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"));
+ JspException e =
+ new JspException(messages.getMessage("imgTag.src"));
+
TagUtils.getInstance().saveException(pageContext, e);
throw e;
}
+
return (this.src);
}
// Deal with an indirect source that has been specified
if (this.srcKey == null) {
- JspException e = new JspException
- (messages.getMessage("imgTag.src"));
+ JspException e =
+ new JspException(messages.getMessage("imgTag.src"));
+
TagUtils.getInstance().saveException(pageContext, e);
throw e;
}
-
- return TagUtils.getInstance().message(
- pageContext,
- getBundle(),
- getLocale(),
- this.srcKey);
+ return TagUtils.getInstance().message(pageContext, getBundle(),
+ getLocale(), this.srcKey);
}
-
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org