Source Code Cross Referenced for JavaScriptService.java in  » Ajax » NextApp-Echo2 » nextapp » echo2 » webrender » service » 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 » NextApp Echo2 » nextapp.echo2.webrender.service 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * This file is part of the Echo Web Application Framework (hereinafter "Echo").
003:         * Copyright (C) 2002-2005 NextApp, Inc.
004:         *
005:         * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006:         *
007:         * The contents of this file are subject to the Mozilla Public License Version
008:         * 1.1 (the "License"); you may not use this file except in compliance with
009:         * the License. You may obtain a copy of the License at
010:         * http://www.mozilla.org/MPL/
011:         *
012:         * Software distributed under the License is distributed on an "AS IS" basis,
013:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014:         * for the specific language governing rights and limitations under the
015:         * License.
016:         *
017:         * Alternatively, the contents of this file may be used under the terms of
018:         * either the GNU General Public License Version 2 or later (the "GPL"), or
019:         * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020:         * in which case the provisions of the GPL or the LGPL are applicable instead
021:         * of those above. If you wish to allow use of your version of this file only
022:         * under the terms of either the GPL or the LGPL, and not to allow others to
023:         * use your version of this file under the terms of the MPL, indicate your
024:         * decision by deleting the provisions above and replace them with the notice
025:         * and other provisions required by the GPL or the LGPL. If you do not delete
026:         * the provisions above, a recipient may use your version of this file under
027:         * the terms of any one of the MPL, the GPL or the LGPL.
028:         */
029:
030:        package nextapp.echo2.webrender.service;
031:
032:        import java.io.IOException;
033:
034:        import nextapp.echo2.webrender.Connection;
035:        import nextapp.echo2.webrender.Service;
036:        import nextapp.echo2.webrender.util.GZipCompressor;
037:        import nextapp.echo2.webrender.util.JavaScriptCompressor;
038:        import nextapp.echo2.webrender.util.Resource;
039:
040:        /**
041:         * A service which renders <code>JavaScript</code> resource files.
042:         */
043:        public class JavaScriptService implements  Service {
044:
045:            /**
046:             * Creates a new <code>JavaScript</code> service from the specified
047:             * resource in the <code>CLASSPATH</code>.
048:             * 
049:             * @param id the <code>Service</code> id
050:             * @param resourceName the <code>CLASSPATH</code> resource name containing
051:             *        the JavaScript content
052:             * @return the created <code>JavaScriptService</code>
053:             */
054:            public static JavaScriptService forResource(String id,
055:                    String resourceName) {
056:                String content = Resource.getResourceAsString(resourceName);
057:                return new JavaScriptService(id, content);
058:            }
059:
060:            /** <code>Service</code> identifier. */
061:            private String id;
062:
063:            /** The JavaScript content in plain text. */
064:            private String content;
065:
066:            /** The JavaScript content in GZip compressed form. */
067:            private byte[] gzipContent;
068:
069:            /**
070:             * Creates a new <code>JavaScriptService</code>.
071:             * 
072:             * @param id the <code>Service</code> id
073:             * @param content the <code>JavaScript content</code>
074:             */
075:            public JavaScriptService(String id, String content) {
076:                super ();
077:                this .id = id;
078:                this .content = JavaScriptCompressor.compress(content);
079:                try {
080:                    gzipContent = GZipCompressor.compress(this .content);
081:                } catch (IOException ex) {
082:                    // Should not occur.
083:                    throw new RuntimeException(
084:                            "Exception compressing JavaScript source.", ex);
085:                }
086:            }
087:
088:            /**
089:             * @see nextapp.echo2.webrender.Service#getId()
090:             */
091:            public String getId() {
092:                return id;
093:            }
094:
095:            /**
096:             * <code>DO_NOT_CACHE</code> is returned for <code>JavaScript</code>
097:             * to avoid possibility of ever running out-of-date JavaScript in the
098:             * event an application is updated and redeployed. 
099:             * 
100:             * @see nextapp.echo2.webrender.Service#getVersion()
101:             */
102:            public int getVersion() {
103:                return DO_NOT_CACHE;
104:            }
105:
106:            /**
107:             * @see nextapp.echo2.webrender.Service#service(nextapp.echo2.webrender.Connection)
108:             */
109:            public void service(Connection conn) throws IOException {
110:                String userAgent = conn.getRequest().getHeader("user-agent");
111:                if (userAgent == null || userAgent.indexOf("MSIE") != -1) {
112:                    // Due to behavior detailed Microsoft Knowledge Base Article Id 312496, 
113:                    // all HTTP compression support is disabled for this browser.
114:                    // Due to the fact that ClientProperties information is not necessarily 
115:                    // available at this stage, browsers which provide deceitful user-agent 
116:                    // headers will also be affected.
117:                    servicePlain(conn);
118:                } else {
119:                    String acceptEncoding = conn.getRequest().getHeader(
120:                            "accept-encoding");
121:                    if (acceptEncoding != null
122:                            && acceptEncoding.indexOf("gzip") != -1) {
123:                        serviceGZipCompressed(conn);
124:                    } else {
125:                        servicePlain(conn);
126:                    }
127:                }
128:            }
129:
130:            /**
131:             * Renders the JavaScript resource using GZip encoding.
132:             * 
133:             * @param conn the relevant <code>Connection</code>
134:             */
135:            private void serviceGZipCompressed(Connection conn)
136:                    throws IOException {
137:                conn.getResponse().setContentType("text/plain");
138:                conn.getResponse().setHeader("Content-Encoding", "gzip");
139:                conn.getOutputStream().write(gzipContent);
140:            }
141:
142:            /**
143:             * Renders the JavaScript resource WITHOUT using GZip encoding.
144:             * 
145:             * @param conn the relevant <code>Connection</code>
146:             */
147:            private void servicePlain(Connection conn) throws IOException {
148:                conn.getResponse().setContentType("text/plain");
149:                conn.getWriter().print(content);
150:            }
151:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.