Source Code Cross Referenced for URLTranscoder.java in  » Portal » Open-Portal » com » sun » portal » wireless » htmlconversion » servlet » 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 » Portal » Open Portal » com.sun.portal.wireless.htmlconversion.servlet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on Mar 12, 2005
003:         */
004:        package com.sun.portal.wireless.htmlconversion.servlet;
005:
006:        import java.io.UnsupportedEncodingException;
007:        import java.net.URLEncoder;
008:        import java.net.URLDecoder;
009:        import java.net.URL;
010:        import java.net.MalformedURLException;
011:
012:        import javax.servlet.http.HttpServletRequest;
013:        import javax.servlet.http.HttpServletResponse;
014:
015:        /**
016:         * Utility class for encoding and decoding URLs
017:         * 
018:         * @author ashwin.mathew@sun.com
019:         */
020:        public class URLTranscoder {
021:
022:            private HttpServletRequest request;
023:
024:            private HttpServletResponse response;
025:
026:            private URL baseURL;
027:
028:            private static final String CHARSET_UTF8 = "UTF-8";
029:
030:            public static final String EQUALS = "=";
031:            public static final String QUERY = "?";
032:
033:            public URLTranscoder(HttpServletRequest request,
034:                    HttpServletResponse response) {
035:                this .request = request;
036:                this .response = response;
037:
038:                String url = request.getParameter(URLScraper.URL_PARAM);
039:
040:                if (url != null) {
041:                    String refererURLspec = URLTranscoder.decode(url);
042:
043:                    try {
044:                        this .baseURL = new URL(refererURLspec);
045:                    } catch (MalformedURLException e) {
046:                        // This should never happen,
047:                        // Since the URL has already been retrieved
048:                        e.printStackTrace();
049:                    }
050:                }
051:            }
052:
053:            public static final String encode(String url) {
054:                String encodedUrl = url;
055:
056:                try {
057:                    encodedUrl = URLEncoder.encode(url, CHARSET_UTF8);
058:                } catch (UnsupportedEncodingException e) {
059:                    // Do nothing, UTF-8 is supported
060:                }
061:
062:                return encodedUrl;
063:            }
064:
065:            public static final String decode(String url) {
066:                String decodedUrl = url;
067:
068:                try {
069:                    decodedUrl = URLDecoder.decode(url, CHARSET_UTF8);
070:                } catch (UnsupportedEncodingException e) {
071:                    // Do nothing, UTF-8 is supported
072:                }
073:
074:                return decodedUrl;
075:            }
076:
077:            /**
078:             * Returns the URL prefix, with the context path added to it.
079:             * 
080:             * @return
081:             */
082:            public String getURLPrefix() {
083:                return getContextPath() + URLScraper.URL_PREFIX;
084:            }
085:
086:            /**
087:             * Returns the request context path.
088:             * @return
089:             */
090:            public String getContextPath() {
091:                return request.getContextPath();
092:            }
093:
094:            /**
095:             * Rewrites a URL with the session id, and encodes it. This
096:             * method will also prefix the current absolute path to the URL
097:             * in case the URL is relative.
098:             * 
099:             * @param url
100:             * @return
101:             */
102:            public String rewriteURL(String url) {
103:                url = resolveURL(url);
104:
105:                StringBuffer rewriteUrlBuffer = new StringBuffer();
106:
107:                rewriteUrlBuffer.append(getURLPrefix());
108:
109:                rewriteUrlBuffer.append(URLScraper.URL_PARAM);
110:                rewriteUrlBuffer.append(EQUALS);
111:                rewriteUrlBuffer.append(URLTranscoder.encode(url));
112:
113:                String rewriteUrl = response.encodeURL(rewriteUrlBuffer
114:                        .toString());
115:
116:                return rewriteUrl;
117:            }
118:
119:            /**
120:             * If a URL is relative, resolves it relative to the
121:             * referer URL.
122:             * 
123:             * @param url
124:             * @return
125:             */
126:            public String resolveURL(String url) {
127:                String resolvedURL = url;
128:
129:                if (baseURL != null) {
130:                    try {
131:                        // Need to do this, in case url is relative
132:                        URL fullURL = new URL(baseURL, url);
133:                        resolvedURL = fullURL.toExternalForm();
134:                    } catch (MalformedURLException e) {
135:                        // Ignore - we'll try to proceed with the URL passed in
136:                        e.printStackTrace();
137:                    }
138:                }
139:
140:                return resolvedURL;
141:            }
142:
143:            public void setBaseURL(String newBaseURL) {
144:                try {
145:                    // Need to do this, in case url is relative
146:                    baseURL = new URL(baseURL, newBaseURL);
147:                } catch (MalformedURLException e) {
148:                    // Ignore - we'll try to proceed normally
149:                    e.printStackTrace();
150:                }
151:            }
152:
153:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.