Revision: 1357
http://stripes.svn.sourceforge.net/stripes/?rev=1357&view=rev
Author: bengunter
Date: 2010-11-23 22:34:37 +0000 (Tue, 23 Nov 2010)
Log Message:
-----------
Fixed STS-751: Add support ala Struts to generate HTML or XHTML compliant close
tags
Modified Paths:
--------------
branches/1.5.x/stripes/resources/stripes.tld
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/FormTag.java
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/HtmlTagSupport.java
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/InputOptionsCollectionTag.java
Added Paths:
-----------
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/PageOptionsTag.java
Modified: branches/1.5.x/stripes/resources/stripes.tld
===================================================================
--- branches/1.5.x/stripes/resources/stripes.tld 2010-11-17 04:20:41 UTC
(rev 1356)
+++ branches/1.5.x/stripes/resources/stripes.tld 2010-11-23 22:34:37 UTC
(rev 1357)
@@ -2216,6 +2216,26 @@
</attribute>
</tag>
+ <tag>
+ <description><![CDATA[
+ Sets options that affect how other tags in this tag library behave.
+ ]]></description>
+ <display-name>page-options</display-name>
+ <name>page-options</name>
+ <tag-class>net.sourceforge.stripes.tag.PageOptionsTag</tag-class>
+ <body-content>empty</body-content>
+ <attribute>
+ <description>
+ The type of HTML to write. Valid values are "html" and
"xhtml". By default
+ Stripes writes XHTML-compatible output which is also valid
HTML4, though
+ the default output does generate warnings with some HTML
validators. The
+ HTML mode specified by this tag overrides the Stripes.HtmlMode
global
+ configuration property.
+ </description>
+
<name>htmlMode</name><required>false</required><rtexprvalue>true</rtexprvalue>
+ </attribute>
+ </tag>
+
<function>
<description>
Returns the name of the supplied Java 5 enumeration value; useful
since EL will
Modified: branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/FormTag.java
===================================================================
--- branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/FormTag.java
2010-11-17 04:20:41 UTC (rev 1356)
+++ branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/FormTag.java
2010-11-23 22:34:37 UTC (rev 1357)
@@ -306,7 +306,7 @@
out.write(StripesConstants.URL_KEY_SOURCE_PAGE);
out.write("\" value=\"");
out.write(getSourcePageValue());
- out.write("\" />");
+ out.write(isXmlTags() ? "\" />" : "\">");
}
/** Get the encrypted value for the hidden _sourcePage field. */
@@ -337,7 +337,7 @@
out.write(StripesConstants.URL_KEY_FIELDS_PRESENT);
out.write("\" value=\"");
out.write(getFieldsPresentValue());
- out.write("\" />");
+ out.write(isXmlTags() ? "\" />" : "\">");
}
/** Get the encrypted value of the __fp hidden field. */
Modified:
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/HtmlTagSupport.java
===================================================================
--- branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/HtmlTagSupport.java
2010-11-17 04:20:41 UTC (rev 1356)
+++ branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/HtmlTagSupport.java
2010-11-23 22:34:37 UTC (rev 1357)
@@ -118,6 +118,16 @@
}
/**
+ * Returns true if HTML tags that have no body should be closed like XML
tags, with "/>".
+ * False if such HTML tags should be closed in the style of HTML4, with
just a ">".
+ *
+ * @see PageOptionsTag#getHtmlMode()
+ */
+ protected boolean isXmlTags() {
+ return
!"html".equalsIgnoreCase(PageOptionsTag.getHtmlMode(pageContext));
+ }
+
+ /**
* Writes out an opening tag. Uses the parameter "tag" to determine the
name of the open tag
* and then uses the map of attributes assembled through various setter
calls to fill in the
* tag attributes.
@@ -175,7 +185,7 @@
writer.print("<");
writer.print(tag);
writeAttributes(writer);
- writer.print(" />");
+ writer.print(isXmlTags() ? " />" : ">");
}
catch (IOException ioe) {
JspException jspe = new JspException("IOException encountered
while writing singleton tag <" +
Modified:
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/InputOptionsCollectionTag.java
===================================================================
---
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/InputOptionsCollectionTag.java
2010-11-17 04:20:41 UTC (rev 1356)
+++
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/InputOptionsCollectionTag.java
2010-11-23 22:34:37 UTC (rev 1357)
@@ -314,7 +314,7 @@
JspWriter out = getPageContext().getOut();
out.write("<optgroup label=\"");
out.write(String.valueOf(entry.group).replaceAll("\"",
"""));
- out.write("\"/>");
+ out.write(isXmlTags() ? "\" />" : "\">");
lastGroup = entry.group;
}
Added:
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/PageOptionsTag.java
===================================================================
--- branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/PageOptionsTag.java
(rev 0)
+++ branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/PageOptionsTag.java
2010-11-23 22:34:37 UTC (rev 1357)
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2010 Timothy Stone.
+ *
+ * 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.
+ * under the License.
+ */
+package net.sourceforge.stripes.tag;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.PageContext;
+
+import net.sourceforge.stripes.controller.StripesFilter;
+
+/**
+ * <p>
+ * Provides a tag to override the {...@link StripesFilter} configuration
property
+ * <code>Stripes.HtmlMode</code>.
+ * </p>
+ * <p>
+ * <code>htmlMode</code> accepts any string value, however any value not equal
to <code>html</code>,
+ * case-insensitive, puts Stripes into its default mode of XHTML-compatible
output.
+ * </p>
+ * <p>
+ * Examples of the tag's use then might be:
+ * </p>
+ * <ul>
+ * <li><s:options htmlMode="html" /> produces HTML4 and HTML5 form
elements, e.g., <img src
+ * … ></li>
+ * <li><s:options htmlMode="xhtml" /> produces XHTML-compatible form
elements, e.g., <img
+ * src … /></li>
+ * <li><s:options htmlMode="default" /> produces XHTML form elements</li>
+ * </ul>
+ * <p>
+ * Typical use of the tag in context of a Stripes application follows:
+ * </p>
+ * <p>
+ * Deployer will set the application RuntimeConfiguration of
<code>Stripes.HtmlMode</code>. A
+ * deployer choosing not to set this option, defaults the Stripes application
to its
+ * XHTML-compatible format.
+ * </p>
+ * <code>Stripes.HtmlMode</code> will set the default X/HTML output for the
<strong>entire</strong>
+ * application. Individual views of the application wishing to alter the
application default will
+ * provide this tag, at or near the beginning of the view, or JSP.</p>
+ *
+ * @author Timothy Stone
+ * @since 1.5.5
+ */
+public class PageOptionsTag extends StripesTagSupport {
+ /** Configuration key that sets the default HTML mode for the application.
*/
+ public static String CFG_KEY_HTML_MODE = "Stripes.HtmlMode";
+
+ /** Request attribute that affects how HTML is rendered by other tags. */
+ public static String REQ_ATTR_HTML_MODE = "__stripes_html_mode";
+
+ /**
+ * Get the HTML mode for the given page context. If the request attribute
+ * {...@value #REQ_ATTR_HTML_MODE} is present then use that value.
Otherwise, use the global
+ * configuration property {...@value #CFG_KEY_HTML_MODE}.
+ */
+ public static String getHtmlMode(PageContext pageContext) {
+ String htmlMode = (String) pageContext.getAttribute(REQ_ATTR_HTML_MODE,
+ PageContext.REQUEST_SCOPE);
+
+ if (htmlMode == null) {
+ htmlMode =
StripesFilter.getConfiguration().getBootstrapPropertyResolver()
+ .getProperty(CFG_KEY_HTML_MODE);
+ }
+
+ return htmlMode;
+ }
+
+ /**
+ * This field is not initialized to null because null is a valid value
that may be passed to
+ * {...@link #setHtmlMode(String)}. Initializing to a constant
differentiates between a field that
+ * was never changed after initialization and a field that was set to null.
+ */
+ private String htmlMode = REQ_ATTR_HTML_MODE;
+
+ @Override
+ public int doStartTag() throws JspException {
+ return SKIP_BODY;
+ }
+
+ @Override
+ public int doEndTag() throws JspException {
+ // This is an intentional use of identity instead of equality
+ if (this.htmlMode != REQ_ATTR_HTML_MODE) {
+ pageContext.getRequest().setAttribute(REQ_ATTR_HTML_MODE,
this.htmlMode);
+ }
+
+ return EVAL_PAGE;
+ }
+
+ /** Set the HTML mode string. */
+ public void setHtmlMode(String htmlMode) {
+ this.htmlMode = htmlMode;
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development