001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package com.sun.rave.web.ui.component;
042:
043: import java.io.IOException;
044: import javax.faces.component.UIComponent;
045: import javax.faces.context.FacesContext;
046: import javax.faces.el.MethodBinding;
047: import javax.faces.el.ValueBinding;
048:
049: /**
050: * <span style="text-decoration: line-through;"></span><span
051: * style="color: rgb(0, 0, 0);">Use the </span><code
052: * style="color: rgb(0, 0, 0);">ui:script</code><span
053: * style="color: rgb(0, 0, 0);"> tag to create a </span><code
054: * style="color: rgb(0, 0, 0);"><script></code><span
055: * style="color: rgb(0, 0, 0);"> element in the rendered
056: * HTML page.
057: * The </span><code
058: * style="color: rgb(0, 0, 0);">ui:script</code><span
059: * style="color: rgb(0, 0, 0);"> tag must be used within
060: * the </span><code
061: * style="color: rgb(0, 0, 0);">ui:head</code><span
062: * style="color: rgb(0, 0, 0);"> tag, or within the </span><code
063: * style="color: rgb(0, 0, 0);">ui:body</code><span
064: * style="color: rgb(0, 0, 0);"> tag. The </span><code
065: * style="color: rgb(0, 0, 0);">ui:script</code><span
066: * style="color: rgb(0, 0, 0);"> tag can be used to
067: * refer to a
068: * Javascript file, by using the url attribute. The tag can also be used
069: * embed Javascript code within the rendered HTML page. </span>
070: * <p style="color: rgb(0, 0, 0);">The
071: * client-side script allows
072: * you to perform some interactive functions such as input checking before
073: * the page is submitted. <br>
074: * </p>
075: * <h3 style="color: rgb(0, 0, 0);">HTML
076: * Elements and Layout</h3>
077: * <span
078: * style="text-decoration: line-through; color: rgb(0, 0, 0);"></span><span
079: * style="color: rgb(0, 0, 0);">The rendered HTML page
080: * contains a <code><script></code>
081: * element with any attributes
082: * specified through the <code>ui:script</code>
083: * tag attributes. <br>
084: * <br>
085: * </span>
086: * <h3 style="color: rgb(0, 0, 0);">Theme
087: * Identifiers</h3>
088: * <span style="color: rgb(0, 0, 0);">None.<br>
089: * </span>
090: * <h3 style="color: rgb(0, 0, 0);">Client
091: * Side Javascript Functions</h3>
092: * <span style="color: rgb(0, 0, 0);">None.
093: * </span><br
094: * style="color: rgb(0, 0, 0);">
095: * <h3 style="color: rgb(0, 0, 0);">Example</h3>
096: * <b style="color: rgb(0, 0, 0);">Example
097: * 1: Create a script tag to a file</b><br
098: * style="color: rgb(0, 0, 0);">
099: * <br style="color: rgb(0, 0, 0);">
100: * <code style="color: rgb(0, 0, 0);">
101: * <ui:script url="/pathtomyjs/myjavascript.js" />
102: * </code><i
103: * style="color: rgb(0, 0, 0);"><br>
104: * </i><br
105: * style="color: rgb(0, 0, 0);">
106: * <b style="color: rgb(0, 0, 0);">Example
107: * 2: Create a script tag with embedded script (Not Recommended)</b><br
108: * style="color: rgb(0, 0, 0);">
109: * <br style="color: rgb(0, 0, 0);">
110: * <code style="color: rgb(0, 0, 0);">
111: * <ui:script>
112: * <br>
113: * <code style="color: rgb(0, 0, 0);">
114: * <f:verbatim>
115: * <br>
116: * function foo(text) {<br>
117: * alert(text);<br>
118: * }<br>
119: * </f:verbatim></code><br>
120: * </ui:script></code><br>
121: * <br><span style="color: rgb(0, 0, 0);">Note: If the embeded script includes characters like "<" or "&", the script
122: * code should be placed in an external file (see Example 1).
123: * </span><br>
124: * <p>Auto-generated component class.
125: * Do <strong>NOT</strong> modify; all changes
126: * <strong>will</strong> be lost!</p>
127: */
128:
129: public abstract class ScriptBase extends
130: javax.faces.component.UIComponentBase {
131:
132: /**
133: * <p>Construct a new <code>ScriptBase</code>.</p>
134: */
135: public ScriptBase() {
136: super ();
137: setRendererType("com.sun.rave.web.ui.Script");
138: }
139:
140: /**
141: * <p>Return the identifier of the component family to which this
142: * component belongs. This identifier, in conjunction with the value
143: * of the <code>rendererType</code> property, may be used to select
144: * the appropriate {@link Renderer} for this component instance.</p>
145: */
146: public String getFamily() {
147: return "com.sun.rave.web.ui.Script";
148: }
149:
150: // charset
151: private String charset = null;
152:
153: /**
154: * <p>Defines the character (charset) encoding of the target URL.
155: * See iana.org for a complete list of character encodings.</p>
156: */
157: public String getCharset() {
158: if (this .charset != null) {
159: return this .charset;
160: }
161: ValueBinding _vb = getValueBinding("charset");
162: if (_vb != null) {
163: return (String) _vb.getValue(getFacesContext());
164: }
165: return null;
166: }
167:
168: /**
169: * <p>Defines the character (charset) encoding of the target URL.
170: * See iana.org for a complete list of character encodings.</p>
171: * @see #getCharset()
172: */
173: public void setCharset(String charset) {
174: this .charset = charset;
175: }
176:
177: // type
178: private String type = null;
179:
180: /**
181: * <p>Indicates the MIME type of the script. Default is "text/javascript"</p>
182: */
183: public String getType() {
184: if (this .type != null) {
185: return this .type;
186: }
187: ValueBinding _vb = getValueBinding("type");
188: if (_vb != null) {
189: return (String) _vb.getValue(getFacesContext());
190: }
191: return "text/javascript";
192: }
193:
194: /**
195: * <p>Indicates the MIME type of the script. Default is "text/javascript"</p>
196: * @see #getType()
197: */
198: public void setType(String type) {
199: this .type = type;
200: }
201:
202: // url
203: private String url = null;
204:
205: /**
206: * <p>Defines the absolute or relative URL to a file that contains the
207: * script. Use this attribute to refer to a file instead of inserting the
208: * script into your HTML document</p>
209: */
210: public String getUrl() {
211: if (this .url != null) {
212: return this .url;
213: }
214: ValueBinding _vb = getValueBinding("url");
215: if (_vb != null) {
216: return (String) _vb.getValue(getFacesContext());
217: }
218: return null;
219: }
220:
221: /**
222: * <p>Defines the absolute or relative URL to a file that contains the
223: * script. Use this attribute to refer to a file instead of inserting the
224: * script into your HTML document</p>
225: * @see #getUrl()
226: */
227: public void setUrl(String url) {
228: this .url = url;
229: }
230:
231: /**
232: * <p>Restore the state of this component.</p>
233: */
234: public void restoreState(FacesContext _context, Object _state) {
235: Object _values[] = (Object[]) _state;
236: super .restoreState(_context, _values[0]);
237: this .charset = (String) _values[1];
238: this .type = (String) _values[2];
239: this .url = (String) _values[3];
240: }
241:
242: /**
243: * <p>Save the state of this component.</p>
244: */
245: public Object saveState(FacesContext _context) {
246: Object _values[] = new Object[4];
247: _values[0] = super .saveState(_context);
248: _values[1] = this .charset;
249: _values[2] = this .type;
250: _values[3] = this.url;
251: return _values;
252: }
253:
254: }
|