Source Code Cross Referenced for HarnessProviderContext.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) 


0001:        /*
0002:         * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
0003:         * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
0004:         */
0005:
0006:        package com.sun.portal.harness;
0007:
0008:        import java.io.File;
0009:        import java.io.FileInputStream;
0010:        import java.io.FileOutputStream;
0011:
0012:        import java.util.Iterator;
0013:        import java.util.Map;
0014:        import java.util.Properties;
0015:        import java.util.List;
0016:        import java.util.Hashtable;
0017:        import java.util.Locale;
0018:        import java.util.StringTokenizer;
0019:        import java.util.Set;
0020:        import java.util.HashMap;
0021:        import java.util.Collections;
0022:
0023:        import java.net.URL;
0024:        import java.net.MalformedURLException;
0025:
0026:        import javax.servlet.http.HttpServletRequest;
0027:        import javax.servlet.http.HttpServletResponse;
0028:        import javax.servlet.ServletConfig;
0029:        import javax.servlet.ServletContext;
0030:        import javax.servlet.http.HttpUtils;
0031:
0032:        import com.sun.portal.desktop.ServletConfigThreadLocalizer;
0033:        import com.sun.portal.desktop.ServletContextThreadLocalizer;
0034:
0035:        import com.sun.portal.providers.context.ContainerProviderContext;
0036:
0037:        import com.sun.portal.desktop.context.PropertiesClientContext;
0038:        import com.sun.portal.desktop.context.PropertiesServiceContext;
0039:        import com.sun.portal.desktop.context.PropertiesConfigContext;
0040:        import com.sun.portal.desktop.context.ContextError;
0041:        import com.sun.portal.desktop.context.UserListener;
0042:        import com.sun.portal.desktop.context.SessionListener;
0043:        import com.sun.portal.desktop.context.TemplateContext;
0044:        import com.sun.portal.desktop.context.ContextError;
0045:        import com.sun.portal.desktop.context.DesktopAppContextThreadLocalizer;
0046:        import com.sun.portal.desktop.context.DesktopContextThreadLocalizer;
0047:        import com.sun.portal.desktop.context.ProviderContextThreadLocalizer;
0048:
0049:        import com.sun.portal.desktop.util.PIParser;
0050:
0051:        import com.sun.portal.desktop.template.TagSwapper;
0052:
0053:        import com.sun.portal.providers.Provider;
0054:        import com.sun.portal.providers.ProviderException;
0055:
0056:        class HarnessProviderContext implements  ContainerProviderContext {
0057:
0058:            private HarnessProviderContext(String user, String configdir,
0059:                    String compfile, String portappdir, String logticket)
0060:                    throws ProviderHarnessException {
0061:                m_User = user;
0062:                m_DesktopLog = TestLog.getLogView(logticket,
0063:                        TestLog.DESKTOP_LOG);
0064:                m_HarnessLog = TestLog.getLogView(logticket,
0065:                        TestLog.HARNESS_LOG);
0066:                m_HarnessLog.setLevel(LogView.MESSAGE);
0067:                m_ClientContext = new PropertiesClientContext(configdir
0068:                        + "/client-context.properties");
0069:                m_ServiceContext = new PropertiesServiceContext(configdir
0070:                        + "/service-context.properties");
0071:                m_Prop = HarnessProperties.makeHarnessProperties(m_User,
0072:                        configdir + "/Users.xml", compfile, portappdir,
0073:                        configdir);
0074:                m_DesktopProperties = new PropertiesConfigContext();
0075:                m_DesktopProperties.init(configdir
0076:                        + "/desktop/desktopconfig.properties");
0077:                m_TplContext = new HarnessTemplateContext();
0078:
0079:                m_TplContext.init(0); // we don't currently do anything with the scan interval
0080:
0081:                m_DTCtx = new HarnessDesktopContext(this );
0082:                m_DTACtx = new HarnessDesktopAppContext(this );
0083:
0084:                // We prefix our session attributes in the HTTP session to avoid conflicts.
0085:
0086:                ++m_PfxCounter;
0087:                m_SessPropPfx = "Prop." + getChannelName() + "("
0088:                        + m_Prop.getProviderClass() + ")" + m_PfxCounter + ":";
0089:            }
0090:
0091:            static HarnessProviderContext makeContext(String user,
0092:                    String configdir, String compfile, String portappdir,
0093:                    String logticket) throws ProviderHarnessException {
0094:                return new HarnessProviderContext(user, configdir, compfile,
0095:                        portappdir, logticket);
0096:            }
0097:
0098:            static void transferDesktop(String source, String configdir)
0099:                    throws ProviderHarnessException {
0100:                PropertiesConfigContext dtc = new PropertiesConfigContext();
0101:                dtc.init(configdir + "/desktop/desktopconfig.properties");
0102:                String tpltarg = dtc.getTemplateBaseDir();
0103:                copyfiles(new File(source), new File(tpltarg));
0104:                String cltarg = dtc.getProviderClassBaseDir();
0105:                copyfiles(new File(tpltarg, "classes"), new File(cltarg));
0106:            }
0107:
0108:            public void setIntegerProperty(String channel, String name,
0109:                    int value) {
0110:                trace("Set integer property \"" + name + "\" for channel \""
0111:                        + channel + "\" to " + value + ".");
0112:                m_Prop.setIntegerProperty(channel, name, value);
0113:            }
0114:
0115:            public void setIntegerProperty(String channel, String name,
0116:                    int value, List pflist) {
0117:                setIntegerProperty(channel, name, value);
0118:            }
0119:
0120:            public String getContentType() {
0121:                return m_ClientContext.getContentType(getClientType());
0122:            }
0123:
0124:            public String getEncoderClassName() {
0125:                return m_ClientContext.getEncoderClassName(getClientType());
0126:            }
0127:
0128:            public int getIntegerProperty(String channel, String name) {
0129:                int ival = m_Prop.getIntegerProperty(channel, name);
0130:                trace("Got integer property \"" + name + "\" for channel \""
0131:                        + channel + "\" = " + ival + ".");
0132:                return ival;
0133:            }
0134:
0135:            public int getIntegerProperty(String channel, String name,
0136:                    List pflist) {
0137:                return getIntegerProperty(channel, name);
0138:            }
0139:
0140:            public String encodeURL(String url) {
0141:                return url;
0142:            }
0143:
0144:            public String getClientTypeProperty(String clientType, String key) {
0145:                String str = m_ClientContext.getClientTypeProperty(clientType,
0146:                        key);
0147:                trace("Got client property \"" + key + "\" for type \""
0148:                        + clientType + "\" = \"" + str + "\".");
0149:                return str;
0150:            }
0151:
0152:            public void setCollectionProperty(String channel, String key,
0153:                    Map val) {
0154:                trace("Set collection property \"" + key + "\" for channel \""
0155:                        + channel + "\".");
0156:                m_Prop.setCollectionProperty(channel, key, val);
0157:            }
0158:
0159:            public Set getClientTypeProperties(String clientType, String key) {
0160:                // FIXME
0161:                return null;
0162:            }
0163:
0164:            public String getLogoutURL() {
0165:                return "http://LOGOUT";
0166:            }
0167:
0168:            public String getLoginURL() {
0169:                return "http://LOGIN";
0170:            }
0171:
0172:            public String getDefaultClientType() {
0173:                String str = m_ClientContext.getDefaultClientType();
0174:                trace("Obtained default client type - " + str + ".");
0175:                return str;
0176:            }
0177:
0178:            public String getClassName(String channel) {
0179:                return m_Prop.getProviderClass();
0180:            }
0181:
0182:            public void setDebugLevel(short l) {
0183:                m_DesktopLog.setLevel(l);
0184:            }
0185:
0186:            // Use the stored request object.  It should be the same thing,
0187:            // but let's be sure.
0188:
0189:            public String getDesktopURL(HttpServletRequest req) {
0190:                return HttpUtils.getRequestURL(m_Request).toString();
0191:            }
0192:
0193:            public String getDesktopURL(HttpServletRequest req, Map query,
0194:                    Map pathInfo) {
0195:                return getDesktopURL(req, query, pathInfo, false);
0196:            }
0197:
0198:            public String getDesktopURL(HttpServletRequest req, Map query,
0199:                    Map pathInfo, boolean escape) {
0200:                StringBuffer buf = new StringBuffer();
0201:                buf.append(getDesktopURL(req));
0202:
0203:                if (pathInfo != null && !pathInfo.isEmpty()) {
0204:                    Map piMap = new HashMap();
0205:                    piMap.put(PIParser.DESKTOP_ARGS, pathInfo);
0206:                    String pathInfoString = PIParser.getPathInfoString(piMap);
0207:                    buf.append("/").append(pathInfoString);
0208:                }
0209:
0210:                // append queryString
0211:                if (query != null && !query.isEmpty()) {
0212:                    StringBuffer queryBuffer = new StringBuffer();
0213:                    // build query string
0214:                    for (Iterator i = query.keySet().iterator(); i.hasNext();) {
0215:                        String key = (String) i.next();
0216:                        String value = (String) query.get(key);
0217:                        queryBuffer.append(key).append("=").append(value);
0218:                        if (i.hasNext()) {
0219:                            queryBuffer.append("&");
0220:                        }
0221:                    }
0222:                    buf.append("?").append(queryBuffer.toString());
0223:                }
0224:                return escape ? escape(buf.toString()) : buf.toString();
0225:            }
0226:
0227:            public String getDesktopURL(HttpServletRequest req, String query,
0228:                    boolean escape) {
0229:                if (query == null || query.length() == 0) {
0230:                    return getDesktopURL(req);
0231:                }
0232:                if (escape) {
0233:                    query = escape(query);
0234:                }
0235:                return getDesktopURL(req) + "?" + query;
0236:            }
0237:
0238:            public void logMessage(Object o, Throwable t) {
0239:                m_DesktopLog.message(LogView.ERROR, o, t);
0240:            }
0241:
0242:            public int getWidth(String channel) {
0243:                return m_Prop.getWidth(channel);
0244:            }
0245:
0246:            public boolean getBooleanProperty(String channel, String name,
0247:                    boolean def) {
0248:                boolean val = m_Prop.getBooleanProperty(channel, name, def);
0249:                trace("Got boolean property \"" + name + "\" for channel \""
0250:                        + channel + "\" = \"" + val + "\".");
0251:                return val;
0252:            }
0253:
0254:            public boolean getBooleanProperty(String channel, String name,
0255:                    boolean def, List pflist) {
0256:                return getBooleanProperty(channel, name, def);
0257:            }
0258:
0259:            public boolean isDebugMessageEnabled() {
0260:                return m_DesktopLog.getLevel() >= LogView.MESSAGE;
0261:            }
0262:
0263:            public boolean isDebugEnabled() {
0264:                return m_DesktopLog.getLevel() != LogView.NOTHING;
0265:            }
0266:
0267:            public boolean isDebugErrorEnabled() {
0268:                return m_DesktopLog.getLevel() >= LogView.ERROR;
0269:            }
0270:
0271:            public String getUserID() {
0272:                return m_User;
0273:            }
0274:
0275:            public boolean isEditable(String channel) {
0276:                String val = getStringProperty(channel, "isEditable");
0277:                Boolean b = new Boolean(val);
0278:                trace("Channel \"" + channel + "\" is "
0279:                        + (b.booleanValue() ? "editable" : "not editable"));
0280:                return b.booleanValue();
0281:            }
0282:
0283:            public StringBuffer getRequestServer(HttpServletRequest req) {
0284:                return HttpUtils.getRequestURL(m_Request);
0285:            }
0286:
0287:            public void debugWarning(Object o) {
0288:                m_DesktopLog.message(LogView.WARNING, o);
0289:            }
0290:
0291:            public void debugMessage(Object o) {
0292:                m_DesktopLog.message(LogView.MESSAGE, o);
0293:            }
0294:
0295:            public int getIntegerProperty(String channel, String name, int def) {
0296:                int ival = m_Prop.getIntegerProperty(channel, name, def);
0297:                trace("Got integer property \"" + name + "\" for channel \""
0298:                        + channel + "\" = \"" + ival + "\".");
0299:                return ival;
0300:            }
0301:
0302:            public int getIntegerProperty(String channel, String name, int def,
0303:                    List pflist) {
0304:                return getIntegerProperty(channel, name, def);
0305:            }
0306:
0307:            public boolean validateSession(HttpServletRequest req) {
0308:                return m_Request.getSession().getAttribute(
0309:                        ProviderHarness.SESSION_KEY) != null;
0310:            }
0311:
0312:            public String getStringProperty(String channel, String name,
0313:                    String def, boolean localized) {
0314:                String str = m_Prop.getStringProperty(channel, name, def,
0315:                        localized);
0316:                trace("Got " + (localized ? "localized " : "unlocalized ")
0317:                        + " String property \"" + name + "\" for channel \""
0318:                        + channel + "\" = \"" + str + "\".");
0319:                return str;
0320:            }
0321:
0322:            public String getStringProperty(String channel, String name,
0323:                    boolean localized) {
0324:                String str = m_Prop.getStringProperty(channel, name, localized);
0325:                trace("Got " + (localized ? "localized " : "unlocalized ")
0326:                        + " String property \"" + name + "\" for channel \""
0327:                        + channel + "\" = \"" + str + "\".");
0328:                return str;
0329:            }
0330:
0331:            public List getLocalePropertiesFilters() {
0332:                return null;
0333:            }
0334:
0335:            // In our world, refresh() is a no-op.
0336:
0337:            public void refresh() {
0338:            }
0339:
0340:            public File getTemplatePath(String name, String file) {
0341:                File f = m_TplContext.getTemplatePath(m_DesktopProperties
0342:                        .getTemplateBaseDir(), getDesktopType(),
0343:                        getLocaleString(), name, getProviderName(name),
0344:                        getClientPath(), file);
0345:                trace("Obtained template path: "
0346:                        + (f == null ? "null" : f.getPath()));
0347:                return f;
0348:            }
0349:
0350:            public File getTemplatePath(String type, String locale, String app,
0351:                    String clientFilePath, String file, String baseDir) {
0352:                return m_TplContext
0353:                        .getTemplatePath(baseDir, type, locale, app,
0354:                                getProviderName(getChannelName()),
0355:                                clientFilePath, file);
0356:            }
0357:
0358:            public File getTemplateMostSpecificPath(String name, String file) {
0359:                File f = m_TplContext.getTemplateMostSpecificPath(
0360:                        m_DesktopProperties.getTemplateBaseDir(),
0361:                        getDesktopType(), getLocaleString(), name,
0362:                        getProviderName(name), getClientPath(), file);
0363:                trace("Obtained template most specific path: "
0364:                        + (f == null ? "null" : f.getPath()));
0365:                return f;
0366:            }
0367:
0368:            public File getTemplateMostSpecificPath(String desktopType,
0369:                    String locale, String name, String clientType, String file,
0370:                    String baseDir) {
0371:                return m_TplContext.getTemplatePath(baseDir, desktopType,
0372:                        locale, name, getProviderName(name), clientType, file);
0373:            }
0374:
0375:            public Iterator getNames(String channel) {
0376:                Iterator it = m_Prop.getNames(channel);
0377:
0378:                StringBuffer buf = new StringBuffer();
0379:                buf.append("Channel \"");
0380:                buf.append(channel);
0381:                buf.append("\" has properties: ");
0382:                String pfx = "";
0383:                while (it.hasNext()) {
0384:                    buf.append(pfx);
0385:                    pfx = ",";
0386:                    buf.append((String) it.next());
0387:                }
0388:                trace(buf.toString());
0389:
0390:                // Have to get iterator again.  We used it up producing the trace message.
0391:
0392:                return m_Prop.getNames(channel);
0393:            }
0394:
0395:            public List getClientPropertiesFilters() {
0396:                // FIXME
0397:                return null;
0398:            }
0399:
0400:            public List getClientPropertiesFilters(String clientType) {
0401:                // FIXME
0402:                return null;
0403:            }
0404:
0405:            public List getClientAndLocalePropertiesFilters() {
0406:                // FIXME
0407:                return null;
0408:            }
0409:
0410:            public short getDebugLevel() {
0411:                return m_DesktopLog.getLevel();
0412:            }
0413:
0414:            public String getClientProperty(String key) {
0415:                Object obj = getSessionProperty(key);
0416:                if (obj == null) {
0417:                    return null;
0418:                }
0419:                return obj.toString();
0420:            }
0421:
0422:            public String getClientTypeProperty(String key) {
0423:                return m_ClientContext.getClientTypeProperty(getClientType(),
0424:                        key);
0425:            }
0426:
0427:            public StringBuffer getTemplate(String desktopType, String locale,
0428:                    String name, String clientType, String file, String baseDir) {
0429:                return (m_TplContext.getTemplate(baseDir, desktopType, locale,
0430:                        name, getProviderName(name), clientType, file))
0431:                        .getTemplateSB();
0432:            }
0433:
0434:            public StringBuffer getTemplate(String desktopType, String locale,
0435:                    String name, String clientType, String file,
0436:                    Hashtable table, String baseDir) {
0437:
0438:                StringBuffer tpl = getTemplate(desktopType, locale, name,
0439:                        clientType, file, baseDir);
0440:                return TagSwapper.doSwap(tpl, table, getStaticContentPath(),
0441:                        name, this );
0442:            }
0443:
0444:            public StringBuffer getTemplate(String name, String file,
0445:                    Hashtable table) {
0446:                StringBuffer tpl = getTemplate(name, file);
0447:                return TagSwapper.doSwap(tpl, table, getStaticContentPath(),
0448:                        name, this );
0449:            }
0450:
0451:            public File[] getTemplatePaths(String name, String file) {
0452:                return m_TplContext.getTemplatePaths(getDesktopType(),
0453:                        getLocaleString(), name, getClientPath(), file);
0454:            }
0455:
0456:            public String getProviderName(String channel) {
0457:                return m_Prop.getProviderName(channel);
0458:            }
0459:
0460:            public int getProviderVersion(String channel) {
0461:                return 1;
0462:            }
0463:
0464:            public boolean existsStringProperty(String channel, String name,
0465:                    boolean localized) {
0466:                boolean val = m_Prop.existsStringProperty(channel, name,
0467:                        localized);
0468:                trace((localized ? "Localized " : "Unlocalized ")
0469:                        + " String property \"" + name + "\" for channel \""
0470:                        + channel + "\" "
0471:                        + (val ? "exists." : "does not exist."));
0472:                return val;
0473:            }
0474:
0475:            public ServletConfig getServletConfig() {
0476:                return ServletConfigThreadLocalizer.get();
0477:            }
0478:
0479:            public boolean existsBooleanProperty(String channel, String name) {
0480:                boolean val = m_Prop.existsBooleanProperty(channel, name);
0481:                trace("Boolean property \"" + name + "\" for channel \""
0482:                        + channel + "\" "
0483:                        + (val ? "exists." : "does not exist."));
0484:                return val;
0485:            }
0486:
0487:            public boolean existsBooleanProperty(String channel, String name,
0488:                    List pflist) {
0489:                return existsBooleanProperty(channel, name);
0490:            }
0491:
0492:            public void init(HttpServletRequest req) {
0493:                m_Request = req;
0494:                DesktopAppContextThreadLocalizer.set(m_DTACtx);
0495:                DesktopContextThreadLocalizer.set(m_DTCtx);
0496:                ProviderContextThreadLocalizer.set(this );
0497:            }
0498:
0499:            // This method is not part of the ProviderContext interface.  Since we don't
0500:            // have DSAME managing our session for us, we have to have a method to resynch with
0501:            // the request on every webevent.  Currently, we can do the same thing we did
0502:            // the first time, namely just set a member pointing to our request so we
0503:            // can use it, and register our desktop contexts so that they are available.
0504:
0505:            void restore(HttpServletRequest req) {
0506:                init(req);
0507:                DesktopAppContextThreadLocalizer.set(m_DTACtx);
0508:                DesktopContextThreadLocalizer.set(m_DTCtx);
0509:                ProviderContextThreadLocalizer.set(this );
0510:            }
0511:
0512:            public Object getSessionProperty(String name) {
0513:                Object obj = m_Request.getSession().getAttribute(
0514:                        m_SessPropPfx + name);
0515:                trace("Got session property \"" + name + "\" = \"" + obj
0516:                        + "\".");
0517:                return obj;
0518:            }
0519:
0520:            public StringBuffer getTemplate(String name, String file) {
0521:
0522:                getTemplatePath(name, file); // for trace message
0523:
0524:                return m_TplContext.getTemplateSB(m_DesktopProperties
0525:                        .getTemplateBaseDir(), getDesktopType(),
0526:                        getLocaleString(), name, getProviderName(name),
0527:                        getClientPath(), file);
0528:            }
0529:
0530:            public boolean getBooleanProperty(String channel, String name) {
0531:                boolean val = m_Prop.getBooleanProperty(channel, name);
0532:                trace("Boolean property \"" + name + "\" for channel \""
0533:                        + channel + "\" "
0534:                        + (val ? "exists." : "does not exist."));
0535:                return val;
0536:            }
0537:
0538:            public boolean getBooleanProperty(String channel, String name,
0539:                    List pflist) {
0540:                return getBooleanProperty(channel, name);
0541:            }
0542:
0543:            public URL getHelp(String channel, HttpServletRequest req)
0544:                    throws MalformedURLException {
0545:                String hu = getStringProperty(channel, "helpURL", true);
0546:                return makeURL(hu, req);
0547:            }
0548:
0549:            public URL getHelp(String channel, String key,
0550:                    HttpServletRequest req) throws MalformedURLException {
0551:                if (!existsStringProperty(channel, key, true)) {
0552:                    return getHelp(channel, req);
0553:                }
0554:
0555:                String hu = getStringProperty(channel, key, true);
0556:                return makeURL(hu, req);
0557:            }
0558:
0559:            private URL makeURL(String hu, HttpServletRequest req)
0560:                    throws MalformedURLException {
0561:
0562:                if (hu.indexOf("://") != -1) {
0563:                    //
0564:                    // looks like a abs url
0565:                    //
0566:                    try {
0567:                        return new URL(hu);
0568:                    } catch (MalformedURLException mfue) {
0569:                        //
0570:                        // string help url was no a well-formed url.  try appending
0571:                        // server and port (treat as a relative url)
0572:                        //
0573:                    }
0574:                }
0575:
0576:                //
0577:                // was not an abs URL, treat as relative
0578:                //
0579:                if (hu.startsWith("/")) {
0580:                    hu = hu.substring(1);
0581:                }
0582:                String path = "http://" + req.getServerName() + ":"
0583:                        + req.getServerPort() + "/" + hu;
0584:                return new URL(path);
0585:            }
0586:
0587:            public boolean existsStringProperty(String channel, String name) {
0588:                boolean val = m_Prop.existsStringProperty(channel, name);
0589:                trace("String property \"" + name + "\" for channel \""
0590:                        + channel + "\" "
0591:                        + (val ? "exists." : "does not exist."));
0592:                return val;
0593:            }
0594:
0595:            public boolean existsStringProperty(String channel, String name,
0596:                    List pflist) {
0597:                return existsStringProperty(channel, name);
0598:            }
0599:
0600:            public void setClientProperty(String key, String val) {
0601:                setSessionProperty(key, val);
0602:            }
0603:
0604:            public void setSessionProperty(String name, String val) {
0605:                m_Request.getSession().setAttribute(m_SessPropPfx + name, val);
0606:                trace("Set session property \"" + name + "\" to \"" + val
0607:                        + "\".");
0608:            }
0609:
0610:            public void setSessionProperty(String name, Object obj) {
0611:                m_Request.getSession().setAttribute(m_SessPropPfx + name, obj);
0612:                trace("Set session property \"" + name + "\" to object \""
0613:                        + obj + "\".");
0614:            }
0615:
0616:            public void debugError(Object o, Throwable t) {
0617:                m_DesktopLog.message(LogView.ERROR, o, t);
0618:            }
0619:
0620:            public void debugMessage(Object o, Throwable t) {
0621:                m_DesktopLog.message(LogView.MESSAGE, o, t);
0622:            }
0623:
0624:            public void debugWarning(Object o, Throwable t) {
0625:                m_DesktopLog.message(LogView.WARNING, o, t);
0626:            }
0627:
0628:            public Object getProperty(String channel, String name, Object def) {
0629:                Object obj = m_Prop.getProperty(channel, name, def);
0630:                trace("Got property \"" + name + "\" for channel \"" + channel
0631:                        + "\" = " + obj.getClass().getName() + " \"" + obj
0632:                        + "\".");
0633:                return obj;
0634:            }
0635:
0636:            public Object getProperty(String channel, String name) {
0637:                Object obj = m_Prop.getProperty(channel, name);
0638:                trace("Got property \"" + name + "\" for channel \"" + channel
0639:                        + "\" = " + obj.getClass().getName() + " \"" + obj
0640:                        + "\".");
0641:                return obj;
0642:            }
0643:
0644:            public int getEditType(String channel) {
0645:                return m_Prop.getEditType(channel);
0646:            }
0647:
0648:            public String getClientPath() {
0649:                String str = m_ClientContext.getClientPath(getClientType());
0650:                trace("Client path - " + str);
0651:                return str;
0652:            }
0653:
0654:            public void debugError(Object o) {
0655:                m_DesktopLog.message(LogView.ERROR, o);
0656:            }
0657:
0658:            // Note - in the "real world" this comes out of the service context,
0659:            // with DSAME providing the user's local.  In our world, it comes from
0660:            // the users.xml file.
0661:
0662:            public String getLocaleString() {
0663:                String str = m_Prop.getLocaleString();
0664:                trace("Locale string - " + str);
0665:                return str;
0666:            }
0667:
0668:            public String getStaticContentPath() {
0669:                return "";
0670:            }
0671:
0672:            public ServletContext getServletContext() {
0673:                return ServletContextThreadLocalizer.get();
0674:            }
0675:
0676:            public void logWarning(Object o, Throwable t) {
0677:                m_DesktopLog.message(LogView.WARNING, o, t);
0678:            }
0679:
0680:            public Map getCollectionProperty(String channel, String name,
0681:                    Map def) {
0682:                return m_Prop.getCollectionProperty(channel, name, def);
0683:            }
0684:
0685:            public Map getCollectionProperty(String channel, String name,
0686:                    Map def, List pflist) {
0687:                return getCollectionProperty(channel, name, def);
0688:            }
0689:
0690:            public Map getCollectionProperty(String channel, String name,
0691:                    Map def, boolean localized) {
0692:                return m_Prop.getCollectionProperty(channel, name, def);
0693:            }
0694:
0695:            public String getClientType() {
0696:                String str = m_ClientContext.getClientType(null);
0697:                trace("Obtained client type - " + str + ".");
0698:                return str;
0699:            }
0700:
0701:            public String getStringProperty(String channel, String name,
0702:                    String def) {
0703:                String str = m_Prop.getStringProperty(channel, name, def);
0704:                trace("Got String property \"" + name + "\" for channel \""
0705:                        + channel + "\" = \"" + str + "\".");
0706:                return str;
0707:            }
0708:
0709:            public String getStringProperty(String channel, String name,
0710:                    String def, List pflist) {
0711:                return getStringProperty(channel, name, def);
0712:            }
0713:
0714:            public String getStringProperty(String channel, String name) {
0715:                String str = m_Prop.getStringProperty(channel, name);
0716:                trace("Got String property \"" + name + "\" for channel \""
0717:                        + channel + "\" = \"" + str + "\".");
0718:                return str;
0719:            }
0720:
0721:            public String getStringProperty(String channel, String name,
0722:                    List pflist) {
0723:                return getStringProperty(channel, name);
0724:            }
0725:
0726:            public boolean isDebugWarningEnabled() {
0727:                return m_DesktopLog.getLevel() >= LogView.WARNING;
0728:            }
0729:
0730:            public String getDescription(String channel) {
0731:                return m_Prop.getDescription(channel);
0732:            }
0733:
0734:            public boolean existsCollectionProperty(String channel, String name) {
0735:                boolean val = m_Prop.existsCollectionProperty(channel, name);
0736:                trace("Collection property \"" + name + "\" for channel \""
0737:                        + channel + "\" "
0738:                        + (val ? "exists." : "does not exist."));
0739:                return val;
0740:            }
0741:
0742:            public boolean existsCollectionProperty(String channel,
0743:                    String name, List pflist) {
0744:                return existsCollectionProperty(channel, name);
0745:            }
0746:
0747:            public boolean existsCollectionProperty(String channel,
0748:                    String name, boolean localized) {
0749:                boolean val = m_Prop.existsCollectionProperty(channel, name,
0750:                        localized);
0751:                trace("Collection property \"" + name + "\" for channel \""
0752:                        + channel + "\" "
0753:                        + (val ? "exists." : "does not exist."));
0754:                return val;
0755:            }
0756:
0757:            public String getSessionID() {
0758:                return m_Request.getSession().getId();
0759:            }
0760:
0761:            public String getAuthenticationType() {
0762:                return "harness";
0763:            }
0764:
0765:            public String getStringAttribute(String name) {
0766:                String str = m_ServiceContext.getStringAttribute(name);
0767:                trace("Service Attribute \"" + name + "\" = \"" + str + "\".");
0768:                return str;
0769:            }
0770:
0771:            public String getTitle(String channel) {
0772:                return m_Prop.getTitle(channel);
0773:            }
0774:
0775:            public void setBooleanProperty(String channel, String name,
0776:                    boolean value) {
0777:                trace("Set boolean property \"" + name + "\" for channel \""
0778:                        + channel + "\" to \"" + value + "\".");
0779:                m_Prop.setBooleanProperty(channel, name, value);
0780:            }
0781:
0782:            public void setBooleanProperty(String channel, String name,
0783:                    boolean value, List pflist) {
0784:                setBooleanProperty(channel, name, value);
0785:            }
0786:
0787:            public String getCharset() {
0788:                // properties based client context ignores the arguments.        
0789:                return m_ClientContext.getCharset("default", Locale.US);
0790:            }
0791:
0792:            public void setStringProperty(String channel, String key, String val) {
0793:                trace("Set String property \"" + key + "\" for channel \""
0794:                        + channel + "\" to \"" + val + "\".");
0795:                m_Prop.setStringProperty(channel, key, val);
0796:            }
0797:
0798:            public void setStringProperty(String channel, String key,
0799:                    String val, List pflist) {
0800:                setStringProperty(channel, key, val);
0801:            }
0802:
0803:            public void setProperty(String channel, String key, Object val) {
0804:                trace("Set object property \"" + key + "\" for channel \""
0805:                        + channel + "\" to \"" + val + "\".");
0806:                m_Prop.setProperty(channel, key, val);
0807:            }
0808:
0809:            public String getDesktopType() {
0810:                return m_ServiceContext.getDesktopType();
0811:            }
0812:
0813:            public boolean existsIntegerProperty(String channel, String name) {
0814:                boolean val = m_Prop.existsIntegerProperty(channel, name);
0815:                trace("Integer property \"" + name + "\" for channel \""
0816:                        + channel + "\" "
0817:                        + (val ? "exists." : "does not exist."));
0818:                return val;
0819:            }
0820:
0821:            public boolean existsIntegerProperty(String channel, String name,
0822:                    List pflist) {
0823:                return existsIntegerProperty(channel, name);
0824:            }
0825:
0826:            public void setCollectionProperty(String channel, String name,
0827:                    List value) {
0828:                trace("Set collection property \"" + name + "\" for channel \""
0829:                        + channel + "\".");
0830:                m_Prop.setCollectionProperty(channel, name, value);
0831:            }
0832:
0833:            public void setCollectionProperty(String channel, String name,
0834:                    List value, List filter) {
0835:                // FIXME
0836:                setCollectionProperty(channel, name, value);
0837:            }
0838:
0839:            public void setCollectionProperty(String channel, String name,
0840:                    Map value, List filter) {
0841:                // FIXME
0842:                setCollectionProperty(channel, name, value);
0843:            }
0844:
0845:            // NOTE - we're hard-coding in HTML escaping, which is
0846:            // the default.  We probably should allow encoder to be overridden.
0847:
0848:            public String escape(String str) {
0849:                StringBuffer buf = new StringBuffer();
0850:
0851:                for (int idx = 0; idx < str.length(); ++idx) {
0852:                    char c = str.charAt(idx);
0853:                    switch (c) {
0854:                    case '\"':
0855:                        buf.append("&quot;");
0856:                        break;
0857:                    case '&':
0858:                        buf.append("&amp;");
0859:                        break;
0860:                    case '<':
0861:                        buf.append("&lt;");
0862:                        break;
0863:                    case '>':
0864:                        buf.append("&gt;");
0865:                        break;
0866:                    default:
0867:                        buf.append(c);
0868:                        break;
0869:                    }
0870:                }
0871:
0872:                return buf.toString();
0873:            }
0874:
0875:            public Locale getLocale() {
0876:                String str = getLocaleString();
0877:
0878:                if (str == null) {
0879:                    return Locale.getDefault();
0880:                }
0881:
0882:                StringTokenizer toks = new StringTokenizer(str, "_");
0883:                String lang = "";
0884:                String country = "";
0885:                String variant = "";
0886:                if (toks.hasMoreTokens()) {
0887:                    lang = toks.nextToken();
0888:                }
0889:                if (toks.hasMoreTokens()) {
0890:                    country = toks.nextToken();
0891:                }
0892:                if (toks.hasMoreTokens()) {
0893:                    variant = toks.nextToken();
0894:                }
0895:
0896:                return new Locale(lang, country, variant);
0897:            }
0898:
0899:            public int getRefreshTime(String channel) {
0900:                return m_Prop.getRefreshTime(channel);
0901:            }
0902:
0903:            public Map getCollectionProperty(String channel, String name) {
0904:                trace("Got collection property \"" + name + "\" for channel \""
0905:                        + channel + ".");
0906:                return m_Prop.getCollectionProperty(channel, name);
0907:            }
0908:
0909:            public Map getCollectionProperty(String channel, String name,
0910:                    List pflist) {
0911:                return getCollectionProperty(channel, name);
0912:            }
0913:
0914:            public Map getCollectionProperty(String channel, String name,
0915:                    boolean localized) {
0916:                trace("Got collection property \"" + name + "\" for channel \""
0917:                        + channel + ".");
0918:                return m_Prop.getCollectionProperty(channel, name, localized);
0919:            }
0920:
0921:            public void setStringAttribute(String name, String val) {
0922:                trace("Set service attribute \"" + name + "\" to \"" + val
0923:                        + "\".");
0924:                m_ServiceContext.setStringAttribute(name, val);
0925:            }
0926:
0927:            /*public void addUserListener(UserListener sl) {
0928:                // FIXME - implement.
0929:            }
0930:            
0931:            public void addUserReference() {
0932:                // FIXME - implement.
0933:            }*/
0934:
0935:            public void addSessionListener(SessionListener sl) {
0936:            }
0937:
0938:            // Not part of the ProviderContext interface.  We obtain our channel name
0939:            // from the developer's XML file, which was interpreted by m_Prop.  We
0940:            // obtain that information through this call before initializing the provider
0941:            // instance for our channel.
0942:
0943:            String getChannelName() {
0944:                return m_Prop.getChannelName();
0945:            }
0946:
0947:            // Not part of the provider interface - user list is obtainable from Users.xml.
0948:
0949:            String[] getUserNames() {
0950:                return m_Prop.getUserNames();
0951:            }
0952:
0953:            String getProviderClass() {
0954:                return m_Prop.getProviderClass();
0955:            }
0956:
0957:            // Not part of the provider interface - "back door" for the parameter editing
0958:            // screens.  Note that the jsp cannot obtain this without processing the requests
0959:            // up front.
0960:
0961:            public HarnessProperties getHarnessProperties(HttpServletRequest req)
0962:                    throws ProviderHarnessException {
0963:                m_Prop.processRequest(req);
0964:                return m_Prop;
0965:            }
0966:
0967:            // Not part of the provider interface.  We provide desktop context as wrappers
0968:            // around HarnessProviderContext, and need these access points.  Package protected
0969:            // so they can't be seen by providers.
0970:
0971:            String getPortalId() {
0972:                return m_DesktopProperties.getPortalId();
0973:            }
0974:
0975:            String getInstanceId() {
0976:                return m_DesktopProperties.getInstanceId();
0977:            }
0978:
0979:            String getTemplateBaseDir() {
0980:                return m_DesktopProperties.getTemplateBaseDir();
0981:            }
0982:
0983:            String getJSPCompilerWARClassPath() {
0984:                return m_DesktopProperties.getJSPCompilerWARClassPath();
0985:            }
0986:
0987:            String getDefaultDesktopType() {
0988:                return m_DesktopProperties.getDefaultDesktopType();
0989:            }
0990:
0991:            String getJSPScratchDir() {
0992:                return getProviderClassBaseDir();
0993:            }
0994:
0995:            short getCookieSupport() {
0996:                return m_ClientContext.getCookieSupport(getClientType());
0997:            }
0998:
0999:            short getAuthlessState() {
1000:                return m_ClientContext.getAuthlessState(getClientType());
1001:            }
1002:
1003:            public String getConfigProperty(String key) {
1004:                return m_DesktopProperties.getConfigProperty(key);
1005:            }
1006:
1007:            public String getParentContainerName(String channel) {
1008:                return null;
1009:            }
1010:
1011:            public Set getRoles() {
1012:                return Collections.EMPTY_SET;
1013:            }
1014:
1015:            /*
1016:             String getSystemIDPath() {
1017:                return m_DesktopProperties.getSystemIDPath();
1018:            }
1019:             */
1020:
1021:            String getProviderClassBaseDir() {
1022:                return m_DesktopProperties.getProviderClassBaseDir();
1023:            }
1024:
1025:            String getPropertiesContextClassName() {
1026:                return m_ServiceContext.getPropertiesContextClassName();
1027:            }
1028:
1029:            String getSessionReturnURLParamName() {
1030:                return m_ServiceContext.getSessionReturnURLParamName();
1031:            }
1032:
1033:            String getNoSessionURL() {
1034:                return m_ServiceContext.getNoSessionURL();
1035:            }
1036:
1037:            StringBuffer getTemplate(String type, String locale, String app,
1038:                    String clientFilePath, String file, Hashtable table,
1039:                    String baseDir, ContainerProviderContext pc) {
1040:                StringBuffer tpl = m_TplContext.getTemplateSB(baseDir, type,
1041:                        locale, app, getProviderName(getChannelName()),
1042:                        clientFilePath, file);
1043:                return TagSwapper.doSwap(tpl, table, getStaticContentPath(),
1044:                        app, pc);
1045:            }
1046:
1047:            File[] getTemplatePaths(String type, String locale, String app,
1048:                    String clientFilePath, String file) {
1049:                return m_TplContext.getTemplatePaths(type, locale, app,
1050:                        clientFilePath, file);
1051:            }
1052:
1053:            StringBuffer getTemplate(String type, String locale, String app,
1054:                    String clientFilePath, String file) {
1055:                return m_TplContext
1056:                        .getTemplateSB(
1057:                                m_DesktopProperties.getTemplateBaseDir(), type,
1058:                                locale, app, getProviderName(getChannelName()),
1059:                                clientFilePath, file);
1060:            }
1061:
1062:            // NOTE - we implement ContainerProviderContext, rather than context, so
1063:            // that we can pass ourselves to TagSwapper.  The ContainerProvider
1064:            // are, in fact, used only in this limited fashion.
1065:
1066:            public StringBuffer getCachedContent(String name) {
1067:                return null;
1068:            }
1069:
1070:            public void addClient(String channel) {
1071:                throw new ContextError("Unexpected call to addClient()");
1072:            }
1073:
1074:            public void initProviders(HttpServletRequest req, String container,
1075:                    List channels, int timeout) {
1076:                throw new ContextError("Unexpected call to initProviders()");
1077:            }
1078:
1079:            // For the purposes of our use of tagswapper, we will assume all Clients exist.
1080:
1081:            public boolean existsClient(String channel) {
1082:                return true;
1083:            }
1084:
1085:            public void addClient(String container, String channel) {
1086:                throw new ContextError("Unexpected call to addClient()");
1087:            }
1088:
1089:            public List getSelectedChannels(String container) {
1090:                throw new ContextError(
1091:                        "Unexpected call to getSelectedChannels()");
1092:            }
1093:
1094:            public Provider getProvider(HttpServletRequest req,
1095:                    String container, String channel) {
1096:                throw new ContextError("Unexpected call to getProvider()");
1097:            }
1098:
1099:            public List getAvailableChannels(String container) {
1100:                throw new ContextError(
1101:                        "Unexpected call to getAvailableChannels()");
1102:            }
1103:
1104:            public void setSelectedChannels(String container, List selelected) {
1105:                throw new ContextError(
1106:                        "Unexpected call to setSelectedChannels()");
1107:            }
1108:
1109:            public long getCachedTime(String name) {
1110:                throw new ContextError("Unexpected call to getCachedTime()");
1111:            }
1112:
1113:            public void setAvailableChannels(String container, List available) {
1114:                throw new ContextError(
1115:                        "Unexpected call to setAvailableChannels()");
1116:            }
1117:
1118:            public Map getContent(HttpServletRequest req,
1119:                    HttpServletResponse res, String container, List channels,
1120:                    int timeout) throws ProviderException {
1121:                throw new ContextError("Unexpected call to getContent()");
1122:            }
1123:
1124:            public StringBuffer getContent(HttpServletRequest req,
1125:                    HttpServletResponse res, String container, String channel)
1126:                    throws ProviderException {
1127:                throw new ContextError("Unexpected call to getContent()");
1128:            }
1129:
1130:            public void putCachedContent(String name, StringBuffer content) {
1131:                throw new ContextError("Unexpected call to putCachedContent()");
1132:            }
1133:
1134:            public void contentChanged(String channelName) {
1135:                throw new ContextError("Unexpected call to contentChanged()");
1136:            }
1137:
1138:            public void allContentChanged() {
1139:                throw new ContextError("Unexpected call to allContentChanged()");
1140:            }
1141:
1142:            public void createChannel(String parentName, String channelName,
1143:                    String providerName) {
1144:                throw new ContextError("Unexpected call to createChannel()");
1145:            }
1146:
1147:            public void createChannel(String channelName, String providerName) {
1148:                throw new ContextError("Unexpected call to createChannel()");
1149:            }
1150:
1151:            public void removeChannel(String parentName, String channelName) {
1152:                throw new ContextError("Unexpected call to removeChannel()");
1153:            }
1154:
1155:            public void removeChannel(String channelName) {
1156:                throw new ContextError("Unexpected call to removeChannel()");
1157:            }
1158:
1159:            public void createContainer(String parentName, String channelName,
1160:                    String providerName) {
1161:                throw new ContextError("Unexpected call to createContainer()");
1162:            }
1163:
1164:            public void createContainer(String channelName, String providerName) {
1165:                throw new ContextError("Unexpected call to createContainer()");
1166:            }
1167:
1168:            public String getDefaultChannelName() {
1169:                throw new ContextError(
1170:                        "Unexpected call to getDefaultChannelName()");
1171:            }
1172:
1173:            public String getTopChannelName(HttpServletRequest req) {
1174:                throw new ContextError("Unexpected call to getTopChannelName()");
1175:            }
1176:
1177:            public boolean existsChannel(String channel) {
1178:                throw new ContextError("Unexpected call to existsChannel()");
1179:            }
1180:
1181:            public int getTemplateScanInterval() {
1182:                return m_DesktopProperties.getTemplateScanInterval();
1183:            }
1184:
1185:            public boolean isAuthless(HttpServletRequest req) {
1186:                return m_DTACtx.isAuthless(req);
1187:            }
1188:
1189:            public String encodeURLParameter(String enc) {
1190:                return enc;
1191:            }
1192:
1193:            public String decodeURLParameter(String dec) {
1194:                return dec;
1195:            }
1196:
1197:            public void copyChannel(String srcName, String dst) {
1198:                throw new ContextError("Unexpected call to copyChannel()");
1199:            }
1200:
1201:            private void trace(String str) {
1202:                m_HarnessLog.message(LogView.MESSAGE, str);
1203:            }
1204:
1205:            private static void copyfiles(File src, File targ)
1206:                    throws ProviderHarnessException {
1207:
1208:                if (!src.exists()) {
1209:                    return;
1210:                }
1211:
1212:                String children[] = src.list();
1213:
1214:                if (children == null) {
1215:                    return;
1216:                }
1217:
1218:                for (int i = 0; i < children.length; ++i) {
1219:                    File chf = new File(src, children[i]);
1220:                    File chtarg = new File(targ, children[i]);
1221:                    if (chf.isDirectory()) {
1222:                        copyfiles(chf, chtarg);
1223:                        continue;
1224:                    }
1225:                    try {
1226:                        targ.mkdirs();
1227:                        FileInputStream fin = new FileInputStream(chf);
1228:                        FileOutputStream fout = new FileOutputStream(chtarg);
1229:                        byte buf[] = new byte[1200];
1230:                        int len;
1231:                        while ((len = fin.read(buf)) > 0) {
1232:                            fout.write(buf, 0, len);
1233:                        }
1234:                        fout.flush();
1235:                        fout.close();
1236:                    } catch (Exception ex) {
1237:                        throw new ProviderHarnessException(
1238:                                "Error transfering files", ex);
1239:                    }
1240:                }
1241:            }
1242:
1243:            private String m_User;
1244:            private LogView m_DesktopLog;
1245:            private LogView m_HarnessLog;
1246:            private PropertiesClientContext m_ClientContext;
1247:            private PropertiesServiceContext m_ServiceContext;
1248:            private HarnessProperties m_Prop;
1249:            private PropertiesConfigContext m_DesktopProperties;
1250:            private HttpServletRequest m_Request;
1251:            private HarnessTemplateContext m_TplContext;
1252:            private String m_SessPropPfx;
1253:            private HarnessDesktopContext m_DTCtx;
1254:            private HarnessDesktopAppContext m_DTACtx;
1255:
1256:            private static int m_PfxCounter = 0;
1257:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.