KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > core > comp > scripting > BScriptResource


1 /*
2  * Copyright (C) 2003 Christian Cryder [christianc@granitepeaks.com]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: BScriptResource.java,v 1.8 2004/02/01 05:16:27 christianc Exp $
19  */

20 package org.enhydra.barracuda.core.comp.scripting;
21
22 import java.util.*;
23
24 import org.apache.log4j.*;
25 import org.w3c.dom.*;
26 import org.w3c.dom.html.*;
27
28 import org.enhydra.barracuda.core.comp.*;
29 import org.enhydra.barracuda.core.comp.renderer.*;
30 import org.enhydra.barracuda.core.comp.renderer.html.*;
31 import org.enhydra.barracuda.core.comp.renderer.xml.*;
32 import org.enhydra.barracuda.core.util.*;
33 import org.enhydra.barracuda.core.util.dom.DOMUtil;
34 import org.enhydra.barracuda.core.view.*;
35 import org.enhydra.barracuda.plankton.data.*;
36
37
38 //csc_102201.1 - created
39
/**
40  * BScriptResource is used to make sure a client side script is available for
41  * use by client scripting code.
42  *
43  * <p>In most cases you will not actually need to bind the component
44  * to a view in order to use it--if you return it from a model, this
45  * will be done for you automatically. If however, you intend to use
46  * the component <em>standalone</em> (ie. manually attaching it to a
47  * specific node in the DOM) or <em>inline</em> (ie. in a toString()),
48  * then you MUST BIND IT TO A VIEW before rendering, or an error will
49  * be generated.
50  */

51 public class BScriptResource extends BComponent {
52
53     //public vars
54
protected static final Logger logger = Logger.getLogger(BScriptResource.class.getName());
55
56     public static final String JavaDoc JS_CLIENT_SERVER_HTTP_LIB = "/org/enhydra/barracuda/core/scripts/ClientServerHTTPLib.js";
57     public static final String JavaDoc JS_FORM_CONTROL = "/org/enhydra/barracuda/core/scripts/FormControl.js";
58     public static final String JavaDoc JS_SCRIPTING_CHECK = "/org/enhydra/barracuda/core/scripts/ScriptingCheck.js";
59
60     //private vars
61
protected String JavaDoc src = null;
62
63     //--------------- Constructors -------------------------------
64
/**
65      * Public noargs constructor
66      */

67     public BScriptResource() {}
68
69     /**
70      * Public constructor which creates the component. When rendered,
71      * it will make sure that the src script is available to the client.
72      *
73      * <p>You should generally only use this constructor when returning
74      * BScriptResource from a Model, as the model components will automatically
75      * bind the component to a view for you. If you use this constructor
76      * in some other situation, you should manually bind the component
77      * to the proper view.
78      *
79      * @param src the src script that backs this component
80      */

81     public BScriptResource(String JavaDoc src) {
82         this(src, null);
83     }
84
85     /**
86      * Public constructor which creates the component and
87      * binds it to a view. When rendered, it will make sure
88      * that the src script is available to the client.
89      *
90      * <p>Null values may be passed in for any parameters,
91      * but if you do so you will need manually provide these
92      * values (via the accessor methods) prior to actually
93      * rendering the component
94      *
95      * @param src the src script that backs this component
96      * @param view the View the component should be bound to
97      */

98     BScriptResource(String JavaDoc src, View view) {
99         if (src!=null) this.setSrc(src);
100         if (view!=null) this.addView(view);
101     }
102
103
104     //--------------- Renderer -----------------------------------
105
/**
106      * Default component renderer factory registrations
107      */

108     static {
109         HTMLRendererFactory rfHTML = new HTMLRendererFactory();
110         installRendererFactory(rfHTML, BScriptResource.class, HTMLElement.class);
111         installRendererFactory(rfHTML, BScriptResource.class, HTMLDocument.class);
112 /*
113         WMLRendererFactory rfWML = new WMLRendererFactory();
114         installRendererFactory(rfWML, BScriptResource.class, HTMLElement.class);
115         installRendererFactory(rfWML, BScriptResource.class, HTMLDocument.class);
116 */

117     }
118
119     /**
120      * HTML RendererFactory
121      */

122     static class HTMLRendererFactory implements RendererFactory {
123         public Renderer getInstance() {return new HTMLScriptResourceRenderer();}
124     }
125
126
127
128     //--------------- BComponent ---------------------------------
129
/**
130      * Set the src for this particular component
131      *
132      * @param isrc the src script that backs this component
133      */

134     public void setSrc(String JavaDoc isrc) {
135         src = isrc;
136         invalidate();
137     }
138
139     /**
140      * Get the src for this particular component
141      *
142      * @return the src for this particular component
143      */

144     public String JavaDoc getSrc() {
145         return src;
146     }
147
148     /**
149      * Render a specific view for the component.
150      *
151      * @param view View to be rendered
152      * @param vc ViewContext for the client view
153      * @throws RenderException if the particular View is not supported
154      * @param list a List of all the views for this component
155      */

156 /*
157 //021102.3_csc - removed, because now its in BComponent
158     protected void renderView (View view, ViewContext vc, int depth) throws RenderException {
159         if (logger.isInfoEnabled()) logger.info("rendering view: "+view);
160
161         //actually render the view according to known interfaces
162         try {
163             Renderer r = getRenderer(view);
164             r.renderComponent(this, view, vc);
165         } catch (DOMException e) {
166             logger.warn("DOM Error:", e);
167             throw new DOMAccessException("Error rendering component in view:"+e, e);
168         }
169     }
170 */

171     /**
172      * Get a String representation of the component
173      */

174     public String JavaDoc toString() {
175         return src;
176     }
177
178 }
Popular Tags