📄 abstractrendererbase.java
字号:
/* * Copyright 2002-2004 the original author or authors. * * 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 de.mindmatters.faces.render.html;import java.io.IOException;import javax.faces.component.UIComponent;import javax.faces.context.ResponseWriter;import javax.faces.render.Renderer;import org.springframework.util.Assert;/** * <strong>AbstractRendererBase</strong> is a convenience base class that * implements helper methods needed for any concrete renderer. * * @author Andreas Kuhrwahl * */public abstract class AbstractRendererBase extends Renderer { /** The standard boolean "passthru" attributes. */ private static String[] booleanPassthruAttributes = { "disabled", "readonly", "ismap" }; /** The standard "passthru" attributes. */ private static String[] passthruAttributes = { "accept", "accesskey", "alt", "bgcolor", "border", "cellpadding", "cellspacing", "charset", "cols", "coords", "dir", "enctype", "frame", "height", "hreflang", "lang", "longdesc", "maxlength", "onblur", "onchange", "onclick", "ondblclick", "onfocus", "onkeydown", "onkeypress", "onkeyup", "onload", "onmousedown", "onmousemove", "onmouseout", "onmouseover", "onmouseup", "onreset", "onselect", "onsubmit", "onunload", "rel", "rev", "rows", "rules", "shape", "size", "style", "summary", "tabindex", "target", "title", "usemap", "width" }; /** * Converts an attribute of the given UIComponent <code>component</code> * with the name <code>attributeName</code> to a boolean value. * * @param component * The associated component * @param attributeName * The name of the attribute to convert * @return <code>true</code> if the attribute exists and equals "true" * <code>false</code> otherwise */ protected final boolean getBooleanAttribute(final UIComponent component, final String attributeName) { Object attribute = component.getAttributes().get(attributeName); boolean result = false; if (attribute != null) { if (attribute instanceof Boolean) { result = ((Boolean) attribute).booleanValue(); } if (attribute instanceof String) { result = ((String) attribute).equalsIgnoreCase("true"); } else { if (!(attribute instanceof String)) { attribute = attribute.toString(); } result = Boolean.valueOf((String) attribute).booleanValue(); } } return result; } /** * Render any boolean "passthru" attributes. * * @param writer * The Responsewriter to use * @param component * The associated component * @throws IOException * if an input/output error occurs * @see AbstractRendererBase#writePassThruAttributes(ResponseWriter, * UIComponent) */ protected final void writeBooleanPassThruAttributes( final ResponseWriter writer, final UIComponent component) throws IOException { Assert.notNull(writer); Assert.notNull(component); for (int i = 0; i < booleanPassthruAttributes.length; i++) { if (getBooleanAttribute(component, booleanPassthruAttributes[i])) { writer.writeAttribute(booleanPassthruAttributes[i], booleanPassthruAttributes[i], booleanPassthruAttributes[i]); } } } /** * Render any "passthru" attributes, where we simply just output the raw * name and value of the attribute. This method is aware of the set of HTML4 * attributes that fall into this bucket. Examples are all the javascript * attributes, alt, rows, cols, etc. * * @param writer * The Responsewriter to use * @param component * The associated component * @throws IOException * if an input/output error occurs */ protected final void writePassThruAttributes(final ResponseWriter writer, final UIComponent component) throws IOException { Assert.notNull(writer); Assert.notNull(component); Object value = null; for (int i = 0; i < passthruAttributes.length; i++) { value = component.getAttributes().get(passthruAttributes[i]); if (value != null) { if (!(value instanceof String)) { value = value.toString(); } writer.writeAttribute(passthruAttributes[i], value, passthruAttributes[i]); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -