Source Code Cross Referenced for Script.java in  » Ajax » zk » org » zkoss » zul » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Ajax » zk » org.zkoss.zul 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Script.java
002:
003:        {{IS_NOTE
004:        	Purpose:
005:        		
006:        	Description:
007:        		
008:        	History:
009:        		Sun Oct 15 12:15:47     2006, Created by tomyeh
010:        }}IS_NOTE
011:
012:        Copyright (C) 2006 Potix Corporation. All Rights Reserved.
013:
014:        {{IS_RIGHT
015:        }}IS_RIGHT
016:         */
017:        package org.zkoss.zul;
018:
019:        import java.util.Iterator;
020:
021:        import org.zkoss.lang.Objects;
022:        import org.zkoss.xml.HTMLs;
023:
024:        import org.zkoss.zk.ui.AbstractComponent;
025:        import org.zkoss.zk.ui.UiException;
026:
027:        /**
028:         * A component to represent script codes running at the client.
029:         * It is the same as HTML SCRIPT tag.
030:         *
031:         * <p>Note: it is the scripting codes running at the client, not at the
032:         * server. Don't confuse it with the <code>zscript</code> element.
033:         *
034:         * <p>To avoid typo, this compnent requires you to specify the type
035:         * ({@link #setType}) -- which is, if JavaScript, "text/javascript".
036:         *
037:         * <p>There are three formats when used in a ZUML page:
038:         *
039:         * <p>Method 1: Specify the URL of the JS file
040:         * <pre><code>&lt;script type="text/javascript" src="my.js"/&gt;
041:         * </code></pre>
042:         *
043:         * <p>Method 2: Specify the JavaScript codes directly
044:         * <pre><code>&lt;script type="text/javascript"&gt;
045:         * some_js_at_browser();
046:         *&lt;/script&gt;
047:         * </code></pre>
048:         *
049:         * <p>Method 3: Specify the JavaScript codes by use of the content
050:         * property ({@link #setContent}).
051:         * <pre><code>&lt;script type="text/javascript"&gt;
052:         * &lt;attribute name="content"&gt;
053:         *  some_js_at_browser();
054:         * &lt;/attribute&gt;
055:         *&lt;/script&gt;
056:         * </code></pre>
057:         *
058:         * @author tomyeh
059:         */
060:        public class Script extends AbstractComponent {
061:            private String _src, _type, _charset;
062:            private String _content;
063:            private boolean _defer;
064:
065:            public Script() {
066:            }
067:
068:            /** Returns the type of this client script.
069:             * <p>Default: null. However, it is invalid.
070:             * In other words, you must specify a correct type.
071:             * For JavaScript, it is "text/javascript".
072:             */
073:            public String getType() {
074:                return _type;
075:            }
076:
077:            /** Sets the type of this client script.
078:             * For JavaScript, it is <code>text/javascript</code>
079:             *
080:             * <p>Note: this property is NOT optional. You must specify one.
081:             */
082:            public void setType(String type) {
083:                if (type == null || type.length() == 0)
084:                    throw new IllegalArgumentException("non-empty is required");
085:
086:                if (!Objects.equals(_type, type)) {
087:                    _type = type;
088:                    invalidate();
089:                }
090:            }
091:
092:            /** Returns the character enconding of the source.
093:             * It is used with {@link #getSrc}.
094:             *
095:             * <p>Default: null.
096:             */
097:            public String getCharset() {
098:                return _charset;
099:            }
100:
101:            /** Sets the character encoding of the source.
102:             * It is used with {@link #setSrc}.
103:             */
104:            public void setCharset(String charset) {
105:                if (charset != null && charset.length() == 0)
106:                    charset = null;
107:
108:                if (!Objects.equals(_charset, charset)) {
109:                    _charset = charset;
110:                    invalidate();
111:                }
112:            }
113:
114:            /** Returns the URI of the source that contains the script codes.
115:             * <p>Default: null.
116:             */
117:            public String getSrc() {
118:                return _src;
119:            }
120:
121:            /** Sets the URI of the source that contains the script codes.
122:             *
123:             * <p>You either add the script codes directly with the {@link Label}
124:             * children, or
125:             * set the URI to load the script codes with {@link #setSrc}.
126:             * But, not both.
127:             *
128:             * @param src the URI of the source that contains the script codes
129:             */
130:            public void setSrc(String src) {
131:                if (src != null && src.length() == 0)
132:                    src = null;
133:
134:                if (!Objects.equals(_src, src)) {
135:                    _src = src;
136:                    invalidate();
137:                }
138:            }
139:
140:            /** Returns whether to defer the execution of the script codes.
141:             *
142:             * <p>Default: false.
143:             */
144:            public boolean isDefer() {
145:                return _defer;
146:            }
147:
148:            /** Sets whether to defer the execution of the script codes.
149:             */
150:            public void setDefer(boolean defer) {
151:                if (_defer != defer) {
152:                    _defer = defer;
153:                    invalidate();
154:                }
155:            }
156:
157:            /** Returns the content of the script element.
158:             * By content we mean the JavaScript codes that will be enclosed
159:             * by the HTML SCRIPT element.
160:             *
161:             * <p>Default: null.
162:             *
163:             * @since 3.0.0
164:             */
165:            public String getContent() {
166:                return _content;
167:            }
168:
169:            /** Sets the content of the script element.
170:             * By content we mean the JavaScript codes that will be enclosed
171:             * by the HTML SCRIPT element.
172:             *
173:             * @since 3.0.0
174:             */
175:            public void setContent(String content) {
176:                if (content != null && content.length() == 0)
177:                    content = null;
178:
179:                if (!Objects.equals(_content, content)) {
180:                    _content = content;
181:                    invalidate();
182:                }
183:            }
184:
185:            //-- Component --//
186:            /** Not childable. */
187:            public boolean isChildable() {
188:                return false;
189:            }
190:
191:            public void redraw(java.io.Writer out) throws java.io.IOException {
192:                if (_type == null)
193:                    throw new UiException(
194:                            "The type is required. For example, text/javascript");
195:
196:                final StringBuffer sb = new StringBuffer(256)
197:                        .append("\n<script");
198:                HTMLs.appendAttribute(sb, "id", getUuid());
199:                HTMLs.appendAttribute(sb, "type", _type);
200:                HTMLs.appendAttribute(sb, "charset", _charset);
201:
202:                if (_src != null)
203:                    HTMLs.appendAttribute(sb, "src", getDesktop()
204:                            .getExecution().encodeURL(_src));
205:
206:                if (_defer)
207:                    sb.append(" defer=\"defer\"");
208:
209:                out.write(sb.append(">\n").toString());
210:
211:                final String content = getContent();
212:                if (content != null) {
213:                    out.write(content);
214:                    out.write('\n');
215:                }
216:
217:                out.write("</script>");
218:            }
219:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.