Source Code Cross Referenced for UWCURLBuilder.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.ssoadapter.SSOAdapter;
010:
011:        import javax.mail.Folder;
012:        import javax.mail.Message;
013:        import javax.mail.MessagingException;
014:        import javax.mail.UIDFolder;
015:
016:        import com.sun.comclient.calendar.DateTime;
017:        import com.sun.comclient.calendar.OperationNotSupportedException;
018:        import com.sun.comclient.calendar.CalendarComponentException;
019:        import com.sun.comclient.calendar.VEvent;
020:        import com.sun.comclient.calendar.VTodo;
021:
022:        import java.io.BufferedReader;
023:        import java.io.InputStreamReader;
024:
025:        import java.net.HttpURLConnection;
026:        import java.net.MalformedURLException;
027:        import java.net.URL;
028:
029:        public class UWCURLBuilder extends URLBuilder implements  MailURL,
030:                CalURL, ABURL {
031:
032:            private String contexturi = null;
033:            private String calid = null;
034:            private final String JES4UWC = "JES 4 UWC";
035:            private final String JES5UWC = "JES 5 UWC";
036:            private String uwcVersion = JES5UWC;
037:
038:            public void init(SSOAdapter ssoAdapter) {
039:                super .init(ssoAdapter);
040:                contexturi = adapterProperties.getProperty("uwcContext");
041:                initUWCVersion();
042:                //JES 4 or previous UWC Mail SSO Adapter does not contain the UWC Context. 
043:                String type = adapterProperties.getProperty("type");
044:                if ((type != null) && (type.equals("MAIL-TYPE"))) {
045:                    if ((uwcVersion.equals(JES4UWC))) {
046:                        setPath("?argv=laurel=on&argv=cal=1");
047:                    } else {
048:                        setPath(contexturi + "/mail");
049:                    }
050:                } else {
051:                    setPath(contexturi);
052:                }
053:            }
054:
055:            /**
056:             * Determines the version of UWC running on the remote host.
057:             * This method is required because the URL interface specifications are different for JES 4 UWC and JES 5 UWC
058:             * The version of UWC is determined by making a HTTP request to "/uwc/auth". For JES 4 UWC and earlier, the clientport 
059:             * points to the messenger express port. Hence for JES 4 a 404 status code should be returned. As a safety we also check
060:             * for the presence of "Communications Express 6 2005Q4" string in the page content. Presence of this string will indicate that
061:             * UWC JES 4 is being used on the remote UWC server
062:             *
063:             * @return	void
064:             */
065:            private void initUWCVersion() {
066:
067:                //If contexturi is absent or blank then default to JES 4
068:                if ((contexturi == null) || (contexturi.trim().length() == 0)) {
069:                    uwcVersion = JES4UWC;
070:                    return;
071:                }
072:
073:                StringBuffer pageContent = new StringBuffer();
074:                StringBuffer urlstr = new StringBuffer(baseURL);
075:                urlstr.append("/" + contexturi + "/auth");
076:                HttpURLConnection urlconn = null;
077:                try {
078:                    URL url = new URL(urlstr.toString());
079:                    urlconn = (HttpURLConnection) url.openConnection();
080:                    urlconn.setInstanceFollowRedirects(false);
081:                    //Check the status code. If it is 404 then assume that the URL is for messenger express
082:                    if (urlconn.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
083:                        uwcVersion = JES4UWC;
084:                        return;
085:                    }
086:                } catch (java.io.IOException ioe) {
087:                    ioe.printStackTrace();
088:                    return;
089:                }
090:                try {
091:                    BufferedReader in = new BufferedReader(
092:                            new InputStreamReader(urlconn.getInputStream()));
093:                    String inputLine = null;
094:                    // Getting the content of the page
095:                    while ((inputLine = in.readLine()) != null) {
096:                        pageContent.append(inputLine);
097:                    }
098:                    in.close();
099:                } catch (java.io.IOException ioe) {
100:                    ioe.printStackTrace();
101:                    return;
102:                }
103:
104:                // Check if the page contents contain string "Communications Express 6 2005Q4"
105:                if ((pageContent.indexOf("Communications Express 6 2005Q4")) > 0) {
106:                    uwcVersion = JES4UWC;
107:                } else {
108:                    uwcVersion = JES5UWC;
109:                }
110:            }
111:
112:            /**
113:             * Lets invoking classes know if per-message urls are available
114:             * in this URLBuilder.
115:             *
116:             * @return	boolean	Are message URLs available
117:             */
118:            public boolean allowsMessageURL() {
119:                return true;
120:            }
121:
122:            /**
123:             * Return URL string for specific message to be opened in mail client.
124:             *
125:             * @param	javax.mail.Message	The message to open
126:             * @return	String	Message URL string
127:             */
128:            public String getMessageURL(javax.mail.Message message) {
129:                if (message == null) {
130:                    return getStartURL();
131:                }
132:                StringBuffer returnURL = new StringBuffer(getBaseURL());
133:                String lang = getLocale().getLanguage();
134:                Folder folder = message.getFolder();
135:                // In order to use UWC, must access proper message using format 
136:                if (uwcVersion.equals(JES4UWC)) {
137:                    returnURL.append("/");
138:                    returnURL.append("?argv=laurel=on&argv=mbox=");
139:                    returnURL.append(encode(message.getFolder().getFullName()));
140:                    returnURL.append("&argv=msg=");
141:                    try {
142:                        returnURL.append(((UIDFolder) folder).getUID(message));
143:                    } catch (MessagingException me) {
144:                        return getStartURL();
145:                    }
146:                    returnURL.append("&argv=cal=1");
147:
148:                } else {
149:                    returnURL.append("/" + contexturi);
150:                    returnURL.append("/mail");
151:                    returnURL.append("?mbox=");
152:                    returnURL.append(encode(message.getFolder().getFullName()));
153:                    returnURL.append("&msg=");
154:                    try {
155:                        returnURL.append(((UIDFolder) folder).getUID(message));
156:                    } catch (MessagingException me) {
157:                        return getStartURL();
158:                    }
159:                }
160:
161:                return returnURL.toString();
162:            }
163:
164:            /**
165:             * Lets invoking classes know if composing URLs are available
166:             * in this URLBuilder.
167:             *
168:             * @return	boolean	Are compisition URLs available
169:             */
170:            public boolean allowsComposeURL() {
171:                return true;
172:            }
173:
174:            /**
175:             * Return URL string to open the client's compose window.
176:             *
177:             * @param	String	Subject of the message
178:             * @param	javax.mail.Address[]	Array of to: addresses
179:             * @param	javax.mail.Address[]	Array of cc: addresses
180:             * @param	javax.mail.Address[]	Array of bcc: addresses
181:             * @return	String	Composition URL string
182:             */
183:            public String getComposeURL(String subject,
184:                    javax.mail.Address[] to, javax.mail.Address[] cc,
185:                    javax.mail.Address[] bcc) {
186:                // With the javascript goop, return a blank compose window
187:                StringBuffer returnURL = new StringBuffer(getBaseURL());
188:                // In order to enable Messenger Express SSO, must access
189:                // proper message using format server/?argv=view=compose&argv=laurel=on
190:                returnURL.append("/" + contexturi);
191:                returnURL.append("/mail");
192:                returnURL.append("?argv=view=compose");
193:                return returnURL.toString();
194:
195:            }
196:
197:            /**
198:             * Lets invoking classes know if multiple view urls are available
199:             * in this URLBuilder.	
200:             *
201:             * @return	boolean	Are view URLs available
202:             */
203:            public boolean allowsViewURL() {
204:                return true;
205:            }
206:
207:            /**
208:             * Responsible for generating the Application Launch Link/URL for the Communications
209:             * Express client.  The Comms Express URL format:
210:             *
211:             *     http://<hostname>:<port>/<contexturi>/calclient/<viewname>
212:             *       ?calid=<calid>
213:             *       &caltype=<caltype>
214:             *       &date=<context date>
215:             *       &category=<category>
216:             *
217:             * viewname : Name of View. [ Mandatory]
218:             *     - values: DayView, WeekView, MonthView
219:             *
220:             * calid : calid of the calendar for which the view is displayed [if this parameter is
221:             *         not present, default calendar is considered]
222:             *         - if there are multiple calendars, they are seperated by comma(,)
223:             *         - if one wants to view a calendar group, assign the groupname
224:             *
225:             * caltype :  will be 'calid' if the calid has single calid value [ default value, i.e
226:             *            if this parameter is no t present, value 'calid' is considered ]
227:             *            - will be 'group' if group-name is the value of calid parameter
228:             *            - will be 'Temporarycalendars" if calid has multiple calids
229:             *
230:             * date : context Date in ISO format (For example : 20040521T065954Z). Context date is
231:             *        date the user has selected to view.
232:             *        -default value : current date
233:             *
234:             * category: specifies the category filter for Events/Tasks to be dsiplayed. Should be
235:             *           'All' if events/tasks from all categories have to be displayed.
236:             *           - default value = 'All'
237:             *
238:             *
239:             * @param provider  CalendarProvider
240:             * @param request   HttpServletRequest
241:             * @return url to access application
242:
243:
244:             *
245:             * @param	String	View
246:             * @param	String	Date
247:             * @return	String	View URL string
248:             */
249:            public String getViewURL(String view, String date) {
250:                StringBuffer returnURL = new StringBuffer(getBaseURL());
251:                returnURL.append("/").append(contexturi);
252:                return returnURL.toString();
253:            }
254:
255:            /**
256:             * Lets invoking classes know if task URLs are available
257:             * in this URLBuilder.
258:             *
259:             * @return	boolean	Are task URLs available
260:             */
261:            public boolean allowsTaskURL() {
262:                return true;
263:            }
264:
265:            /*
266:             * Return URL string for specific task to be opened in the Communications 
267:             * Express client.
268:             *
269:             * http://<hostname>:<port>/<contexturi>/calclient/ViewTaskData?todoUid=<taskid>&calid=<calid>
270:             *
271:             * If the event/todo is recurrring one, you need to pass the recurrence id of event
272:             * (parameter name is rid)
273:             *
274:             * @param	Object	Task Object
275:             * @return	String	Task URL string
276:             */
277:            public String getTaskURL(Object task) {
278:                VTodo vtask = (VTodo) task;
279:                StringBuffer taskURL = new StringBuffer(getBaseURL());
280:                String calid = getCalendarToView();
281:                String taskid = null;
282:                DateTime recurrenceDateTime = null;
283:
284:                try {
285:                    if (vtask != null) {
286:                        taskid = vtask.getID();
287:                        recurrenceDateTime = vtask.getRecurrenceID();
288:
289:                        taskURL.append("/").append(contexturi).append(
290:                                "/calclient/ViewTaskData").append(
291:                                "?todoUid=" + taskid).append("&calid=" + calid);
292:
293:                        if ((vtask.isRecurring())
294:                                && (recurrenceDateTime != null)) {
295:                            taskURL.append("&rid="
296:                                    + recurrenceDateTime.toISO8601());
297:                        }
298:
299:                    }
300:                } catch (OperationNotSupportedException onse) {
301:                    // Debug message here
302:                } catch (CalendarComponentException cce) {
303:                    // Debug message here
304:                }
305:                return taskURL.toString();
306:            }
307:
308:            /**
309:             * Lets invoking classes know if event URLs are available
310:             * in this URLBuilder.
311:             *
312:             * @return	boolean	Are event URLs available
313:             */
314:            public boolean allowsEventURL() {
315:                return true;
316:            }
317:
318:            /**
319:             * Return URL string for specific event to be opened in cal client.
320:             *
321:             * @param	Object	Event Object
322:             * @return	String	Event URL string
323:             */
324:            public String getEventURL(Object event) {
325:                VEvent vevent = (VEvent) event;
326:                StringBuffer eventURL = new StringBuffer(getBaseURL());
327:                String calid = getCalendarToView();
328:                String eventid = null;
329:                DateTime recurrenceDateTime = null;
330:                try {
331:
332:                    if (vevent != null) {
333:                        eventid = vevent.getID();
334:                        recurrenceDateTime = vevent.getRecurrenceID();
335:
336:                        eventURL.append("/").append(contexturi).append(
337:                                "/calclient/ViewEventData").append(
338:                                "?eventid=" + eventid)
339:                                .append("&calid=" + calid);
340:
341:                        if ((vevent.isRecurring())
342:                                && (recurrenceDateTime != null)) {
343:                            eventURL.append("&rid="
344:                                    + recurrenceDateTime.toISO8601());
345:                        }
346:
347:                    }
348:                } catch (OperationNotSupportedException onse) {
349:                    // Debug message here
350:                } catch (CalendarComponentException cce) {
351:                    // Debug message here
352:                }
353:                return eventURL.toString();
354:            }
355:
356:            /**
357:             * Sets the calendar id
358:             *
359:             * @param	String	Calendar ID
360:             */
361:            public void setCalid(String calid) {
362:                this .calid = calid;
363:            }
364:
365:            /**
366:             * Return the calendar id
367:             *
368:             * @return	String	Calendar ID
369:             */
370:            public String getCalid() {
371:                return calid;
372:            }
373:
374:            // if the calid is set, then use this value, otherwise
375:            // use "user" and "domain" from SSO adapter
376:            //
377:            private String getCalendarToView() {
378:                StringBuffer cid = new StringBuffer();
379:
380:                if ((calid != null) && (calid.length() > 0)) {
381:                    return encode(calid);
382:
383:                } else {
384:                    if ((user != null) && (user.length() > 0)) {
385:                        cid.append(encode(user));
386:
387:                        if ((domain != null) && (domain.length() > 0)) {
388:                            cid.append("%40"); // URL encoding value for '@'
389:                            cid.append(encode(domain));
390:                        }
391:                    }
392:                }
393:
394:                return cid.toString();
395:            }
396:
397:            /**
398:             * Lets invoking classes know if contact urls are available
399:             * in this URLBuilder.  
400:             *
401:             * @return	boolean	Are contact URLs available
402:             */
403:            public boolean allowsContactURL() {
404:                return false;
405:            }
406:
407:            /**
408:             * Return URL string for specific contact to be opened in ab client.
409:             *
410:             * @param	Object	contact
411:             * @return	String	View URL string
412:             */
413:            public String getContactURL(Object contact) {
414:                return getStartURL();
415:            }
416:
417:            /**
418:             * Lets invoking clasess know is composeEvent is available
419:             * in this URLBuilder
420:             * @return boolean , is composeEvent available
421:             */
422:            public boolean allowsComposeEventURL() {
423:                return true;
424:            }
425:
426:            /**
427:             * Lets invoking clasess know is composeTask is available
428:             * in this URLBuilder
429:             * @return boolean , is composeTask available
430:             */
431:            public boolean allowsComposeTaskURL() {
432:                return true;
433:            }
434:
435:            /**
436:             * Return URL string to open the client's composeEvent window.
437:             *
438:             * @param	String	Subject of the event
439:             * @param	DateTime the DateTimeat which event should be created
440:             * @return	String	Composition URL string
441:             */
442:            public String getComposeEventURL(DateTime time) {
443:                if (time == null) {
444:                    time = new DateTime(); //it is not aware of timezone
445:                }
446:                StringBuffer stBuff = new StringBuffer(getStartURL());
447:                stBuff
448:                        .append("/calclient/EditEvent?category=All&viewctx=day&date="
449:                                + time.toISO8601());
450:                if (calid != null && calid.length() > 0) {
451:                    stBuff.append("&caltype=calid&calid=" + calid);
452:                }
453:                return stBuff.toString();
454:            }
455:
456:            /**
457:             * Return URL string to open the client's composeTask window.
458:             *
459:             * @param	String	Subject of the task
460:             * @param	DateTime the DateTimeat which event should be created
461:             * @return	String	Composition URL string
462:             */
463:            public String getComposeTaskURL(DateTime time) {
464:                if (time == null) {
465:                    time = new DateTime(); //it is not aware of timezone
466:                }
467:                StringBuffer stBuff = new StringBuffer(getStartURL());
468:                stBuff
469:                        .append("/calclient/NewTask?category=All&viewctx=day&date="
470:                                + time.toISO8601());
471:                if (calid != null && calid.length() > 0) {
472:                    stBuff.append("&caltype=calid&calid=" + calid);
473:                }
474:                return stBuff.toString();
475:            }
476:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.