KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > gumby > tags > Resource


1 package org.sapia.gumby.tags;
2
3 import java.net.URL JavaDoc;
4
5 import org.sapia.gumby.RenderContext;
6 import org.sapia.gumby.factory.ContextAware;
7 import org.sapia.util.xml.confix.ConfigurationException;
8 import org.sapia.util.xml.confix.ObjectCreationCallback;
9
10 /**
11  * @author Yanick Duchesne
12  *
13  * <dl>
14  * <dt><b>Copyright: </b>
15  * <dd>Copyright &#169; 2002-2005 <a HREF="http://www.sapia-oss.org">Sapia Open
16  * Source Software </a>. All Rights Reserved.</dd>
17  * </dt>
18  * <dt><b>License: </b>
19  * <dd>Read the license.txt file of the jar or visit the <a
20  * HREF="http://www.sapia-oss.org/license.html">license page </a> at the Sapia
21  * OSS web site</dd>
22  * </dt>
23  * </dl>
24  */

25 public class Resource implements ObjectCreationCallback, ContextAware {
26
27   private String JavaDoc _src;
28   private RenderContext _ctx;
29
30   public void setText(String JavaDoc src) {
31     setSrc(src);
32   }
33
34   public void setSrc(String JavaDoc src) {
35     _src = src;
36   }
37
38   /**
39    * @see org.sapia.gumby.factory.ContextAware#handleContext(org.sapia.gumby.RenderContext)
40    */

41   public void handleContext(RenderContext context) {
42     _ctx = context;
43   }
44
45   /**
46    * @see org.sapia.util.xml.confix.ObjectCreationCallback#onCreate()
47    */

48   public Object JavaDoc onCreate() throws ConfigurationException {
49     if(_src == null) {
50       throw new ConfigurationException("Resource not specified");
51     }
52
53     URL JavaDoc url = _ctx.getSettings().resolveURL(_src);
54     if(url == null) {
55       throw new ConfigurationException("Could not find resource: " + _src);
56     }
57     return url;
58   }
59
60 }
61
Popular Tags