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


001:        /*
002:         * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
003:         * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004:         */
005:
006:        package com.sun.portal.harness;
007:
008:        import java.io.Serializable;
009:        import java.util.HashMap;
010:        import java.util.Vector;
011:        import java.util.List;
012:        import java.util.StringTokenizer;
013:
014:        import java.net.URL;
015:        import java.net.MalformedURLException;
016:
017:        import javax.servlet.ServletContext;
018:        import javax.servlet.RequestDispatcher;
019:
020:        import javax.servlet.http.HttpServletRequest;
021:        import javax.servlet.http.HttpServletResponse;
022:        import javax.servlet.http.HttpSession;
023:        import javax.servlet.http.HttpSessionBindingListener;
024:        import javax.servlet.http.HttpSessionBindingEvent;
025:
026:        import javax.servlet.jsp.PageContext;
027:        import javax.servlet.jsp.JspWriter;
028:
029:        import com.sun.portal.providers.Provider;
030:        import com.sun.portal.providers.ProviderEditTypes;
031:        import com.sun.portal.providers.ProviderWidths;
032:
033:        import com.sun.portal.desktop.context.ContextError;
034:        import com.sun.portal.desktop.context.ProviderContextThreadLocalizer;
035:        import com.sun.portal.desktop.context.ProviderClassLoader;
036:        import com.sun.portal.desktop.ServletConfigThreadLocalizer;
037:        import com.sun.portal.desktop.ServletContextThreadLocalizer;
038:        import com.sun.portal.desktop.RequestThreadLocalizer;
039:
040:        public class ProviderHarness implements  HttpSessionBindingListener,
041:                Serializable, ProviderWidths {
042:
043:            // URL arguments which may be constructed by external entry points to the simulator
044:
045:            public static final String ARG_USERNAME = "USERNAME";
046:            public static final String ARG_COMPFILE = "COMPFILE";
047:            public static final String ARG_PORTAPPDIR = "PORTAPPDIR";
048:            public static final String ARG_CONFIGDIR = "CONFIGDIR";
049:            public static final String ARG_CLASSPATH = "CLASSPATH";
050:            public static final String ARG_DOCROOT = "DOCROOT";
051:            public static final String ARG_PARFILE = "PARFILE";
052:            public static final String ARG_PROFEDIT = "PROFEDITOR";
053:            public static final String ARG_DESKTOP_XFER = "DESKTOP_XFER";
054:            public static final String ARGPFX_DEBUGTRACE = "DBGTRACE_";
055:
056:            // Visible to the simulator jsp.
057:
058:            public static final String ARG_ACTION = "action";
059:            public static final String ACT_DEBUGCLEAR = "debugclear";
060:            public static final String ACT_PRESERVE = "preserve";
061:            public static final String ACT_CONTENT = "content";
062:            public static final String ACT_PROCESS = "process";
063:            public static final String ACT_EDIT = "edit";
064:
065:            public static final int CTY_NORMAL = 0;
066:            public static final int CTY_EDITFORM = 1;
067:            public static final int CTY_EDITFIELDS = 2;
068:
069:            // Other argument strings are package protected, and used for internal interaction
070:
071:            static final String SESSION_KEY = "desktop.Simulator.ProviderHarness";
072:            static final String HARNESS_PORTLET_PROVIDER_CLASS = "com.sun.portal.harness.HarnessPortletProvider";
073:
074:            //context path name that used to store in the request attribute
075:            private static final String CONTEXT_PATH_ATTRIBUTE = "javax.servlet.include.context_path";
076:
077:            public ProviderHarness(String compfile, String username) {
078:                m_ProviderClass = null;
079:                m_UserName = username;
080:                m_CacheKey = "UNDEFINED";
081:                m_ProcessingEdit = false;
082:                m_DisplayEditForm = false;
083:                m_IsStreamContent = false;
084:                m_ContentType = CTY_NORMAL;
085:                m_Content = "";
086:                m_CompFile = compfile;
087:                m_PortAppDir = null;
088:                m_ConfigDir = defaultConfigDir();
089:                m_ProfEditor = "PSSimPropEd.jsp";
090:            }
091:
092:            public String getTitle() {
093:                return m_Title;
094:            }
095:
096:            public boolean isEditable() {
097:                return m_IsEditable;
098:            }
099:
100:            public String getDescription() {
101:                return m_Description;
102:            }
103:
104:            public String getProviderClass() {
105:                return m_ProviderClass;
106:            }
107:
108:            public String getUserName() {
109:                return m_UserName;
110:            }
111:
112:            public String getLocaleString() {
113:                return m_LocaleString;
114:            }
115:
116:            public String getHelpURL() {
117:                return m_HelpURL;
118:            }
119:
120:            public String getProfileEditorURL() {
121:                return m_ProfEditor;
122:            }
123:
124:            public String getDetails() {
125:
126:                StringBuffer desc = new StringBuffer();
127:
128:                try {
129:                    switch (m_Provider.getWidth()) {
130:                    case WIDTH_THICK:
131:                        desc.append("WIDTH_THICK");
132:                        break;
133:                    case WIDTH_THIN:
134:                        desc.append("WIDTH_THIN");
135:                        break;
136:                    case WIDTH_FULL_TOP:
137:                        desc.append("WIDTH_FULL_TOP");
138:                        break;
139:                    case WIDTH_FULL_BOTTOM:
140:                        desc.append("WIDTH_FULL_BOTTOM");
141:                        break;
142:                    default:
143:                        desc.append("Unknown width - " + m_Provider.getWidth());
144:                        break;
145:                    }
146:                } catch (Exception ex) {
147:                }
148:
149:                return desc.toString();
150:            }
151:
152:            public String getContent() throws ProviderHarnessException {
153:
154:                if (!m_IsStreamContent)
155:                    return m_Content;
156:
157:                JspWriter out = m_PageContext.getOut();
158:
159:                try {
160:                    out.flush();
161:                    StreamTestedProvider stp = (StreamTestedProvider) m_Provider;
162:                    stp.streamContent(m_ContentType != CTY_NORMAL, m_Request,
163:                            m_Response);
164:                } catch (Exception ex) {
165:                    throw new ProviderHarnessException(
166:                            "Exception while streaming content.", ex);
167:                }
168:
169:                return "";
170:            }
171:
172:            public void getUserList(Vector v) throws ProviderHarnessException {
173:                v.clear();
174:                for (int i = 0; i < m_UserNames.length; ++i) {
175:                    v.addElement(m_UserNames[i]);
176:                }
177:            }
178:
179:            public String getConfigDir() {
180:                return m_ConfigDir;
181:            }
182:
183:            public String getCompFile() {
184:                return m_CompFile;
185:            }
186:
187:            public String getPortAppDir() {
188:                return m_PortAppDir;
189:            }
190:
191:            // static entry points into getUserNames for standalone environment "login" page.
192:
193:            public static void getUserList(HttpServletRequest req, Vector v)
194:                    throws ProviderHarnessException {
195:                UsersFile.getUserNames(getConfigDir(req) + "/Users.xml", v);
196:            }
197:
198:            public static String getConfigDir(HttpServletRequest req) {
199:
200:                String cdir = req.getParameter(ARG_CONFIGDIR);
201:                if (cdir != null)
202:                    return cdir;
203:
204:                return defaultConfigDir();
205:            }
206:
207:            private void createContent() throws ProviderHarnessException {
208:
209:                // Try to obtain the stuff which can cause errors here, so that we've
210:                // already processed the error by the time the simulator jsp asks for it.
211:
212:                try {
213:                    m_Title = m_Provider.getTitle();
214:                } catch (ContextError ex) {
215:                    recordPrError(ex, "getTitle");
216:                    m_Title = ex.getMessage();
217:                } catch (Exception ex) {
218:                    recordPrError(ex, "getTitle");
219:                    m_Title = ex.getMessage();
220:                }
221:
222:                try {
223:                    m_IsEditable = m_Provider.isEditable();
224:                } catch (ContextError ex) {
225:                    recordPrError(ex, "isEditable");
226:                    m_IsEditable = false;
227:                } catch (Exception ex) {
228:                    recordPrError(ex, "isEditable");
229:                    m_IsEditable = false;
230:                }
231:
232:                try {
233:                    m_Description = m_Provider.getDescription();
234:                } catch (ContextError ex) {
235:                    recordPrError(ex, "getDescription");
236:                    m_Description = ex.getMessage();
237:                } catch (Exception ex) {
238:                    recordPrError(ex, "getDescription");
239:                    m_Description = ex.getMessage();
240:                }
241:
242:                try {
243:                    URL u = m_Provider.getHelp(m_Request);
244:                    if (u == null) {
245:                        m_HelpURL = null;
246:                    } else {
247:                        m_HelpURL = u.toString();
248:
249:                        // YUCK.  We "know" that our jsp is going to show up in the URL
250:                        // as constructed by the provider.  Stripping off at that point
251:                        // leaves us our desktop workspace.
252:
253:                        int idx = m_HelpURL.indexOf(".jsp");
254:                        if (idx > 0) {
255:                            m_HelpURL = m_HelpURL.substring(idx + 4);
256:                        }
257:                    }
258:                } catch (ContextError ex) {
259:                    recordPrError(ex, "getHelp");
260:                    m_HelpURL = null;
261:                } catch (Exception ex) {
262:                    recordPrError(ex, "getHelp");
263:                    m_HelpURL = null;
264:                }
265:
266:                m_IsStreamContent = false;
267:
268:                if (m_DisplayEditForm) {
269:
270:                    StringBuffer buf;
271:                    int edtype;
272:                    try {
273:                        m_ContentType = m_Provider.getEditType() == ProviderEditTypes.EDIT_SUBSET ? CTY_EDITFIELDS
274:                                : CTY_EDITFORM;
275:
276:                        if (m_Provider instanceof  StreamTestedProvider) {
277:                            StreamTestedProvider stp = (StreamTestedProvider) m_Provider;
278:                            if (stp
279:                                    .requiresStream(StreamTestedProvider.STREAM_EDIT_FORM)) {
280:                                m_IsStreamContent = true;
281:                                return;
282:                            }
283:                        }
284:
285:                        buf = m_Provider.getEdit(m_Request, m_Response);
286:                    } catch (ContextError ex) {
287:                        recordPrError(ex, "getEdit");
288:                        m_Content = ex.getMessage();
289:                        return;
290:                    } catch (Exception ex) {
291:                        recordPrError(ex, "getEdit");
292:                        m_Content = ex.getMessage();
293:                        return;
294:                    }
295:
296:                    m_Content = buf.toString();
297:
298:                    return;
299:                }
300:
301:                m_ContentType = CTY_NORMAL;
302:
303:                try {
304:                    if (m_Provider instanceof  StreamTestedProvider) {
305:                        StreamTestedProvider stp = (StreamTestedProvider) m_Provider;
306:                        if (stp
307:                                .requiresStream(StreamTestedProvider.STREAM_CONTENT)) {
308:                            m_IsStreamContent = true;
309:                            return;
310:                        }
311:                    }
312:
313:                    m_Content = m_Provider.getContent(m_Request, m_Response)
314:                            .toString();
315:                } catch (ContextError ex) {
316:                    recordPrError(ex, "getContent");
317:                    m_Content = ex.getMessage();
318:                    //ex.printStackTrace();
319:
320:                    return;
321:                } catch (Exception ex) {
322:                    recordPrError(ex, "getContent");
323:                    m_Content = ex.getMessage();
324:                    //ex.printStackTrace();
325:                    return;
326:                }
327:            }
328:
329:            public int getContentType() {
330:                return m_ContentType;
331:            }
332:
333:            public void getLogViews(Vector v) {
334:                TestLog.getLogViews(m_LogTicket, v);
335:            }
336:
337:            public String getDesktopURL() {
338:                return m_DesktopURL;
339:            }
340:
341:            public String getProviderError() {
342:                return m_ProviderError;
343:            }
344:
345:            public String getKey() {
346:                return m_CacheKey;
347:            }
348:
349:            static public ProviderHarness getHarness(HttpServletRequest req,
350:                    HttpServletResponse resp, PageContext pctx)
351:                    throws ProviderHarnessException {
352:
353:                HttpSession sess = req.getSession();
354:                String cfile = req.getParameter(ARG_COMPFILE);
355:                ProviderHarness ph;
356:
357:                ServletConfigThreadLocalizer.set(pctx.getServletConfig());
358:                ServletContextThreadLocalizer.set(pctx.getServletConfig()
359:                        .getServletContext());
360:
361:                RequestThreadLocalizer.set(req, resp);
362:
363:                if (cfile == null) {
364:                    ph = (ProviderHarness) sess.getAttribute(SESSION_KEY);
365:                    if (ph == null) {
366:                        throw new ProviderHarnessException(
367:                                "Cannot find ProviderHarness in Session");
368:                    }
369:
370:                    ph.restoreProvider(req, resp, pctx);
371:                    return ph;
372:                }
373:
374:                String user = req.getParameter(ARG_USERNAME);
375:                if (user == null || user.equals("")) {
376:                    user = UsersFile.DEFAULT_USER;
377:                }
378:
379:                // NOTE -  all other setAttributes should be done via the "guarded" refreshSelfInSession()
380:                // call so as to avoid removing providers through internally generated valueUnbound calls.
381:
382:                ph = new ProviderHarness(cfile, user);
383:                sess.setAttribute(SESSION_KEY, ph);
384:
385:                ph.initProvider(req, resp, pctx, user);
386:                return ph;
387:            }
388:
389:            // Entry point for the property edit screen, which only needs the properties
390:
391:            public static HarnessProperties getHarnessProperties(
392:                    HttpServletRequest req) throws ProviderHarnessException {
393:                HttpSession sess = req.getSession();
394:
395:                ProviderHarness ph = (ProviderHarness) sess
396:                        .getAttribute(SESSION_KEY);
397:                if (ph == null) {
398:                    throw new ProviderHarnessException(
399:                            "Cannot find ProviderHarness in Session");
400:                }
401:
402:                return ph.getCachedProperties(req);
403:            }
404:
405:            public void valueUnbound(
406:                    HttpSessionBindingEvent httpSessionBindingEvent) {
407:                if (!m_IgnoreClear) {
408:                    try {
409:                        clearProvider();
410:                    } catch (Exception ex) {
411:                        System.out
412:                                .println("!!!! EXCEPTION WHILE UNBINDING PROVIDER HARNESS: "
413:                                        + ex.getMessage());
414:                    }
415:                }
416:            }
417:
418:            public void valueBound(
419:                    HttpSessionBindingEvent httpSessionBindingEvent) {
420:            }
421:
422:            // HACK - jsp provider, on refreshes, seems to cause output stream to
423:            // not flush unless we do it explicitly
424:
425:            public void finishPage() throws ProviderHarnessException {
426:                JspWriter out = m_PageContext.getOut();
427:                try {
428:                    out.flush();
429:                } catch (Exception ex) {
430:                    throw new ProviderHarnessException(
431:                            "Exception flushing output stream.", ex);
432:                }
433:            }
434:
435:            static String defaultConfigDir() {
436:
437:                String cdir = System.getProperty("ps.configdir");
438:                if (cdir != null)
439:                    return cdir;
440:
441:                return DEF_CONFIGDIR;
442:            }
443:
444:            private void initProvider(HttpServletRequest req,
445:                    HttpServletResponse resp, PageContext pctx, String username)
446:                    throws ProviderHarnessException {
447:
448:                initTransients(req, resp, pctx);
449:
450:                String profed = req.getParameter(ARG_PROFEDIT);
451:                if (profed != null) {
452:                    m_ProfEditor = profed;
453:                }
454:
455:                String cfgdir = req.getParameter(ARG_CONFIGDIR);
456:                if (cfgdir != null) {
457:                    m_ConfigDir = cfgdir;
458:                }
459:
460:                m_LogTicket = TestLog.open(m_ConfigDir + "/tmp");
461:
462:                String dtxfer = req.getParameter(ARG_DESKTOP_XFER);
463:                if (dtxfer != null) {
464:                    HarnessProviderContext.transferDesktop(dtxfer, m_ConfigDir);
465:                }
466:
467:                String pAppDir = req.getParameter(ARG_PORTAPPDIR);
468:                if (pAppDir != null) {
469:                    m_PortAppDir = pAppDir;
470:                }
471:
472:                processControlArguments(req);
473:
474:                synchronized (m_ProviderCache) {
475:                    try {
476:                        HarnessProviderContext ctx = HarnessProviderContext
477:                                .makeContext(m_UserName, m_ConfigDir,
478:                                        m_CompFile, m_PortAppDir, m_LogTicket);
479:                        m_UserNames = ctx.getUserNames();
480:                        m_LocaleString = ctx.getLocaleString();
481:                        m_ProviderClass = ctx.getProviderClass();
482:                        ctx.init(req);
483:
484:                        String name = ctx.getChannelName();
485:                        ++m_ProviderCounter;
486:                        m_CacheKey = name + "(" + m_ProviderClass + ")#"
487:                                + m_ProviderCounter;
488:                        ProviderContextThreadLocalizer.set(ctx);
489:                        ProviderClassLoader loader = ProviderClassLoader
490:                                .getInstance(m_ProviderClass, ctx
491:                                        .getProviderClassBaseDir());
492:                        Class cls = loader.loadClass(m_ProviderClass);
493:                        if (cls == null) {
494:                            throw new ProviderHarnessException(
495:                                    "Cannot obtain provider class - "
496:                                            + m_ProviderClass);
497:                        }
498:                        m_Provider = (Provider) cls.newInstance();
499:                        //System.out.println("ProviderHarness.initProvider():CLASSLOADER:
500:                        //"+m_Provider.getClass().getClassLoader()+",+loader+", "+dloader);
501:
502:                        //sets the portlets in the HarnessPortletProvider
503:                        if (m_PortAppDir != null) {
504:                            HarnessPortletProvider.setPortlets(ctx
505:                                    .getHarnessProperties(req).getPortlets());
506:                        }
507:                        m_Provider.init(name, req);
508:                        m_ProviderCache.put(m_CacheKey, m_Provider);
509:                        m_ProviderCache.put(m_CacheKey + CONTEXT_SUFFIX, ctx);
510:                        m_DesktopURL = ctx.getDesktopURL(m_Request);
511:                    } catch (Exception ex) {
512:                        throw new ProviderHarnessException(
513:                                "Exception in provider initialization", ex);
514:                    }
515:                }
516:
517:                clearContent();
518:                createContent();
519:                refreshSelfInSession();
520:            }
521:
522:            private void restoreProvider(HttpServletRequest req,
523:                    HttpServletResponse resp, PageContext pctx)
524:                    throws ProviderHarnessException {
525:
526:                initTransients(req, resp, pctx);
527:                processControlArguments(req);
528:
529:                synchronized (m_ProviderCache) {
530:                    m_Provider = (Provider) m_ProviderCache.get(m_CacheKey);
531:                    HarnessProviderContext ctx = (HarnessProviderContext) m_ProviderCache
532:                            .get(m_CacheKey + CONTEXT_SUFFIX);
533:                    if (m_Provider == null || ctx == null) {
534:                        throw new ProviderHarnessException(
535:                                "Provider or its context not in cache: "
536:                                        + m_CacheKey);
537:                    }
538:                    ctx.restore(req);
539:                }
540:
541:                URL redirectURL = runAction();
542:                refreshSelfInSession();
543:
544:                try {
545:                    if (redirectURL != null) {
546:                        //generates a relative path and use request dispatcher 
547:                        // to dispatch it.
548:                        String urlStr = redirectURL.toString();
549:                        String contextPath = (String) req
550:                                .getAttribute(CONTEXT_PATH_ATTRIBUTE);
551:                        int start = urlStr.indexOf(contextPath);
552:                        String relStr = urlStr.substring(start
553:                                + contextPath.length(), urlStr.length());
554:
555:                        ServletContext sc = ServletConfigThreadLocalizer.get()
556:                                .getServletContext();
557:                        RequestDispatcher dispatcher = sc
558:                                .getRequestDispatcher(relStr);
559:                        dispatcher.include(req, resp);
560:
561:                    }
562:                } catch (Exception ie) {
563:                    throw new ProviderHarnessException(
564:                            "Error occur while redirecting the url: "
565:                                    + ie.getMessage());
566:
567:                }
568:
569:            }
570:
571:            private HarnessProperties getCachedProperties(HttpServletRequest req)
572:                    throws ProviderHarnessException {
573:                synchronized (m_ProviderCache) {
574:                    HarnessProviderContext ctx = (HarnessProviderContext) m_ProviderCache
575:                            .get(m_CacheKey + CONTEXT_SUFFIX);
576:                    if (ctx == null) {
577:                        throw new ProviderHarnessException(
578:                                "Provider context not in cache: " + m_CacheKey);
579:                    }
580:                    return ctx.getHarnessProperties(req);
581:                }
582:            }
583:
584:            private void clearProvider() throws ProviderHarnessException {
585:                synchronized (m_ProviderCache) {
586:                    TestLog.close(m_LogTicket);
587:                    m_ProviderCache.remove(m_CacheKey);
588:                    m_ProviderCache.remove(m_CacheKey + CONTEXT_SUFFIX);
589:                }
590:            }
591:
592:            private URL runAction() throws ProviderHarnessException {
593:
594:                String act = m_Request.getParameter(ARG_ACTION);
595:                if (act == null)
596:                    act = "";
597:
598:                // process the actions which imply use of our previous content, and return afterwards
599:
600:                if (act.equalsIgnoreCase(ACT_PRESERVE)) {
601:                    return null;
602:                }
603:
604:                if (act.equalsIgnoreCase(ACT_DEBUGCLEAR)) {
605:                    TestLog.clear(m_LogTicket);
606:                    return null;
607:                }
608:
609:                // NOW handle the channel's edit processing, if called for.  At this point, we can also clear
610:                // our old debug output, since the channel is "doing something" at this point.
611:
612:                TestLog.clear(m_LogTicket);
613:
614:                if (m_ProviderClass.equals(HARNESS_PORTLET_PROVIDER_CLASS)) {
615:                    URL redirectURL = null;
616:                    m_ProcessingEdit = false;
617:                    if (act.equalsIgnoreCase(ACT_PROCESS)) {
618:                        redirectURL = processEdit();
619:                        if (redirectURL == null) {
620:                            try {
621:                                redirectURL = new URL(m_DesktopURL
622:                                        + "?action=content");
623:                            } catch (MalformedURLException me) {
624:                                System.out.println("MailformedURLException");
625:                            }
626:                        }
627:                        return redirectURL;
628:                    }
629:                }
630:
631:                if (m_ProcessingEdit) {
632:                    m_ProcessingEdit = false;
633:                    if (act.equalsIgnoreCase(ACT_PROCESS)) {
634:                        processEdit();
635:                    }
636:                }
637:
638:                // The rest of the actions imply content creation.
639:
640:                clearContent();
641:
642:                try {
643:                    if (act.equalsIgnoreCase(ACT_EDIT)
644:                            && m_Provider.isEditable()) {
645:                        m_DisplayEditForm = true;
646:                        m_ProcessingEdit = true;
647:                    }
648:                } catch (ContextError ex) {
649:                    recordPrError(ex, "isEditable");
650:                } catch (Exception ex) {
651:                    recordPrError(ex, "isEditable");
652:                }
653:
654:                createContent();
655:                return null;
656:            }
657:
658:            private URL processEdit() throws ProviderHarnessException {
659:
660:                try {
661:
662:                    if (m_Provider instanceof  StreamTestedProvider) {
663:                        StreamTestedProvider stp = (StreamTestedProvider) m_Provider;
664:                        if (stp
665:                                .requiresStream(StreamTestedProvider.STREAM_PROCESS_EDIT)) {
666:                            return stp.streamProcessEdit(m_Request, m_Response);
667:                        }
668:                    }
669:
670:                    return m_Provider.processEdit(m_Request, m_Response);
671:                } catch (ContextError ex) {
672:                    recordPrError(ex, "processEdit");
673:                    return null;
674:                } catch (Exception ex) {
675:                    recordPrError(ex, "processEdit");
676:                    return null;
677:                }
678:            }
679:
680:            private void initTransients(HttpServletRequest req,
681:                    HttpServletResponse resp, PageContext pctx) {
682:
683:                m_Provider = null;
684:                m_Request = req;
685:                m_Response = resp;
686:                m_PageContext = pctx;
687:                m_ProviderError = null;
688:            }
689:
690:            private void processControlArguments(HttpServletRequest req)
691:                    throws ProviderHarnessException {
692:
693:                Vector v = new Vector();
694:                TestLog.getLogViews(m_LogTicket, v);
695:
696:                for (int i = 0; i < v.size(); ++i) {
697:                    LogView lv = (LogView) v.elementAt(i);
698:                    String dbgarg = req.getParameter(ARGPFX_DEBUGTRACE
699:                            + lv.getName());
700:                    if (dbgarg != null) {
701:                        try {
702:                            lv.setLevel(Short.valueOf(dbgarg).shortValue());
703:                        } catch (Exception ex) {
704:                        }
705:                    }
706:                }
707:            }
708:
709:            private void clearContent() {
710:                m_DisplayEditForm = false;
711:                m_IsStreamContent = false;
712:                m_Content = "Content has not been created yet.";
713:            }
714:
715:            private void refreshSelfInSession() {
716:
717:                synchronized (m_ProviderCache) {
718:                    m_IgnoreClear = true;
719:                    m_Request.getSession().setAttribute(SESSION_KEY, this );
720:                    m_IgnoreClear = false;
721:                }
722:            }
723:
724:            private void recordPrError(Throwable err, String meth) {
725:                String newerr = "Error in provider method " + meth + "(): "
726:                        + err.toString();
727:                if (m_ProviderError != null) {
728:                    m_ProviderError = m_ProviderError + "\n" + newerr;
729:                } else {
730:                    m_ProviderError = newerr;
731:                }
732:
733:                LogView log = TestLog.getLogView(m_LogTicket,
734:                        TestLog.HARNESS_LOG);
735:                log.message(LogView.ERROR, "Error in provider " + meth + "()",
736:                        err);
737:            }
738:
739:            private String m_UserName;
740:            private String m_LocaleString;
741:            private String m_Content;
742:            private String m_ConfigDir;
743:            private String m_CompFile;
744:            private String m_PortAppDir;
745:            private boolean m_DisplayEditForm;
746:            private int m_ContentType;
747:            private String m_CacheKey;
748:            private boolean m_ProcessingEdit;
749:            private String m_LogTicket;
750:            private String m_UserNames[];
751:            private String m_DesktopURL;
752:            private String m_ProfEditor;
753:            private String m_ProviderClass;
754:
755:            private transient Provider m_Provider = null;
756:            private transient HttpServletRequest m_Request = null;
757:            private transient HttpServletResponse m_Response = null;
758:            private transient PageContext m_PageContext = null;
759:            private transient String m_ProviderError = null;
760:            private transient String m_Title = null;
761:            private transient boolean m_IsEditable = false;
762:            private transient String m_Description = null;
763:            private transient String m_HelpURL = null;
764:
765:            // HACK - StreamTestedProvider is a mechanism meant to test JSPProvider or
766:            // any other provider type like it.  These providers implement an alternate
767:            // interface which allows the servlet representing the provider to be
768:            // dispatched within the context of our current servlet.
769:
770:            private boolean m_IsStreamContent;
771:
772:            private static final String LIST_SEP = ", ";
773:            private static final String DEF_CONFIGDIR = "/etc/opt/SUNWportal";
774:            private static final String CONTEXT_SUFFIX = ".CONTEXT";
775:
776:            private static boolean m_IgnoreClear = false;
777:            private static int m_ProviderCounter = 0;
778:            private static HashMap m_ProviderCache = new HashMap();
779:
780:            private static String COPYRIGHT = "Copyright ? 2002 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, "
781:                    + "California 95054, U.S.A. All rights reserved.U.S. Government Rights - Commercial "
782:                    + "software.  Government users are subject to the Sun Microsystems, Inc. standard "
783:                    + "license agreement and applicable provisions of the FAR and its supplements.  Use "
784:                    + "is subject to license terms.\n\n"
785:                    + "Sun,  Sun Microsystems,  the Sun logo,  Java,  Solaris,  Sun ONE,  Sun ONE "
786:                    + "Studio,  Sun ONE Portletx Builder and  the Sun ONE logo are trademarks or "
787:                    + "registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.\n\n"
788:                    + "This product is covered and controlled by U.S. Export Control laws and may be "
789:                    + "subject to the export or import laws in other countries.  Nuclear, missile, "
790:                    + "chemical biological weapons or nuclear maritime end uses or end users, whether "
791:                    + "direct or indirect, are strictly prohibited.  Export or reexport to countries "
792:                    + "subject to U.S. embargo or to entities identified on U.S. export exclusion "
793:                    + "lists, including, but not limited to, the denied persons and specially "
794:                    + "designated nationals lists is strictly prohibited.";
795:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.