001 // Copyright 2004, 2005 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.tapestry.html;
016
017 import org.apache.tapestry.AbstractComponent;
018 import org.apache.tapestry.IAsset;
019 import org.apache.tapestry.IMarkupWriter;
020 import org.apache.tapestry.IRequestCycle;
021 import org.apache.tapestry.Tapestry;
022
023 /**
024 * Used to insert an image. To create a rollover image, use the {@link Rollover}
025 * class, which integrates a link with the image assets used with the button. [<a
026 * href="../../../../../ComponentReference/Image.html">Component Reference</a>]
027 *
028 * @author Howard Lewis Ship
029 */
030
031 public abstract class Image extends AbstractComponent
032 {
033
034 /**
035 * Renders the <img> element.
036 */
037
038 protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
039 {
040 // Doesn't contain a body so no need to do anything on rewind (assumes
041 // no
042 // sideffects to accessor methods via bindings).
043
044 if (cycle.isRewinding()) return;
045
046 IAsset imageAsset = getImage();
047
048 if (imageAsset == null)
049 throw Tapestry.createRequiredParameterException(this, "image");
050
051 String imageURL = imageAsset.buildURL();
052
053 writer.beginEmpty("img");
054
055 writer.attribute("src", imageURL);
056
057 renderInformalParameters(writer, cycle);
058
059 writer.closeTag();
060 }
061
062 public abstract IAsset getImage();
063 }