Source Code Cross Referenced for PentahoSystem.java in  » Report » pentaho-report » org » pentaho » core » system » 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 » Report » pentaho report » org.pentaho.core.system 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Copyright 2006 Pentaho Corporation.  All rights reserved. 
0003:         * This software was developed by Pentaho Corporation and is provided under the terms 
0004:         * of the Mozilla Public License, Version 1.1, or any later version. You may not use 
0005:         * this file except in compliance with the license. If you need a copy of the license, 
0006:         * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho 
0007:         * BI Platform.  The Initial Developer is Pentaho Corporation.
0008:         *
0009:         * Software distributed under the Mozilla Public License is distributed on an "AS IS" 
0010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or  implied. Please refer to 
0011:         * the license for the specific language governing your rights and limitations.
0012:         *
0013:         * @created May 6, 2005 
0014:         * @author James Dixon
0015:         * 
0016:         */
0017:
0018:        package org.pentaho.core.system;
0019:
0020:        import java.net.MalformedURLException;
0021:        import java.net.URL;
0022:        import java.util.ArrayList;
0023:        import java.util.Collections;
0024:        import java.util.HashMap;
0025:        import java.util.Iterator;
0026:        import java.util.List;
0027:        import java.util.Locale;
0028:        import java.util.Map;
0029:        import java.util.StringTokenizer;
0030:
0031:        import org.acegisecurity.GrantedAuthorityImpl;
0032:        import org.apache.commons.collections.list.UnmodifiableList;
0033:        import org.apache.commons.lang.StringUtils;
0034:        import org.dom4j.Document;
0035:        import org.dom4j.DocumentHelper;
0036:        import org.dom4j.Element;
0037:        import org.dom4j.Node;
0038:        import org.pentaho.core.cache.CacheManager;
0039:        import org.pentaho.core.output.IContentOutputHandler;
0040:        import org.pentaho.core.publisher.IPentahoPublisher;
0041:        import org.pentaho.core.repository.IContentRepository;
0042:        import org.pentaho.core.repository.IRuntimeRepository;
0043:        import org.pentaho.core.repository.ISolutionRepository;
0044:        import org.pentaho.core.runtime.IActionParameter;
0045:        import org.pentaho.core.runtime.IBackgroundExecution;
0046:        import org.pentaho.core.runtime.IRuntimeContext;
0047:        import org.pentaho.core.session.IPentahoSession;
0048:        import org.pentaho.core.session.StandaloneSession;
0049:        import org.pentaho.core.solution.HttpRequestParameterProvider;
0050:        import org.pentaho.core.solution.HttpSessionParameterProvider;
0051:        import org.pentaho.core.solution.IParameterProvider;
0052:        import org.pentaho.core.solution.ISolutionEngine;
0053:        import org.pentaho.core.solution.SimpleOutputHandler;
0054:        import org.pentaho.core.solution.SimpleParameterProvider;
0055:        import org.pentaho.core.subscribe.ISubscriptionScheduler;
0056:        import org.pentaho.core.subscribe.quartz.QuartzSubscriptionScheduler;
0057:        import org.pentaho.core.ui.IPentahoUrlFactory;
0058:        import org.pentaho.core.ui.IXMLComponent;
0059:        import org.pentaho.core.ui.SimpleUrlFactory;
0060:        import org.pentaho.core.util.IUITemplater;
0061:        import org.pentaho.messages.Messages;
0062:        import org.pentaho.messages.util.LocaleHelper;
0063:        import org.pentaho.util.IVersionHelper;
0064:        import org.pentaho.util.VersionHelper;
0065:        import org.pentaho.util.logging.ILogger;
0066:        import org.pentaho.util.logging.Logger;
0067:
0068:        import com.pentaho.repository.subscribe.ISubscriptionRepository;
0069:        import com.pentaho.security.SecurityUtils;
0070:        import com.pentaho.security.UserDetailsRoleListService;
0071:        import com.pentaho.security.acls.IAclHolder;
0072:        import com.pentaho.security.acls.IAclPublisher;
0073:        import com.pentaho.security.acls.voter.IAclVoter;
0074:
0075:        public class PentahoSystem {
0076:
0077:            public static final boolean debug = true;
0078:
0079:            public static final boolean trace = false;
0080:
0081:            public static final boolean ignored = false; // used to suppress compiler
0082:
0083:            public static int loggingLevel = ILogger.ERROR;
0084:
0085:            private static IApplicationContext applicationContext;
0086:
0087:            protected static final String CONTENT_REPOSITORY = "IContentRepository"; //$NON-NLS-1$
0088:
0089:            protected static final String RUNTIME_REPOSITORY = "IRuntimeRepository"; //$NON-NLS-1$
0090:
0091:            private static final String SOLUTION_REPOSITORY = "ISolutionRepository"; //$NON-NLS-1$
0092:
0093:            protected static final String SOLUTION_ENGINE = "ISolutionEngine"; //$NON-NLS-1$
0094:
0095:            public static final String BACKGROUND_EXECUTION = "IBackgroundExecution"; //$NON-NLS-1$
0096:
0097:            public static final String SCOPE_GLOBAL = "global"; //$NON-NLS-1$
0098:
0099:            /**
0100:             * maps an interface name to an instance of a class that implements the interface classNameMap, scopeMap, and globalObjectsMap are related Map<String, Object>
0101:             */
0102:            private static Map globalObjectsMap = Collections
0103:                    .synchronizedMap(new HashMap());
0104:
0105:            private static Map globalAttributes;
0106:
0107:            private static SimpleParameterProvider globalParameters;
0108:
0109:            private static ISystemSettings systemSettings;
0110:
0111:            private static List publishers;
0112:
0113:            private static List listeners;
0114:
0115:            /**
0116:             * Maps an interface name to the scope as defined in the pentaho.xml file classNameMap, scopeMap, and globalObjectsMap are related
0117:             */
0118:            private static Map scopeMap;
0119:
0120:            /**
0121:             * maps interface name to a class name that implements the interface classNameMap, scopeMap, and globalObjectsMap are related Map<String, String>
0122:             */
0123:            private static Map classNameMap;
0124:
0125:            private static Map initializationFailureDetailsMap = new HashMap();
0126:
0127:            private static HashMap sessionCreateMap;
0128:
0129:            private static IRuntimeRepository runtimeRepository;
0130:
0131:            private static IContentRepository contentRepository;
0132:
0133:            private static final List RequiredObjects = new ArrayList();
0134:
0135:            private static final List KnownOptionalObjects = new ArrayList();
0136:
0137:            private static final List IgnoredObjects = new ArrayList();
0138:
0139:            public static final int SYSTEM_NOT_INITIALIZED = -1;
0140:
0141:            public static final int SYSTEM_INITIALIZED_OK = 0;
0142:
0143:            public static final int SYSTEM_LISTENERS_FAILED = (int) Math.pow(2,
0144:                    0); // 1
0145:
0146:            public static final int SYSTEM_OBJECTS_FAILED = (int) Math
0147:                    .pow(2, 1); // 2
0148:
0149:            public static final int SYSTEM_PUBLISHERS_FAILED = (int) Math.pow(
0150:                    2, 2); // 4
0151:
0152:            public static final int SYSTEM_AUDIT_FAILED = (int) Math.pow(2, 3); // 8
0153:
0154:            public static final int SYSTEM_PENTAHOXML_FAILED = (int) Math.pow(
0155:                    2, 4); // 16
0156:
0157:            public static final int SYSTEM_SETTINGS_FAILED = (int) Math.pow(2,
0158:                    5); // 32
0159:
0160:            private static int initializedStatus = SYSTEM_NOT_INITIALIZED;
0161:
0162:            private static final String SUBSCRIPTION_REPOSITORY = "ISubscriptionRepository"; //$NON-NLS-1$
0163:
0164:            private static final String ACL_PUBLISHER = "IAclPublisher"; //$NON-NLS-1$
0165:
0166:            private static final String ACL_VOTER = "IAclVoter"; //$NON-NLS-1$
0167:
0168:            private static final String CACHE_MANAGER = "CACHE_MANAGER"; //$NON-NLS-1$
0169:
0170:            // private static Map globalObjectsMap = Collections.synchronizedMap(new
0171:            // HashMap());
0172:            private static UserDetailsRoleListService userDetailsRoleListService;
0173:
0174:            private static final List ACLFileExtensionList = new ArrayList();
0175:
0176:            private static final List UnmodifiableACLFileExtensionList = UnmodifiableList
0177:                    .decorate(ACLFileExtensionList);
0178:
0179:            private static List logoutListeners = Collections
0180:                    .synchronizedList(new ArrayList());
0181:
0182:            // private static ISolutionRepository solutionRepository;
0183:
0184:            // TODO even if logging is not configured messages need to make it out to
0185:            // the console
0186:
0187:            static {
0188:                RequiredObjects.add(SOLUTION_ENGINE);
0189:                RequiredObjects.add(SOLUTION_REPOSITORY);
0190:                RequiredObjects.add(RUNTIME_REPOSITORY);
0191:                RequiredObjects.add(ACL_VOTER);
0192:
0193:                // TODO: Make subscription repository voluntary
0194:                RequiredObjects.add(SUBSCRIPTION_REPOSITORY);
0195:
0196:                KnownOptionalObjects.add(CONTENT_REPOSITORY);
0197:                KnownOptionalObjects.add("IUITemplater"); //$NON-NLS-1$
0198:                KnownOptionalObjects.add("IUserFilesComponent"); //$NON-NLS-1$
0199:                KnownOptionalObjects.add(BACKGROUND_EXECUTION);
0200:
0201:                IgnoredObjects.add("IAuditEntry"); //$NON-NLS-1$
0202:            }
0203:
0204:            public static synchronized boolean retrySystemInit() {
0205:                IApplicationContext appContext = applicationContext;
0206:                publishers.clear();
0207:                listeners.clear();
0208:                scopeMap.clear();
0209:                sessionCreateMap.clear();
0210:                globalAttributes.clear();
0211:                globalParameters = null;
0212:                publishers = null;
0213:                scopeMap = null;
0214:                sessionCreateMap = null;
0215:                globalAttributes = null;
0216:                return init(appContext);
0217:            }
0218:
0219:            public static boolean init(IApplicationContext pApplicationContext) {
0220:                return init(pApplicationContext, null);
0221:            }
0222:
0223:            public static boolean init(IApplicationContext pApplicationContext,
0224:                    Map listenerMap) {
0225:                initializedStatus = SYSTEM_INITIALIZED_OK;
0226:                // No longer using the Messages.properties for version information
0227:                //VersionHelper.setVersion(Messages.getString("PentahoSystem.SYSTEM_PLATFORM_VERSION")); //$NON-NLS-1$
0228:                //VersionHelper.setBuild(Messages.getString("PentahoSystem.SYSTEM_PLATFORM_BUILD_NUMBER")); //$NON-NLS-1$	
0229:
0230:                publishers = new ArrayList();
0231:                listeners = new ArrayList();
0232:                scopeMap = new HashMap();
0233:                classNameMap = new HashMap();
0234:                sessionCreateMap = new HashMap();
0235:                globalAttributes = Collections.synchronizedMap(new HashMap());
0236:                globalParameters = new SimpleParameterProvider(globalAttributes);
0237:
0238:                applicationContext = pApplicationContext;
0239:
0240:                String propertyPath = applicationContext.getSolutionPath(""); //$NON-NLS-1$
0241:                propertyPath = propertyPath.replaceAll("\\\\", "/"); //$NON-NLS-1$ //$NON-NLS-2$
0242:                System.setProperty("pentaho.solutionpath", propertyPath); //$NON-NLS-1$
0243:
0244:                if (LocaleHelper.getLocale() == null) {
0245:                    LocaleHelper.setLocale(Locale.getDefault());
0246:                }
0247:
0248:                systemSettings = new PathBasedSystemSettings();
0249:
0250:                // Set Up ACL File Extensions by reading pentaho.xml for acl-files
0251:                //
0252:                // Read the files that are permitted to have ACLs on them from
0253:                // the pentaho.xml.
0254:                //
0255:                String aclFiles = PentahoSystem.getSystemSetting(
0256:                        "acl-files", "xaction,url");//$NON-NLS-1$ //$NON-NLS-2$
0257:                StringTokenizer st = new StringTokenizer(aclFiles, ","); //$NON-NLS-1$
0258:                String extn;
0259:                while (st.hasMoreElements()) {
0260:                    extn = st.nextToken();
0261:                    if (!extn.startsWith(".")) { //$NON-NLS-1$
0262:                        extn = "." + extn; //$NON-NLS-1$
0263:                    }
0264:                    ACLFileExtensionList.add(extn);
0265:                }
0266:
0267:                //
0268:                // Set up cache manager
0269:                //
0270:                try {
0271:                    CacheManager cacheManager = new CacheManager();
0272:                    globalObjectsMap.put(CACHE_MANAGER, cacheManager);
0273:                } catch (Throwable th) {
0274:                    // TODO: Log an appropriate message
0275:                    // th.printStackTrace();
0276:                    Logger.warn(PentahoSystem.class,
0277:                            "CacheManager.WARNING_NO_CACHE_CONFIGURED"); //$NON-NLS-1$
0278:                }
0279:
0280:                List settingsList = systemSettings
0281:                        .getSystemSettings("pentaho-system"); //$NON-NLS-1$
0282:                if (null == settingsList) {
0283:                    // the application context is not configure correctly
0284:                    Logger
0285:                            .error(
0286:                                    PentahoSystem.class.getName(),
0287:                                    Messages
0288:                                            .getErrorString(
0289:                                                    "PentahoSystem.ERROR_0001_SYSTEM_SETTINGS_INVALID", systemSettings.getSystemCfgSourceName())); //$NON-NLS-1$
0290:                    initializedStatus |= SYSTEM_SETTINGS_FAILED;
0291:                    addInitializationFailureMessage(
0292:                            SYSTEM_SETTINGS_FAILED,
0293:                            Messages
0294:                                    .getErrorString("PentahoSystem.ERROR_0001_SYSTEM_SETTINGS_INVALID")); //$NON-NLS-1$
0295:                }
0296:
0297:                initXMLFactories();
0298:
0299:                // Check the audit log class to make sure it's there.
0300:                String auditClass = systemSettings
0301:                        .getSystemSetting(
0302:                                "objects/IAuditEntry", "org.pentaho.core.audit.AuditFileEntry"); //$NON-NLS-1$ //$NON-NLS-2$
0303:                if (!checkClassExists(auditClass)) {
0304:                    initializedStatus |= SYSTEM_OBJECTS_FAILED
0305:                            | SYSTEM_AUDIT_FAILED;
0306:                    String msg = Messages
0307:                            .getErrorString(
0308:                                    "PentahoSystem.ERROR_0020_SPECIFIED_CLASS_NOT_FOUND", //$NON-NLS-1$
0309:                                    null == auditClass ? "unknown" : auditClass); //$NON-NLS-1$
0310:                    Logger.error(PentahoSystem.class.getName(), msg);
0311:                    addInitializationFailureMessage(SYSTEM_OBJECTS_FAILED, msg);
0312:                    return false;
0313:                }
0314:
0315:                StandaloneSession session = new StandaloneSession(
0316:                        "system session"); //$NON-NLS-1$
0317:                loggingLevel = Logger.getLogLevel(systemSettings
0318:                        .getSystemSetting("log-level", "ERROR")); //$NON-NLS-1$//$NON-NLS-2$
0319:                Logger.setLogLevel(loggingLevel);
0320:
0321:                // to guarantee hostnames in SSL mode are not being spoofed
0322:                registerHostnameVerifier();
0323:
0324:                // boolean isOk = true;
0325:
0326:                // store a list of the publsihers
0327:                List publisherNodes = systemSettings
0328:                        .getSystemSettings("publishers/*"); //$NON-NLS-1$
0329:                if (publisherNodes != null) {
0330:                    Iterator publisherIterator = publisherNodes.iterator();
0331:                    while (publisherIterator.hasNext()) {
0332:                        String publisherClass = ((Node) publisherIterator
0333:                                .next()).getText();
0334:                        IPentahoPublisher publisher = (IPentahoPublisher) createObject(publisherClass);
0335:                        if (publisher != null) {
0336:                            publishers.add(publisher);
0337:                        } else {
0338:                            String msg = Messages
0339:                                    .getErrorString(
0340:                                            "PentahoSystem.ERROR_0010_COULD_NOT_CREATE_PUBLISHER", publisherClass); //$NON-NLS-1$
0341:                            Logger.error(PentahoSystem.class.getName(), msg);
0342:                            initializedStatus |= SYSTEM_PUBLISHERS_FAILED;
0343:                            addInitializationFailureMessage(
0344:                                    SYSTEM_PUBLISHERS_FAILED, msg);
0345:                            return false;
0346:                        }
0347:                    }
0348:                }
0349:
0350:                // store a list of the system listeners
0351:                try {
0352:                    listeners = createSystemListeners(listenerMap, session);
0353:                } catch (PentahoSystemException e) {
0354:                    String msg = e.getLocalizedMessage();
0355:                    Logger.error(PentahoSystem.class.getName(), msg, e);
0356:                    initializedStatus |= SYSTEM_LISTENERS_FAILED;
0357:                    addInitializationFailureMessage(SYSTEM_LISTENERS_FAILED,
0358:                            msg);
0359:                    return false;
0360:                }
0361:
0362:                //
0363:                // TODO: Should this be required now, and should this be the spot to check
0364:                // it?
0365:                //
0366:                if (null == userDetailsRoleListService) {
0367:                    String msg = Messages
0368:                            .getErrorString("PentahoSystem.ERROR_0007_USERDETAILSROLELISTSERVICE_NOT_SET"); //$NON-NLS-1$
0369:                    Logger.error(PentahoSystem.class.getName(), msg);
0370:                    addInitializationFailureMessage(SYSTEM_LISTENERS_FAILED,
0371:                            msg);
0372:                    return false;
0373:                }
0374:
0375:                // get the list of session creation actions
0376:                // TODO need to specify if authentication is optional
0377:                List sessionCreateClasses = systemSettings
0378:                        .getSystemSettings("system-actions/*"); //$NON-NLS-1$
0379:                if (sessionCreateClasses != null) {
0380:                    Iterator sessionCreateIterator = sessionCreateClasses
0381:                            .iterator();
0382:                    while (sessionCreateIterator.hasNext()) {
0383:                        Node sessionActionNode = (Node) sessionCreateIterator
0384:                                .next();
0385:
0386:                        String sessionCreateClass = sessionActionNode.getName();
0387:                        String scope = sessionActionNode.selectSingleNode(
0388:                                "@scope").getText(); //$NON-NLS-1$
0389:                        String actionName = sessionActionNode.getText();
0390:                        List sessionActionList = (List) sessionCreateMap
0391:                                .get(sessionCreateClass);
0392:                        if (sessionActionList == null) {
0393:                            sessionActionList = new ArrayList();
0394:                            sessionCreateMap.put(sessionCreateClass,
0395:                                    sessionActionList);
0396:                            // Force the actions to also be available from sub-action execution
0397:                            // and from
0398:                            // background execution.
0399:                            sessionCreateMap
0400:                                    .put(
0401:                                            "org.pentaho.core.session.UserSession", sessionActionList); //$NON-NLS-1$
0402:                        }
0403:                        sessionActionList
0404:                                .add(new String[] { scope, actionName });
0405:                    }
0406:                }
0407:
0408:                return true;
0409:            }
0410:
0411:            private static List createSystemListeners(Map listenerMap,
0412:                    IPentahoSession session) throws PentahoSystemException {
0413:                assert null != systemSettings : Messages
0414:                        .getErrorString("PentahoSystem.ERROR_0026_SETTINGS_MUST_BE_NONNULL"); //$NON-NLS-1$
0415:                List localListeners = new ArrayList();
0416:                boolean isOk = true;
0417:                // store a list of the system listeners
0418:                List systemListenerNodes = systemSettings
0419:                        .getSystemSettings("system-listeners/*"); //$NON-NLS-1$
0420:                if (systemListenerNodes != null) {
0421:                    Iterator systemListenerIterator = systemListenerNodes
0422:                            .iterator();
0423:                    isOk = true;
0424:                    while (systemListenerIterator.hasNext()) {
0425:                        Node listenerNode = (Node) systemListenerIterator
0426:                                .next();
0427:                        String systemListenerClass = listenerNode.getText();
0428:                        String listenerName = listenerNode.getName();
0429:                        if (listenerMap != null
0430:                                && listenerMap.get(listenerName) == null) {
0431:                            continue;
0432:                        }
0433:                        IPentahoSystemListener listener = (IPentahoSystemListener) createObject(systemListenerClass);
0434:                        if (listener != null) {
0435:                            localListeners.add(listener);
0436:                            try {
0437:                                isOk = listener.startup(session);
0438:                                if (!isOk) {
0439:                                    throw new PentahoSystemException(
0440:                                            Messages
0441:                                                    .getErrorString(
0442:                                                            "PentahoSystem.ERROR_0014_STARTUP_FAILURE", systemListenerClass)); //$NON-NLS-1$
0443:                                }
0444:                            } catch (Throwable e) {
0445:                                throw new PentahoSystemException(
0446:                                        Messages
0447:                                                .getErrorString(
0448:                                                        "PentahoSystem.ERROR_0014_STARTUP_FAILURE", systemListenerClass), e); //$NON-NLS-1$
0449:                            }
0450:                        } else {
0451:                            throw new PentahoSystemException(
0452:                                    Messages
0453:                                            .getErrorString(
0454:                                                    "PentahoSystem.ERROR_0011_COULD_NOT_CREATE_LISTENER", systemListenerClass)); //$NON-NLS-1$
0455:                        }
0456:                    }
0457:                }
0458:                return localListeners;
0459:            }
0460:
0461:            /**
0462:             * Using data in the systemSettings (this data typically originates in the pentaho.xml file), initialize 3 System properties to explicitly identify the Transformer, SAX, and DOM factory implementations. (i.e. Crimson, Xerces, Xalan,
0463:             * Saxon, etc.)
0464:             * 
0465:             * For background on the purpose of this method, take a look at the notes/URLs below:
0466:             * 
0467:             * Java[tm] API for XML Processing (JAXP):Frequently Asked Questions http://java.sun.com/webservices/jaxp/reference/faqs/index.html
0468:             * 
0469:             * Plugging in a Transformer and XML parser http://xml.apache.org/xalan-j/usagepatterns.html#plug
0470:             * 
0471:             * http://marc2.theaimsgroup.com/?l=xml-apache-general&m=101344910514822&w=2 Q. How do I use a different JAXP compatible implementation?
0472:             * 
0473:             * The JAXP 1.1 API allows applications to plug in different JAXP compatible implementations of parsers or XSLT processors. For example, when an application wants to create a new JAXP DocumentBuilderFactory instance, it calls the staic
0474:             * method DocumentBuilderFactory.newInstance(). This causes a search for the name of a concrete subclass of DocumentBuilderFactory using the following order: - The value of a system property like javax.xml.parsers.DocumentBuilderFactory
0475:             * if it exists and is accessible. - The contents of the file $JAVA_HOME/jre/lib/jaxp.properties if it exists. - The Jar Service Provider mechanism specified in the Jar File Specification. A jar file can have a resource (i.e. an embedded
0476:             * file) such as META-INF/javax/xml/parsers/DocumentBuilderFactory containing the name of the concrete class to instantiate. - The fallback platform default implementation.
0477:             * 
0478:             * Of the above ways to specify an implementation, perhaps the most useful is the jar service provider mechanism. To use this mechanism, place the implementation jar file on your classpath. For example, to use Xerces 1.4.4 instead of the
0479:             * version of Crimson which is bundled with JDK 1.4 (Java Development Kit version 1.4), place xerces.jar in your classpath. This mechanism also works with older versions of the JDK which do not bundle JAXP. If you are using JDK 1.4 and
0480:             * above, see the following question for potential problems. see http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#Service%20Provider
0481:             * 
0482:             */
0483:            private static void initXMLFactories() {
0484:                // assert systemSettings != null : "systemSettings property must be set
0485:                // before calling initXMLFactories.";
0486:
0487:                String xpathToXMLFactoryNodes = "xml-factories/factory-impl"; //$NON-NLS-1$
0488:                List nds = systemSettings
0489:                        .getSystemSettings(xpathToXMLFactoryNodes);
0490:                if (null != nds) {
0491:                    for (Iterator it = nds.iterator(); it.hasNext();) {
0492:                        Node nd = (Node) it.next();
0493:                        Node nameAttr = nd.selectSingleNode("@name"); //$NON-NLS-1$
0494:                        Node implAttr = nd.selectSingleNode("@implementation"); //$NON-NLS-1$
0495:                        if (null != nameAttr && null != implAttr) {
0496:                            String name = nameAttr.getText();
0497:                            String impl = implAttr.getText();
0498:                            System.setProperty(name, impl);
0499:                        } else {
0500:                            Logger
0501:                                    .error(
0502:                                            PentahoSystem.class.getName(),
0503:                                            Messages
0504:                                                    .getErrorString(
0505:                                                            "PentahoSystem.ERROR_0025_LOAD_XML_FACTORY_PROPERTIES_FAILED", //$NON-NLS-1$ 
0506:                                                            xpathToXMLFactoryNodes));
0507:                        }
0508:                    }
0509:                }
0510:            }
0511:
0512:            public static boolean getInitializedOK() {
0513:                return initializedStatus == SYSTEM_INITIALIZED_OK;
0514:            }
0515:
0516:            public static int getInitializedStatus() {
0517:                return initializedStatus;
0518:            }
0519:
0520:            private static List getAdditionalInitializationFailureMessages(
0521:                    int failureBit) {
0522:                List l = (List) initializationFailureDetailsMap
0523:                        .get(new Integer(failureBit));
0524:                return l;
0525:            }
0526:
0527:            public static List getInitializationFailureMessages() {
0528:                List rtn = new ArrayList();
0529:                if (hasFailed(SYSTEM_SETTINGS_FAILED)) {
0530:                    rtn
0531:                            .add(Messages
0532:                                    .getString(
0533:                                            "PentahoSystem.USER_INITIALIZATION_SYSTEM_SETTINGS_FAILED", PathBasedSystemSettings.SYSTEM_CFG_PATH_KEY));//$NON-NLS-1$
0534:                    List l = getAdditionalInitializationFailureMessages(SYSTEM_SETTINGS_FAILED);
0535:                    if (l != null) {
0536:                        rtn.addAll(l);
0537:                    }
0538:                }
0539:                if (hasFailed(SYSTEM_PUBLISHERS_FAILED)) {
0540:                    rtn
0541:                            .add(Messages
0542:                                    .getString("PentahoSystem.USER_INITIALIZATION_SYSTEM_PUBLISHERS_FAILED"));//$NON-NLS-1$
0543:                    List l = getAdditionalInitializationFailureMessages(SYSTEM_PUBLISHERS_FAILED);
0544:                    if (l != null) {
0545:                        rtn.addAll(l);
0546:                    }
0547:                }
0548:                if (hasFailed(SYSTEM_OBJECTS_FAILED)) {
0549:                    rtn
0550:                            .add(Messages
0551:                                    .getString("PentahoSystem.USER_INITIALIZATION_SYSTEM_OBJECTS_FAILED"));//$NON-NLS-1$
0552:                    List l = getAdditionalInitializationFailureMessages(SYSTEM_OBJECTS_FAILED);
0553:                    if (l != null) {
0554:                        rtn.addAll(l);
0555:                    }
0556:                }
0557:                if (hasFailed(SYSTEM_AUDIT_FAILED)) {
0558:                    rtn
0559:                            .add(Messages
0560:                                    .getString("PentahoSystem.USER_INITIALIZATION_SYSTEM_AUDIT_FAILED"));//$NON-NLS-1$
0561:                    List l = getAdditionalInitializationFailureMessages(SYSTEM_AUDIT_FAILED);
0562:                    if (l != null) {
0563:                        rtn.addAll(l);
0564:                    }
0565:                }
0566:                if (hasFailed(SYSTEM_LISTENERS_FAILED)) {
0567:                    rtn
0568:                            .add(Messages
0569:                                    .getString("PentahoSystem.USER_INITIALIZATION_SYSTEM_LISTENERS_FAILED"));//$NON-NLS-1$
0570:                    List l = getAdditionalInitializationFailureMessages(SYSTEM_LISTENERS_FAILED);
0571:                    if (l != null) {
0572:                        rtn.addAll(l);
0573:                    }
0574:                }
0575:                if (hasFailed(SYSTEM_PENTAHOXML_FAILED)) {
0576:                    rtn
0577:                            .add(Messages
0578:                                    .getString("PentahoSystem.USER_INITIALIZATION_SYSTEM_PENTAHOXML_FAILED"));//$NON-NLS-1$
0579:                    List l = getAdditionalInitializationFailureMessages(SYSTEM_PENTAHOXML_FAILED);
0580:                    if (l != null) {
0581:                        rtn.addAll(l);
0582:                    }
0583:                }
0584:                return rtn;
0585:            }
0586:
0587:            public static synchronized void addInitializationFailureMessage(
0588:                    int failureBit, String message) {
0589:                Integer i = new Integer(failureBit);
0590:                List l = (List) initializationFailureDetailsMap.get(i);
0591:                if (l == null) {
0592:                    l = new ArrayList();
0593:                    initializationFailureDetailsMap.put(i, l);
0594:                }
0595:                l.add("&nbsp;&nbsp;&nbsp;" + message);//$NON-NLS-1$
0596:            }
0597:
0598:            private static final boolean hasFailed(int errorToCheck) {
0599:                return ((initializedStatus & errorToCheck) == errorToCheck);
0600:            }
0601:
0602:            protected static boolean checkClassExists(String className) {
0603:                try {
0604:                    Class.forName(className);
0605:                    return true;
0606:                } catch (Throwable t) {
0607:                }
0608:                return false;
0609:            }
0610:
0611:            public static boolean loadStartupObject(IPentahoSession session,
0612:                    String objectName, boolean required) {
0613:                String scope;
0614:                String objectClass = PentahoSystem.getSystemSetting(
0615:                        "objects/" + objectName, null); //$NON-NLS-1$
0616:                scope = PentahoSystem.getSystemSetting(
0617:                        "objects/" + objectName + "/@scope", null); //$NON-NLS-1$ //$NON-NLS-2$
0618:                return loadStartupObject(session, objectName, required,
0619:                        objectClass, scope);
0620:            }
0621:
0622:            /**
0623:             * 
0624:             * 
0625:             * @param session
0626:             * @param interfaceName
0627:             *          name of the interface implemented by the class specifed by <code>objectClass</code>
0628:             * @param required
0629:             * @param objectClass
0630:             * @param scope
0631:             *          String identifying the scope. If it is null, the scope will default to session
0632:             * @return boolean indicating succes (true) or failure (false). Method fails when: objectClass is null, and required is true scope is global and objectClass is the name of a class that the class-loader is unable to create
0633:             */
0634:            public static boolean loadStartupObject(IPentahoSession session,
0635:                    String objectName, boolean required, String objectClass,
0636:                    String scope) {
0637:                if (debug)
0638:                    Logger
0639:                            .debug(
0640:                                    PentahoSystem.class.getName(),
0641:                                    Messages
0642:                                            .getString(
0643:                                                    "PentahoSystem.DEBUG_CLASS_INFO", objectName, objectClass, scope)); //$NON-NLS-1$
0644:                if (objectClass == null) {
0645:                    if (required) {
0646:                        Logger
0647:                                .error(
0648:                                        PentahoSystem.class.getName(),
0649:                                        Messages
0650:                                                .getErrorString(
0651:                                                        "PentahoSystem.ERROR_0021_OBJECT_NOT_SPECIFIED", objectName)); //$NON-NLS-1$
0652:                        return false;
0653:                    } else {
0654:                        Logger
0655:                                .warn(
0656:                                        PentahoSystem.class.getName(),
0657:                                        Messages
0658:                                                .getErrorString(
0659:                                                        "PentahoSystem.ERROR_0021_OBJECT_NOT_SPECIFIED", objectName)); //$NON-NLS-1$
0660:                        return true;
0661:                    }
0662:                }
0663:                if (scope == null) {
0664:                    Logger
0665:                            .warn(
0666:                                    PentahoSystem.class.getName(),
0667:                                    Messages
0668:                                            .getString(
0669:                                                    "PentahoSystem.WARNING_OBJECT_SCOPE_MISSING", objectName)); //$NON-NLS-1$
0670:                    scope = HttpSessionParameterProvider.SCOPE_SESSION;
0671:                }
0672:                classNameMap.put(objectName, objectClass);
0673:                scopeMap.put(objectName, scope);
0674:                if (SCOPE_GLOBAL.equals(scope)) {
0675:                    try {
0676:                        Object obj = PentahoSystem.createObject(objectClass);
0677:                        if (obj == null) {
0678:                            Logger
0679:                                    .error(
0680:                                            PentahoSystem.class.getName(),
0681:                                            Messages
0682:                                                    .getErrorString(
0683:                                                            "PentahoSystem.ERROR_0022_COULD_NOT_CREATE_OBJECT", objectName)); //$NON-NLS-1$
0684:                            return false;
0685:                        } else {
0686:                            globalObjectsMap.put(objectName, obj);
0687:                        }
0688:                        if (obj instanceof  IPentahoInitializer) {
0689:                            ((IPentahoInitializer) obj).init(session);
0690:                        }
0691:
0692:                    } catch (ClassCastException e) {
0693:                        // TODO surface this error
0694:                        e.printStackTrace();
0695:                    } catch (Throwable t) {
0696:                        // TODO surface this error
0697:                        t.printStackTrace();
0698:
0699:                    }
0700:                }
0701:
0702:                return true;
0703:            }
0704:
0705:            public static IVersionHelper getVersionHelper(
0706:                    IPentahoSession session) {
0707:                Object obj = getObject(session, "IVersionHelper"); //$NON-NLS-1$
0708:                if (obj == null) {
0709:                    obj = new VersionHelper();
0710:                    globalObjectsMap.put("IVersionHelper", obj); //$NON-NLS-1$
0711:                    scopeMap.put("IVersionHelper", SCOPE_GLOBAL); //$NON-NLS-1$
0712:                }
0713:                return (IVersionHelper) obj;
0714:            }
0715:
0716:            public static IUITemplater getUITemplater(IPentahoSession session) {
0717:                Object obj = getObject(session, "IUITemplater"); //$NON-NLS-1$
0718:                return (IUITemplater) obj;
0719:            }
0720:
0721:            public static IBackgroundExecution getBackgroundExecutionHandler(
0722:                    IPentahoSession session) {
0723:                Object obj = getObject(session, BACKGROUND_EXECUTION);
0724:                return (IBackgroundExecution) obj;
0725:            }
0726:
0727:            public static IXMLComponent getUserFilesComponent(
0728:                    IPentahoSession session) {
0729:                Object obj = getObject(session, "IUserFilesComponent"); //$NON-NLS-1$
0730:                return (IXMLComponent) obj;
0731:            }
0732:
0733:            public static IContentOutputHandler getOutputHandlerFromHandlerId(
0734:                    String objectName, IPentahoSession session) {
0735:                Object handlerObj = PentahoSystem
0736:                        .getObject(session, objectName);
0737:                if (handlerObj == null) {
0738:                    Logger
0739:                            .error(
0740:                                    PentahoSystem.class.getName(),
0741:                                    Messages
0742:                                            .getErrorString(
0743:                                                    "PentahoSystem.ERROR_0027_UNDEFINED_OUTPUT", objectName)); //$NON-NLS-1$
0744:                    return null;
0745:                }
0746:                if (handlerObj instanceof  IContentOutputHandler) {
0747:                    return (IContentOutputHandler) handlerObj;
0748:                } else {
0749:                    Logger
0750:                            .error(
0751:                                    PentahoSystem.class.getName(),
0752:                                    Messages
0753:                                            .getErrorString(
0754:                                                    "PentahoSystem.ERROR_0028_NOT_CONTENT_OUTPUT_HANDLER", objectName)); //$NON-NLS-1$
0755:                    return null;
0756:                }
0757:            }
0758:
0759:            public static IContentOutputHandler getOutputDestinationFromContentRef(
0760:                    String contentTag, IPentahoSession session) {
0761:
0762:                int pos = contentTag.indexOf(':');
0763:                if (pos == -1) {
0764:                    Logger
0765:                            .error(
0766:                                    PentahoSystem.class.getName(),
0767:                                    Messages
0768:                                            .getErrorString(
0769:                                                    "PentahoSystem.ERROR_0029_OUTPUT_HANDLER_NOT_SPECIFIED", contentTag)); //$NON-NLS-1$
0770:                    return null;
0771:                }
0772:                String handlerId = contentTag.substring(0, pos);
0773:                String contentRef = contentTag.substring(pos + 1);
0774:                IContentOutputHandler output = getOutputHandlerFromHandlerId(
0775:                        handlerId, session);
0776:                if (output != null) {
0777:                    output.setHandlerId(handlerId);
0778:                    output.setSession(session);
0779:                    output.setContentRef(contentRef);
0780:                }
0781:                return output;
0782:            }
0783:
0784:            public static Object getObject(IPentahoSession session,
0785:                    String objectName) {
0786:                /*
0787:                 * if( scopeMap == null ) { // we were not initialized Logger.error( PentahoSystem.class.getName(), Messages.getErrorString("ProPentahoSystem.ERROR_0003_PRO_PENTAHO_SYSTEM_NOT_INITIALIZED") ); //$NON-NLS-1$ return null; }
0788:                 */
0789:                String scope = (String) scopeMap.get(objectName);
0790:
0791:                if (SCOPE_GLOBAL.equalsIgnoreCase(scope)) {
0792:                    Object rtn = globalObjectsMap.get(objectName);
0793:                    if (rtn instanceof  IPentahoInitializer) {
0794:                        ((IPentahoInitializer) rtn).init(session);
0795:                    }
0796:                    return rtn;
0797:                } else if (HttpSessionParameterProvider.SCOPE_SESSION
0798:                        .equalsIgnoreCase(scope)) {
0799:                    Object attribute = session.getAttribute(objectName);
0800:
0801:                    if ((attribute != null)) {
0802:                        // Set the session which is a threadlocal...
0803:                        if (attribute instanceof  IPentahoInitializer) {
0804:                            ((IPentahoInitializer) attribute).init(session);
0805:                        }
0806:                        return attribute;
0807:                    }
0808:                    String clazz = (String) classNameMap.get(objectName);
0809:                    attribute = PentahoSystem.createObject(clazz);
0810:                    if (attribute instanceof  IPentahoInitializer) {
0811:                        ((IPentahoInitializer) attribute).init(session);
0812:                    }
0813:                    session.setAttribute(objectName, attribute);
0814:                    return attribute;
0815:                }
0816:                Logger
0817:                        .error(
0818:                                PentahoSystem.class.getName(),
0819:                                Messages
0820:                                        .getErrorString(
0821:                                                "PentahoSystem.ERROR_0023_COULD_NOT_RETURN_OBJECT", objectName, scope)); //$NON-NLS-1$
0822:                return null;
0823:
0824:            }
0825:
0826:            /**
0827:             * First load the required objects, then the optional objects, and then the objects that are specified in the system configuration file (pentaho.xml) as children of the <object> element, except for those specified in the RequiredObjects
0828:             * list, KnownOptionalObjects list, or IgnoredObjects list.
0829:             * 
0830:             * @param session
0831:             * @return boolean set to true on success, else false
0832:             */
0833:            protected static boolean initGlobalObjects(IPentahoSession session) {
0834:                for (int i = 0; i < RequiredObjects.size(); i++) {
0835:                    loadStartupObject(session, (String) RequiredObjects.get(i),
0836:                            true);
0837:                }
0838:                for (int i = 0; i < KnownOptionalObjects.size(); i++) {
0839:                    loadStartupObject(session, (String) KnownOptionalObjects
0840:                            .get(i), false);
0841:                }
0842:
0843:                // Now, iterate over the rest of the objects in the Objects list
0844:                // looking for other objects to create/load
0845:                List objectClasses = systemSettings
0846:                        .getSystemSettings("objects/*"); //$NON-NLS-1$
0847:                if (objectClasses != null) {
0848:                    for (int i = 0; i < objectClasses.size(); i++) {
0849:                        Node objectNode = (Node) objectClasses.get(i);
0850:                        String className = objectNode.getText();
0851:                        String name = objectNode.getName();
0852:                        if (shouldLoad(name)) {
0853:                            String scope = objectNode.valueOf("@scope"); //$NON-NLS-1$
0854:                            loadStartupObject(session, name, false, className,
0855:                                    scope);
0856:                        }
0857:                    }
0858:                }
0859:
0860:                sessionStartup(session, false);
0861:                return true;
0862:            }
0863:
0864:            /**
0865:             * Identifies if the class that implements the interface (<code>intefaceName</code>) should be created. More generally, identifies if <code>interfaceName</code> is in any of the lists
0866:             * <code>RequiredObjects, KnownOptionalObjects, or IgnoredObjects</code>.
0867:             * 
0868:             * @param interfaceName
0869:             *          String identifying the name of an interface
0870:             * @return boolean set to true if <code>interfaceName</code> is NOT in any of the lists <code>RequiredObjects, KnownOptionalObjects, or IgnoredObjects</code>.
0871:             */
0872:            private static boolean shouldLoad(String interfaceName) {
0873:                return ((!RequiredObjects.contains(interfaceName))
0874:                        && (!KnownOptionalObjects.contains(interfaceName)) && (!IgnoredObjects
0875:                        .contains(interfaceName)));
0876:            }
0877:
0878:            public static String getSystemName() {
0879:                return Messages.getString("PentahoSystem.USER_SYSTEM_TITLE"); //$NON-NLS-1$;
0880:            }
0881:
0882:            /**
0883:             * Get the list of action sequence document paths to configured at sessions scope
0884:             * 
0885:             * @param className
0886:             *          Name of a class that implements IPentahoSession
0887:             * 
0888:             * @return List of action sequence document paths.
0889:             */
0890:            public static List getSessionCreateActions(String className) {
0891:                return (null != sessionCreateMap) ? (List) sessionCreateMap
0892:                        .get(className) : null;
0893:            }
0894:
0895:            public static IParameterProvider getGlobalParameters() {
0896:                return globalParameters;
0897:            }
0898:
0899:            public static void sessionStartup(IPentahoSession session) {
0900:                sessionStartup(session, true);
0901:            }
0902:
0903:            public static void clearGlobals() {
0904:                globalAttributes.clear();
0905:            }
0906:
0907:            public static Object putInGlobalAttributesMap(Object key,
0908:                    Object value) {
0909:                return globalAttributes.put(key, value);
0910:            }
0911:
0912:            public static Object removeFromGlobalAttributesMap(Object key) {
0913:                return globalAttributes.remove(key);
0914:            }
0915:
0916:            public static void sessionStartup(IPentahoSession session,
0917:                    boolean doSession) {
0918:                List actions = getSessionCreateActions(session.getClass()
0919:                        .getName());
0920:                if (actions == null) {
0921:                    // nothing to do...
0922:                    return;
0923:                }
0924:
0925:                if (!session.isAuthenticated() && doSession) {
0926:                    return;
0927:                }
0928:                boolean doGlobals = globalAttributes.size() == 0;
0929:                // TODO this needs more validation
0930:                Iterator actionsIterator = actions.iterator();
0931:                while (actionsIterator.hasNext()) {
0932:                    String tmp[] = (String[]) actionsIterator.next();
0933:                    String scope = tmp[0];
0934:                    if (PentahoSystem.SCOPE_GLOBAL.equals(scope) && !doGlobals) {
0935:                        // see if this has been done already
0936:                        continue;
0937:                    } else if (HttpSessionParameterProvider.SCOPE_SESSION
0938:                            .equals(scope)
0939:                            && !doSession) {
0940:                        continue;
0941:                    }
0942:                    String actionStr = tmp[1];
0943:                    // parse the actionStr out to identify an action
0944:                    ActionInfo actionInfo = parseActionString(actionStr);
0945:                    if (actionInfo != null) {
0946:                        // now execute the action...
0947:
0948:                        SimpleOutputHandler outputHandler = null;
0949:
0950:                        String instanceId = null;
0951:
0952:                        ISolutionEngine solutionEngine = PentahoSystem
0953:                                .getSolutionEngineInstance(session);
0954:                        solutionEngine.setLoggingLevel(loggingLevel);
0955:                        solutionEngine.init(session);
0956:
0957:                        String baseUrl = ""; //$NON-NLS-1$	
0958:                        HashMap parameterProviderMap = new HashMap();
0959:                        HttpSessionParameterProvider sessionParameters = new HttpSessionParameterProvider(
0960:                                session);
0961:                        parameterProviderMap.put(
0962:                                HttpSessionParameterProvider.SCOPE_SESSION,
0963:                                sessionParameters);
0964:
0965:                        IPentahoUrlFactory urlFactory = new SimpleUrlFactory(
0966:                                baseUrl);
0967:
0968:                        ArrayList messages = new ArrayList();
0969:
0970:                        IRuntimeContext context = null;
0971:                        try {
0972:                            context = solutionEngine
0973:                                    .execute(
0974:                                            actionInfo.getSolutionName(),
0975:                                            actionInfo.getPath(),
0976:                                            actionInfo.getActionName(),
0977:                                            "Session startup actions", false, true, instanceId, false, parameterProviderMap, outputHandler, null, urlFactory, messages); //$NON-NLS-1$
0978:
0979:                            if (context.getStatus() == IRuntimeContext.RUNTIME_STATUS_SUCCESS) {
0980:                                // now grab any outputs
0981:                                Iterator outputNameIterator = context
0982:                                        .getOutputNames().iterator();
0983:                                while (outputNameIterator.hasNext()) {
0984:
0985:                                    String attributeName = (String) outputNameIterator
0986:                                            .next();
0987:                                    IActionParameter output = context
0988:                                            .getOutputParameter(attributeName);
0989:
0990:                                    Object data = output.getValue();
0991:                                    if (data != null) {
0992:                                        if (HttpSessionParameterProvider.SCOPE_SESSION
0993:                                                .equals(scope)) {
0994:                                            session
0995:                                                    .removeAttribute(attributeName);
0996:                                            session.setAttribute(attributeName,
0997:                                                    data);
0998:                                        } else if (PentahoSystem.SCOPE_GLOBAL
0999:                                                .equals(scope)) {
1000:                                            globalAttributes
1001:                                                    .remove(attributeName);
1002:                                            globalAttributes.put(attributeName,
1003:                                                    data);
1004:                                        } else {
1005:                                            Logger
1006:                                                    .error(
1007:                                                            PentahoSystem.class
1008:                                                                    .getName(),
1009:                                                            Messages
1010:                                                                    .getErrorString(
1011:                                                                            "PentahoSystem.ERROR_0024_BAD_SCOPE_SYSTEM_ACTION", scope)); //$NON-NLS-1$
1012:                                        }
1013:                                    }
1014:                                }
1015:                            }
1016:                        } finally {
1017:                            if (context != null) {
1018:                                context.dispose();
1019:                            }
1020:                        }
1021:
1022:                    } else {
1023:                        Logger
1024:                                .error(
1025:                                        PentahoSystem.class.getName(),
1026:                                        Messages
1027:                                                .getErrorString(
1028:                                                        "PentahoSystem.ERROR_0016_COULD_NOT_PARSE_ACTION", actionStr)); //$NON-NLS-1$
1029:                    }
1030:                }
1031:            }
1032:
1033:            /**
1034:             * TODO the method PentahoSystem.parseActionString() should be converted into a ctor for this class, and then removed. Callers should be adjusted. ActionResource.getLocationInSolution should be refactored into a method in this class, and
1035:             * callers adjusted. In general, the solutionName, path and actionName should likely be abstracted into an opaque class that can be passed around, instead of passing around 3 strings, and manually combining and parsing them in many
1036:             * places.
1037:             * 
1038:             * @author Steven Barkdull
1039:             * 
1040:             */
1041:            static public class ActionInfo {
1042:                private String solutionName;
1043:
1044:                private String path;
1045:
1046:                private String actionName;
1047:
1048:                ActionInfo(String solutionName, String path, String actionName) {
1049:                    this .solutionName = solutionName;
1050:                    this .path = path;
1051:                    this .actionName = actionName;
1052:                }
1053:
1054:                public String getActionName() {
1055:                    return actionName;
1056:                }
1057:
1058:                public String getPath() {
1059:                    return path;
1060:                }
1061:
1062:                public String getSolutionName() {
1063:                    return solutionName;
1064:                }
1065:            }
1066:
1067:            public static ActionInfo parseActionString(String actionString) {
1068:                return parseActionString(actionString, true);
1069:            }
1070:
1071:            /**
1072:             * Break an action string into it's 3 components: the solution Id, the path to action file, and the action name
1073:             * 
1074:             * @param actionString
1075:             * @return
1076:             */
1077:            public static ActionInfo parseActionString(String actionString,
1078:                    boolean mustBeComplete) {
1079:                // parse a string in this format samples/reporting/JFR/report.xml into
1080:                // the solution, path, and document name
1081:                if (actionString == null) {
1082:                    return null;
1083:                }
1084:
1085:                // first normalize the path separators
1086:                actionString = actionString.replace('\\', '/');
1087:
1088:                // remove a leading '/'
1089:                if (actionString.charAt(0) == '/') {
1090:                    actionString = actionString.substring(1);
1091:                }
1092:
1093:                String solution;
1094:                String path = ""; //$NON-NLS-1$
1095:                String name;
1096:                int idx1 = actionString.indexOf('/');
1097:                int idx2 = actionString.lastIndexOf('/');
1098:                if (idx1 == -1) {
1099:                    if (mustBeComplete) {
1100:                        // this is not a valid action String
1101:                        return null;
1102:                    } else {
1103:                        if (StringUtils.isEmpty(actionString)) {
1104:                            return null;
1105:                        } else {
1106:                            return new ActionInfo(actionString, null, null);
1107:                        }
1108:                    }
1109:                }
1110:                solution = actionString.substring(0, idx1);
1111:                name = actionString.substring(idx2 + 1);
1112:                if (idx2 > idx1) {
1113:                    path = actionString.substring(idx1 + 1, idx2);
1114:                }
1115:                // see if the name has an extension
1116:                if (!mustBeComplete && name.indexOf('.') == -1) {
1117:                    // not really a filename
1118:                    path = path + '/' + name;
1119:                    name = null;
1120:                }
1121:                return new ActionInfo(solution, path, name);
1122:            }
1123:
1124:            public static void shutdown() {
1125:                if (LocaleHelper.getLocale() == null) {
1126:                    LocaleHelper.setLocale(Locale.getDefault());
1127:                }
1128:                if (listeners != null) {
1129:                    Iterator systemListenerIterator = listeners.iterator();
1130:                    while (systemListenerIterator.hasNext()) {
1131:                        IPentahoSystemListener listener = (IPentahoSystemListener) systemListenerIterator
1132:                                .next();
1133:                        if (listener != null) {
1134:                            try {
1135:                                listener.shutdown();
1136:                            } catch (Throwable e) {
1137:                                Logger
1138:                                        .error(
1139:                                                PentahoSystem.class.getName(),
1140:                                                Messages
1141:                                                        .getErrorString(
1142:                                                                "PentahoSystem.ERROR_0015_SHUTDOWN_FAILURE", listener.getClass().getName()), e); //$NON-NLS-1$
1143:                            }
1144:                        }
1145:                    }
1146:                }
1147:            }
1148:
1149:            public static IApplicationContext getApplicationContext() {
1150:                return applicationContext;
1151:            }
1152:
1153:            public static ISolutionEngine getSolutionEngineInstance(
1154:                    IPentahoSession session) {
1155:                // TODO support session and solution and request based scopes
1156:                String scope = (String) scopeMap.get(SOLUTION_ENGINE);
1157:                if (SCOPE_GLOBAL.equalsIgnoreCase(scope)) {
1158:                    return (ISolutionEngine) globalObjectsMap
1159:                            .get(SOLUTION_ENGINE);
1160:                } else if (HttpSessionParameterProvider.SCOPE_SESSION
1161:                        .equalsIgnoreCase(scope)) {
1162:                    if (session == null) {
1163:                        Logger
1164:                                .error(
1165:                                        PentahoSystem.class.getName(),
1166:                                        Messages
1167:                                                .getErrorString("PentahoSystem.ERROR_0003_COULD_NOT_CREATE_SOLUTION_ENGINE")); //$NON-NLS-1$
1168:                        return null;
1169:                    }
1170:                    Object attribute = session.getAttribute(SOLUTION_ENGINE);
1171:                    if ((attribute != null)
1172:                            && (attribute instanceof  ISolutionEngine)) {
1173:                        // Set the session which is a threadlocal...
1174:                        ISolutionEngine solutionEngine = (ISolutionEngine) attribute;
1175:                        return solutionEngine;
1176:                    }
1177:                    String solutionEngineClass = (String) classNameMap
1178:                            .get(SOLUTION_ENGINE);
1179:                    Object obj = createObject(solutionEngineClass);
1180:                    if (obj == null || !(obj instanceof  ISolutionEngine)) {
1181:                        Logger
1182:                                .error(
1183:                                        PentahoSystem.class.getName(),
1184:                                        Messages
1185:                                                .getErrorString("PentahoSystem.ERROR_0003_COULD_NOT_CREATE_SOLUTION_ENGINE")); //$NON-NLS-1$
1186:                        return null;
1187:                    }
1188:                    ISolutionEngine solutionEngine = (ISolutionEngine) obj;
1189:                    session.setAttribute(SOLUTION_ENGINE, solutionEngine);
1190:                    return solutionEngine;
1191:                } else if (HttpRequestParameterProvider.SCOPE_REQUEST
1192:                        .equalsIgnoreCase(scope)) {
1193:                    if (session == null) {
1194:                        Logger
1195:                                .error(
1196:                                        PentahoSystem.class.getName(),
1197:                                        Messages
1198:                                                .getErrorString("PentahoSystem.ERROR_0003_COULD_NOT_CREATE_SOLUTION_ENGINE")); //$NON-NLS-1$
1199:                        return null;
1200:                    }
1201:                    String solutionEngineClass = (String) classNameMap
1202:                            .get(SOLUTION_ENGINE);
1203:                    Object obj = createObject(solutionEngineClass);
1204:                    if (obj == null || !(obj instanceof  ISolutionEngine)) {
1205:                        Logger
1206:                                .error(
1207:                                        PentahoSystem.class.getName(),
1208:                                        Messages
1209:                                                .getErrorString("PentahoSystem.ERROR_0003_COULD_NOT_CREATE_SOLUTION_ENGINE")); //$NON-NLS-1$
1210:                        return null;
1211:                    }
1212:                    ISolutionEngine solutionEngine = (ISolutionEngine) obj;
1213:                    return solutionEngine;
1214:                }
1215:
1216:                return null;
1217:            }
1218:
1219:            public static IContentRepository getContentRepository(
1220:                    IPentahoSession session) {
1221:                String scope = (String) scopeMap.get(CONTENT_REPOSITORY);
1222:                if (SCOPE_GLOBAL.equalsIgnoreCase(scope)) {
1223:                    return (IContentRepository) globalObjectsMap
1224:                            .get(CONTENT_REPOSITORY);
1225:                } else if (HttpSessionParameterProvider.SCOPE_SESSION
1226:                        .equalsIgnoreCase(scope)) {
1227:                    if (session == null) {
1228:                        Logger
1229:                                .error(
1230:                                        PentahoSystem.class.getName(),
1231:                                        Messages
1232:                                                .getErrorString("PentahoSystem.ERROR_0009_COULD_NOT_CREATE_CONTENT_REPOSITORY")); //$NON-NLS-1$
1233:                        return null;
1234:                    }
1235:                    Object attribute = null;
1236:                    try {
1237:                        attribute = session.getAttribute(CONTENT_REPOSITORY);
1238:                    } catch (Throwable t) {
1239:                        session
1240:                                .error(Messages
1241:                                        .getErrorString("PentahoSystem.ERROR_0012_COULD_NOT_GET_CONTENT_REPOSITORY")); //$NON-NLS-1$
1242:                    }
1243:                    if ((attribute != null)
1244:                            && (attribute instanceof  IContentRepository)) {
1245:                        // Set the session which is a threadlocal...
1246:                        IContentRepository repository = (IContentRepository) attribute;
1247:                        repository.setSession(session);
1248:                        if (contentRepository == null) {
1249:                            contentRepository = repository;
1250:                        }
1251:                        return repository;
1252:                    }
1253:                    String contentRepositoryClass = (String) classNameMap
1254:                            .get(CONTENT_REPOSITORY);
1255:                    Object obj = createObject(contentRepositoryClass);
1256:                    if (obj == null || !(obj instanceof  IContentRepository)) {
1257:                        Logger
1258:                                .error(
1259:                                        PentahoSystem.class.getName(),
1260:                                        Messages
1261:                                                .getErrorString("PentahoSystem.ERROR_0009_COULD_NOT_CREATE_CONTENT_REPOSITORY")); //$NON-NLS-1$
1262:                        return null;
1263:                    }
1264:                    IContentRepository repository = (IContentRepository) obj;
1265:                    repository.setSession(session);
1266:                    session.setAttribute(CONTENT_REPOSITORY, repository);
1267:                    if (contentRepository == null) {
1268:                        contentRepository = repository;
1269:                    }
1270:                    return repository;
1271:                }
1272:                return null;
1273:            }
1274:
1275:            public static ISolutionRepository getSolutionRepository(
1276:                    IPentahoSession session) {
1277:                String scope = (String) scopeMap.get(SOLUTION_REPOSITORY);
1278:
1279:                // TODO support local-scoped solution repository
1280:
1281:                if (SCOPE_GLOBAL.equalsIgnoreCase(scope)) {
1282:                    return (ISolutionRepository) globalObjectsMap
1283:                            .get(SOLUTION_REPOSITORY);
1284:                } else if (HttpSessionParameterProvider.SCOPE_SESSION
1285:                        .equalsIgnoreCase(scope)) {
1286:                    if (session == null) {
1287:                        Logger
1288:                                .error(
1289:                                        PentahoSystem.class.getName(),
1290:                                        Messages
1291:                                                .getErrorString("PentahoSystem.ERROR_0005_COULD_NOT_CREATE_SOLUTION_REPOSITORY")); //$NON-NLS-1$
1292:                        return null;
1293:                    }
1294:                    Object attribute = session
1295:                            .getAttribute(SOLUTION_REPOSITORY);
1296:                    if ((attribute != null)
1297:                            && (attribute instanceof  ISolutionRepository)) {
1298:                        // Set the session which is a threadlocal...
1299:                        ISolutionRepository aSolutionRepository = (ISolutionRepository) attribute;
1300:                        aSolutionRepository.init(session);
1301:                        aSolutionRepository.setLoggingLevel(loggingLevel);
1302:                        return aSolutionRepository;
1303:                    }
1304:                    String solutionRepositoryClass = (String) classNameMap
1305:                            .get(SOLUTION_REPOSITORY);
1306:                    Object obj = createObject(solutionRepositoryClass);
1307:                    if (obj == null || !(obj instanceof  ISolutionRepository)) {
1308:                        Logger
1309:                                .error(
1310:                                        PentahoSystem.class.getName(),
1311:                                        Messages
1312:                                                .getErrorString("PentahoSystem.ERROR_0005_COULD_NOT_CREATE_SOLUTION_REPOSITORY")); //$NON-NLS-1$
1313:                        return null;
1314:                    }
1315:                    ISolutionRepository aSolutionRepository = (ISolutionRepository) obj;
1316:                    aSolutionRepository.init(session);
1317:                    aSolutionRepository.setLoggingLevel(loggingLevel);
1318:                    session.setAttribute(SOLUTION_REPOSITORY,
1319:                            aSolutionRepository);
1320:                    return aSolutionRepository;
1321:                }
1322:                return null;
1323:            }
1324:
1325:            public static IRuntimeRepository getRuntimeRepository(
1326:                    IPentahoSession session) {
1327:                String scope = (String) scopeMap.get(RUNTIME_REPOSITORY);
1328:                if (SCOPE_GLOBAL.equalsIgnoreCase(scope)) {
1329:                    return (IRuntimeRepository) globalObjectsMap
1330:                            .get(RUNTIME_REPOSITORY);
1331:                } else if (HttpSessionParameterProvider.SCOPE_SESSION
1332:                        .equalsIgnoreCase(scope)) {
1333:                    if (session == null) {
1334:                        Logger
1335:                                .error(
1336:                                        PentahoSystem.class.getName(),
1337:                                        Messages
1338:                                                .getErrorString("PentahoSystem.ERROR_0007_COULD_NOT_CREATE_RUNTIME_REPOSITORY")); //$NON-NLS-1$
1339:                        return null;
1340:                    }
1341:                    Object attribute = session.getAttribute(RUNTIME_REPOSITORY);
1342:                    if ((attribute != null)
1343:                            && (attribute instanceof  IRuntimeRepository)) {
1344:                        // Set the session which is a threadlocal...
1345:                        IRuntimeRepository repository = (IRuntimeRepository) attribute;
1346:                        repository.setSession(session);
1347:                        if (runtimeRepository == null) {
1348:                            runtimeRepository = repository;
1349:                        }
1350:                        return repository;
1351:                    }
1352:                    String runtimeRepositoryClass = (String) classNameMap
1353:                            .get(RUNTIME_REPOSITORY);
1354:                    Object obj = createObject(runtimeRepositoryClass);
1355:                    if (obj == null || !(obj instanceof  IRuntimeRepository)) {
1356:                        Logger
1357:                                .error(
1358:                                        PentahoSystem.class.getName(),
1359:                                        Messages
1360:                                                .getErrorString("PentahoSystem.ERROR_0007_COULD_NOT_CREATE_RUNTIME_REPOSITORY")); //$NON-NLS-1$
1361:                        return null;
1362:                    }
1363:                    IRuntimeRepository repository = (IRuntimeRepository) obj;
1364:                    repository.setSession(session);
1365:                    session.setAttribute(RUNTIME_REPOSITORY, repository);
1366:                    if (runtimeRepository == null) {
1367:                        runtimeRepository = repository;
1368:                    }
1369:                    return repository;
1370:                }
1371:                return null;
1372:            }
1373:
1374:            public static IAclPublisher getAclPublisher(IPentahoSession session) {
1375:                Object obj = PentahoSystem.getObject(session, ACL_PUBLISHER);
1376:                return (IAclPublisher) obj;
1377:            }
1378:
1379:            public static IAclVoter getAclVoter(IPentahoSession session) {
1380:                Object obj = PentahoSystem.getObject(session, ACL_VOTER);
1381:                return (IAclVoter) obj;
1382:            }
1383:
1384:            public static ISubscriptionRepository getSubscriptionRepository(
1385:                    IPentahoSession session) {
1386:                Object obj = PentahoSystem.getObject(session,
1387:                        SUBSCRIPTION_REPOSITORY);
1388:                return (ISubscriptionRepository) obj;
1389:            }
1390:
1391:            public static ISubscriptionScheduler getSubscriptionScheduler() {
1392:                // TODO This should be configurable
1393:                return (new QuartzSubscriptionScheduler());
1394:            }
1395:
1396:            public static Object createObject(String className, ILogger logger) {
1397:
1398:                Object object = null;
1399:                try {
1400:
1401:                    Class componentClass = Class.forName(className.trim());
1402:                    object = componentClass.newInstance();
1403:
1404:                } catch (Throwable t) {
1405:                    String msg = Messages
1406:                            .getErrorString(
1407:                                    "PentahoSystem.ERROR_0013_COULD_NOT_CREATE_OBEJCT", className); //$NON-NLS-1$
1408:                    if (null == logger) {
1409:                        Logger.fatal(PentahoSystem.class.getName(), msg, t);
1410:                    } else {
1411:                        logger.fatal(msg, t);
1412:                    }
1413:                }
1414:                return object;
1415:            }
1416:
1417:            public static void setUserDetailsRoleListService(
1418:                    UserDetailsRoleListService value) {
1419:                userDetailsRoleListService = value;
1420:            }
1421:
1422:            public static UserDetailsRoleListService getUserDetailsRoleListService() {
1423:                return userDetailsRoleListService;
1424:            }
1425:
1426:            public static Object createObject(String className) {
1427:
1428:                return createObject(className, null);
1429:            }
1430:
1431:            public static String getSystemSetting(String path,
1432:                    String settingName, String defaultValue) {
1433:                return systemSettings.getSystemSetting(path, settingName,
1434:                        defaultValue);
1435:            }
1436:
1437:            public static String getSystemSetting(String settingName,
1438:                    String defaultValue) {
1439:                // TODO make this more efficient using caching
1440:                return systemSettings.getSystemSetting(settingName,
1441:                        defaultValue);
1442:            }
1443:
1444:            public static ISystemSettings getSystemSettings() {
1445:                return systemSettings;
1446:            }
1447:
1448:            public static void refreshSettings() {
1449:                systemSettings.resetSettingsCache();
1450:            }
1451:
1452:            public static String publish(IPentahoSession session,
1453:                    String className) {
1454:                Iterator publisherIterator = publishers.iterator();
1455:                // TODO: audit this
1456:                while (publisherIterator.hasNext()) {
1457:                    IPentahoPublisher publisher = (IPentahoPublisher) publisherIterator
1458:                            .next();
1459:                    if (publisher != null
1460:                            && (className == null || className.equals(publisher
1461:                                    .getClass().getName()))) {
1462:                        try {
1463:                            return publisher.publish(session, loggingLevel);
1464:                        } catch (Throwable e) {
1465:
1466:                        }
1467:                    }
1468:                }
1469:                return Messages
1470:                        .getErrorString("PentahoSystem.ERROR_0017_PUBLISHER_NOT_FOUND"); //$NON-NLS-1$
1471:            }
1472:
1473:            public static List getPublisherList() {
1474:                return publishers;
1475:            }
1476:
1477:            public static Document getPublishersDocument() {
1478:
1479:                Document document = DocumentHelper.createDocument();
1480:                Element root = document.addElement("publishers"); //$NON-NLS-1$
1481:
1482:                Iterator publisherIterator = publishers.iterator();
1483:                // TODO: audit this
1484:                // refresh the system settings
1485:                while (publisherIterator.hasNext()) {
1486:                    IPentahoPublisher publisher = (IPentahoPublisher) publisherIterator
1487:                            .next();
1488:                    if (publisher != null) {
1489:                        try {
1490:                            Element publisherNode = root
1491:                                    .addElement("publisher"); //$NON-NLS-1$
1492:                            publisherNode
1493:                                    .addElement("name").setText(publisher.getName()); //$NON-NLS-1$
1494:                            publisherNode
1495:                                    .addElement("description").setText(publisher.getDescription()); //$NON-NLS-1$
1496:                            publisherNode
1497:                                    .addElement("class").setText(publisher.getClass().getName()); //$NON-NLS-1$
1498:
1499:                        } catch (Throwable e) {
1500:
1501:                        }
1502:                    }
1503:                }
1504:
1505:                return document;
1506:
1507:            }
1508:
1509:            public static void systemEntryPoint() {
1510:                if (applicationContext != null) {
1511:                    applicationContext.invokeEntryPoints();
1512:                }
1513:            }
1514:
1515:            public static void systemExitPoint() {
1516:                if (applicationContext != null) {
1517:                    applicationContext.invokeExitPoints();
1518:                }
1519:            }
1520:
1521:            private static void registerHostnameVerifier() {
1522:                try {
1523:                    final String LOCALHOST = "localhost"; //$NON-NLS-1$
1524:                    String tmphost = "localhost"; //$NON-NLS-1$
1525:                    try {
1526:                        String baseURL = PentahoSystem.getApplicationContext()
1527:                                .getBaseUrl();
1528:                        if (null == baseURL) {
1529:                            return;
1530:                        }
1531:                        URL url = new URL(baseURL);
1532:                        tmphost = url.getHost();
1533:                    } catch (MalformedURLException e) {
1534:                        // TODO sbarkdull, localize
1535:                        Logger
1536:                                .warn(
1537:                                        PentahoSystem.class.getName(),
1538:                                        Messages
1539:                                                .getErrorString("PentahoSystem.ERROR_0030_VERIFIER_FAILED"), e); //$NON-NLS-1$
1540:
1541:                    }
1542:                    final String host = tmphost;
1543:
1544:                    javax.net.ssl.HostnameVerifier myHv = new javax.net.ssl.HostnameVerifier() {
1545:                        public boolean verify(String hostName,
1546:                                javax.net.ssl.SSLSession session) {
1547:                            if (hostName.equals(host)
1548:                                    || hostName.equals(LOCALHOST)) {
1549:                                return true;
1550:                            }
1551:                            return false;
1552:                        }
1553:                    };
1554:                    javax.net.ssl.HttpsURLConnection
1555:                            .setDefaultHostnameVerifier(myHv);
1556:                } catch (Throwable t) {
1557:                    Logger
1558:                            .warn(
1559:                                    PentahoSystem.class.getName(),
1560:                                    Messages
1561:                                            .getErrorString("PentahoSystem.ERROR_0030_VERIFIER_FAILED"), t); //$NON-NLS-1$
1562:                }
1563:            }
1564:
1565:            // Security Helpers
1566:
1567:            public static boolean isGranted(IPentahoSession session,
1568:                    String roleName) {
1569:                GrantedAuthorityImpl grantedAuthority = new GrantedAuthorityImpl(
1570:                        roleName);
1571:                return SecurityUtils.isGranted(session, grantedAuthority);
1572:            }
1573:
1574:            public static boolean isAdministrator(IPentahoSession session) {
1575:                return SecurityUtils.isPentahoAdministrator(session);
1576:            }
1577:
1578:            public static boolean hasAccess(IPentahoSession session,
1579:                    IAclHolder holder, int mask) {
1580:                IAclVoter voter = getAclVoter(session);
1581:                return voter.hasAccess(session, holder, mask);
1582:            }
1583:
1584:            public static CacheManager getCacheManager() {
1585:                Object obj = globalObjectsMap.get(CACHE_MANAGER);
1586:                return (CacheManager) obj;
1587:            }
1588:
1589:            public static List getACLFileExtensionList() {
1590:                return UnmodifiableACLFileExtensionList;
1591:            }
1592:
1593:            // Stuff for the logout listener subsystem
1594:            public static void addLogoutListener(ILogoutListener listener) {
1595:                // add items to vector of listeners
1596:                if (logoutListeners.contains(listener)) {
1597:                    return;
1598:                }
1599:                logoutListeners.add(listener);
1600:            }
1601:
1602:            public static ILogoutListener remove(ILogoutListener listener) {
1603:                if (logoutListeners.remove(listener)) {
1604:                    return listener;
1605:                }
1606:                return null;
1607:            }
1608:
1609:            public static void invokeLogoutListeners(IPentahoSession session) {
1610:                Iterator iter = logoutListeners.iterator();
1611:                while (iter.hasNext()) {
1612:                    ILogoutListener listener = (ILogoutListener) iter.next();
1613:                    listener.onLogout(session);
1614:                }
1615:            }
1616:
1617:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.