craigmcc 2004/08/06 21:53:35 Modified: contrib/struts-faces build.xml contrib/struts-faces/src/conf struts-faces.xml contrib/struts-faces/src/java/org/apache/struts/faces/component MessageComponent.java contrib/struts-faces/src/java/org/apache/struts/faces/renderer MessageRenderer.java WriteRenderer.java contrib/struts-faces/src/java/org/apache/struts/faces/taglib MessageTag.java contrib/struts-faces/src/sysclient/org/apache/struts/faces/sysclient SimpleTestCase.java contrib/struts-faces/web/systest simple.jsp contrib/struts-faces/web/systest/WEB-INF faces-config.xml struts-config.xml Added: contrib/struts-faces/src/systest/org/apache/struts/faces/systest ApplicationResources.properties BindingBean.java SimpleBean.java Removed: contrib/struts-faces/src/java/org/apache/struts/faces/taglib SubviewTag.java Log: Remove <s:subview> tag, since <f:subview> makes it redundant. Add filter property on MessageComponent and <s:message> tag. Add system tests for <s:loadMessages>, <s:message>, and <s:write>. Revision Changes Path 1.16 +0 -4 jakarta-struts/contrib/struts-faces/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/jakarta-struts/contrib/struts-faces/build.xml,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- build.xml 3 Aug 2004 07:01:07 -0000 1.15 +++ build.xml 7 Aug 2004 04:53:34 -0000 1.16 @@ -562,7 +562,6 @@ <!-- Compile Java Sources --> <mkdir dir="${build.home}/webapps/systest/WEB-INF/classes"/> -<!-- <javac srcdir="src/systest" destdir="${build.home}/webapps/systest/WEB-INF/classes" debug="${compile.debug}" @@ -570,16 +569,13 @@ optimize="${compile.optimize}"> <classpath refid="classpath" /> </javac> ---> <!-- Copy non-Java Sources --> -<!-- <copy todir="${build.home}/webapps/systest/WEB-INF/classes"> <fileset dir="src/systest"> <exclude name="**/*.java"/> </fileset> </copy> ---> </target> 1.9 +19 -46 jakarta-struts/contrib/struts-faces/src/conf/struts-faces.xml Index: struts-faces.xml =================================================================== RCS file: /home/cvs/jakarta-struts/contrib/struts-faces/src/conf/struts-faces.xml,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- struts-faces.xml 26 Jul 2004 19:34:48 -0000 1.8 +++ struts-faces.xml 7 Aug 2004 04:53:35 -0000 1.9 @@ -590,6 +590,15 @@ <p>Substitution parameters for the message may be nested inside this tag by using the <code>parameter</code> tag from the standard HTML RenderKit tag library.</p> + + <p>Additional control over the rendering process is specified by the + following optional attributes, with default values as indicated:</p> + <ul> + <li><strong>filter</strong> - Set to <code>true</code> to filter the + rendered text for characters that are sensitive in HTML, or + <code>false</code> to skip filtering. By default, rendered text + is filtered.</li> + </ul> </description> <attribute> @@ -614,6 +623,16 @@ </attribute> <attribute> + <name>filter</name> + <required>false</required> + <rtexprvalue>false</rtexprvalue> + <description> + <p>Should we filter the output for characters that are sensitive + in HTML? The default value is <code>true</code>.</p> + </description> + </attribute> + + <attribute> <name>id</name> <required>false</required> <rtexprvalue>false</rtexprvalue> @@ -713,52 +732,6 @@ <rtexprvalue>false</rtexprvalue> <description> Context-relative path to the resource for this relative link. - </description> - </attribute> - - <attribute> - <name>rendered</name> - <required>false</required> - <rtexprvalue>false</rtexprvalue> - <description> - Boolean attribute indicating whether this component should be - rendered or not. - </description> - </attribute> - - </tag> - - - <tag> - - <name>subview</name> - <summary> - Struts-Specific Substitute for JSF Core "subview" tag - </summary> - <tag-class>org.apache.struts.faces.taglib.SubviewTag</tag-class> - <body-content>JSP</body-content> - <description> - <p>This tag is functionally equivalent to the "subview" tag in the - JavaServer Faces Core Tag Library, and is present only to support - opportunities for additional debugging.</p> - </description> - - <attribute> - <name>binding</name> - <required>false</required> - <rtexprvalue>false</rtexprvalue> - <description> - <p>Value binding expression to bind this component to - a backing bean property.</p> - </description> - </attribute> - - <attribute> - <name>id</name> - <required>true</required> - <rtexprvalue>false</rtexprvalue> - <description> - <p>Component identifier of the component corresponding to this tag.</p> </description> </attribute> 1.2 +53 -7 jakarta-struts/contrib/struts-faces/src/java/org/apache/struts/faces/component/MessageComponent.java Index: MessageComponent.java =================================================================== RCS file: /home/cvs/jakarta-struts/contrib/struts-faces/src/java/org/apache/struts/faces/component/MessageComponent.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MessageComponent.java 8 Jul 2004 01:11:28 -0000 1.1 +++ MessageComponent.java 7 Aug 2004 04:53:35 -0000 1.2 @@ -57,6 +57,13 @@ /** + * <p>Flag indicating whether output should be filtered.</p> + */ + private boolean filter = true; + private boolean filterSet = false; + + + /** * <p>Message key to use for message lookup.</p> */ private String key = null; @@ -115,6 +122,41 @@ /** + * <p>Return a flag indicating whether filtering should take place.</p> + */ + public boolean isFilter() { + + if (filterSet) { + return filter; + } + ValueBinding vb = getValueBinding("filter"); + if (vb != null) { + Boolean value = (Boolean) vb.getValue(getFacesContext()); + if (null == value) { + return filter; + } + return value.booleanValue(); + } else { + return filter; + } + + } + + + /** + * <p>Set the flag indicating that the output value should be filtered.</p> + * + * @param filter The new filter flag + */ + public void setFilter(boolean filter) { + + this.filter = filter; + this.filterSet = true; + + } + + + /** * <p>Return the message key.</p> */ public String getKey() { @@ -209,9 +251,11 @@ Object values[] = (Object[]) state; super.restoreState(context, values[0]); bundle = (String) values[1]; - key = (String) values[2]; - style = (String) values[3]; - styleClass = (String) values[4]; + filter = ((Boolean) values[2]).booleanValue(); + filterSet = ((Boolean) values[3]).booleanValue(); + key = (String) values[4]; + style = (String) values[5]; + styleClass = (String) values[6]; } @@ -223,12 +267,14 @@ */ public Object saveState(FacesContext context) { - Object values[] = new Object[5]; + Object values[] = new Object[7]; values[0] = super.saveState(context); values[1] = bundle; - values[2] = key; - values[3] = style; - values[4] = styleClass; + values[2] = filter ? Boolean.TRUE : Boolean.FALSE; + values[3] = filterSet ? Boolean.TRUE : Boolean.FALSE; + values[4] = key; + values[5] = style; + values[6] = styleClass; return values; } 1.7 +13 -3 jakarta-struts/contrib/struts-faces/src/java/org/apache/struts/faces/renderer/MessageRenderer.java Index: MessageRenderer.java =================================================================== RCS file: /home/cvs/jakarta-struts/contrib/struts-faces/src/java/org/apache/struts/faces/renderer/MessageRenderer.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- MessageRenderer.java 8 Mar 2004 02:49:54 -0000 1.6 +++ MessageRenderer.java 7 Aug 2004 04:53:35 -0000 1.7 @@ -29,6 +29,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.struts.Globals; import org.apache.struts.util.MessageResources; +import org.apache.struts.util.ResponseUtils; /** @@ -106,8 +107,17 @@ Object args[] = (Object[]) list.toArray(new Object[list.size()]); // Look up the requested message - return (resources.getMessage(context.getViewRoot().getLocale(), - key, args)); + String text = resources.getMessage(context.getViewRoot().getLocale(), + key, args); + Boolean filter = (Boolean) component.getAttributes().get("filter"); + if (filter == null) { + filter = Boolean.FALSE; + } + if (filter.booleanValue()) { + return (ResponseUtils.filter(text)); + } else { + return (text); + } } 1.7 +8 -3 jakarta-struts/contrib/struts-faces/src/java/org/apache/struts/faces/renderer/WriteRenderer.java Index: WriteRenderer.java =================================================================== RCS file: /home/cvs/jakarta-struts/contrib/struts-faces/src/java/org/apache/struts/faces/renderer/WriteRenderer.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- WriteRenderer.java 8 Jul 2004 01:11:28 -0000 1.6 +++ WriteRenderer.java 7 Aug 2004 04:53:35 -0000 1.7 @@ -67,12 +67,17 @@ } ResponseWriter writer = context.getResponseWriter(); + String id = component.getId(); String style = (String) component.getAttributes().get("style"); String styleClass = (String) component.getAttributes().get("styleClass"); - if ((style != null) || (styleClass != null)) { + if ((id != null) || (style != null) || (styleClass != null)) { writer.startElement("span", component); + if (id != null) { + writer.writeAttribute("id", component.getClientId(context), + "id"); + } if (style != null) { writer.writeAttribute("style", style, "style"); } @@ -87,7 +92,7 @@ "," + text + ")"); } writer.write(text); - if ((style != null) || (styleClass != null)) { + if ((id != null) || (style != null) || (styleClass != null)) { writer.endElement("span"); } 1.9 +14 -1 jakarta-struts/contrib/struts-faces/src/java/org/apache/struts/faces/taglib/MessageTag.java Index: MessageTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/contrib/struts-faces/src/java/org/apache/struts/faces/taglib/MessageTag.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- MessageTag.java 8 Jul 2004 01:11:28 -0000 1.8 +++ MessageTag.java 7 Aug 2004 04:53:35 -0000 1.9 @@ -35,6 +35,17 @@ /** + * <p>Flag indicating that rendered content should be filtered for + * characters that are sensitive in HTML.</p> + */ + private String filter = null; + + public void setFilter(String filter) { + this.filter = filter; + } + + + /** * <p>Message key used to retrieve the requested message */ private String key = null; @@ -53,6 +64,7 @@ public void release() { super.release(); + filter = null; key = null; } @@ -93,6 +105,7 @@ protected void setProperties(UIComponent component) { super.setProperties(component); + setBooleanAttribute(component, "filter", filter); setStringAttribute(component, "key", key); } 1.2 +103 -1 jakarta-struts/contrib/struts-faces/src/sysclient/org/apache/struts/faces/sysclient/SimpleTestCase.java Index: SimpleTestCase.java =================================================================== RCS file: /home/cvs/jakarta-struts/contrib/struts-faces/src/sysclient/org/apache/struts/faces/sysclient/SimpleTestCase.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SimpleTestCase.java 3 Aug 2004 07:01:09 -0000 1.1 +++ SimpleTestCase.java 7 Aug 2004 04:53:35 -0000 1.2 @@ -25,6 +25,7 @@ import com.gargoylesoftware.htmlunit.html.HtmlHead; import com.gargoylesoftware.htmlunit.html.HtmlLink; import com.gargoylesoftware.htmlunit.html.HtmlPage; +import com.gargoylesoftware.htmlunit.html.HtmlSpan; import java.net.URL; import java.util.ArrayList; @@ -142,6 +143,59 @@ /** + * <p>Verify that the loadMessages tag properly exposes a Struts + * MessageResources instance as a Map.</p> + */ + public void testLoadMessages() throws Exception { + + HtmlSpan span = null; + + span = (HtmlSpan) element("lookup-simple"); + assertNotNull(span); + assertEquals("Resource Simple Text", span.asText()); + + span = (HtmlSpan) element("lookup-filtered"); + assertNotNull(span); + assertEquals("Resource <b>Filtered</b> Text", span.asText()); + + span = (HtmlSpan) element("lookup-unfiltered"); + assertNotNull(span); + assertEquals("Resource Unfiltered Text", span.asText()); + + } + + + /** + * <p>Verify the presence and contents of several message components.</p> + */ + public void testMessage() throws Exception { + + HtmlSpan span = null; + + span = (HtmlSpan) element("message-direct"); + assertNotNull(span); + assertEquals("Resource Simple Text", span.asText()); + + span = (HtmlSpan) element("message-indirect"); + assertNotNull(span); + assertEquals("Resource Simple Text", span.asText()); + + span = (HtmlSpan) element("message-filtered"); + assertNotNull(span); + assertEquals("Resource <b>Filtered</b> Text", span.asText()); + + span = (HtmlSpan) element("message-unfiltered"); + assertNotNull(span); + assertEquals("Resource Unfiltered Text", span.asText()); + + span = (HtmlSpan) element("message-substitute"); + assertNotNull(span); + assertEquals("From Here to Eternity", span.asText()); + + } + + + /** * <p>Verify the presence and contents of a stylesheet element.</p> */ public void testStylesheet() throws Exception { @@ -173,11 +227,59 @@ /** + * <p>Verify the proper operation of clientId in a subview.</p. + */ + public void testSubview() throws Exception { + + HtmlSpan span = null; + + span = (HtmlSpan) element("subview:write1"); + assertNotNull(span); + assertEquals("subview:write1", span.asText()); + + } + + + /** * <p>Verify the title of the returned page.</p> */ public void testTitle() throws Exception { assertEquals("simple", title()); + + } + + + /** + * <p>Verify the presence and contents of several write components.</p> + */ + public void testWrite() throws Exception { + + HtmlSpan span = null; + + span = (HtmlSpan) element("write-literal"); + assertNotNull(span); + assertEquals("Literal Write Content", span.asText()); + + span = (HtmlSpan) element("write-filtered"); + assertNotNull(span); + assertEquals("Literal <b>Filtered</b> Content", span.asText()); + + span = (HtmlSpan) element("write-unfiltered"); + assertNotNull(span); + assertEquals("Literal Unfiltered Content", span.asText()); + + span = (HtmlSpan) element("retrieved-literal"); + assertNotNull(span); + assertEquals("Retrieved Simple Content", span.asText()); + + span = (HtmlSpan) element("retrieved-filtered"); + assertNotNull(span); + assertEquals("Retrieved <b>Filtered</b> Content", span.asText()); + + span = (HtmlSpan) element("retrieved-unfiltered"); + assertNotNull(span); + assertEquals("Retrieved Unfiltered Content", span.asText()); } 1.1 jakarta-struts/contrib/struts-faces/src/systest/org/apache/struts/faces/systest/ApplicationResources.properties Index: ApplicationResources.properties =================================================================== errors.header=[EH] errors.footer=[EF] errors.prefix=[EP] errors.suffix=[ES] resource.simple=Resource Simple Text resource.filtered=Resource <b>Filtered</b> Text resource.unfiltered=Resource <b>Unfiltered</b> Text resource.substitute=From {0} to {1} 1.1 jakarta-struts/contrib/struts-faces/src/systest/org/apache/struts/faces/systest/BindingBean.java Index: BindingBean.java =================================================================== /* * Copyright 2002,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.faces.systest; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; /** * <p>Bean used to test the <code>binding</code> attribute for * selected components.</p> */ public class BindingBean { private UIComponent write1 = null; public UIComponent getWrite1() { return this.write1; } public void setWrite1(UIComponent write1) { this.write1 = write1; } public String getWrite1ClientId() { return write1.getClientId(FacesContext.getCurrentInstance()); } } 1.1 jakarta-struts/contrib/struts-faces/src/systest/org/apache/struts/faces/systest/SimpleBean.java Index: SimpleBean.java =================================================================== /* * Copyright 2002,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.faces.systest; /** * <p>Simple JavaBean for use in managed bean and value binding tests.</p> */ public class SimpleBean { public String getEternity() { return "Eternity"; } public String getSimpleResource() { return "resource.simple"; } public String getSimpleContent() { return "Retrieved Simple Content"; } public String getFilteredContent() { return "Retrieved <b>Filtered</b> Content"; } public String getUnfilteredContent() { return "Retrieved <b>Unfiltered</b> Content"; } } 1.2 +56 -1 jakarta-struts/contrib/struts-faces/web/systest/simple.jsp Index: simple.jsp =================================================================== RCS file: /home/cvs/jakarta-struts/contrib/struts-faces/web/systest/simple.jsp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- simple.jsp 3 Aug 2004 07:01:09 -0000 1.1 +++ simple.jsp 7 Aug 2004 04:53:35 -0000 1.2 @@ -29,7 +29,62 @@ <s:stylesheet path="/stylesheet.css"/> </head> <body> - This is the body text + + <s:message id="message-direct" + bundle="messages" + key="resource.simple"/> + <s:message id="message-indirect" + bundle="messages" + value="#{simple.simpleResource}"/> + <s:message id="message-filtered" + bundle="messages" + key="resource.filtered"/> + <s:message id="message-unfiltered" + bundle="messages" + filter="false" + key="resource.unfiltered"/> + <s:message id="message-substitute" + bundle="messages" + key="resource.substitute"> + <f:param + value="Here"/> + <f:param + value="#{simple.eternity}"/> + </s:message> + + <s:loadMessages + messages="messages" + var="lookup"/> + <s:write id="lookup-simple" + value="#{lookup['resource.simple']}"/> + <s:write id="lookup-filtered" + value="#{lookup['resource.filtered']}"/> + <s:write id="lookup-unfiltered" + filter="false" + value="#{lookup['resource.unfiltered']}"/> + + <s:write id="write-literal" + value="Literal Write Content"/> + <s:write id="write-filtered" + value="Literal <b>Filtered</b> Content"/> + <s:write id="write-unfiltered" + filter="false" + value="Literal <b>Unfiltered</b> Content"/> + + <s:write id="retrieved-literal" + value="#{simple.simpleContent}"/> + <s:write id="retrieved-filtered" + value="#{simple.filteredContent}"/> + <s:write id="retrieved-unfiltered" + filter="false" + value="#{simple.unfilteredContent}"/> + + <f:subview id="subview"> + <s:write id="write1" + binding="#{binding.write1}" + value="#{binding.write1ClientId}"/> + </f:subview> + </body> </s:html> </f:view> 1.2 +16 -0 jakarta-struts/contrib/struts-faces/web/systest/WEB-INF/faces-config.xml Index: faces-config.xml =================================================================== RCS file: /home/cvs/jakarta-struts/contrib/struts-faces/web/systest/WEB-INF/faces-config.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- faces-config.xml 3 Aug 2004 07:01:09 -0000 1.1 +++ faces-config.xml 7 Aug 2004 04:53:35 -0000 1.2 @@ -27,4 +27,20 @@ <faces-config> + <managed-bean> + <managed-bean-name>binding</managed-bean-name> + <managed-bean-class> + org.apache.struts.faces.systest.BindingBean + </managed-bean-class> + <managed-bean-scope>request</managed-bean-scope> + </managed-bean> + + <managed-bean> + <managed-bean-name>simple</managed-bean-name> + <managed-bean-class> + org.apache.struts.faces.systest.SimpleBean + </managed-bean-class> + <managed-bean-scope>request</managed-bean-scope> + </managed-bean> + </faces-config> 1.2 +2 -3 jakarta-struts/contrib/struts-faces/web/systest/WEB-INF/struts-config.xml Index: struts-config.xml =================================================================== RCS file: /home/cvs/jakarta-struts/contrib/struts-faces/web/systest/WEB-INF/struts-config.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- struts-config.xml 3 Aug 2004 07:01:09 -0000 1.1 +++ struts-config.xml 7 Aug 2004 04:53:35 -0000 1.2 @@ -170,10 +170,9 @@ <!-- ========== Message Resources Definitions =========================== --> -<!-- <message-resources - parameter="org.apache.struts.webapp.example.ApplicationResources"/> ---> + key="messages" + parameter="org.apache.struts.faces.systest.ApplicationResources"/> <!-- ========== Plug Ins Configuration ================================== -->
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]