Source Code Cross Referenced for SunCalURLBuilder.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.sun.comclient.calendar.socs.SOCSCalendarStore;
010:        import com.sun.comclient.calendar.CalendarStoreException;
011:
012:        import com.sun.ssoadapter.SSOAdapter;
013:
014:        import java.io.BufferedReader;
015:        import java.io.InputStreamReader;
016:        import java.io.IOException;
017:
018:        import java.net.URLConnection;
019:        import java.net.MalformedURLException;
020:        import java.net.URL;
021:
022:        import com.sun.comclient.calendar.DateTime;
023:
024:        import com.sun.comclient.calendar.socs.SOCSEvent;
025:        import com.sun.comclient.calendar.socs.SOCSTodo;
026:
027:        public class SunCalURLBuilder extends URLBuilder implements  CalURL {
028:
029:            protected String calid = null;
030:            protected String sid = null;
031:
032:            public void init(SSOAdapter ssoAdapter) {
033:                super .init(ssoAdapter);
034:                if (!serverSSOEnabled) {
035:                    getSession();
036:                }
037:            }
038:
039:            /**
040:             *	Checks whether the current sid for Calendar Express has
041:             *	timed out. This is done by checking if the page returned by 
042:             *	/check_id.wcap.  If 1, then the session is still valid.
043:             *
044:             *@return	boolean
045:             */
046:            public boolean isValidSession() {
047:
048:                if (sid == null) {
049:                    return false;
050:                }
051:
052:                String vid = null;
053:                StringBuffer urlstr = new StringBuffer(baseURL);
054:                urlstr.append("/check_id.wcap?fmt-out=text%2Fxml&id=");
055:                urlstr.append(encode(sid));
056:
057:                vid = pullDataFromURL(urlstr.toString(),
058:                        "<X-NSCP-WCAP-CHECK-ID>", "</X-NSCP-WCAP-CHECK-ID>");
059:                if ((vid != null) && (vid.equals("1"))) {
060:                    return true;
061:                } else {
062:                    return false;
063:                }
064:            }
065:
066:            /**
067:             * Authenticate the user to Calendar Express. If the return
068:             * data contains the sid then the user is considered authenticated.
069:             * Also sets the path to the authenticated location with the sid.
070:             *
071:             * @return		String - session ID to use for URLs, null for any problems
072:             **/
073:            public void getSession() {
074:
075:                // Get the calendar session id for the calendar store. This is stored in SOCSSession
076:                //
077:                String eprc = adapterProperties.getProperty(
078:                        "enablePerRequestConnection", "false");
079:
080:                if (eprc.equals("true")) {
081:                    // check for admin proxy authentication
082:                    if (useProxyAuth) {
083:                        user = adapterProperties.getProperty("proxyAdminUid");
084:                        password = adapterProperties
085:                                .getProperty("proxyAdminPassword");
086:                    }
087:                    // Build the single sign on URL and generate WCAP login
088:                    StringBuffer urlstr = new StringBuffer(baseURL);
089:                    urlstr.append("/login.wcap?fmt-out=text%2Fxml&");
090:                    urlstr.append("password=");
091:                    urlstr.append(encode(password));
092:                    urlstr.append("&user=");
093:                    urlstr.append(encode(user));
094:                    if (useProxyAuth) {
095:                        if ((proxyAuthUid != null)
096:                                && (proxyAuthUid.length() > 0)) {
097:                            urlstr.append("&proxyauth=");
098:                            urlstr.append(encode(proxyAuthUid));
099:                        }
100:                    }
101:                    // This could use some kind of xml parser to pull the sid
102:                    sid = pullDataFromURL(urlstr.toString(),
103:                            "<X-NSCP-WCAP-SESSION-ID>",
104:                            "</X-NSCP-WCAP-SESSION-ID>");
105:                } else {
106:                    SOCSCalendarStore socsStore = (SOCSCalendarStore) ssoAdapter
107:                            .getConnection();
108:                    try {
109:                        sid = socsStore.getSOCSSession().getID();
110:                    } catch (CalendarStoreException cse) {
111:                        return;
112:                    }
113:                }
114:                StringBuffer pathBuf = new StringBuffer("/command.shtml?id=");
115:                if (sid != null) {
116:                    pathBuf.append(encode(sid));
117:                }
118:                setPath(pathBuf.toString());
119:            }
120:
121:            /**
122:             * Open a URL connection and return the data between startDelim and endDelim
123:             *
124:             * @param	String	The URL to use
125:             * @param	String	The start delimiter
126:             * @param	String	The end delimiter
127:             * @return	String	Data between delimiters, null for any problems
128:             **/
129:            private String pullDataFromURL(String urlString, String startDelim,
130:                    String endDelim) {
131:                String data = null;
132:                String line = null;
133:                BufferedReader in = null;
134:                URLConnection urlconn = null;
135:                URL url = null;
136:
137:                try {
138:                    url = new URL(urlString);
139:                    urlconn = (URLConnection) url.openConnection();
140:                    urlconn.setDoInput(true);
141:                    urlconn.setDoOutput(true);
142:                    urlconn.setUseCaches(false);
143:                    in = new BufferedReader(new InputStreamReader(urlconn
144:                            .getInputStream()));
145:
146:                    while ((line = in.readLine()) != null) {
147:                        if (line.indexOf(startDelim) != -1) {
148:                            int start = line.indexOf(startDelim)
149:                                    + startDelim.length();
150:                            int end = line.indexOf(endDelim);
151:                            data = line.substring(start, end);
152:                            break;
153:                        }
154:                    }
155:
156:                    in.close();
157:                } catch (MalformedURLException mue) {
158:                    return null;
159:                } catch (IOException ie) {
160:                    return null;
161:                }
162:                return data;
163:            }
164:
165:            /**
166:             * Return URL string for calendar client.
167:             * Defaults to baseURL + path
168:             *
169:             * @param	String	Calendar id show
170:             * @return	String	start URL string
171:             */
172:            public String getStartURL() {
173:                return getStartURLForComp() + "&view=overview";
174:            }
175:
176:            private String getStartURLForComp() {
177:                StringBuffer messageURL = new StringBuffer(baseURL);
178:                if ((path != null) && (path.length() > 0)) {
179:                    messageURL.append(path);
180:                    if ((calid != null) && (calid.length() > 0)) {
181:                        messageURL.append("&calid=");
182:                        messageURL.append(encode(calid));
183:                        if ((domain != null) && (domain.length() > 0)) {
184:                            messageURL.append("%40"); // URL encoding value for '@'
185:                            messageURL.append(encode(domain));
186:                        }
187:                    }
188:                }
189:                return messageURL.toString();
190:
191:            }
192:
193:            /**
194:             * Sets the calendar id
195:             *
196:             * @param	String	Calendar ID
197:             */
198:            public void setCalid(String calid) {
199:                this .calid = calid;
200:            }
201:
202:            /**
203:             * Return the calendar id
204:             *
205:             * @return	String	Calendar ID
206:             */
207:            public String getCalid() {
208:                return calid;
209:            }
210:
211:            /**
212:             * Lets invoking classes know if multiple view urls are available
213:             * in this URLBuilder.  
214:             *
215:             * @return	boolean	Are view URLs available
216:             */
217:            public boolean allowsViewURL() {
218:                return false;
219:            }
220:
221:            /**
222:             * Return URL string for specific view to be opened in cal client.
223:             *
224:             * @param	String	View
225:             * @param	String	Date
226:             * @return	String	View URL string
227:             */
228:            public String getViewURL(String view, String date) {
229:                return getStartURL();
230:            }
231:
232:            /**
233:             * Lets invoking classes know if task URLs are available
234:             * in this URLBuilder.  
235:             *
236:             * @return	boolean	Are task URLs available
237:             */
238:            public boolean allowsTaskURL() {
239:                return true;
240:            }
241:
242:            /**
243:             * Return URL string for specific task to be opened in cal client.
244:             *
245:             * @param	Object	Task Object
246:             * @return	String	Task URL string
247:             */
248:            public String getTaskURL(Object task) {
249:                if (task != null) {
250:                    if (task instanceof  SOCSTodo) {
251:                        SOCSTodo todo = (SOCSTodo) task;
252:                        StringBuffer sb = new StringBuffer(getStartURLForComp());
253:                        sb.append("&view=new_task&uid=" + todo.getID());
254:                        if (todo.isRecurring()) {
255:                            sb.append("&rid="
256:                                    + (((DateTime) (todo.getRecurrenceID()))
257:                                            .getTimeInMillis() / 1000));
258:                        } else {
259:                            sb.append("&rid=0");
260:                        }
261:                        return sb.toString();
262:                    }
263:                }
264:                return getStartURL();
265:            }
266:
267:            /**
268:             * Lets invoking classes know if event URLs are available
269:             * in this URLBuilder.
270:             *
271:             * @return	boolean	Are event URLs available
272:             */
273:            public boolean allowsEventURL() {
274:                return true;
275:            }
276:
277:            /**
278:             * Return URL string for specific event to be opened in cal client.
279:             *
280:             * @param	Object	Event Object
281:             * @return	String	Event URL string
282:             */
283:            public String getEventURL(Object event) {
284:                if (event != null) {
285:                    if (event instanceof  SOCSEvent) {
286:                        SOCSEvent eventV = (SOCSEvent) event;
287:                        StringBuffer sb = new StringBuffer(getStartURLForComp());
288:                        sb.append("&view=new_event&uid=" + eventV.getID());
289:                        if (eventV.isRecurring()) {
290:                            sb.append("&rid="
291:                                    + (((DateTime) (eventV.getRecurrenceID()))
292:                                            .getTimeInMillis() / 1000));
293:                        } else {
294:                            sb.append("&rid=0");
295:                        }
296:                        return sb.toString();
297:                    } else {
298:                        return getStartURL();
299:                    }
300:                }
301:                return getStartURL();
302:            }
303:
304:            /**
305:             * Lets invoking clasess know is composeEvent is available
306:             * in this URLBuilder
307:             * @return boolean , is composeEvent available
308:             */
309:            public boolean allowsComposeEventURL() {
310:                return false;
311:            }
312:
313:            /**
314:             * Lets invoking clasess know is composeTask is available
315:             * in this URLBuilder
316:             * @return boolean , is composeTask available
317:             */
318:            public boolean allowsComposeTaskURL() {
319:                return false;
320:            }
321:
322:            /**
323:             * Return URL string to open the client's composeEvent window.
324:             *
325:             * @param	String	Subject of the event
326:             * @param	DateTime the DateTimeat which event should be created
327:             * @return	String	Composition URL string
328:             */
329:            public String getComposeEventURL(DateTime datetime) {
330:                return getStartURL();
331:            }
332:
333:            /**
334:             * Return URL string to open the client's composeTask window.
335:             *
336:             * @param	String	Subject of the task
337:             * @param	DateTime the DateTimeat which event should be created
338:             * @return	String	Composition URL string
339:             */
340:            public String getComposeTaskURL(DateTime datetime) {
341:                return getStartURL();
342:
343:            }
344:
345:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.