Source Code Cross Referenced for JavascriptUtils.java in  » J2EE » wicket » org » apache » wicket » util » string » 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 » J2EE » wicket » org.apache.wicket.util.string 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.wicket.util.string;
018:
019:        import org.apache.wicket.Response;
020:
021:        /**
022:         * Provide some helpers to write javascript related tags to the response object.
023:         * 
024:         * @author Juergen Donnerstag
025:         */
026:        public class JavascriptUtils {
027:
028:            /** Script open tag */
029:            public final static String SCRIPT_OPEN_TAG = "<script type=\"text/javascript\"><!--/*--><![CDATA[/*><!--*/\n";
030:
031:            /** Script close tag */
032:            public final static String SCRIPT_CLOSE_TAG = "\n/*-->]]>*/</script>\n";
033:
034:            /** Script open tag */
035:            public final static String SCRIPT_CONTENT_PREFIX = "<!--/*--><![CDATA[/*><!--*/\n";
036:
037:            /** Script close tag */
038:            public final static String SCRIPT_CONTENT_SUFFIX = "\n/*-->]]>*/";
039:
040:            /** The response object */
041:            private final Response response;
042:
043:            /**
044:             * Construct.
045:             * 
046:             * @param response
047:             *            The response object
048:             * @param id 
049:             */
050:            public JavascriptUtils(final Response response, String id) {
051:                this .response = response;
052:                writeOpenTag(response, id);
053:            }
054:
055:            /**
056:             * Constructor without id for backward compatibility
057:             * 
058:             * @param response
059:             *            The response object
060:             * @param id 
061:             */
062:            public JavascriptUtils(final Response response) {
063:                this .response = response;
064:                writeOpenTag(response);
065:            }
066:
067:            /**
068:             * Escape quotes and double quotes so that they can be part of e.g. an alert
069:             * call.
070:             * 
071:             * @param input
072:             *            input
073:             * @return Escaped version of the input
074:             */
075:            public static CharSequence escapeQuotes(final CharSequence input) {
076:                CharSequence s = input;
077:                if (s != null) {
078:                    s = Strings.replaceAll(s, "'", "\\'");
079:                }
080:                return s;
081:            }
082:
083:            /**
084:             * Write a reference to a javascript file to the response object
085:             * 
086:             * @param response
087:             *            The HTTP response
088:             * @param url
089:             *            The javascript file URL
090:             * @param id
091:             *            Unique identifier of element
092:             */
093:            public static void writeJavascriptUrl(final Response response,
094:                    final CharSequence url, final String id) {
095:                response.write("<script type=\"text/javascript\" ");
096:                if (id != null) {
097:                    response.write("id=\"" + id + "\" ");
098:                }
099:                response.write("src=\"");
100:                response.write(url);
101:                response.println("\"></script>");
102:            }
103:
104:            /**
105:             * Write a reference to a javascript file to the response object
106:             * 
107:             * @param response
108:             *            The HTTP response
109:             * @param url
110:             *            The javascript file URL
111:             */
112:            public static void writeJavascriptUrl(final Response response,
113:                    final CharSequence url) {
114:                writeJavascriptUrl(response, url, null);
115:            }
116:
117:            /**
118:             * Write the simple text to the response object surrounded by a script tag.
119:             * 
120:             * @param response
121:             *            The HTTP: response
122:             * @param text
123:             *            The text to added in between the script tags
124:             * @param id
125:             *            Unique identifier of element
126:             */
127:            public static void writeJavascript(final Response response,
128:                    final CharSequence text, String id) {
129:                writeOpenTag(response, id);
130:                response.write(text);
131:                writeCloseTag(response);
132:            }
133:
134:            /**
135:             * Write the simple text to the response object surrounded by a script tag.
136:             * 
137:             * @param response
138:             *            The HTTP: response
139:             * @param text
140:             *            The text to added in between the script tags
141:             */
142:            public static void writeJavascript(final Response response,
143:                    final CharSequence text) {
144:                writeJavascript(response, text, null);
145:            }
146:
147:            /**
148:             * 
149:             * @param response
150:             * @param id 
151:             */
152:            public static void writeOpenTag(final Response response, String id) {
153:                response.write("<script type=\"text/javascript\" ");
154:                if (id != null) {
155:                    response.write("id=\"" + id + "\"");
156:                }
157:                response.write(">");
158:                response.write(SCRIPT_CONTENT_PREFIX);
159:            }
160:
161:            /**
162:             * 
163:             * @param response
164:             */
165:            public static void writeOpenTag(final Response response) {
166:                writeOpenTag(response, null);
167:            }
168:
169:            /**
170:             * 
171:             * @param response
172:             */
173:            public static void writeCloseTag(final Response response) {
174:                response.write(SCRIPT_CONTENT_SUFFIX);
175:                response.println("</script>\n");
176:
177:            }
178:
179:            /**
180:             * @see Response#write(java.lang.CharSequence)
181:             * @param script
182:             */
183:            public void write(final CharSequence script) {
184:                response.write(script);
185:            }
186:
187:            /**
188:             * @see Response#println(java.lang.CharSequence)
189:             * @param script
190:             */
191:            public void println(final CharSequence script) {
192:                response.println(script);
193:            }
194:
195:            /**
196:             * Write the script close tag to the response. The response output stream
197:             * remains open.
198:             */
199:            public void close() {
200:                writeCloseTag(response);
201:            }
202:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.