001: /*
002: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
003: *
004: * "The contents of this file are subject to the Mozilla Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License at
007: * http://www.mozilla.org/MPL/
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
011: * License for the specific language governing rights and limitations under
012: * the License.
013: *
014: * The Original Code is ICEfaces 1.5 open source software code, released
015: * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
016: * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
017: * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
018: *
019: * Contributor(s): _____________________.
020: *
021: * Alternatively, the contents of this file may be used under the terms of
022: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
023: * License), in which case the provisions of the LGPL License are
024: * applicable instead of those above. If you wish to allow use of your
025: * version of this file only under the terms of the LGPL License and not to
026: * allow others to use your version of this file under the MPL, indicate
027: * your decision by deleting the provisions above and replace them with
028: * the notice and other provisions required by the LGPL License. If you do
029: * not delete the provisions above, a recipient may use your version of
030: * this file under either the MPL or the LGPL License."
031: *
032: */
033:
034: package com.icesoft.faces.renderkit.dom_html_basic;
035:
036: import com.icesoft.faces.context.DOMContext;
037: import com.icesoft.faces.context.effects.LocalEffectEncoder;
038: import org.w3c.dom.Element;
039:
040: import javax.faces.component.UIComponent;
041: import javax.faces.context.FacesContext;
042: import java.io.IOException;
043: import java.util.Iterator;
044:
045: public class GroupRenderer extends DomBasicRenderer {
046:
047: public boolean getRendersChildren() {
048: return true;
049: }
050:
051: public void encodeBegin(FacesContext facesContext,
052: UIComponent uiComponent) throws IOException {
053:
054: // render a span if either of the style or style class attributes
055: // are present
056: String style = (String) uiComponent.getAttributes()
057: .get("style");
058: String styleClass = (String) uiComponent.getAttributes().get(
059: "styleClass");
060: boolean requiresSpan = requiresRootElement(style, styleClass,
061: uiComponent);
062:
063: DOMContext domContext = DOMContext.attachDOMContext(
064: facesContext, uiComponent);
065:
066: if (requiresSpan) {
067: if (!domContext.isInitialized()) {
068: Element rootSpan = createRootElement(domContext);
069: domContext.setRootNode(rootSpan);
070: setRootElementId(facesContext, rootSpan, uiComponent);
071: }
072: Element rootSpan = (Element) domContext.getRootNode();
073: DOMContext.removeChildren(rootSpan);
074: renderStyleAndStyleClass(style, styleClass, rootSpan);
075: }
076: Element rootSpan = (Element) domContext.getRootNode();
077: LocalEffectEncoder.encodeLocalEffects(uiComponent, rootSpan,
078: facesContext);
079: domContext.streamWrite(facesContext, uiComponent, domContext
080: .getRootNode(), rootSpan);
081: domContext.stepInto(uiComponent);
082: }
083:
084: public void encodeChildren(FacesContext facesContext,
085: UIComponent uiComponent) throws IOException {
086: validateParameters(facesContext, uiComponent, null);
087: DOMContext domContext = DOMContext.getDOMContext(facesContext,
088: uiComponent);
089: Iterator children = uiComponent.getChildren().iterator();
090: while (children.hasNext()) {
091: UIComponent nextChild = (UIComponent) children.next();
092: if (nextChild.isRendered()) {
093: encodeParentAndChildren(facesContext, nextChild);
094: }
095: }
096: // set the cursor here since nothing happens in encodeEnd
097: domContext.stepOver();
098: domContext.streamWrite(facesContext, uiComponent);
099: }
100:
101: public void encodeEnd(FacesContext facesContext,
102: UIComponent uiComponent) throws IOException {
103: validateParameters(facesContext, uiComponent, null);
104: }
105:
106: protected Element createRootElement(DOMContext domContext) {
107: return domContext.createElement(HTML.SPAN_ELEM);
108: }
109:
110: protected void renderStyleAndStyleClass(String style,
111: String styleClass, Element root) {
112: if (styleClass != null) {
113: root.setAttribute(HTML.CLASS_ATTR, styleClass);
114: }
115: if (style != null && style.length() > 0) {
116: root.setAttribute(HTML.STYLE_ATTR, style);
117: } else {
118: root.removeAttribute(HTML.STYLE_ATTR);
119: }
120: }
121:
122: /**
123: * @param style
124: * @param styleClass
125: * @param uiComponent
126: * @return boolean
127: */
128: private boolean requiresRootElement(String style,
129: String styleClass, UIComponent uiComponent) {
130: return idNotNull(uiComponent) || style != null
131: || styleClass != null;
132: }
133:
134: }
|