Source Code Cross Referenced for YahooTranslatorHelper.java in  » Portal » Open-Portal » com » sun » portal » rproxy » rewriter » yahoo » 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.rproxy.rewriter.yahoo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001 Sun Microsystems, Inc.  All rights reserved.
003:         * PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms.
004:         */
005:        package com.sun.portal.rproxy.rewriter.yahoo;
006:
007:        import java.net.MalformedURLException;
008:        import java.net.URLDecoder;
009:        import java.net.URLEncoder;
010:        import java.security.MessageDigest;
011:        import java.security.NoSuchAlgorithmException;
012:        import java.util.List;
013:        import java.util.Map;
014:
015:        import sun.misc.BASE64Encoder;
016:
017:        import com.sun.portal.rewriter.util.Debug;
018:        import com.sun.portal.rewriter.util.StringHelper;
019:        import com.sun.portal.rewriter.util.collections.ListMap;
020:        import com.sun.portal.rewriter.util.uri.DecoratedURI;
021:        import com.sun.portal.rproxy.rewriter.SRAPTranslatorHelper;
022:        import com.sun.portal.rproxy.rewriter.util.uri.SRAPGatewayURI;
023:
024:        public final class YahooTranslatorHelper {
025:            private static final String YPB_URL = "ypburl";
026:
027:            private static final String MD5_SIGN = "sign";
028:
029:            private static final String DOT_DONE = ".done";
030:
031:            public static String doTranslate(SRAPGatewayURI aGatewayURI,
032:                    DecoratedURI aYahooURI) {
033:                String lAbsoluteURIString = aYahooURI.toExternalForm();
034:
035:                final String bQuery = StringHelper.normalize(aYahooURI
036:                        .getDecoratee().getQuery());
037:                final String translatedQuery = translateQuery(bQuery,
038:                        aGatewayURI);
039:
040:                if (translatedQuery == bQuery) {
041:                    return lAbsoluteURIString;
042:                } else {
043:                    lAbsoluteURIString = aYahooURI.getFullFileURI() + "?"
044:                            + translatedQuery + aYahooURI.getReference();
045:                }
046:
047:                return lAbsoluteURIString;
048:            }// doTranslate()
049:
050:            /**
051:             * Identifies the Yahoo URL's and parses the query string. 1. Authentication
052:             * URL 2. Edit URL 3. Logout URL Rewrites the query strings and recomputes
053:             * the MD5 sum for the authentication URL
054:             * 
055:             * @see com.sun.portal.rproxy.rewriter.yahoo.QueryParser
056:             * @see com.sun.portal.rproxy.rewriter.yahoo.YahooException
057:             */
058:            private static String translateQuery(final String aQuery,
059:                    final SRAPGatewayURI aGatewayURI) {
060:                try {
061:                    ListMap bParamMap = null;
062:                    String urlKey = YPB_URL;
063:                    if (isYahooAuthURL(aQuery)) {
064:                        bParamMap = rewriteParam(urlKey, aQuery, aGatewayURI);
065:                        String newMD5 = computeYahooSign(bParamMap);
066:                        bParamMap.put(urlKey, URLEncoder.encode(bParamMap.get(
067:                                urlKey).toString()));
068:                        bParamMap.put(MD5_SIGN, newMD5);
069:                    } else if (isYahooLogoutURL(aQuery)) {
070:                        bParamMap = rewriteParam(urlKey, aQuery, aGatewayURI);
071:                    } else if (isYahooEditURL(aQuery)) {
072:                        urlKey = DOT_DONE;
073:                        bParamMap = rewriteParam(urlKey, aQuery, aGatewayURI);
074:                    } else {
075:                        return aQuery;
076:                    }
077:
078:                    // BugNo:4889146
079:                    return toQueryForm(bParamMap);
080:                } catch (MalformedURLException e) {
081:                    return aQuery;
082:                }
083:            }// translateQuery()
084:
085:            /**
086:             * ressurects the query string with the new MD5 sum and the rewritten url.
087:             */
088:            private static String toQueryForm(final ListMap aParamMap) {
089:                List lKeys = aParamMap.keyList();
090:                StringBuffer lResult = new StringBuffer();
091:
092:                for (int i = 0; i < lKeys.size(); i++) {
093:                    String bKey = lKeys.get(i).toString();
094:                    String bValue = aParamMap.get(bKey).toString();
095:
096:                    if (i != 0) {
097:                        lResult.append("&");
098:                    }
099:
100:                    if (bValue == null) {
101:                        lResult.append(bKey).append("=");
102:                    } else {
103:                        lResult.append(bKey).append("=").append(bValue);
104:                    }
105:                }
106:
107:                return lResult.toString();
108:            }// toQueryForm()
109:
110:            /**
111:             * Scans for Yahoo Edit URL
112:             */
113:            private static boolean isYahooEditURL(String url) {
114:                if (url.indexOf(DOT_DONE) != -1) {
115:                    return true;
116:                }
117:
118:                return false;
119:            }// isYahooEditURL()
120:
121:            /**
122:             * Scans for Yahoo Logout URL
123:             */
124:            private static boolean isYahooLogoutURL(String url) {
125:                if (url.indexOf(YPB_URL) != -1) {
126:                    return true;
127:                }
128:                return false;
129:            }// isYahooLogoutURL()
130:
131:            /**
132:             * Scans for Yahoo URL in Auth URL in the query String
133:             */
134:            private static boolean isYahooAuthURL(String url) {
135:                if (url.indexOf("&ypburl") != -1 && url.indexOf("&sign") != -1) {
136:                    return true;
137:                }
138:                return false;
139:            }// isYahooAuthURL()
140:
141:            /**
142:             * Computes the MD5 sum for Yahoo digest authentication.
143:             * 
144:             * TBD : Need a generic mechanism at the gateway to support any digest
145:             * authentication scheme
146:             * 
147:             * Order of entry to be passed to this function
148:             * 
149:             * String[] signArgs = new String[] {_corporateYahooID, _login, _usernum,
150:             * _ypburl, _ma, _corporateYahooPassword};
151:             * 
152:             * Signs and appends the MD5 Sum for Yahoo Authentication
153:             */
154:            private static String computeYahooSign(Map aParamMap) {
155:                String[] args = new String[] {
156:                        YahooConfigManager.getCorporateID(),
157:                        aParamMap.get("login").toString(),
158:                        aParamMap.get("usernum").toString(),
159:                        aParamMap.get(YPB_URL).toString(),
160:                        aParamMap.get("ma").toString(),
161:                        YahooConfigManager.getCorporatePassword(), };
162:                try {
163:                    MessageDigest bMessageDigest = MessageDigest
164:                            .getInstance("MD5");
165:
166:                    for (int i = 0; i < args.length; i++) {
167:                        if (args[i] != null) {
168:                            bMessageDigest.update(args[i].getBytes());
169:                        }
170:                    }
171:
172:                    StringBuffer bSignBuffer = new StringBuffer(
173:                            (new BASE64Encoder()).encodeBuffer(bMessageDigest
174:                                    .digest()));
175:                    // to remove the space appended at the end
176:                    bSignBuffer = new StringBuffer(bSignBuffer.substring(0, 24));
177:
178:                    int length = bSignBuffer.length();
179:                    for (int i = 0; i < length; i++) {
180:                        switch (bSignBuffer.charAt(i)) {
181:                        case '+': {
182:                            bSignBuffer.setCharAt(i, '.');
183:                            break;
184:                        }
185:                        case '/': {
186:                            bSignBuffer.setCharAt(i, '_');
187:                            break;
188:                        }
189:                        case '=': {
190:                            bSignBuffer.setCharAt(i, '-');
191:                            break;
192:                        }
193:                        default: {
194:                            break;
195:                        }
196:                        }
197:                    }// if
198:
199:                    return bSignBuffer.toString();
200:                } catch (NoSuchAlgorithmException e) {
201:                    Debug.error("MD5 Algorithm Not Found", e);
202:                }
203:
204:                return "MD5AlgorithmNotFound";
205:            }// computeYahooSign()
206:
207:            private static ListMap rewriteParam(final String aParamName,
208:                    final String aQuery, final SRAPGatewayURI aGatewayURI)
209:                    throws MalformedURLException {
210:                ListMap lParamMap = QueryParser.parseQueryString(aQuery);
211:                String paramvalue = lParamMap.get(aParamName).toString();
212:                // BugNo:4889146
213:                DecoratedURI lURI = new DecoratedURI(URLDecoder
214:                        .decode(paramvalue));
215:                String lModifiedURI = SRAPTranslatorHelper.prefixGateway(
216:                        aGatewayURI, lURI);
217:                lParamMap.put(aParamName, lModifiedURI);
218:                return lParamMap;
219:            }// rewriteParam()
220:
221:        }// class YahooTranslatorHelper
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.