001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package com.sun.rave.web.ui.renderer;
042:
043: import java.io.IOException;
044: import javax.faces.component.UIComponent;
045: import javax.faces.context.FacesContext;
046: import javax.faces.context.ResponseWriter;
047: import com.sun.rave.web.ui.component.Frame;
048: import com.sun.rave.web.ui.util.RenderingUtilities;
049:
050: /**
051: * <p>Renderer for a {@link Frame} component.</p>
052: */
053:
054: public class FrameRenderer extends AbstractRenderer {
055:
056: // ======================================================== Static Variables
057:
058: /**
059: * <p>The set of String pass-through attributes to be rendered.</p>
060: */
061: private static final String stringAttributes[] = { "name",
062: "scrolling" }; //NOI18N
063:
064: // -------------------------------------------------------- Renderer Methods
065:
066: /**
067: * <p>Render the appropriate element start for the outermost
068: * element.</p>
069: *
070: * @param context <code>FacesContext</code> for the current request
071: * @param component component to be rendered
072: * @param writer <code>ResponseWriter</code> to which the element
073: * start should be rendered
074: *
075: * @exception IOException if an input/output error occurs
076: */
077: protected void renderStart(FacesContext context,
078: UIComponent component, ResponseWriter writer)
079: throws IOException {
080: Frame frame = (Frame) component;
081:
082: // I don't think this is the correct way to write the XML
083: // header /avk
084:
085: if (!RenderingUtilities.isPortlet(context)) {
086: writer.startElement("frame", component);
087: }
088:
089: }
090:
091: /**
092: * <p>Render the appropriate element attributes, followed by the
093: * nested <code><head></code> element, plus the beginning
094: * of a nested <code><body></code> element.</p>
095: *
096: * @param context <code>FacesContext</code> for the current request
097: * @param component component to be rendered
098: * @param writer <code>ResponseWriter</code> to which the element
099: * start should be rendered
100: *
101: * @exception IOException if an input/output error occurs
102: */
103: protected void renderAttributes(FacesContext context,
104: UIComponent component, ResponseWriter writer)
105: throws IOException {
106:
107: Frame frame = (Frame) component;
108:
109: // Render a nested "head" element
110: if (!RenderingUtilities.isPortlet(context)) {
111: //id
112: String id = frame.getClientId(context);
113: if (id != null) {
114: writer.writeAttribute("id", id, null); //NOI18N
115: }
116: //url
117: String url = frame.getUrl();
118: if (url != null) {
119: RenderingUtilities.renderURLAttribute(context, writer,
120: component, "src", //NOI18N
121: url, null); //NOI18N
122: }
123: //class
124: String styleClass = frame.getStyleClass();
125: if (styleClass != null) {
126: writer.writeAttribute("class", styleClass, null); //NOI18N
127: }
128: //style
129: String style = frame.getStyle();
130: if (style != null) {
131: writer.writeAttribute("style", style, null); //NOI18N
132: }
133: //write out the rest of the attributes
134: addStringAttributes(context, component, writer,
135: stringAttributes);
136:
137: //frameborder
138: boolean border = frame.isFrameBorder();
139: if (border) {
140: writer.writeAttribute("frameborder", "1", null); //NOI18N
141: } else {
142: writer.writeAttribute("frameborder", "0", null); //NOI18N
143: }
144: //longdesc
145: String longdesc = frame.getLongDesc();
146: if (longdesc != null) {
147: writer.writeAttribute("longdesc", longdesc, null); //NOI18N
148: }
149: //marginWidth
150: Integer marginWidth = new Integer(frame.getMarginWidth());
151: if (frame.getMarginWidth() >= 0) {
152: writer.writeAttribute("marginwidth", marginWidth
153: .toString(), null); //NOI18N
154: }
155: //marginHeight
156: Integer marginHeight = new Integer(frame.getMarginHeight());
157: if (frame.getMarginHeight() >= 0) {
158: writer.writeAttribute("marginheight", marginHeight
159: .toString(), null); //NOI18N
160: }
161:
162: renderResizeAttribute(writer, component);
163:
164: //tooltip
165: String toolTip = frame.getToolTip();
166: if (toolTip != null) {
167: writer.writeAttribute("title", toolTip, "toolTip"); //NOI18N
168: }
169: }
170:
171: }
172:
173: /**
174: * <p>Render the appropriate element end.</p>
175: *
176: * @param context <code>FacesContext</code> for the current request
177: * @param component component to be rendered
178: * @param writer <code>ResponseWriter</code> to which the element
179: * start should be rendered
180: *
181: * @exception IOException if an input/output error occurs
182: */
183: protected void renderEnd(FacesContext context,
184: UIComponent component, ResponseWriter writer)
185: throws IOException {
186:
187: Frame frame = (Frame) component;
188:
189: // End the outermost "html" element
190: if (!RenderingUtilities.isPortlet(context)) {
191: writer.write(" />"); //NOI18N
192: writer.write("\n"); //NOI18N
193: }
194:
195: }
196:
197: // ---------------------------------------------------s- protected Methods
198:
199: protected void renderResizeAttribute(ResponseWriter writer,
200: UIComponent comp) throws IOException {
201: //noresize
202: boolean noresize = ((Frame) comp).isNoResize();
203: if (noresize) {
204: writer.writeAttribute("noresize", "noresize", null); //NOI18N
205: }
206: }
207: }
|