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 com.sun.rave.web.ui.component.ImageHyperlink;
044: import com.sun.rave.web.ui.component.ImageComponent;
045: import com.sun.rave.web.ui.util.ConversionUtilities;
046: import com.sun.rave.web.ui.util.RenderingUtilities;
047: import java.io.IOException;
048: import javax.faces.component.UIComponent;
049:
050: import javax.faces.context.FacesContext;
051: import javax.faces.context.ResponseWriter;
052:
053: /**
054: * <p>This class is responsible for rendering the {@link ImageHyperlink} component for the
055: * HTML Render Kit.</p> <p> The {@link ImageHyperlink} component can be used as an anchor, a
056: * plain hyperlink or a hyperlink that submits the form depending on how the
057: * properites are filled out for the component </p>
058: */
059: public class ImageHyperlinkRenderer extends HyperlinkRenderer {
060:
061: // -------------------------------------------------------- Static Variables
062:
063: private static final String IMAGEFACTORY = "com.sun.rave.web.ui.component.util.factories.ImageComponentFactory"; //NOI18N
064:
065: // for positioning of the label.
066: private static final String LABEL_LEFT = "left"; //NOI8N
067: private static final String LABEL_RIGHT = "right"; //NOI8N
068:
069: // -------------------------------------------------------- Renderer Methods
070: protected void finishRenderAttributes(FacesContext context,
071: UIComponent component, ResponseWriter writer)
072: throws IOException {
073: //create an image component based on image attributes
074: //write out image as escaped text
075: //TODO: suppress the text field from the XML
076: ImageHyperlink ilink = (ImageHyperlink) component;
077:
078: // ImageURL
079: ImageComponent ic = ilink.getImageFacet();
080:
081: //TODO: use static text
082: // <RAVE>
083: // String label = ilink.getText();
084:
085: // If there is no text property set, then label == null which prevents
086: // rendering anything at all
087: Object text = ilink.getText();
088: String label = (text == null) ? null : ConversionUtilities
089: .convertValueToString(component, text);
090: // </RAVE>
091: if (label != null
092: && ilink.getTextPosition().equalsIgnoreCase(LABEL_LEFT)) {
093: writer.writeText(label, null);
094: // <RAVE>
095: writer.write(" ");
096: // </RAVE>
097: }
098: if (ic != null) {
099: RenderingUtilities.renderComponent(ic, context);
100: }
101:
102: if (label != null
103: && ilink.getTextPosition()
104: .equalsIgnoreCase(LABEL_RIGHT)) {
105: // <RAVE>
106: writer.write(" ");
107: // </RAVE>
108: writer.writeText(label, null);
109: }
110:
111: }
112:
113: // --------------------------------------------------------- Private Methods
114:
115: }
|