|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
Image.java | 100% | 100% | 100% | 100% |
|
1 | // Copyright 2004, 2005 The Apache Software Foundation | |
2 | // | |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | // you may not use this file except in compliance with the License. | |
5 | // You may obtain a copy of the License at | |
6 | // | |
7 | // http://www.apache.org/licenses/LICENSE-2.0 | |
8 | // | |
9 | // Unless required by applicable law or agreed to in writing, software | |
10 | // distributed under the License is distributed on an "AS IS" BASIS, | |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | // See the License for the specific language governing permissions and | |
13 | // limitations under the License. | |
14 | ||
15 | package org.apache.tapestry.html; | |
16 | ||
17 | import org.apache.tapestry.AbstractComponent; | |
18 | import org.apache.tapestry.IAsset; | |
19 | import org.apache.tapestry.IMarkupWriter; | |
20 | import org.apache.tapestry.IRequestCycle; | |
21 | import org.apache.tapestry.Tapestry; | |
22 | ||
23 | /** | |
24 | * Used to insert an image. To create a rollover image, use the {@link Rollover} class, which | |
25 | * integrates a link with the image assets used with the button. [<a | |
26 | * href="../../../../../ComponentReference/Image.html">Component Reference</a>] | |
27 | * | |
28 | * @author Howard Lewis Ship | |
29 | */ | |
30 | ||
31 | public abstract class Image extends AbstractComponent | |
32 | { | |
33 | /** | |
34 | * Renders the <img> element. | |
35 | */ | |
36 | ||
37 | 26 | protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) |
38 | { | |
39 | // Doesn't contain a body so no need to do anything on rewind (assumes no | |
40 | // sideffects to accessor methods via bindings). | |
41 | ||
42 | 26 | if (cycle.isRewinding()) |
43 | 2 | return; |
44 | ||
45 | 24 | IAsset imageAsset = getImage(); |
46 | ||
47 | 24 | if (imageAsset == null) |
48 | 2 | throw Tapestry.createRequiredParameterException(this, "image"); |
49 | ||
50 | 22 | String imageURL = imageAsset.buildURL(); |
51 | ||
52 | 22 | writer.beginEmpty("img"); |
53 | ||
54 | 22 | writer.attribute("src", imageURL); |
55 | ||
56 | 22 | renderInformalParameters(writer, cycle); |
57 | ||
58 | 22 | writer.closeTag(); |
59 | } | |
60 | ||
61 | public abstract IAsset getImage(); | |
62 | } |
|