Source Code Cross Referenced for __Provider__.java in  » Portal » Open-Portal » __PACKAGE__ » 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 » __PACKAGE__ 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
003:         * Use is subject to license terms.
004:         */package __PACKAGE__;
005:
006:        import java.net.MalformedURLException;
007:        import java.net.URL;
008:        import java.util.Map;
009:        import java.util.HashMap;
010:
011:        import javax.servlet.http.HttpServletRequest;
012:        import javax.servlet.http.HttpServletResponse;
013:
014:        import com.sun.portal.providers.context.ProviderContext;
015:        import com.sun.portal.providers.context.ProviderContextException;
016:        import com.sun.portal.desktop.context.ProviderContextThreadLocalizer;
017:        import com.sun.portal.providers.Provider;
018:        import com.sun.portal.providers.ProviderWidths;
019:        import com.sun.portal.providers.ProviderEditTypes;
020:        import com.sun.portal.providers.ProviderException;
021:        import com.sun.portal.providers.UnknownEditTypeException;
022:
023:        // The basis of a provider implementation using the ProviderContext is supplied.
024:        // It is not absolutely required that you retain that implementation to define
025:        // a provider from scratch, but it will likely be useful.
026:
027:        public class __NAME__ implements  Provider, ProviderWidths,
028:                ProviderEditTypes {
029:
030:            private String providerName = null;
031:            private ProviderContext pc = null;
032:
033:            private static Map widthMap = null;
034:            private static Map editTypeMap = null;
035:
036:            static {
037:                widthMap = new HashMap();
038:
039:                //
040:                // pre-calc mapping of string width settings that
041:                // are read from the DP to integer width
042:                // types, so we do not need to do the string
043:                // calc's each time ...
044:                //
045:                widthMap.put("thin", new Integer(WIDTH_THIN));
046:                widthMap.put("THIN", new Integer(WIDTH_THIN));
047:                widthMap.put("Thin", new Integer(WIDTH_THIN));
048:
049:                widthMap.put("thick", new Integer(WIDTH_THICK));
050:                widthMap.put("THICK", new Integer(WIDTH_THICK));
051:                widthMap.put("Thick", new Integer(WIDTH_THICK));
052:
053:                widthMap.put("full_top", new Integer(WIDTH_FULL_TOP));
054:                widthMap.put("FULL_TOP", new Integer(WIDTH_FULL_TOP));
055:                widthMap.put("Full_Top", new Integer(WIDTH_FULL_TOP));
056:
057:                widthMap.put("full_bottom", new Integer(WIDTH_FULL_BOTTOM));
058:                widthMap.put("FULL_BOTTOM", new Integer(WIDTH_FULL_BOTTOM));
059:                widthMap.put("Full_Bottom", new Integer(WIDTH_FULL_BOTTOM));
060:
061:                editTypeMap = new HashMap();
062:
063:                editTypeMap.put("edit_subset", new Integer(EDIT_SUBSET));
064:                editTypeMap.put("EDIT_SUBSET", new Integer(EDIT_SUBSET));
065:                editTypeMap.put("Edit_Subset", new Integer(EDIT_SUBSET));
066:
067:                editTypeMap.put("edit_complete", new Integer(EDIT_COMPLETE));
068:                editTypeMap.put("EDIT_COMPLETE", new Integer(EDIT_COMPLETE));
069:                editTypeMap.put("Edit_Complete", new Integer(EDIT_COMPLETE));
070:            }
071:
072:            /**
073:             * Initializes the provider.
074:             * <p>
075:             * This method must be called by clients of the provider object
076:             * when the provider object is created (after it is constructed, or
077:             * before the object is used). This method should not be called more
078:             * than once per object.
079:             *
080:             * @param name Unique name identifying this provider.  This value
081:             * should always be returned from <code>getName()</code>.
082:             *
083:             * @param req The HTTP request object corresponding to the HTTP request
084:             * that caused this provider object to be created. This request may be
085:             * used to extract session or user information that could be used to
086:             * gain access to external resources.
087:             *
088:             * @exception ProviderException If there was an error initializing the
089:             * provider. How this exception is handled is up to the client of the
090:             * provider object.
091:             *
092:             * @see com.sun.portal.providers.Provider#getName     
093:             */
094:            public void init(String pName, HttpServletRequest request)
095:                    throws ProviderException {
096:                //
097:                providerName = pName;
098:
099:                pc = getProviderContext(request);
100:            }
101:
102:            /**
103:             * Gets the provider's objects default view.
104:             * This method is called by the clients of the provider object
105:             * to request the provider's default view.
106:             * <p>
107:             * This method may return null if the provider does not implement a default
108:             * view. In this case, the provider should return false from its
109:             * isPresentable() method.
110:             *   
111:             * @return StringBuffer holding the content.
112:             *
113:             * @param request An HttpServletRequest that contains
114:             * information related to this request for content.
115:             *
116:             * @param response An HttpServletResponse that allows the provider
117:             * to influence the 
118:             * overall response for the desktop page (besides generating the content).
119:             *
120:             * @exception ProviderException If there was an error generating the
121:             * content. How this exception is handled is up to the client of the
122:             * provider object.
123:             *   
124:             * @see com.sun.portal.providers.ProviderException
125:             */
126:            public StringBuffer getContent(HttpServletRequest request,
127:                    HttpServletResponse response) throws ProviderException {
128:                //
129:                StringBuffer sbContent = new StringBuffer();
130:
131:                // Start: Generate default view content
132:
133:                // End: Generate default view content
134:
135:                //
136:                return sbContent;
137:            }
138:
139:            /**
140:             * Gets the edit view for the provider.
141:             * <p>
142:             * This method is called by the clients of the provider object
143:             * to request the provider's edit view.   
144:             * <p>
145:             * This method must generate either a complete document, or a subset,
146:             * depending on the return value of <code>.getEditType()</code>.
147:             * <p>
148:             * A subset document should include all code that goes between
149:             * the <code>FORM</code> tags.  The exception is that the
150:             * <i>submit</i> and <i>cancel</i> buttons should <i>not</i> be
151:             * generated. A subset document is always submitted back to the
152:             * desktop servlet, where control is passed to the provider's
153:             * <code>processEdit()</code> method for processing the
154:             * form data.
155:             * <p>
156:             * If a complete document is returned,
157:             * there are several restrictions:
158:             * <ul>
159:             * <li>It must be a complete, valid form.
160:             * <li>The form must have an encoding type of
161:             * "application/x-www-form-urlencoded".
162:             * <li>The form action must point back to the desktop servlet.
163:             * Typically, this is "/portal/dt".
164:             * <li>The form must specify a valid action to the desktop servlet
165:             * as defined in the DesktopSerlvet javadocs.
166:             * </ul>
167:             * <p><i>
168:             * The above restrictions only apply if the form is to be submitted
169:             * to the desktop servlet. If the form is submitted to a third-party
170:             * CGI or servlet, the format will depend on what this entity is
171:             * expecting.
172:             * </i>
173:             * <p>
174:             * This method may return null if the provider does not implement an edit
175:             * view. In this case, the provider should return false from its
176:             * isEditable() method.
177:             *
178:             * @return StringBuffer holding the html edit form.
179:             *
180:             * @param request An HttpServletRequest that
181:             * contains information related to this request for content.
182:             *
183:             * @param response An HttpServletResponse that
184:             * allows the provider to influence the 
185:             * overall response for the desktop page (besides generating the content).
186:             * 
187:             * @exception ProviderException If there was an error generating the
188:             * edit form. How this exception is handled is up to the client of the
189:             * provider object.
190:             *
191:             * @see com.sun.portal.providers.Provider#getContent
192:             * @see com.sun.portal.providers.Provider#isEditable
193:             * @see com.sun.portal.providers.Provider#processEdit
194:             * @see com.sun.portal.providers.Provider#getEditType
195:             * @see com.sun.portal.desktop.DesktopServlet
196:             * @see com.sun.portal.providers.ProviderException     
197:             */
198:            public StringBuffer getEdit(HttpServletRequest request,
199:                    HttpServletResponse response) throws ProviderException {
200:                //
201:                StringBuffer sbContent = new StringBuffer();
202:
203:                // Start: Generate edit view content
204:                // If editType property is "edit_complete", please include Cancel and
205:                // Finished buttons in your edit view content.
206:
207:                // End: Generate edit view content
208:
209:                //
210:                return sbContent;
211:            }
212:
213:            /**
214:             * Processes a form for this provider.
215:             * <p>
216:             * This method is called to process form data associated with the
217:             * provider. Typically, this method is called to process the edit page
218:             * generated from the getEdit() method. Usually, the client calling
219:             * this method on a provider object is the desktop servlet.
220:             * <p>
221:             * Form data, passed into this method in the request, has been decoded into
222:             * Unicode.
223:             * <p>
224:             * When the desktop servlet receives a request where the action is 
225:             * "process", it looks at the
226:             * parameters to identify which provider will handle the action, through
227:             * this method. The request passed in contains the parameters.
228:             * <p>
229:             * After calling this method, the desktop servlet will re-direct to the URL
230:             * returned from this method. Therefore, the result of a provider post
231:             * can be any desktop serlvet action, or the content of an arbitrary URL.
232:             * For more information on constructing desktop serlvet URLs, see
233:             * <code>DesktopSerlvet</code>.
234:             *
235:             * @return The URL that the iPS desktop will re-direct to. A value
236:             * of null should indicate to the client that it should return to its
237:             * default view.
238:             *
239:             * @param request An HttpServletRequest that contains
240:             * information related to this
241:             * request for content.
242:             *
243:             * @param response An HttpServletResponse that allows the
244:             * provider to influence the 
245:             * overall response for the desktop page (besides generating the content).
246:             *
247:             * @exception ProviderException If there was an error processing
248:             * the edit form. How this exception is handled is up to the client of the
249:             * provider object.
250:             *
251:             * @return The URL that the iPS desktop will re-direct to. A value
252:             * of null should indicate to the client that it should return to its
253:             * default view.
254:             *
255:             * @see com.sun.portal.providers.Provider#getEdit
256:             * @see com.sun.portal.providers.Provider#isEditable
257:             * @see com.sun.portal.providers.InvalidEditFormDataException
258:             * @see com.sun.portal.desktop.DesktopServlet
259:             */
260:            public URL processEdit(HttpServletRequest request,
261:                    HttpServletResponse response) throws ProviderException {
262:                //
263:
264:                // Hint: You may want to use request.getParameter method.
265:
266:                // If you get errornous request parameters, you may want to specify
267:                // error page URL.
268:                // Re-generate desktop
269:                return null;
270:            }
271:
272:            /**
273:             * Gets the description of this provider.
274:             *
275:             * @return The description of this provider.
276:             * @see com.sun.portal.providers.Provider#init
277:             */
278:            public String getDescription() throws ProviderException {
279:                try {
280:                    return pc.getStringProperty(getName(), "description", true);
281:                } catch (ProviderContextException pce) {
282:                    throw new ProviderException("getDescription(): ", pce);
283:                }
284:            }
285:
286:            /**
287:             * Gets the edit form type of the provider.
288:             * <p>
289:             * This method returns, and therefore defines, the edit form type
290:             * for provider.
291:             *
292:             * @return The edit type; either <code>EDIT_SUBSET</code> or
293:             * <code>EDIT_COMPLETE</code>
294:             *
295:             * @exception UnknownEditTypeException If an unknown or undefined
296:             * edit type is encountered.
297:             *
298:             * @see com.sun.portal.providers.Provider#getEdit
299:             * @see com.sun.portal.providers.ProviderEditTypes
300:             */
301:            public int getEditType() throws UnknownEditTypeException {
302:                String val = null;
303:                try {
304:                    val = pc.getStringProperty(getName(), "editType");
305:                } catch (ProviderContextException pce) {
306:                    throw new UnknownEditTypeException("getEditType(): ", pce);
307:                }
308:                Integer type = (Integer) editTypeMap.get(val);
309:
310:                if (type == null) {
311:                    throw new UnknownEditTypeException(
312:                            "ProviderAdapter.getEditType(): unknown edit type="
313:                                    + val);
314:                }
315:
316:                return type.intValue();
317:            }
318:
319:            /**
320:             * Gets the help URL for this provider.
321:             * <p>
322:             * The returned help URL can be either fully-qualified URL string (e.g.,
323:             * <i>http://server:port/portal/docs/en_US/desktop/usedesk.htm</i>)
324:             * or a relative path (e.g., <i>desktop/usedesk.htm)</i>). When it is
325:             * relative path, the desktop software will prepend the server request
326:             * string (e.g., <i>http://server:port/portal</i>, plus the 
327:             * document root (e.g., <i>/docs/</i>), plus the user locale (e.g., 
328:             * <i>en_US/</i>) to it to resolve the full URL.
329:             * @return A URL pointing to the help page for the provider. A return
330:             * value of null should signify that this provider does not have a
331:             * help page.
332:             *
333:             */
334:            public URL getHelp(HttpServletRequest request)
335:                    throws ProviderException {
336:                try {
337:                    String docroot = pc.getStringProperty(getName(), "docroot",
338:                            true);
339:                    String hu = pc
340:                            .getStringProperty(getName(), "helpURL", true);
341:                    return new URL("http:/" + docroot + hu);
342:                } catch (Exception pce) {
343:                    throw new ProviderException("getHelp(): ", pce);
344:                }
345:            }
346:
347:            /**
348:             * Gets the name of this provider.
349:             * <p>
350:             * The name returned from this method must match the name of the provider
351:             * that it was initialized with.
352:             *
353:             * @return The name of this provider.
354:             */
355:            public String getName() {
356:                return providerName;
357:            }
358:
359:            /**
360:             * Gets the refresh time for this provider, in seconds.
361:             * <p>
362:             * Clients of the provider object should use this value to determine
363:             * if they should fetch a fresh default view for the provider.<br><br>
364:             * If the return value from this method is X, they may choose to
365:             * not fetch fresh content (and use a cached copy instead) if less than
366:             * X seconds has elapsed since the last time content was fetched.
367:             * <p>
368:             * If provider content is expected to change very infrequently, this
369:             * method can return some value so that the provider's content
370:             * is not fetched every time the front page is drawn, thereby
371:             * saving significant processing time.
372:             * <p>
373:             * Clients may choose not to use this value.
374:             *
375:             * @return >0, refresh time in number of seconds that a container should
376:             *             wait before expiring a content cache.
377:             *          0, container should never cache channel's content.
378:             *         -1, container may cache channel's content indefinitely.
379:             */
380:            public long getRefreshTime() throws ProviderException {
381:                String refreshTime = null;
382:                try {
383:                    refreshTime = pc
384:                            .getStringProperty(getName(), "refreshTime");
385:                } catch (ProviderContextException pce) {
386:                    throw new ProviderException("getRefreshTime(): ", pce);
387:                }
388:                if (refreshTime != null && refreshTime.length() != 0) {
389:                    return Long.parseLong(refreshTime);
390:                } else {
391:                    return 0;
392:                }
393:            }
394:
395:            /**
396:             * Gets the title of this provider.
397:             *
398:             * @return The title of this provider.
399:             */
400:            public String getTitle() throws ProviderException {
401:                try {
402:                    return pc.getStringProperty(getName(), "title", true);
403:                } catch (ProviderContextException pce) {
404:                    throw new ProviderException("ProviderAdapter.getTitle(): ",
405:                            pce);
406:                }
407:            }
408:
409:            /**
410:             * Gets the width of this provider.
411:             * <p>
412:             * Clients of the provider object may call this method, allowing the channel
413:             * to suggest how much / what type of screen real estate it requires.
414:             * The return value of this method is only a suggestion,
415:             * clients are free to interpret the return value or ignore it all together.
416:             *
417:             * @return The width of this provider, either <code>WIDTH_THICK</code>
418:             * or <code>WIDTH_THIN</code> or <code>WIDTH_FULL_TOP</code>
419:             * or <code>WIDTH_FULL_BOTTOM</code>.
420:             * @see com.sun.portal.providers.ProviderWidths#WIDTH_THIN
421:             * @see com.sun.portal.providers.ProviderWidths#WIDTH_THICK
422:             * @see com.sun.portal.providers.ProviderWidths#WIDTH_FULL_TOP
423:             * @see com.sun.portal.providers.ProviderWidths#WIDTH_FULL_BOTTOM
424:             * @exception ProviderException When there was an exception getting the width
425:             */
426:            public int getWidth() throws ProviderException {
427:                String val = null;
428:                try {
429:                    val = pc.getStringProperty(getName(), "width");
430:                } catch (ProviderContextException pce) {
431:                    throw new ProviderException("getWidth(): ", pce);
432:                }
433:                Integer width = (Integer) widthMap.get(val);
434:
435:                if (width == null) {
436:                    throw new ProviderException(
437:                            "getWidth(): unknown width type=" + val);
438:                }
439:
440:                return width.intValue();
441:            }
442:
443:            /**
444:             * This method determines if the provider has an edit view.
445:             *
446:             * @return <code>true</code> or <code>false</code>, indicating if the
447:             * provider has an edit view.
448:             * @see com.sun.portal.providers.Provider#getEdit
449:             * @see com.sun.portal.providers.Provider#processEdit     
450:             */
451:            public boolean isEditable() throws ProviderException {
452:                try {
453:                    return pc.getBooleanProperty(getName(), "isEditable");
454:                } catch (ProviderContextException pce) {
455:                    throw new ProviderException("isEditable(): ", pce);
456:                }
457:            }
458:
459:            /**
460:             * Determines if the provider is presentable based on the client device type.
461:             *
462:             * @return <code>true</code> or <code>false</code>, indicating if the
463:             * provider is presentable to the user's client device.
464:             */
465:            public boolean isPresentable() {
466:
467:                boolean genericHTML = true;
468:                boolean htmlContent = true;
469:                String defaultContentType = "text/html";
470:
471:                try {
472:                    String property = getClientProperty("genericHTML");
473:                    if (property != null) {
474:                        genericHTML = property.equals("true");
475:                    }
476:                } catch (ProviderException pe) {
477:                    if (pc.getClientType() != null) {
478:                        genericHTML = pc.getClientType().equals("genericHTML");
479:                    }
480:                }
481:
482:                String val = pc.getContentType();
483:                if (val != null) {
484:                    htmlContent = val.equals(defaultContentType);
485:                }
486:
487:                if (genericHTML && htmlContent) {
488:                    return true;
489:                }
490:                return false;
491:            }
492:
493:            //
494:            // The following three methods have been deprecated.
495:            // Please do not edit them.
496:            //
497:
498:            public StringBuffer getContent(Map m) throws ProviderException {
499:                return null;
500:            }
501:
502:            public StringBuffer getEdit(Map m) throws ProviderException {
503:                return null;
504:            }
505:
506:            public URL processEdit(Map m) throws ProviderException {
507:                return null;
508:            }
509:
510:            //
511:            // The above three methods have been deprecated.
512:            // Please do not edit them.
513:            //
514:
515:            // Methods used in default implementation.
516:
517:            private ProviderContext getProviderContext(
518:                    HttpServletRequest request) throws ProviderException {
519:                //
520:                ProviderContext context = ProviderContextThreadLocalizer.get();
521:                if (context == null) {
522:                    throw new ProviderException(
523:                            "__NAME__: Could not get provider context.");
524:                }
525:
526:                //
527:                return context;
528:            }
529:
530:            private String getClientProperty(String propertyName)
531:                    throws ProviderException {
532:                //
533:                String propertyValue = null;
534:
535:                if (propertyName != null) {
536:                    propertyValue = pc.getClientProperty(propertyName);
537:                } else {
538:                    throw new ProviderException(
539:                            "__NAME__: Unable to get client property: "
540:                                    + propertyName);
541:                }
542:
543:                //
544:                return propertyValue;
545:            }
546:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.