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


001:        /*
002:         *
003:         * Copyright 2000 Sun Microsystems, Inc.	All rights reserved.
004:         * PROPRIETARY/CONFIDENTIAL.	Use of this product is subject to license terms.
005:         */
006:
007:        package com.sun.portal.comm.url;
008:
009:        import com.iplanet.am.sdk.AMException;
010:        import com.iplanet.am.sdk.AMStoreConnection;
011:        import com.iplanet.am.sdk.AMUser;
012:
013:        import com.iplanet.sso.SSOToken;
014:        import com.iplanet.sso.SSOException;
015:
016:        import com.sun.ssoadapter.SSOAdapter;
017:        import com.sun.ssoadapter.SSOAdapterException;
018:
019:        import java.util.Properties;
020:        import java.net.URLEncoder;
021:        import java.util.Locale;
022:        import java.util.StringTokenizer;
023:
024:        public abstract class URLBuilder {
025:
026:            protected Properties adapterProperties = null;
027:            protected String user = null;
028:            protected String password = null;
029:            protected String domain = null;
030:            protected boolean serverSSOEnabled = false;
031:            protected boolean useProxyAuth = false;
032:            protected String proxyAuthUid = null;
033:            protected String baseURL = null;
034:            protected String path = null;
035:            protected String encoding = null;
036:            protected SSOAdapter ssoAdapter = null;
037:            protected String debugid = null;
038:
039:            /**
040:             * Lets invoking classes know if the client start url is available
041:             * in this URLBuilder.  Defaults to true
042:             *
043:             * @return	boolean	Is client start URL available
044:             */
045:            public boolean allowsStartURL() {
046:                return true;
047:            }
048:
049:            /**
050:             * Return URL string for mail client.
051:             * Defaults to baseURL + path
052:             *
053:             * @return	String	start URL string
054:             */
055:            public String getStartURL() {
056:                String messageURL = baseURL;
057:                if ((path != null) && (path.length() > 0)) {
058:                    messageURL += path;
059:                }
060:                return messageURL;
061:            }
062:
063:            /**
064:             *	Inits all the important items
065:             *
066:             */
067:            public void init(SSOAdapter ssoAdapter) {
068:                this .ssoAdapter = ssoAdapter;
069:                adapterProperties = ssoAdapter.getProperties();
070:                // Set the base URL from ssoadapter properties
071:                initBaseURL();
072:                // Set the serverSSOEnabled var from ssoadapter properties
073:                if (adapterProperties.getProperty("serverSSOEnabled", "")
074:                        .equalsIgnoreCase("true")) {
075:                    serverSSOEnabled = true;
076:                } else {
077:                    serverSSOEnabled = false;
078:                }
079:                // Do additional settings if server is not SSO Enabled
080:                if (!serverSSOEnabled) {
081:                    initLogonProperties(ssoAdapter);
082:                }
083:
084:                // debugging identifier
085:                String adapterName = ssoAdapter.getName();
086:                try {
087:                    SSOToken token = ssoAdapter.getSSOToken();
088:                    debugid = token.getPrincipal().getName() + " ssoadapter="
089:                            + adapterName + " ";
090:                } catch (Exception e) {
091:                    debugid = " ssoadapter=" + adapterName + " ";
092:                }
093:            }
094:
095:            /**
096:             *	Sets the logon properties from sso adapter preferences and the AMStore
097:             *  if using proxy auth.
098:             *
099:             */
100:            protected void initLogonProperties(SSOAdapter ssoAdapter) {
101:                if (adapterProperties == null) {
102:                    adapterProperties = ssoAdapter.getProperties();
103:                }
104:                String enableProxyAuth = adapterProperties
105:                        .getProperty("enableProxyAuth");
106:                if ((enableProxyAuth != null)
107:                        && (enableProxyAuth.equals("true"))) {
108:                    useProxyAuth = true;
109:                    user = adapterProperties.getProperty("proxyAdminUid");
110:                    password = adapterProperties
111:                            .getProperty("proxyAdminPassword");
112:                    AMStoreConnection amsc = null;
113:                    AMUser auser = null;
114:                    String usrAttr = adapterProperties.getProperty(
115:                            "userAttribute", "uid");
116:                    try {
117:                        SSOToken ssotoken = ssoAdapter.getSSOToken();
118:                        amsc = new AMStoreConnection(ssotoken);
119:                        auser = amsc.getUser(ssotoken.getPrincipal().getName());
120:                        proxyAuthUid = auser.getStringAttribute(usrAttr);
121:                    } catch (SSOException ssoe) {
122:                        // Debug message here
123:                    } catch (AMException ame) {
124:                        // Debug message here
125:                    } catch (SSOAdapterException ssoae) {
126:                        // Debug message here
127:                    }
128:                } else {
129:                    user = adapterProperties.getProperty("uid");
130:                    password = adapterProperties.getProperty("password");
131:                }
132:                domain = adapterProperties.getProperty("domain");
133:            }
134:
135:            /**
136:             *	Sets the base URL from sso adapter preferences.
137:             *
138:             *  Constructs base URL per the following SSO adapter properties:
139:             *
140:             *  - clientProtocol, protocol, defaults to "http"
141:             *  - clientHost, host, defaults to "nohostsetinpreferences"
142:             *  - clientPort, port, defaults to "80"
143:             *
144:             */
145:            protected void initBaseURL() {
146:
147:                StringBuffer sb = new StringBuffer();
148:
149:                // client protocol
150:                String clientProtocol = adapterProperties.getProperty(
151:                        "clientProtocol", adapterProperties.getProperty(
152:                                "protocol", "http"));
153:                //for addrBook till 6.4 does not have clientProtocol/protocol defined, remove after 6.4
154:                if (clientProtocol.equals("undef")) {
155:                    clientProtocol = "http";
156:                }
157:
158:                sb.append(clientProtocol);
159:                sb.append("://");
160:
161:                // client host 
162:                String clientHost = adapterProperties.getProperty("clientHost",
163:                        adapterProperties.getProperty("host",
164:                                "nohostsetinpreferences"));
165:                if ((clientHost == null) || (clientHost.trim().length() == 0))
166:                    clientHost = adapterProperties.getProperty("host",
167:                            "nohostsetinpreferences");
168:                sb.append(clientHost);
169:                sb.append(':');
170:
171:                // client port
172:                String clientPort = adapterProperties.getProperty("clientPort",
173:                        adapterProperties.getProperty("port", "80"));
174:
175:                sb.append(clientPort);
176:                baseURL = sb.toString();
177:            }
178:
179:            /**
180:             *	Returns the base URL
181:             *
182:             *@return	String	The base URL
183:             */
184:            public String getBaseURL() {
185:                return baseURL;
186:            }
187:
188:            /**
189:             *	Sets the URL path
190:             *
191:             */
192:            public void setPath(String path) {
193:                if (((path != null) && (!path.equals("")))
194:                        && (path.charAt(0) != '/')) {
195:                    this .path = "/" + path;
196:                } else {
197:                    this .path = path;
198:                }
199:            }
200:
201:            /**
202:             *	Returns the URL path
203:             *
204:             *@return	String	The URL path
205:             */
206:            public String getPath() {
207:                return path;
208:            }
209:
210:            /**
211:             *	Is the server SSO-Enabled
212:             *
213:             *@return	boolean	server SSO-Enabled
214:             */
215:            public boolean getServerSSOEnabled() {
216:                return serverSSOEnabled;
217:            }
218:
219:            /**
220:             *	Set whether the server is SSO-Enabled
221:             *
222:             *@param	boolean	server SSO-Enabled
223:             */
224:            public void setServerSSOEnabled(boolean serverSSOEnabled) {
225:                this .serverSSOEnabled = serverSSOEnabled;
226:            }
227:
228:            /**
229:             *	Get the SSO Adapter properties
230:             *
231:             *@return	Properties	SSO Adapter properties
232:             */
233:            public Properties getAdapterProperties() {
234:                return adapterProperties;
235:            }
236:
237:            /**
238:             *	Set the SSO Adapter properties
239:             *
240:             *@param	Properties	SSO Adapter properties
241:             */
242:            public void setAdapterProperties(Properties adapterProperties) {
243:                this .adapterProperties = adapterProperties;
244:            }
245:
246:            /**
247:             *	Return the response character encoding
248:             *
249:             *@return	String	The response character encoding
250:             */
251:            public String getEncoding() {
252:                return encoding;
253:            }
254:
255:            /**
256:             *	Set the response character encoding
257:             *
258:             * @param	String	The response character encoding
259:             */
260:            public void setEncoding(String encoding) {
261:                this .encoding = encoding;
262:            }
263:
264:            /**
265:             *	Encode a string.  Return initial string on any errors
266:             *
267:             * @param	String	The string to be encoded
268:             * @return	String	The encoded string
269:             */
270:            public String encode(String text) {
271:                try {
272:                    if (text != null) {
273:                        return URLEncoder.encode(text, getEncoding());
274:                    }
275:                } catch (java.io.UnsupportedEncodingException uee) {
276:                    // Debug message here
277:                }
278:                return text;
279:            }
280:
281:            /**
282:             * Get user locale
283:             * 
284:             * @ return Locale Users locale
285:             */
286:            public Locale getLocale() {
287:                String userLocaleString = "en_US";
288:                SSOToken session = null;
289:
290:                try {
291:                    session = ssoAdapter.getSSOToken();
292:                    if (session != null) {
293:                        userLocaleString = session.getProperty("Locale");
294:                    }
295:                } catch (Exception e) {
296:                }
297:
298:                StringTokenizer localeTokens = new StringTokenizer(
299:                        userLocaleString, "_");
300:
301:                String userLangString = (localeTokens.hasMoreTokens() ? localeTokens
302:                        .nextToken()
303:                        : "");
304:                String userCountryString = (localeTokens.hasMoreTokens() ? localeTokens
305:                        .nextToken()
306:                        : "");
307:                String userVariantString = (localeTokens.hasMoreTokens() ? localeTokens
308:                        .nextToken()
309:                        : "");
310:
311:                Locale userLocale = new java.util.Locale(userLangString,
312:                        userCountryString, userVariantString);
313:                return userLocale;
314:            }
315:
316:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.