KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > ui > component > ActionComponent


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11  * the license for the specific language governing your rights and limitations.
12  *
13  * @created Sep 21, 2005
14  * @author James Dixon
15  */

16
17 package org.pentaho.ui.component;
18
19 import java.io.ByteArrayOutputStream JavaDoc;
20 import java.io.File JavaDoc;
21 import java.util.List JavaDoc;
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.pentaho.messages.Messages;
25 import org.pentaho.core.runtime.IRuntimeContext;
26 import org.pentaho.core.session.IPentahoSession;
27 import org.pentaho.core.solution.ISolutionEngine;
28 import org.pentaho.core.solution.SimpleOutputHandler;
29 import org.pentaho.core.system.PentahoSystem;
30 import org.pentaho.core.ui.IPentahoUrlFactory;
31 import org.pentaho.messages.util.LocaleHelper;
32 import org.pentaho.ui.BaseUIComponent;
33
34 public class ActionComponent extends BaseUIComponent {
35
36     private static final long serialVersionUID = 1217363866006312765L;
37
38     private static final Log logger = LogFactory.getLog(ActionComponent.class);
39
40     private String JavaDoc solutionName;
41
42     private String JavaDoc actionPath;
43
44     private String JavaDoc actionName;
45
46     private String JavaDoc instanceId;
47
48     private int outputPreference;
49
50     public ActionComponent(String JavaDoc solutionName, String JavaDoc actionPath, String JavaDoc actionName, String JavaDoc instanceId, int outputPreference, IPentahoUrlFactory urlFactory, List JavaDoc messages) {
51         super(urlFactory, messages, solutionName + File.separator + actionPath);
52         this.solutionName = solutionName;
53         this.actionName = actionName;
54         this.actionPath = actionPath;
55         this.instanceId = instanceId;
56         this.outputPreference = outputPreference;
57     }
58
59     public ActionComponent(String JavaDoc actionString, String JavaDoc instanceId, int outputPreference, IPentahoUrlFactory urlFactory, List JavaDoc messages) {
60         super(urlFactory, messages, null);
61         String JavaDoc info[] = PentahoSystem.parseActionString(actionString);
62         if (info != null && info.length == 3) {
63             solutionName = info[0];
64             actionPath = info[1];
65             actionName = info[2];
66         }
67         setSourcePath(solutionName + File.separator + actionPath);
68         this.instanceId = instanceId;
69         this.outputPreference = outputPreference;
70     }
71
72     public Log getLogger() {
73         return logger;
74     }
75
76     public boolean validate() {
77         return true;
78     }
79
80     public String JavaDoc getContent(String JavaDoc mimeType) {
81         IPentahoSession userSession = getSession();
82
83         ByteArrayOutputStream JavaDoc outputStream = new ByteArrayOutputStream JavaDoc();
84
85         SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true);
86         outputHandler.setOutputPreference(outputPreference);
87
88         ISolutionEngine solutionEngine = PentahoSystem.getSolutionEngineInstance(getSession());
89         solutionEngine.setLoggingLevel(getLoggingLevel());
90         solutionEngine.init(userSession);
91
92         IRuntimeContext context = null;
93         try {
94             context = solutionEngine.execute(solutionName, actionPath, actionName, Messages.getString("BaseTest.DEBUG_JUNIT_TEST"), false, true, instanceId, false, getParameterProviders(), outputHandler, null, urlFactory, getMessages()); //$NON-NLS-1$
95
} finally {
96             if (context != null) {
97                 context.dispose();
98             }
99         }
100
101         // TODO test the return result
102
String JavaDoc result = ""; //$NON-NLS-1$
103
try {
104             result = outputStream.toString(LocaleHelper.getSystemEncoding());
105         } catch (Exception JavaDoc e) {
106             return outputStream.toString();
107         }
108         return result;
109
110     }
111
112 }
113
Popular Tags