You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gr...@apache.org on 2005/11/08 23:53:56 UTC
svn commit: r331917 - in /myfaces/share/trunk/src/java/org/apache/myfaces:
component/EscapeCapable.java renderkit/html/HtmlRendererUtils.java
renderkit/html/HtmlTextRendererBase.java
Author: grantsmith
Date: Tue Nov 8 14:53:54 2005
New Revision: 331917
URL: http://svn.apache.org/viewcvs?rev=331917&view=rev
Log:
Implemented escape attribute for HtmlSelectBooleanCheckbox tomahawk component. MYFACES-407
Added:
myfaces/share/trunk/src/java/org/apache/myfaces/component/EscapeCapable.java
Modified:
myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlRendererUtils.java
myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlTextRendererBase.java
Added: myfaces/share/trunk/src/java/org/apache/myfaces/component/EscapeCapable.java
URL: http://svn.apache.org/viewcvs/myfaces/share/trunk/src/java/org/apache/myfaces/component/EscapeCapable.java?rev=331917&view=auto
==============================================================================
--- myfaces/share/trunk/src/java/org/apache/myfaces/component/EscapeCapable.java (added)
+++ myfaces/share/trunk/src/java/org/apache/myfaces/component/EscapeCapable.java Tue Nov 8 14:53:54 2005
@@ -0,0 +1,30 @@
+/*
+ * Copyright 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.myfaces.component;
+
+/**
+ * EscapeCapable interface for extended components
+ * By default, escape is true, and the components have the default behaviour.
+ * When escape is false, the renderer should not escape output.
+ *
+ * @author Grant Smith (latest modification by $Author: grantsmith $)
+ */
+
+public interface EscapeCapable {
+ boolean isEscape();
+ void setEscape(boolean escape);
+}
Modified: myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlRendererUtils.java
URL: http://svn.apache.org/viewcvs/myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlRendererUtils.java?rev=331917&r1=331916&r2=331917&view=diff
==============================================================================
--- myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlRendererUtils.java (original)
+++ myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlRendererUtils.java Tue Nov 8 14:53:54 2005
@@ -35,6 +35,8 @@
import org.apache.myfaces.renderkit.html.util.HTMLEncoder;
import org.apache.myfaces.renderkit.html.util.JavascriptUtils;
import org.apache.myfaces.component.DisplayValueOnlyCapable;
+import org.apache.myfaces.component.EscapeCapable;
+import org.apache.myfaces.component.html.ext.HtmlSelectBooleanCheckbox;
/**
* @author Manfred Geiler (latest modification by $Author$)
@@ -60,7 +62,7 @@
* @param component
*/
public static void decodeUIInput(FacesContext facesContext,
- UIComponent component) {
+ UIComponent component) {
if (!(component instanceof EditableValueHolder)) {
throw new IllegalArgumentException("Component "
+ component.getClientId(facesContext)
@@ -76,7 +78,7 @@
if(paramMap.containsKey(clientId))
{
((EditableValueHolder) component).setSubmittedValue(paramMap
- .get(clientId));
+ .get(clientId));
}
else
{
@@ -92,7 +94,7 @@
* @param component
*/
public static void decodeUISelectBoolean(FacesContext facesContext,
- UIComponent component) {
+ UIComponent component) {
if (!(component instanceof EditableValueHolder)) {
throw new IllegalArgumentException("Component "
+ component.getClientId(facesContext)
@@ -108,8 +110,8 @@
if (paramMap.containsKey(clientId)) {
String reqValue = (String) paramMap.get(clientId);
if ((reqValue.equalsIgnoreCase("on")
- || reqValue.equalsIgnoreCase("yes") || reqValue
- .equalsIgnoreCase("true"))) {
+ || reqValue.equalsIgnoreCase("yes") || reqValue
+ .equalsIgnoreCase("true"))) {
((EditableValueHolder) component)
.setSubmittedValue(Boolean.TRUE);
} else {
@@ -126,7 +128,7 @@
{
return isDisplayValueOnly(component) ||
isTrue(component.getAttributes().get("disabled")) ||
- isTrue(component.getAttributes().get("readOnly"));
+ isTrue(component.getAttributes().get("readOnly"));
}
private static boolean isTrue(Object obj)
@@ -144,7 +146,7 @@
* @param component
*/
public static void decodeUISelectMany(FacesContext facesContext,
- UIComponent component) {
+ UIComponent component) {
if (!(component instanceof EditableValueHolder)) {
throw new IllegalArgumentException("Component "
+ component.getClientId(facesContext)
@@ -178,7 +180,7 @@
* @param component
*/
public static void decodeUISelectOne(FacesContext facesContext,
- UIComponent component) {
+ UIComponent component) {
if (!(component instanceof EditableValueHolder)) {
throw new IllegalArgumentException("Component "
+ component.getClientId(facesContext)
@@ -230,30 +232,30 @@
*/
public static void renderListbox(FacesContext facesContext,
- UISelectOne selectOne, boolean disabled, int size)
+ UISelectOne selectOne, boolean disabled, int size)
throws IOException {
internalRenderSelect(facesContext, selectOne, disabled, size, false);
}
public static void renderListbox(FacesContext facesContext,
- UISelectMany selectMany, boolean disabled, int size)
+ UISelectMany selectMany, boolean disabled, int size)
throws IOException {
internalRenderSelect(facesContext, selectMany, disabled, size, true);
}
public static void renderMenu(FacesContext facesContext,
- UISelectOne selectOne, boolean disabled) throws IOException {
+ UISelectOne selectOne, boolean disabled) throws IOException {
internalRenderSelect(facesContext, selectOne, disabled, 1, false);
}
public static void renderMenu(FacesContext facesContext,
- UISelectMany selectMany, boolean disabled) throws IOException {
+ UISelectMany selectMany, boolean disabled) throws IOException {
internalRenderSelect(facesContext, selectMany, disabled, 1, true);
}
private static void internalRenderSelect(FacesContext facesContext,
- UIComponent uiComponent, boolean disabled, int size,
- boolean selectMany) throws IOException {
+ UIComponent uiComponent, boolean disabled, int size,
+ boolean selectMany) throws IOException {
ResponseWriter writer = facesContext.getResponseWriter();
writer.startElement(HTML.SELECT_ELEM, uiComponent);
@@ -372,8 +374,8 @@
* @throws IOException
*/
public static void renderSelectOptions(FacesContext context,
- UIComponent component, Converter converter, Set lookupSet,
- List selectItemList) throws IOException {
+ UIComponent component, Converter converter, Set lookupSet,
+ List selectItemList) throws IOException {
ResponseWriter writer = context.getResponseWriter();
for (Iterator it = selectItemList.iterator(); it.hasNext();) {
@@ -421,8 +423,24 @@
writer.writeAttribute("class", labelClass, "labelClass");
}
+ boolean escape;
+ if (component instanceof EscapeCapable)
+ {
+ escape = ((EscapeCapable)component).isEscape();
+ }
+ else
+ {
+ escape = RendererUtils.getBooleanAttribute(component, JSFAttr.ESCAPE_ATTR,
+ true); //default is to escape
+ }
- writer.writeText(selectItem.getLabel(), null);
+ if (escape)
+ {
+ writer.writeText(selectItem.getLabel(), null);
+ } else
+ {
+ writer.write(selectItem.getLabel());
+ }
writer.endElement(HTML.OPTION_ELEM);
}
@@ -478,13 +496,13 @@
* @throws java.io.IOException
*/
public static boolean renderHTMLAttribute(ResponseWriter writer,
- String componentProperty, String attrName, Object value)
+ String componentProperty, String attrName, Object value)
throws IOException {
if (!RendererUtils.isDefaultAttributeValue(value)) {
// render JSF "styleClass" and "itemStyleClass" attributes as "class"
- String htmlAttrName =
- attrName.equals(HTML.STYLE_CLASS_ATTR) ?
- HTML.CLASS_ATTR : attrName;
+ String htmlAttrName =
+ attrName.equals(HTML.STYLE_CLASS_ATTR) ?
+ HTML.CLASS_ATTR : attrName;
writer.writeAttribute(htmlAttrName, value, componentProperty);
return true;
}
@@ -497,7 +515,7 @@
* @throws java.io.IOException
*/
public static boolean renderHTMLAttribute(ResponseWriter writer,
- UIComponent component, String componentProperty, String htmlAttrName)
+ UIComponent component, String componentProperty, String htmlAttrName)
throws IOException {
Object value = component.getAttributes().get(componentProperty);
return renderHTMLAttribute(writer, componentProperty, htmlAttrName,
@@ -509,7 +527,7 @@
* @throws java.io.IOException
*/
public static boolean renderHTMLAttributes(ResponseWriter writer,
- UIComponent component, String[] attributes) throws IOException {
+ UIComponent component, String[] attributes) throws IOException {
boolean somethingDone = false;
for (int i = 0, len = attributes.length; i < len; i++) {
String attrName = attributes[i];
@@ -553,7 +571,7 @@
}
public static boolean renderOptionalEndElement(ResponseWriter writer,
- UIComponent component, String elementName, String[] attributes)
+ UIComponent component, String elementName, String[] attributes)
throws IOException {
boolean endElementNeeded = false;
for (int i = 0, len = attributes.length; i < len; i++) {
@@ -574,7 +592,7 @@
public static void writeIdIfNecessary(ResponseWriter writer, UIComponent component,
FacesContext facesContext)
- throws IOException
+ throws IOException
{
if(component.getId()!=null && !component.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
{
@@ -584,7 +602,7 @@
public static void renderDisplayValueOnlyForSelects(FacesContext facesContext, UIComponent
uiComponent)
- throws IOException
+ throws IOException
{
ResponseWriter writer = facesContext.getResponseWriter();
@@ -600,7 +618,7 @@
writeIdIfNecessary(writer, uiComponent, facesContext);
renderDisplayValueOnlyAttributes(uiComponent, writer);
writer.writeText(RendererUtils.getConvertedStringValue(facesContext,uiComponent,
- converter,((UISelectBoolean) uiComponent).getValue()),JSFAttr.VALUE_ATTR);
+ converter,((UISelectBoolean) uiComponent).getValue()),JSFAttr.VALUE_ATTR);
writer.endElement(HTML.SPAN_ELEM);
}
@@ -678,8 +696,8 @@
}
private static void renderSelectOptionsAsText(FacesContext context,
- UIComponent component, Converter converter, Set lookupSet,
- List selectItemList, boolean isSelectOne) throws IOException {
+ UIComponent component, Converter converter, Set lookupSet,
+ List selectItemList, boolean isSelectOne) throws IOException {
ResponseWriter writer = context.getResponseWriter();
for (Iterator it = selectItemList.iterator(); it.hasNext();) {
@@ -697,10 +715,10 @@
if (lookupSet.contains(itemStrValue)) { //TODO/FIX: we always compare the String vales, better fill lookupSet with Strings only when useSubmittedValue==true, else use the real item value Objects
if( ! isSelectOne )
- writer.startElement(HTML.LI_ELEM, component);
+ writer.startElement(HTML.LI_ELEM, component);
writer.writeText(selectItem.getLabel(), null);
if( ! isSelectOne )
- writer.endElement(HTML.LI_ELEM);
+ writer.endElement(HTML.LI_ELEM);
if( isSelectOne )
{
@@ -816,7 +834,7 @@
}
public static void renderHiddenCommandFormParams(ResponseWriter writer,
- Set dummyFormParams) throws IOException {
+ Set dummyFormParams) throws IOException {
for (Iterator it = dummyFormParams.iterator(); it.hasNext();) {
Object name = it.next();
renderHiddenInputField(writer, name, null);
@@ -963,28 +981,28 @@
for (int i = 0; i < supportedContentTypeArray.length; i++)
{
- String supportedContentType = supportedContentTypeArray[i].trim();
+ String supportedContentType = supportedContentTypeArray[i].trim();
- for (int j = 0; j < contentTypeList.size(); j++)
+ for (int j = 0; j < contentTypeList.size(); j++)
+ {
+ String contentType = (String) contentTypeList.get(j);
+
+ if (contentType.indexOf(supportedContentType) != -1)
{
- String contentType = (String) contentTypeList.get(j);
+ if (isHTMLContentType(contentType)) {
+ selectedContentType = HTML_CONTENT_TYPE;
+ }
- if (contentType.indexOf(supportedContentType) != -1)
- {
- if (isHTMLContentType(contentType)) {
- selectedContentType = HTML_CONTENT_TYPE;
- }
-
- else if (isXHTMLContentType(contentType)) {
- selectedContentType = XHTML_CONTENT_TYPE;
- }
- break;
+ else if (isXHTMLContentType(contentType)) {
+ selectedContentType = XHTML_CONTENT_TYPE;
}
- }
- if (selectedContentType!=null)
- {
break;
}
+ }
+ if (selectedContentType!=null)
+ {
+ break;
+ }
}
if(selectedContentType==null)
@@ -1011,8 +1029,8 @@
public static boolean isXHTMLContentType(String contentType)
{
return contentType.indexOf(XHTML_CONTENT_TYPE) != -1 ||
- contentType.indexOf(APPLICATION_XML_CONTENT_TYPE) != -1 ||
- contentType.indexOf(TEXT_XML_CONTENT_TYPE) != -1;
+ contentType.indexOf(APPLICATION_XML_CONTENT_TYPE) != -1 ||
+ contentType.indexOf(TEXT_XML_CONTENT_TYPE) != -1;
}
private static List splitContentTypeListString(String contentTypeListString)
Modified: myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlTextRendererBase.java
URL: http://svn.apache.org/viewcvs/myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlTextRendererBase.java?rev=331917&r1=331916&r2=331917&view=diff
==============================================================================
--- myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlTextRendererBase.java (original)
+++ myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlTextRendererBase.java Tue Nov 8 14:53:54 2005
@@ -17,6 +17,7 @@
import org.apache.myfaces.renderkit.JSFAttr;
import org.apache.myfaces.renderkit.RendererUtils;
+import org.apache.myfaces.component.EscapeCapable;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
@@ -64,7 +65,7 @@
{
String text = RendererUtils.getStringValue(facesContext, component);
boolean escape;
- if (component instanceof HtmlOutputText)
+ if (component instanceof HtmlOutputText || component instanceof EscapeCapable)
{
escape = ((HtmlOutputText)component).isEscape();
}