KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > components > Insert


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.components;
16
17 import java.text.Format JavaDoc;
18
19 import org.apache.hivemind.ApplicationRuntimeException;
20 import org.apache.tapestry.AbstractComponent;
21 import org.apache.tapestry.IMarkupWriter;
22 import org.apache.tapestry.IRequestCycle;
23
24 /**
25  * Used to insert some text (from a parameter) into the HTML. [ <a
26  * HREF="../../../../../ComponentReference/Insert.html">Component Reference </a>]
27  *
28  * @author Howard Lewis Ship
29  */

30
31 public abstract class Insert extends AbstractComponent
32 {
33     /**
34      * Prints its value parameter, possibly formatted by its format parameter.
35      */

36
37     protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
38     {
39         if (cycle.isRewinding())
40             return;
41
42         Object JavaDoc value = getValue();
43
44         if (value == null)
45             return;
46
47         String JavaDoc insert = null;
48
49         Format JavaDoc format = getFormat();
50
51         if (format == null)
52         {
53             insert = value.toString();
54         }
55         else
56         {
57             try
58             {
59                 insert = format.format(value);
60             }
61             catch (Exception JavaDoc ex)
62             {
63                 throw new ApplicationRuntimeException(ComponentMessages.unableToFormat(
64                         this,
65                         value,
66                         ex), this, getBinding("format").getLocation(), ex);
67             }
68         }
69
70         String JavaDoc styleClass = getStyleClass();
71
72         if (styleClass != null)
73         {
74             writer.begin("span");
75             writer.attribute("class", styleClass);
76
77             renderInformalParameters(writer, cycle);
78         }
79
80         writer.print(insert, getRaw());
81         
82         if (styleClass != null)
83             writer.end(); // <span>
84
}
85
86     public abstract Object JavaDoc getValue();
87
88     public abstract Format JavaDoc getFormat();
89
90     public abstract String JavaDoc getStyleClass();
91
92     public abstract boolean getRaw();
93
94 }
Popular Tags